File: generated_descriptions.rb

package info (click to toggle)
ruby-rspec 3.12.0c0e1m1s0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,752 kB
  • sloc: ruby: 69,818; sh: 1,861; makefile: 99
file content (41 lines) | stat: -rw-r--r-- 1,196 bytes parent folder | download | duplicates (4)
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
module RSpec
  module Matchers
    class << self
      # @private
      attr_accessor :last_matcher, :last_expectation_handler
    end

    # @api private
    # Used by rspec-core to clear the state used to generate
    # descriptions after an example.
    def self.clear_generated_description
      self.last_matcher = nil
      self.last_expectation_handler = nil
    end

    # @api private
    # Generates an an example description based on the last expectation.
    # Used by rspec-core's one-liner syntax.
    def self.generated_description
      return nil if last_expectation_handler.nil?
      "#{last_expectation_handler.verb} #{last_description}"
    end

    # @private
    def self.last_description
      last_matcher.respond_to?(:description) ? last_matcher.description : <<-MESSAGE
When you call a matcher in an example without a String, like this:

specify { expect(object).to matcher }

or this:

it { is_expected.to matcher }

RSpec expects the matcher to have a #description method. You should either
add a String to the example this matcher is being used in, or give it a
description method. Then you won't have to suffer this lengthy warning again.
MESSAGE
    end
  end
end