Class: RSpec::Mocks::SimpleMessageExpectation

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/mocks/message_expectation.rb

Overview

A message expectation that only allows concrete return values to be set for a message. While this same effect can be achieved using a standard MessageExpecation, this version is much faster and so can be used as an optimization.

Instance Method Summary (collapse)

Constructor Details

- (SimpleMessageExpectation) initialize(message, response, error_generator, backtrace_line = nil)

Returns a new instance of SimpleMessageExpectation



12
13
14
15
# File 'lib/rspec/mocks/message_expectation.rb', line 12

def initialize(message, response, error_generator, backtrace_line = nil)
  @message, @response, @error_generator, @backtrace_line = message.to_sym, response, error_generator, backtrace_line
  @received = false
end

Instance Method Details

- (Boolean) called_max_times?

Returns:

  • (Boolean)


26
27
28
# File 'lib/rspec/mocks/message_expectation.rb', line 26

def called_max_times?
  false
end

- (Object) invoke(*_)



17
18
19
20
# File 'lib/rspec/mocks/message_expectation.rb', line 17

def invoke(*_)
  @received = true
  @response
end

- (Boolean) matches?(message, *_)

Returns:

  • (Boolean)


22
23
24
# File 'lib/rspec/mocks/message_expectation.rb', line 22

def matches?(message, *_)
  @message == message.to_sym
end

- (Object) verify_messages_received



30
31
32
33
34
35
36
# File 'lib/rspec/mocks/message_expectation.rb', line 30

def verify_messages_received
  InsertOntoBacktrace.line(@backtrace_line) do
    unless @received
      @error_generator.raise_expectation_error(@message, 1, ArgumentListMatcher::MATCH_ALL, 0, nil)
    end
  end
end