This file is indexed.

/usr/share/doc/ruby-rspec-mocks/features/configuring_responses/yielding.feature is in ruby-rspec-mocks 3.4.0c3e0m1s1-1ubuntu1.

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Feature: Yielding

  Use `and_yield` to make the test double yield the provided arguments when it receives the
  message. If the caller does not provide a block, or the caller's block does not accept the
  provided arguments, an error will be raised. If you want to yield multiple times, chain
  multiple `and_yield` calls together.

  Scenario: Yield an argument
    Given a file named "yield_arguments_spec.rb" with:
      """ruby
      RSpec.describe "Making it yield arguments" do
        it "yields the provided args" do
          dbl = double
          allow(dbl).to receive(:foo).and_yield(2, 3)

          x = y = nil
          dbl.foo { |a, b| x, y = a, b }
          expect(x).to eq(2)
          expect(y).to eq(3)
        end
      end
      """
     When I run `rspec yield_arguments_spec.rb`
     Then the examples should all pass

  Scenario: It fails when the caller does not provide a block
    Given a file named "no_caller_block_spec.rb" with:
      """ruby
      RSpec.describe "Making it yield" do
        it "fails when the caller does not provide a block" do
          dbl = double
          allow(dbl).to receive(:foo).and_yield(2, 3)
          dbl.foo
        end
      end
      """
     When I run `rspec no_caller_block_spec.rb`
     Then it should fail with:
      """
      #<Double (anonymous)> asked to yield |[2, 3]| but no block was passed
      """

  Scenario: It fails when the caller's block does not accept the provided arguments
    Given a file named "arg_mismatch_spec.rb" with:
      """ruby
      RSpec.describe "Making it yield" do
        it "fails when the caller's block does not accept the provided arguments" do
          dbl = double
          allow(dbl).to receive(:foo).and_yield(2, 3)
          dbl.foo { |x| }
        end
      end
      """
     When I run `rspec arg_mismatch_spec.rb`
     Then it should fail with:
      """
      #<Double (anonymous)> yielded |2, 3| to block with arity of 1
      """

  Scenario: Yield multiple times
    Given a file named "yield_multiple_times_spec.rb" with:
      """
      RSpec.describe "Making it yield multiple times" do
        it "yields the specified args in succession" do
          yielded = []

          dbl = double
          allow(dbl).to receive(:foo).and_yield(1).and_yield(2).and_yield(3)
          dbl.foo { |x| yielded << x }

          expect(yielded).to eq([1, 2, 3])
        end
      end
      """
    When I run `rspec yield_multiple_times_spec.rb`
    Then the examples should all pass