Class: Spy::API::HaveReceived

Inherits:
Object
  • Object
show all
Defined in:
lib/spy/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name) ⇒ HaveReceived

Returns a new instance of HaveReceived.



22
23
24
25
# File 'lib/spy/api.rb', line 22

def initialize(method_name)
  @method_name = method_name
  @with = nil
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



20
21
22
# File 'lib/spy/api.rb', line 20

def actual
  @actual
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



20
21
22
# File 'lib/spy/api.rb', line 20

def method_name
  @method_name
end

Instance Method Details

#descriptionObject



52
53
54
# File 'lib/spy/api.rb', line 52

def description
  "to have received #{method_name.inspect}#{args_message}"
end

#failure_message_for_shouldObject



44
45
46
# File 'lib/spy/api.rb', line 44

def failure_message_for_should
  "expected #{actual.inspect} to have received #{method_name.inspect}#{args_message}"
end

#failure_message_for_should_notObject



48
49
50
# File 'lib/spy/api.rb', line 48

def failure_message_for_should_not
  "expected #{actual.inspect} to not have received #{method_name.inspect}#{args_message}, but did"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/spy/api.rb', line 27

def matches?(actual)
  @actual = actual
  case @with
  when Proc
    spy.has_been_called_with?(&@with)
  when Array
    spy.has_been_called_with?(*@with)
  else
    spy.has_been_called?
  end
end

#with(*args, &block) ⇒ Object



39
40
41
42
# File 'lib/spy/api.rb', line 39

def with(*args, &block)
  @with = block_given? ? block : args
  self
end