/usr/share/doc/ruby-rspec-mocks/features/configuring_responses/calling_the_original_implementation.feature is in ruby-rspec-mocks 3.5.0c3e0m0s0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | Feature: Calling the original implementation
Use `and_call_original` to make a partial double response as it normally would. This can
be useful when you want to expect a message without interfering with how it responds. You
can also use it to configure the default response for most arguments, and then override
that for specific arguments using `with`.
Note: `and_call_original` is only supported on partial doubles, as normal test doubles do
not have an original implementation.
Background:
Given a file named "lib/calculator.rb" with:
"""ruby
class Calculator
def self.add(x, y)
x + y
end
end
"""
Scenario: `and_call_original` makes the partial double respond as it normally would
Given a file named "spec/and_call_original_spec.rb" with:
"""ruby
require 'calculator'
RSpec.describe "and_call_original" do
it "responds as it normally would" do
expect(Calculator).to receive(:add).and_call_original
expect(Calculator.add(2, 3)).to eq(5)
end
end
"""
When I run `rspec spec/and_call_original_spec.rb`
Then the examples should all pass
Scenario: `and_call_original` can configure a default response that can be overriden for specific args
Given a file named "spec/and_call_original_spec.rb" with:
"""ruby
require 'calculator'
RSpec.describe "and_call_original" do
it "can be overriden for specific arguments using #with" do
allow(Calculator).to receive(:add).and_call_original
allow(Calculator).to receive(:add).with(2, 3).and_return(-5)
expect(Calculator.add(2, 2)).to eq(4)
expect(Calculator.add(2, 3)).to eq(-5)
end
end
"""
When I run `rspec spec/and_call_original_spec.rb`
Then the examples should all pass
|