Class: Hegel::Generators::CompositeGenerator::BlockTestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/hegel/generators.rb,
sig/hegel.rbs

Overview

The draw surface a composite block receives. #draw reaches an inner generator's own #do_draw directly -- the same non-recording path ArrayGenerator#draw_element and every other compound generator's do_draw already takes -- rather than the real Hegel::TestCase#draw, which records. TestCase's own class comment states the invariant this preserves: a compound generator making several native calls produces exactly one report line for the value it built, not one per call. A composite block draws exactly the way a generator author's own do_draw does, so it is held to the same rule; letting the block reach the recording #draw instead would turn one composite draw into as many report lines as it made nested draws.

#draw_integer/#draw_boolean are defined here for the same reason, not left to a method_missing delegation to the wrapped TestCase: the real TestCase already exposes both as recording methods, and a blanket delegation would let those two reach the engine unrecorded-in-name only, still bypassing the single-report-line rule #draw exists to keep the same way plain #draw would.

Instance Method Summary collapse

Constructor Details

#initialize(tc) ⇒ BlockTestCase

Returns a new instance of BlockTestCase.

Parameters:

  • tc (Object)


797
798
799
# File 'lib/hegel/generators.rb', line 797

def initialize(tc)
  @tc = tc
end

Instance Method Details

#draw(generator) ⇒ Object

Draws generator without recording a report line of its own.

Parameters:

Returns:

  • (Object)


802
803
804
# File 'lib/hegel/generators.rb', line 802

def draw(generator)
  generator.do_draw(@tc)
end

#draw_boolean(p = 0.5) ⇒ Boolean

hegel_generate_boolean, without recording (see #draw).

Parameters:

  • p (Float) (defaults to: 0.5)

Returns:

  • (Boolean)


812
813
814
# File 'lib/hegel/generators.rb', line 812

def draw_boolean(p = 0.5)
  @tc.generate_boolean(p)
end

#draw_integer(min_value, max_value) ⇒ Integer

hegel_generate_integer, without recording (see #draw).

Parameters:

  • min_value (Integer)
  • max_value (Integer)

Returns:

  • (Integer)


807
808
809
# File 'lib/hegel/generators.rb', line 807

def draw_integer(min_value, max_value)
  @tc.generate_integer(min_value, max_value)
end