Method: Pbt.property

Defined in:
lib/pbt.rb

.property(*args, **kwargs, &predicate) ⇒ Property

Create a property-based test with arbitraries. To run the test, pass the returned value to ‘Pbt.assert` method. Be aware that using both positional and keyword arguments is not supported.

Examples:

Basic usage

Pbt.property(Pbt.integer) do |n|
  # your test code here
end

Use multiple arbitraries

Pbt.property(Pbt.string, Pbt.symbol) do |str, sym|
  # your test code here
end

Use hash arbitraries

Pbt.property(x: Pbt.integer, y: Pbt.integer) do |x, y|
  # your test code here
end

Parameters:

  • args (Array<Arbitrary>)

    Arbitraries to generate values. You can pass one or more arbitraries.

  • kwargs (Hash<Symbol,Arbitrary>)

    Arbitraries to generate values. You can pass arbitraries with keyword arguments.

  • predicate (Proc)

    Test code that receives generated values and runs the test.

Returns:

  • (Property)

42
43
44
45
# File 'lib/pbt.rb', line 42

def self.property(*args, **kwargs, &predicate)
  arb = to_arbitrary(args, kwargs)
  Check::Property.new(arb, &predicate)
end