Module: Minitest::Assertions

Included in:
Proptest::Property
Defined in:
lib/minitest/proptest_plugin.rb

Instance Method Summary collapse

Instance Method Details

#property(&f) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/minitest/proptest_plugin.rb', line 52

def property(&f)
  random_thunk = if Proptest.instance_variable_defined?(:@_random_seed)
                   r = Proptest.instance_variable_get(:@_random_seed)
                   ->() { Proptest::DEFAULT_RANDOM.call(r) }
                 else
                   Proptest::DEFAULT_RANDOM
                 end

  file, methodname = caller.first.split(/:\d+:in +/)
  classname = self.class.name
  methodname.gsub!(/(?:^`|'$)/, '')

  prop = Minitest::Proptest::Property.new(
    f,
    file,
    methodname,
    random: random_thunk,
    max_success: Proptest.max_success,
    max_discard_ratio: Proptest.max_discard_ratio,
    max_size: Proptest.max_size,
    max_shrinks: Proptest.max_shrinks,
    previous_failure: Proptest.reporter.lookup(file, classname, methodname)
  )
  prop.run!
  self.assertions += prop.calls

  if prop.status.valid? && !prop.trivial
    Proptest.strike_failure(file, classname, methodname)
  else
    unless prop.status.exhausted? || prop.status.invalid?
      Proptest.record_failure(file, classname, methodname, prop.result.map(&:value))
    end

    raise Minitest::Assertion, prop.explain
  end
end