Live data from Hacker News

Show HN: PBT – A property-based testing library for Ruby

github.com

1–10 of 37 posts

Show HN: PBT – A property-based testing library for Ruby

#1
Hello HN,

I introduce a property-based testing tool for Ruby. Ruby's ease of test-writing and rich ecosystem are widely acclaimed. However, property-based testing is not as widely used as in other languages such as Haskell or Elixir, and I think this is because there is no de facto testing tool.

This gem currently not only has the basic functionality of stateless property-based testing but also has the following features:

- Support verbose mode that allows you to see its shrinking procedure and algorithms.

- Support several concurrency/parallel executions of each test. As of now, Ractor/Thread/Process are available. (The default is sequential, considering benchmark results and actual use cases)

Happy hacking!

Show HN: PBT – A property-based testing library for Ruby
github.com

Re: Show HN: PBT – A property-based testing library for Ruby

#4

Can this be used alongside rspec? Like have these be tests that are included in the rspec test run, and have the results alongside your other rspec tests?

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.

Re: Show HN: PBT – A property-based testing library for Ruby

#8

Interesting! I wonder how this could be applied to a Rails project (since that's what ruby is most used for). For example how would it know to test a wide selection of possible values for different variables if they're not explicitly set up?

> Rails [...] that's what ruby is most used for

I wish that wasn't the case, I use Ruby heavily for gluing different systems together.

Re: Show HN: PBT – A property-based testing library for Ruby

#9

Interesting! I wonder how this could be applied to a Rails project (since that's what ruby is most used for). For example how would it know to test a wide selection of possible values for different variables if they're not explicitly set up?

I imagine it wouldn't be too hard to build up your own data generators for Rails models (or other entities).

Re: Show HN: PBT – A property-based testing library for Ruby

#10
Very specific question: when tests fail due to a single example, you suggest creating a specific assertion with the given seed.

I imagine the seed is used to generate data and depending on the order of your generators, it produces different results.

For example, in:

    PBT.assert(seed = ..) do
      PBT.property(PBT.integer, PBT.string) ...
    end
Would changing the order of parameters to `property` change the actual test case?
Post reply on HN