Class: RSpec::Mocks::Matchers::Receive
- Inherits:
-
Object
- Object
- RSpec::Mocks::Matchers::Receive
- Defined in:
- lib/rspec/mocks/matchers/receive.rb
Defined Under Namespace
Classes: Customization
Instance Method Summary (collapse)
-
- (Receive) initialize(message, block)
constructor
A new instance of Receive.
- - (Object) setup_allowance(subject)
- - (Object) setup_any_instance_allowance(subject)
- - (Object) setup_any_instance_expectation(subject)
- - (Object) setup_any_instance_negative_expectation(subject)
- - (Object) setup_expectation(subject) (also: #matches?)
- - (Object) setup_negative_expectation(subject) (also: #does_not_match?)
Constructor Details
- (Receive) initialize(message, block)
A new instance of Receive
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rspec/mocks/matchers/receive.rb', line 5 def initialize(, block) @message = @block = block @recorded_customizations = [] # MRI, JRuby and RBX report the caller inconsistently; MRI # reports an extra "in `new'" line in the backtrace that the # others do not include. The safest way to find the right # line is to search for the first line BEFORE rspec/mocks/syntax.rb. @backtrace_line = caller.find do |line| !line.split(':').first.end_with?('rspec/mocks/syntax.rb') end end |
Instance Method Details
- (Object) setup_allowance(subject)
33 34 35 |
# File 'lib/rspec/mocks/matchers/receive.rb', line 33 def setup_allowance(subject, &block) setup_mock_proxy_method_substitute(subject, :add_stub, block) end |
- (Object) setup_any_instance_allowance(subject)
45 46 47 |
# File 'lib/rspec/mocks/matchers/receive.rb', line 45 def setup_any_instance_allowance(subject, &block) setup_any_instance_method_substitute(subject, :stub, block) end |
- (Object) setup_any_instance_expectation(subject)
37 38 39 |
# File 'lib/rspec/mocks/matchers/receive.rb', line 37 def setup_any_instance_expectation(subject, &block) setup_any_instance_method_substitute(subject, :should_receive, block) end |
- (Object) setup_any_instance_negative_expectation(subject)
41 42 43 |
# File 'lib/rspec/mocks/matchers/receive.rb', line 41 def setup_any_instance_negative_expectation(subject, &block) setup_any_instance_method_substitute(subject, :should_not_receive, block) end |
- (Object) setup_expectation(subject) Also known as: matches?
19 20 21 |
# File 'lib/rspec/mocks/matchers/receive.rb', line 19 def setup_expectation(subject, &block) setup_mock_proxy_method_substitute(subject, :add_message_expectation, block) end |
- (Object) setup_negative_expectation(subject) Also known as: does_not_match?
24 25 26 27 28 29 30 |
# 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 Customization.new(:never, [], nil) setup_expectation(subject, &block) end |