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/stateful/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

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"0.7.0"

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:

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

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

  • Test code that receives generated values and runs the test.

Returns:



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

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

.stateful(model:, sut:, max_steps: 20) ⇒ Pbt::Stateful::Property

Create a stateful property-based test backed by a model and a SUT factory. The returned object is compatible with Pbt.assert / Pbt.check.

The model object is expected to provide:

  • initial_state
  • commands(state) -> Array of command objects

Each command object is expected to provide:

  • name
  • arguments (an arbitrary) or arguments(state)
  • applicable?(state) -> bool or applicable?(state, args) -> bool
  • next_state(state, args)
  • run!(sut, args) -> result
  • verify!(before_state:, after_state:, args:, result:, sut:)

Parameters:

  • Factory proc that returns a fresh SUT per run.

  • (defaults to: 20)

Returns:



67
68
69
# File 'lib/pbt.rb', line 67

def self.stateful(model:, sut:, max_steps: 20)
  Stateful::Property.new(model:, sut:, max_steps:)
end