Class: RSpec::Mocks::Matchers::Receive Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Matcher
|
|
Inherits: | Object |
Defined in: | rspec-mocks/lib/rspec/mocks/matchers/receive.rb |
Class Method Summary
- .new(message, block) ⇒ Receive constructor Internal use only
Instance Method Summary
- #description Internal use only
-
#does_not_match?(subject, &block)
Alias for #setup_negative_expectation.
- #matcher_name Internal use only
-
#matches?(subject, &block)
Alias for #setup_expectation.
- #setup_allowance(subject, &block) Internal use only
- #setup_any_instance_allowance(subject, &block) Internal use only
- #setup_any_instance_expectation(subject, &block) Internal use only
- #setup_any_instance_negative_expectation(subject, &block) Internal use only
- #setup_expectation(subject, &block) (also: #matches?) Internal use only
- #setup_negative_expectation(subject, &block) (also: #does_not_match?) Internal use only
- #describable private Internal use only
- #move_block_to_last_customization(block) private Internal use only
- #setup_any_instance_method_substitute(subject, method, block) private Internal use only
- #setup_method_substitute(host, method, block, *args) private Internal use only
- #setup_mock_proxy_method_substitute(subject, method, block) private Internal use only
- #warn_if_any_instance(expression, subject) private Internal use only
Instance Method Details
#describable (private)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 71
def describable @describable ||= DefaultDescribable.new(@message) end
#description
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 20
def description describable.description_for("receive") end
#does_not_match?(subject, &block)
Alias for #setup_negative_expectation.
# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 39
alias does_not_match? setup_negative_expectation
#matcher_name
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 16
def matcher_name "receive" end
#matches?(subject, &block)
Alias for #setup_expectation.
# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 28
alias matches? setup_expectation
#move_block_to_last_customization(block) (private)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 108
def move_block_to_last_customization(block) last = @recorded_customizations.last return block unless last last.block ||= block nil end
#setup_allowance(subject, &block)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 41
def setup_allowance(subject, &block) warn_if_any_instance("allow", subject) setup_mock_proxy_method_substitute(subject, :add_stub, block) end
#setup_any_instance_allowance(subject, &block)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 54
def setup_any_instance_allowance(subject, &block) setup_any_instance_method_substitute(subject, :stub, block) end
#setup_any_instance_expectation(subject, &block)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 46
def setup_any_instance_expectation(subject, &block) setup_any_instance_method_substitute(subject, :should_receive, block) end
#setup_any_instance_method_substitute(subject, method, block) (private)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 91
def setup_any_instance_method_substitute(subject, method, block) proxy = ::RSpec::Mocks.space.any_instance_proxy_for(subject) setup_method_substitute(proxy, method, block) end
#setup_any_instance_negative_expectation(subject, &block)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 50
def setup_any_instance_negative_expectation(subject, &block) setup_any_instance_method_substitute(subject, :should_not_receive, block) end
#setup_expectation(subject, &block) Also known as: #matches?
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 24
def setup_expectation(subject, &block) warn_if_any_instance("expect", subject) @describable = setup_mock_proxy_method_substitute(subject, :, block) end
#setup_method_substitute(host, method, block, *args) (private)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 96
def setup_method_substitute(host, method, block, *args) args << @message.to_sym block = move_block_to_last_customization(block) expectation = host.__send__(method, *args, &(@block || block)) @recorded_customizations.each do |customization| customization.playback_onto(expectation) end expectation end
#setup_mock_proxy_method_substitute(subject, method, block) (private)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 86
def setup_mock_proxy_method_substitute(subject, method, block) proxy = ::RSpec::Mocks.space.proxy_for(subject) setup_method_substitute(proxy, method, block) end
#setup_negative_expectation(subject, &block) Also known as: #does_not_match?
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 30
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
#warn_if_any_instance(expression, subject) (private)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/matchers/receive.rb', line 75
def warn_if_any_instance(expression, subject) return unless AnyInstance::Proxy === subject RSpec.warning( "`#{expression}(#{subject.klass}.any_instance).to` " \ "is probably not what you meant, it does not operate on " \ "any instance of `#{subject.klass}`. " \ "Use `#{expression}_any_instance_of(#{subject.klass}).to` instead." ) end