Class: RSpec::Mocks::AnyInstance::Proxy
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/any_instance/proxy.rb
Overview
The ‘AnyInstance::Recorder` is responsible for redefining the klass’s instance method in order to add any stubs/expectations the first time the method is called. It’s not capable of updating a stub on an instance that’s already been previously stubbed (either directly, or via ‘any_instance`).
This proxy sits in front of the recorder and delegates both to it and to the ‘RSpec::Mocks::Proxy` for each already mocked or stubbed instance of the class, in order to propagates changes to the instances.
Note that unlike ‘RSpec::Mocks::Proxy`, this proxy class is stateless and is not persisted in `RSpec::Mocks.space`.
Proxying for the message expectation fluent interface (typically chained off of the return value of one of these methods) is provided by the ‘FluentInterfaceProxy` class below.
Instance Method Summary collapse
- #expect_chain(*chain, &block) ⇒ Object
-
#initialize(recorder, target_proxies) ⇒ Proxy
constructor
A new instance of Proxy.
- #klass ⇒ Object
- #should_not_receive(method_name, &block) ⇒ Object
- #should_receive(method_name, &block) ⇒ Object
- #stub(method_name_or_method_map, &block) ⇒ Object
- #stub_chain(*chain, &block) ⇒ Object
- #unstub(method_name) ⇒ Object
Constructor Details
#initialize(recorder, target_proxies) ⇒ Proxy
Returns a new instance of Proxy.
22 23 24 25 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/any_instance/proxy.rb', line 22 def initialize(recorder, target_proxies) @recorder = recorder @target_proxies = target_proxies end |
Instance Method Details
#expect_chain(*chain, &block) ⇒ Object
55 56 57 58 59 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/any_instance/proxy.rb', line 55 def expect_chain(*chain, &block) (__method__, chain, block) do |proxy| Mocks::ExpectChain.expect_chain_on(proxy.object, *chain, &block) end end |
#klass ⇒ Object
27 28 29 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/any_instance/proxy.rb', line 27 def klass @recorder.klass end |
#should_not_receive(method_name, &block) ⇒ Object
71 72 73 74 75 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/any_instance/proxy.rb', line 71 def should_not_receive(method_name, &block) (__method__, [method_name], block) do |proxy| proxy.(method_name, &block).never end end |
#should_receive(method_name, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/any_instance/proxy.rb', line 61 def should_receive(method_name, &block) (__method__, [method_name], block) do |proxy| # Yeah, this is a bit odd...but if we used `add_message_expectation` # then it would act like `expect_every_instance_of(klass).to receive`. # The any_instance recorder takes care of validating that an instance # received the message. proxy.add_stub(method_name, &block) end end |
#stub(method_name_or_method_map, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/any_instance/proxy.rb', line 31 def stub(method_name_or_method_map, &block) if Hash === method_name_or_method_map method_name_or_method_map.each do |method_name, return_value| stub(method_name).and_return(return_value) end else (__method__, [method_name_or_method_map], block) do |proxy| proxy.add_stub(method_name_or_method_map, &block) end end end |
#stub_chain(*chain, &block) ⇒ Object
49 50 51 52 53 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/any_instance/proxy.rb', line 49 def stub_chain(*chain, &block) (__method__, chain, block) do |proxy| Mocks::StubChain.stub_chain_on(proxy.object, *chain, &block) end end |