File: partial_doubles.feature

package info (click to toggle)
ruby-rspec 3.9.0c2e2m1s3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,612 kB
  • sloc: ruby: 67,456; sh: 1,572; makefile: 98
file content (34 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download | duplicates (5)
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
Feature: Partial doubles

  When the `verify_partial_doubles` configuration option is set, the same argument and
  method existence checks that are performed for [`object_double`](./using-an-object-double) are also performed on
  [partial doubles](../basics/partial-test-doubles). You should set this unless you have a good reason not to. It defaults to off
  only for backwards compatibility.

  Scenario: doubling an existing object
    Given a file named "spec/user_spec.rb" with:
      """ruby
      class User
        def save; false; end
      end

      def save_user(user)
        "saved!" if user.save
      end

      RSpec.configure do |config|
        config.mock_with :rspec do |mocks|
          mocks.verify_partial_doubles = true
        end
      end

      RSpec.describe '#save_user' do
        it 'renders message on success' do
          user = User.new
          expect(user).to receive(:saave).and_return(true) # Typo in name
          expect(save_user(user)).to eq("saved!")
        end
      end
      """
    When I run `rspec spec/user_spec.rb`
    Then the output should contain "1 example, 1 failure"