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



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

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

#at_least(n) ⇒ Object



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

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

#at_most(n) ⇒ Object



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

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

#exactly(n) ⇒ Object



149
150
151
152
# File 'lib/spec/mocks/message_expectation.rb', line 149

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

#matches_name_but_not_args(sym, args) ⇒ Object



125
126
127
# File 'lib/spec/mocks/message_expectation.rb', line 125

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)


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

def negative_expectation_for?(sym)
  return false
end

#neverObject



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

def never
  @expected_received_count = 0
  self
end

#once(&block) ⇒ Object



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

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

#ordered(&block) ⇒ Object



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

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

#times(&block) ⇒ Object



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

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

#twice(&block) ⇒ Object



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

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

#verify_messages_receivedObject



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/spec/mocks/message_expectation.rb', line 129

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



143
144
145
146
147
# File 'lib/spec/mocks/message_expectation.rb', line 143

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