Module: Expectations::DelegateRecorder

Defined in:
lib/expectations/delegate_recorder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#delegation_resultObject

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_messageObject



31
32
33
# File 'lib/expectations/delegate_recorder.rb', line 31

def failure_message
  "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 mocha_error_message(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

#verifyObject



27
28
29
# File 'lib/expectations/delegate_recorder.rb', line 27

def verify
  :a_delegated_return_value == delegation_result
end