Class: RSpec::Mocks::Matchers::ReceiveMessages

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

Instance Method Summary (collapse)

Constructor Details

- (ReceiveMessages) initialize(message_return_value_hash)

Returns a new instance of ReceiveMessages



7
8
9
10
# File 'lib/rspec/mocks/matchers/receive_messages.rb', line 7

def initialize(message_return_value_hash)
  @message_return_value_hash = message_return_value_hash
  @backtrace_line = CallerFilter.first_non_rspec_line
end

Instance Method Details

- (Object) name



12
13
14
# File 'lib/rspec/mocks/matchers/receive_messages.rb', line 12

def name
  "receive_messages"
end

- (Object) setup_allowance(subject)



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

def setup_allowance(subject)
  warn_about_block if block_given?
  each_message_on( proxy_on(subject) ) do |host, message, return_value|
    host.add_simple_stub(message, return_value)
  end
end

- (Object) setup_any_instance_allowance(subject)



45
46
47
48
# File 'lib/rspec/mocks/matchers/receive_messages.rb', line 45

def setup_any_instance_allowance(subject)
  warn_about_block if block_given?
  any_instance_of(subject).stub(@message_return_value_hash)
end

- (Object) setup_any_instance_expectation(subject)



38
39
40
41
42
43
# File 'lib/rspec/mocks/matchers/receive_messages.rb', line 38

def setup_any_instance_expectation(subject)
  warn_about_block if block_given?
  each_message_on( any_instance_of(subject) ) do |host, message, return_value|
    host.should_receive(message).and_return(return_value)
  end
end

- (Object) setup_expectation(subject) Also known as: matches?



16
17
18
19
20
21
# File 'lib/rspec/mocks/matchers/receive_messages.rb', line 16

def setup_expectation(subject)
  warn_about_block if block_given?
  each_message_on( proxy_on(subject) ) do |host, message, return_value|
    host.add_simple_expectation(message, return_value, @backtrace_line)
  end
end

- (Object) setup_negative_expectation(subject) Also known as: does_not_match?



24
25
26
27
28
# File 'lib/rspec/mocks/matchers/receive_messages.rb', line 24

def setup_negative_expectation(subject)
  raise NegationUnsupportedError,
    "`expect(...).to_not receive_messages` is not supported since it " +
    "doesn't really make sense. What would it even mean?"
end

- (Object) warn_about_block



50
51
52
# File 'lib/rspec/mocks/matchers/receive_messages.rb', line 50

def warn_about_block
  raise "Implementation blocks aren't supported with `receive_messages`"
end