This file is indexed.

/usr/share/doc/ruby-rspec-expectations/features/custom_matchers/define_diffable_matcher.feature is in ruby-rspec-expectations 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
Feature: define diffable matcher

  When a matcher is defined as diffable, the output will include a diff of the submitted objects when the objects are more than simple primitives.

  Scenario: define a diffable matcher
    Given a file named "diffable_matcher_spec.rb" with:
      """ruby
      RSpec::Matchers.define :be_just_like do |expected|
        match do |actual|
          actual == expected
        end

        diffable
      end

      RSpec.describe "two\nlines" do
        it { is_expected.to be_just_like("three\nlines") }
      end
      """
    When I run `rspec ./diffable_matcher_spec.rb`
    Then it should fail with:
      """
             Diff:
             @@ -1,3 +1,3 @@
             -three
             +two
              lines
      """

  Scenario: Redefine actual

    Sometimes is neccessary to overwrite actual to make diffing work, e.g. if `actual` is a name of a file you want to read from. For this to work you need to overwrite `@actual` in your matcher.

    Given a file named "redefine_actual_matcher_spec.rb" with:
      """ruby
      RSpec::Matchers.define :have_content do |expected|
        match do |actual|
          @actual = File.read(actual).chomp

          values_match? expected, @actual
        end

        diffable
      end

      RSpec.describe 'Compare files' do
        context 'when content is equal' do
          it { expect('data.txt').to have_content 'Data' }
        end

        context 'when files are different' do
          it { expect('data.txt').to have_content "No\nData\nhere" }
        end
      end
      """
    And a file named "data.txt" with:
    """
    Data
    """
    When I run `rspec ./redefine_actual_matcher_spec.rb --format documentation`
    Then the exit status should not be 0
    And the output should contain:
    """
    2 examples, 1 failure
    """
    And the output should contain:
    """
           @@ -1,4 +1,2 @@
           -No
            Data
           -here
    """