• Download Gist
Property-Based Testing in RSpec.md
Markdown

Features

  • Run for length of time
  • Run for number of iterations
  • Run for both and stop at whichever comes first
  • Reuse RSpec structure
  • Running semantics:
    • I want to run for N iterations limited to X minutes in CI
    • I want to run for a few seconds with rake
    • I want to run for a shorter period of time with guard

Terminology

Property

Invariant

Data

DSL

require 'something'
require 'something/rspec'

describe String do
  describe "#reverse" do    
    let(:string) { "foo bar" }

    it "reverses" do
      expect(string.reverse).to eq("rab oof")
    end

    generative do
      data(:string) { String.random }

      it "maintains length" do
        expect(string.reverse.length).to eq(string.length)
      end

      it "is not destructive" do
        expect(string.reverse.reverse).to eq(string)
      end
    end
  end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.