Class: RSpec::Mocks::Matchers::Receive

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

Instance Method Summary (collapse)

Constructor Details

- (Receive) initialize(message, block)

Returns a new instance of Receive



8
9
10
11
12
# File 'lib/rspec/mocks/matchers/receive.rb', line 8

def initialize(message, block)
  @message                 = message
  @block                   = block
  @recorded_customizations = []
end

Instance Method Details

- (Object) name



14
15
16
# File 'lib/rspec/mocks/matchers/receive.rb', line 14

def name
  "receive"
end

- (Object) setup_allowance(subject, &block)



35
36
37
38
# File 'lib/rspec/mocks/matchers/receive.rb', line 35

def setup_allowance(subject, &block)
  warn_if_any_instance("allow", subject)
  setup_mock_proxy_method_substitute(subject, :add_stub, block)
end

- (Object) setup_any_instance_allowance(subject, &block)



48
49
50
# File 'lib/rspec/mocks/matchers/receive.rb', line 48

def setup_any_instance_allowance(subject, &block)
  setup_any_instance_method_substitute(subject, :stub, block)
end

- (Object) setup_any_instance_expectation(subject, &block)



40
41
42
# File 'lib/rspec/mocks/matchers/receive.rb', line 40

def setup_any_instance_expectation(subject, &block)
  setup_any_instance_method_substitute(subject, :should_receive, block)
end

- (Object) setup_any_instance_negative_expectation(subject, &block)



44
45
46
# File 'lib/rspec/mocks/matchers/receive.rb', line 44

def setup_any_instance_negative_expectation(subject, &block)
  setup_any_instance_method_substitute(subject, :should_not_receive, block)
end

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



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

def setup_expectation(subject, &block)
  warn_if_any_instance("expect", subject)
  setup_mock_proxy_method_substitute(subject, :add_message_expectation, block)
end

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



24
25
26
27
28
29
30
31
32
# File 'lib/rspec/mocks/matchers/receive.rb', line 24

def setup_negative_expectation(subject, &block)
  # ensure `never` goes first for cases like `never.and_return(5)`,
  # where `and_return` is meant to raise an error
  @recorded_customizations.unshift ExpectationCustomization.new(:never, [], nil)

  warn_if_any_instance("expect", subject)

  setup_expectation(subject, &block)
end