This file is indexed.

/usr/share/doc/ruby-rspec-core/features/mock_framework_integration/use_any_framework.feature is in ruby-rspec-core 3.7.0c1e0m0s1-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
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
Feature: mock with an alternative framework

  In addition to rspec, mocha, flexmock, and RR, you can choose an alternate
  framework as the mocking framework. You (or the framework authors) just needs
  to provide an adapter that hooks RSpec's events into those of the framework.

  A mock framework adapter must expose three methods:

  * `setup_mocks_for_rspec`
    * called before each example is run
  * `verify_mocks_for_rspec`
    * called after each example is run
    * this is where message expectation failures should result in an error with
      the appropriate failure message
  * `teardown_mocks_for_rspec`
    * called after `verify_mocks_for_rspec`
    * use this to clean up resources, restore objects to earlier state, etc
    * guaranteed to run even if there are failures

  Scenario: Mock with alternate framework
    Given a file named "expector.rb" with:
      """ruby
      class Expector
        class << self
          def expectors
            @expectors ||= []
          end

          def clear_expectors
            expectors.clear
          end

          def verify_expectors
            expectors.each {|d| d.verify}
          end
        end

        def initialize
          self.class.expectors << self
        end

        def expectations
          @expectations ||= []
        end

        def expect(message)
          expectations << message.to_s
        end

        def verify
          unless expectations.empty?
            raise expectations.map {|e|
              "expected #{e}, but it was never received"
            }.join("\n")
          end
        end

      private

        def method_missing(name, *args, &block)
          expectations.delete(name.to_s)
        end

      public

        module RSpecAdapter
          def setup_mocks_for_rspec
            # no setup necessary
          end

          def verify_mocks_for_rspec
            Expector.verify_expectors
          end

          def teardown_mocks_for_rspec
            Expector.clear_expectors
          end
        end
      end
      """

    Given a file named "example_spec.rb" with:
      """ruby
      require File.expand_path("../expector", __FILE__)

      RSpec.configure do |config|
        config.mock_with Expector::RSpecAdapter
      end

      RSpec.describe Expector do
        it "passes when message is received" do
          expector = Expector.new
          expector.expect(:foo)
          expector.foo
        end

        it "fails when message is received" do
          expector = Expector.new
          expector.expect(:foo)
        end
      end
      """
    When I run `rspec example_spec.rb --format doc`
    Then the exit status should be 1
    And the output should contain "2 examples, 1 failure"
    And the output should contain "fails when message is received (FAILED - 1)"