HNHacker News
TopNewBestAskShowJobs

ohbarye

88 karma · joined January 12, 2019

submissionscomments
ohbarye··on Show HN: PBT – A property-based testing library for Ruby
It's very basic content though, here's the slides of my presentation at RubyKaigi 2024. This also includes the PBT gems's explanations.

https://speakerdeck.com/ohbarye/unlocking-potential-of-prope...

Speaking of my personal story, I used the fast-check documentation and Fred Herbert's book (their links are in the README) to study.

ohbarye··on Show HN: PBT – A property-based testing library for Ruby
I love seeing people suggest clever names I couldn't have thought of.
ohbarye··on Show HN: PBT – A property-based testing library for Ruby
Good point. There's already such a project to run PBT based on RBS. I'm also keeping an eye on this.

https://github.com/ksss/raap

ohbarye··on Show HN: PBT – A property-based testing library for Ruby
Wow, I didn't know about them. Thanks for letting me know!
ohbarye··on Show HN: PBT – A property-based testing library for Ruby
Yeah, the easiest way is to generate attributes and instantiate any Rails model like the one below:

    Pbt.assert do
      Pbt.property(name: Pbt.printable_string, age: Pbt.integer(min: 0, max: 100)) do |name:, age:|
        user = User.new(name: name, age: age)
        # write your test here
      end
    end
ohbarye··on Show HN: PBT – A property-based testing library for Ruby
I think there are usually three actions a programmer can take when PBT fails.

- Create a test case that doesn't depend on PBT as you suggest.

- Fix the production code being tested since its failure is an unexpected bug.

- Fix the PBT itself. This means that the programmer has had wrong assumption for the test target.

I think it's difficult for the tool to know which choice is the best on a failure. But if there's any good idea, I'd like to incorporate it. :)

ohbarye··on Show HN: PBT – A property-based testing library for Ruby
>yes, because you're changing the order in which the random draws are interpreted. But this isn't a problem in practice because you generally aren't changing the generator in the middle of debugging a failure.

Correct. The test inputs are determined by a seed and generators (including the order of generators).

ohbarye··on Show HN: PBT – A property-based testing library for Ruby
I can really empathize. Hope the Ruby ecosystem gets more compatible with Ractor.
ohbarye··on Show HN: PBT – A property-based testing library for Ruby
Thank you.

In my opinion, PBT should be used in combination with example-based testing. Besides, since example-based testing cases account for the majority of tests, I think it's rare that PBT's execution time is dominant.

As for the combination and usages, refs: https://medium.com/criteo-engineering/introduction-to-proper...

ohbarye··on Show HN: PBT – A property-based testing library for Ruby
Thank you. I hope the gem will make your testing life happier!
ohbarye··on Show HN: PBT – A property-based testing library for Ruby
The answer to both questions is yes.

This gem doesn't aim to reimplement a testing framework. It can also be considered just an assertion. You can use this alongside any testing framework like RSpec, minitest, and etc.

ohbarye··on Implement DNS in a Weekend
Maybe not only 100 lines of code though, I think of Code Crafters. https://github.com/codecrafters-io/build-your-own-x
ohbarye··on An Overview Of Upcoming Ruby on Rails 7.1 Features Part 1
This comment describes well. https://github.com/rails/rails/pull/45553#issuecomment-11795...
ohbarye··on Kyoto Tycoon in 2019
That's new to me even though I'm Japanese. lol