Module: AssertRepeated

Included in:
Test::Unit::TestCase
Defined in:
lib/assert_repeated.rb

Instance Method Summary collapse

Instance Method Details

#assert_repeatedly(count, matcher = true, message = nil) ⇒ Object

Check that the block returns matcher count times

Usage

assert_repeatedly(100, /awesome/) { "tests are awesome" }

Arguments

count

number of times to run the block

matcher

what to compare against the block’s result (using #=== )

message

optional message to return when the assertion fails



43
44
45
46
47
48
49
50
# File 'lib/assert_repeated.rb', line 43

def assert_repeatedly(count, matcher=true, message=nil)
  count.times do
    result = yield
    assert_block(build_message(message, "<?> is not ?.", result, matcher)){ false } unless matcher === result
  end
  # increment the count
  assert true
end

#assert_repeatedly_false(count, message = nil, &block) ⇒ Object

Check that the block returns false count times.

Arguments

count

number of times to run the block

message

optional message to return when the assertion fails

block

block that runs for the assertion; expected to evaluate to false



29
30
31
# File 'lib/assert_repeated.rb', line 29

def assert_repeatedly_false(count, message=nil, &block)
  assert_repeatedly count, false, message, &block
end

#assert_repeatedly_true(count, message = nil, &block) ⇒ Object

Check that the block returns true count times.

Arguments

count

number of times to run the block

message

optional message to return when the assertion fails

block

block that runs for the assertion; expected to evaluate to true



19
20
21
# File 'lib/assert_repeated.rb', line 19

def assert_repeatedly_true(count, message=nil, &block)
  assert_repeatedly count, true, message, &block
end