Class: Crspec::Mock::ReceiveMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/crspec/mock/double.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name) ⇒ ReceiveMatcher

Returns a new instance of ReceiveMatcher.



174
175
176
177
178
179
180
181
182
# File 'lib/crspec/mock/double.rb', line 174

def initialize(method_name)
  @method_name = method_name.to_sym
  @expected_args = nil
  @return_values = nil
  @raise_exception = nil
  @yield_args = nil
  @expected_count = 1
  @count_constraint = :exact
end

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



172
173
174
# File 'lib/crspec/mock/double.rb', line 172

def method_name
  @method_name
end

Instance Method Details

#and_raise(exception = StandardError, message = nil) ⇒ Object



194
195
196
197
198
# File 'lib/crspec/mock/double.rb', line 194

def and_raise(exception = StandardError, message = nil)
  @raise_exception = exception
  @raise_message = message
  self
end

#and_return(*values) ⇒ Object



189
190
191
192
# File 'lib/crspec/mock/double.rb', line 189

def and_return(*values)
  @return_values = values
  self
end

#and_yield(*args) ⇒ Object



200
201
202
203
# File 'lib/crspec/mock/double.rb', line 200

def and_yield(*args)
  @yield_args = args
  self
end

#at_least(n) ⇒ Object



223
224
225
226
227
# File 'lib/crspec/mock/double.rb', line 223

def at_least(n)
  @expected_count = n
  @count_constraint = :at_least
  self
end

#exactly(n) ⇒ Object



217
218
219
220
221
# File 'lib/crspec/mock/double.rb', line 217

def exactly(n)
  @expected_count = n
  @count_constraint = :exact
  self
end

#onceObject



205
206
207
208
209
# File 'lib/crspec/mock/double.rb', line 205

def once
  @expected_count = 1
  @count_constraint = :exact
  self
end

#setup_allow(target) ⇒ Object



229
230
231
232
233
# File 'lib/crspec/mock/double.rb', line 229

def setup_allow(target)
  chain = StubChain.new(target, @method_name)
  apply_chain_options(chain)
  chain
end

#setup_expect(target) ⇒ Object



235
236
237
238
239
240
241
# File 'lib/crspec/mock/double.rb', line 235

def setup_expect(target)
  chain = ExpectationChain.new(target, @method_name)
  chain.instance_variable_set(:@expected_count, @expected_count)
  chain.instance_variable_set(:@count_constraint, @count_constraint)
  apply_chain_options(chain)
  chain
end

#twiceObject



211
212
213
214
215
# File 'lib/crspec/mock/double.rb', line 211

def twice
  @expected_count = 2
  @count_constraint = :exact
  self
end

#with(*args) ⇒ Object



184
185
186
187
# File 'lib/crspec/mock/double.rb', line 184

def with(*args)
  @expected_args = args
  self
end