Sha256: b2236b40f7984dd559790c0b779aca9a6abac3173539b1ed41495bac288b93fb

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

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 overridden 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 overridden 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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opal-rspec-1.1.0.alpha3 rspec-mocks/upstream/features/configuring_responses/calling_the_original_implementation.feature
opal-rspec-1.1.0.alpha2 rspec-mocks/upstream/features/configuring_responses/calling_the_original_implementation.feature
opal-rspec-1.1.0.alpha1 rspec-mocks/upstream/features/configuring_responses/calling_the_original_implementation.feature
opal-rspec-1.0.0 rspec-mocks/upstream/features/configuring_responses/calling_the_original_implementation.feature
opal-rspec-1.0.0.alpha1 rspec-mocks/upstream/features/configuring_responses/calling_the_original_implementation.feature