Module: Handoff

Included in:
Test::Unit::TestCase
Defined in:
lib/handoff.rb,
lib/handoff/assertion.rb,
lib/handoff/usage_error.rb,
lib/handoff/verifying_delegate.rb,
lib/handoff/argument_normalizer.rb

Overview

require (or require_gem) ‘handoff’ and #assert_handoff can be called from any Test::Unit::TestCase test method to create a new Handoff::Assertion.

After defining Handoff, this file includes it in Test::Unit::TestCase.

Defined Under Namespace

Modules: ArgumentNormalizer Classes: Assertion, UsageError, VerifyingDelegate

Constant Summary collapse

TEARDOWN_ALIAS =
:teardown_before_handoff_rewrite

Instance Method Summary collapse

Instance Method Details

#assert_handoffObject



12
13
14
15
16
17
# File 'lib/handoff.rb', line 12

def assert_handoff
  ensure_handoff_teardown_defined
  a = Handoff::Assertion.new(self, caller)
  handoff_assertions << a
  a
end

#conduct_and_clear_handoffsObject



34
35
36
37
38
39
40
# File 'lib/handoff.rb', line 34

def conduct_and_clear_handoffs
  begin
    handoff_assertions.each {|a| a.conduct }
  ensure
    handoff_assertions.clear
  end
end

#ensure_handoff_teardown_definedObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/handoff.rb', line 19

def ensure_handoff_teardown_defined
  return if respond_to?(TEARDOWN_ALIAS)
  class << self
    alias_method TEARDOWN_ALIAS, :teardown
    def teardown
      conduct_and_clear_handoffs
      send TEARDOWN_ALIAS
    end
  end
end

#handoff_assertionsObject



30
31
32
# File 'lib/handoff.rb', line 30

def handoff_assertions
  @handoff_assertions ||= []
end