Class: Handoff::Assertion
- Inherits:
-
Struct
- Object
- Struct
- Handoff::Assertion
- Defined in:
- lib/handoff/assertion.rb
Overview
This is where the fluent stuff is. Get an assertion by calling Handoff#assert_handoff. Specify the delegating behavior with
-
from
orfrom_any
, -
to
, -
for
,for_method
orfor_methods
, and -
(optionally)
with
orwith_arguments
.
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#delegator ⇒ Object
readonly
Returns the value of attribute delegator.
-
#method_map ⇒ Object
readonly
:stopdoc:.
-
#test ⇒ Object
Returns the value of attribute test.
Instance Method Summary collapse
-
#conduct ⇒ Object
:stopdoc:.
-
#for_methods(*args) ⇒ Object
(also: #for_method, #for)
Tells the assertion what delegating methods to test and what methods in the delegate they should delegate to.
-
#from(delegator) ⇒ Object
Specifies the object being tested, returning self.
-
#from_any(class_under_test) ⇒ Object
Creates an instance of
class_under_test
with no arguments and uses it as the object under test. -
#to(delegate_accessor) ⇒ Object
Specifies the accessor the object under test will use to acquire its delegate, returning self.
- #with_arguments(*args) ⇒ Object (also: #with)
-
#with_no_arguments ⇒ Object
Specifies that the assertion should pass no arguments to the delegating method and require that no arguments are sent to the target method.
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace
13 14 15 |
# File 'lib/handoff/assertion.rb', line 13 def backtrace @backtrace end |
#delegator ⇒ Object (readonly)
Returns the value of attribute delegator.
17 18 19 |
# File 'lib/handoff/assertion.rb', line 17 def delegator @delegator end |
#method_map ⇒ Object (readonly)
:stopdoc:
16 17 18 |
# File 'lib/handoff/assertion.rb', line 16 def method_map @method_map end |
#test ⇒ Object
Returns the value of attribute test
13 14 15 |
# File 'lib/handoff/assertion.rb', line 13 def test @test end |
Instance Method Details
#conduct ⇒ Object
:stopdoc:
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/handoff/assertion.rb', line 69 def conduct validate_sufficiently_specified method_map.each do |delegating_method, target_method| = VerifyingDelegate.new(target_method, @args||[]) accessor = @delegate_accessor (class << @delegator; self; end).class_eval do define_method(accessor) { } end send_args = [delegating_method] send_args.concat @args if @args actual_return = @delegator.send *send_args test.instance_eval {add_assertion} expected_return = .happy_return if expected_return != actual_return backtrace = self.backtrace delegate_accessor = @delegate_accessor test.instance_eval do add_failure "`#{delegating_method}' didn't delegate to `#{delegate_accessor}.#{target_method}'", backtrace end end end end |
#for_methods(*args) ⇒ Object Also known as: for_method, for
Tells the assertion what delegating methods to test and what methods in the delegate they should delegate to.
:call-seq: for_methods(:delegating_method1, :delegating_method2, …)
for_methods({:delegating_method1 => :target_method1, :delegating_method2 => :target_method2})
args
-
symbols representing the delegating methods if they are not renamed, or a Hash mapping methods in the delegating class to methods in the delegate.
48 49 50 51 |
# File 'lib/handoff/assertion.rb', line 48 def for_methods(*args) @method_map = ArgumentNormalizer.to_method_map(args) self end |
#from(delegator) ⇒ Object
Specifies the object being tested, returning self.
28 29 30 31 |
# File 'lib/handoff/assertion.rb', line 28 def from delegator @delegator = delegator self end |
#from_any(class_under_test) ⇒ Object
Creates an instance of class_under_test
with no arguments and uses it as the object under test.
23 24 25 |
# File 'lib/handoff/assertion.rb', line 23 def from_any class_under_test from(class_under_test.new) end |
#to(delegate_accessor) ⇒ Object
Specifies the accessor the object under test will use to acquire its delegate, returning self.
35 36 37 38 |
# File 'lib/handoff/assertion.rb', line 35 def to(delegate_accessor) @delegate_accessor = delegate_accessor self end |
#with_arguments(*args) ⇒ Object Also known as: with
55 56 57 58 |
# File 'lib/handoff/assertion.rb', line 55 def with_arguments *args @args = args self end |
#with_no_arguments ⇒ Object
Specifies that the assertion should pass no arguments to the delegating method and require that no arguments are sent to the target method.
63 64 65 |
# File 'lib/handoff/assertion.rb', line 63 def with_no_arguments with_arguments end |