Class: Spec::Mocks::MessageExpectation

Inherits:
BaseExpectation show all
Defined in:
lib/spec/mocks/message_expectation.rb

Direct Known Subclasses

NegativeMessageExpectation

Instance Attribute Summary

Attributes inherited from BaseExpectation

#sym

Instance Method Summary collapse

Methods inherited from BaseExpectation

#and_raise, #and_return, #and_throw, #and_yield, #expected_args, #initialize, #invoke, #matches

Constructor Details

This class inherits a constructor from Spec::Mocks::BaseExpectation

Instance Method Details

#any_number_of_times(&block) ⇒ Object



180
181
182
183
184
# File 'lib/spec/mocks/message_expectation.rb', line 180

def any_number_of_times(&block)
  @method_block = block if block
  @expected_received_count = :any
  self
end

#at_least(n) ⇒ Object



165
166
167
168
# File 'lib/spec/mocks/message_expectation.rb', line 165

def at_least(n)
  set_expected_received_count :at_least, n
  self
end

#at_most(n) ⇒ Object



170
171
172
173
# File 'lib/spec/mocks/message_expectation.rb', line 170

def at_most(n)
  set_expected_received_count :at_most, n
  self
end

#exactly(n) ⇒ Object



160
161
162
163
# File 'lib/spec/mocks/message_expectation.rb', line 160

def exactly(n)
  set_expected_received_count :exactly, n
  self
end

#matches_name_but_not_args(sym, args) ⇒ Object



136
137
138
# File 'lib/spec/mocks/message_expectation.rb', line 136

def matches_name_but_not_args(sym, args)
  @sym == sym and not @args_expectation.check_args(args)
end

#negative_expectation_for?(sym) ⇒ Boolean

Returns:

  • (Boolean)


210
211
212
# File 'lib/spec/mocks/message_expectation.rb', line 210

def negative_expectation_for?(sym)
  return false
end

#neverObject



186
187
188
189
# File 'lib/spec/mocks/message_expectation.rb', line 186

def never
  @expected_received_count = 0
  self
end

#once(&block) ⇒ Object



191
192
193
194
195
# File 'lib/spec/mocks/message_expectation.rb', line 191

def once(&block)
  @method_block = block if block
  @expected_received_count = 1
  self
end

#ordered(&block) ⇒ Object



203
204
205
206
207
208
# File 'lib/spec/mocks/message_expectation.rb', line 203

def ordered(&block)
  @method_block = block if block
  @order_group.register(self)
  @ordered = true
  self
end

#times(&block) ⇒ Object



175
176
177
178
# File 'lib/spec/mocks/message_expectation.rb', line 175

def times(&block)
  @method_block = block if block
  self
end

#twice(&block) ⇒ Object



197
198
199
200
201
# File 'lib/spec/mocks/message_expectation.rb', line 197

def twice(&block)
  @method_block = block if block
  @expected_received_count = 2
  self
end

#verify_messages_receivedObject



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/spec/mocks/message_expectation.rb', line 140

def verify_messages_received        
  return if @expected_received_count == :any
  return if (@at_least) && (@received_count >= @expected_received_count)
  return if (@at_most) && (@received_count <= @expected_received_count)
  return if @expected_received_count == @received_count
    
  begin
    @error_generator.raise_expectation_error(@sym, @expected_received_count, @received_count, *@args_expectation.args)
  rescue => error
    error.backtrace.insert(0, @expected_from)
    Kernel::raise error
  end
end

#with(*args, &block) ⇒ Object



154
155
156
157
158
# File 'lib/spec/mocks/message_expectation.rb', line 154

def with(*args, &block)
  @method_block = block if block
  @args_expectation = ArgumentExpectation.new(args)
  self
end