Module: Expectations::DelegateRecorder
- Defined in:
- lib/expectations/delegate_recorder.rb
Instance Attribute Summary collapse
-
#delegation_result ⇒ Object
Returns the value of attribute delegation_result.
Instance Method Summary collapse
- #delegate!(meth) ⇒ Object
- #failure_message ⇒ Object
- #mocha_error_message(ex) ⇒ Object
- #subject! ⇒ Object
- #to(receiver) ⇒ Object
- #verify ⇒ Object
Instance Attribute Details
#delegation_result ⇒ Object
Returns the value of attribute delegation_result.
2 3 4 |
# File 'lib/expectations/delegate_recorder.rb', line 2 def delegation_result @delegation_result end |
Instance Method Details
#delegate!(meth) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/expectations/delegate_recorder.rb', line 4 def delegate!(meth) @meth = meth recorder = self mod = Module.new do define_method meth do |*args| recorder.delegation_result = super(*args) end end subject.extend mod end |
#failure_message ⇒ Object
31 32 33 |
# File 'lib/expectations/delegate_recorder.rb', line 31 def "expected #{subject}.#{@meth} to return the value of #{subject}.#{@receiver}.#{@meth}; however, #{subject}.#{@meth} returned #{delegation_result.inspect}" end |
#mocha_error_message(ex) ⇒ Object
35 36 37 |
# File 'lib/expectations/delegate_recorder.rb', line 35 def (ex) "expected #{subject} to delegate #{@meth} to #{@receiver}; however, #{subject}.#{@meth} was never called -- #{ex}" end |
#subject! ⇒ Object
20 21 22 23 24 25 |
# File 'lib/expectations/delegate_recorder.rb', line 20 def subject! @subject_mock = Object.new @subject_mock.expects(@meth).returns(:a_delegated_return_value) subject.stubs(@receiver).returns(@subject_mock) subject end |
#to(receiver) ⇒ Object
15 16 17 18 |
# File 'lib/expectations/delegate_recorder.rb', line 15 def to(receiver) @receiver = receiver self end |
#verify ⇒ Object
27 28 29 |
# File 'lib/expectations/delegate_recorder.rb', line 27 def verify :a_delegated_return_value == delegation_result end |