1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
# frozen_string_literal: true
module Hypothesis
# A TestCase class provides a concrete representation of
# an executing test case. You do not normally need to use this
# within the body of the test, but it exists to be used as
# an argument to {Hypothesis::Possibilities::built_as}.
# @!visibility private
class TestCase
# @!visibility private
attr_reader :draws, :print_log, :print_draws, :wrapped_data
# @!visibility private
def initialize(wrapped_data, print_draws: false, record_draws: false)
@wrapped_data = wrapped_data
@draws = [] if record_draws
@print_log = [] if print_draws
@depth = 0
end
def assume(condition)
raise UnsatisfiedAssumption unless condition
end
# @!visibility private
def any(possible = nil, name: nil, &block)
top_level = @depth.zero?
begin
@depth += 1
possible ||= block
@wrapped_data.start_draw
result = possible.provide(&block)
@wrapped_data.stop_draw
if top_level
draws&.push(result)
print_log&.push([name, result.inspect])
end
result
ensure
@depth -= 1
end
end
end
end
|