Module: Pbt

Extended by:
Arbitrary::ArbitraryMethods, Check::ConfigurationMethods, Check::RunnerMethods
Defined in:
lib/pbt.rb,
lib/pbt/version.rb,
lib/pbt/check/case.rb,
lib/pbt/check/tosser.rb,
lib/pbt/check/property.rb,
lib/pbt/arbitrary/constant.rb,
lib/pbt/arbitrary/arbitrary.rb,
lib/pbt/check/configuration.rb,
lib/pbt/check/runner_methods.rb,
lib/pbt/reporter/run_details.rb,
lib/pbt/check/runner_iterator.rb,
lib/pbt/reporter/run_execution.rb,
lib/pbt/arbitrary/map_arbitrary.rb,
lib/pbt/arbitrary/array_arbitrary.rb,
lib/pbt/arbitrary/tuple_arbitrary.rb,
lib/pbt/arbitrary/choose_arbitrary.rb,
lib/pbt/arbitrary/filter_arbitrary.rb,
lib/pbt/arbitrary/one_of_arbitrary.rb,
lib/pbt/arbitrary/arbitrary_methods.rb,
lib/pbt/arbitrary/integer_arbitrary.rb,
lib/pbt/arbitrary/constant_arbitrary.rb,
lib/pbt/reporter/run_details_reporter.rb,
lib/pbt/arbitrary/fixed_hash_arbitrary.rb,
lib/pbt/check/rspec_adapter/integration.rb,
lib/pbt/check/rspec_adapter/property_extension.rb,
lib/pbt/check/rspec_adapter/predicate_block_inspector.rb

Defined Under Namespace

Modules: Arbitrary, Check, Reporter Classes: InvalidConfiguration, PropertyFailure

Constant Summary collapse

VERSION =
"0.4.2"

Class Method Summary collapse

Methods included from Arbitrary::ArbitraryMethods

alphanumeric_char, alphanumeric_string, array, ascii_char, ascii_string, boolean, char, choose, constant, date, fixed_hash, float, future_date, future_time, hash, hexa, hexa_string, integer, nat, nil, one_of, past_date, past_time, printable_ascii_char, printable_ascii_string, printable_char, printable_string, set, symbol, time, tuple

Methods included from Check::RunnerMethods

assert, check

Methods included from Check::Tosser

#toss

Methods included from Check::ConfigurationMethods

configuration, configure

Class Method Details

.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