Class: AncientMock::ExpectationDefinition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ ExpectationDefinition

Returns a new instance of ExpectationDefinition.



77
78
79
80
# File 'lib/ancient_mock.rb', line 77

def initialize(message)
  @message = message
  @invocation_count = 0
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



75
76
77
# File 'lib/ancient_mock.rb', line 75

def message
  @message
end

#return_valueObject (readonly)

Returns the value of attribute return_value.



75
76
77
# File 'lib/ancient_mock.rb', line 75

def return_value
  @return_value
end

Instance Method Details

#and_return(return_value) ⇒ Object



82
83
84
85
# File 'lib/ancient_mock.rb', line 82

def and_return(return_value)
  @return_value = return_value
  self
end

#callObject



97
98
99
100
# File 'lib/ancient_mock.rb', line 97

def call
  @invocation_count += 1
  @return_value
end

#matches?(message, *arguments) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
# File 'lib/ancient_mock.rb', line 92

def matches?(message, *arguments)
  message == @message &&
    (@arguments.nil? || arguments == @arguments)
end

#verifyObject



102
103
104
105
106
# File 'lib/ancient_mock.rb', line 102

def verify
  if @invocation_count != 1
    raise ExpectationNotSatisfied
  end
end

#with(*arguments) ⇒ Object



87
88
89
90
# File 'lib/ancient_mock.rb', line 87

def with(*arguments)
  @arguments = arguments
  self
end