Properb

Property-based testing in Ruby, with RSpec integration.

Installation

This project

Usage

To install, add the following to your spec/spec_helper.rb file:

RSpec.configure do |config|
  Properb.rspec_install(config)
end

Then you can use generate and it_always in your tests to create property-based tests:

describe "#sort" do
  generate(strings: array(string))

  it_always "preserves the number of elements", num_tests: 200 do
    expect(strings.sort.length).to be == strings.length
  end

  it_always "has the first and last elements in sorted order" do
    assume(strings).to_not be_empty
    sorted = strings.sort
    expect(sorted[0]).to be <= sorted[-1]
  end

  it_always "creates pairwise sorted elements", num_tests: 200 do
    # assume(strings.length).to be >= 2
    assume(strings.uniq).to eq(strings)
    sorted = strings.sort
    (0...sorted.length - 1).each do |i|
      expect(sorted[i]).to be < sorted[i + 1]
    end
  end
end

Development

This project uses Guix as its main dependency management system. A development environment can be created by running:

guix shell --development --file=guix.scm

Contributing

Bug reports and changes are welcome on SourceHut at https://sr.ht/~czan/properb/.