Show HN: PBT – A property-based testing library for Ruby (github.com)
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!
36 comments
[ 4.4 ms ] story [ 78.8 ms ] threadThis 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.
I wish that wasn't the case, I use Ruby heavily for gluing different systems together.
From a systems perspective, I had to switch to python because it has pyroute2, which supports rtnl, devlink, ethtool and more.
I would have thought ruby had a full-fledged netlink library right now considering the stability of chef and puppet.
But all I could find was this from 8 years ago: https://github.com/BytemarkHosting/netlinkrb
I started off with ruby for systems glue but now I have a mix of python and ruby. I wish it was all ruby but the lack of updated “glue gems” and the prevalence of updated “glue eggs” means python really is the “glue language winner”.
Yeah, that's so typical. I've almost become used to this, seeing useful gems being very old. To me, I see that as either abandoned (which means I have to fork it and polish it) or the gem is considered complete.
Why do you not wish it was all Python?
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...
I imagine the seed is used to generate data and depending on the order of your generators, it produces different results.
For example, in:
Would changing the order of parameters to `property` change the actual test case?@OP:
I wonder if the README (and possibly runner) should suggest writing a test-case that doesn't rely on PBT when the user wants to preserve a case for future testing.
The issue here is that if you're saving a singular example and it represents a weird corner case, it's totally conceivable that a small change will result in an invisible change to that test case.
Another idea: it'd be great if the test could simply take examples that are failing and add them to a `failing_examples.rb` or some such. I know I'd use a feature like this quite a bit.
- 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. :)
Correct. The test inputs are determined by a seed and generators (including the order of generators).
Edited to add: D'oh! There's an explanation in the linked repo.
https://arialdomartini.github.io/property-testing
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.
[1] https://github.com/DRMacIver/minithesis
[2] https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.E...
It would be cool if we could eventually make use of RBS or inline Sorbet or something better than both to get the types for property testing for free.
https://github.com/ksss/raap