File: matcher_definition_spec.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 (37 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download | duplicates (6)
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
require "spec_helper"

module RSpec
  module Support
    RSpec.describe "matcher definitions" do
      RSpec::Matchers.define :fake_matcher do |expected|
        match { |actual| expected == actual }
        description { :fake_matcher }
      end

      RSpec::Matchers.define :matcher_with_no_description do
        match { true }
        undef description
      end

      describe ".rspec_description_for_object" do
        it "returns the object for a non matcher object" do
          o = Object.new
          expect(RSpec::Support.rspec_description_for_object(o)).to be o
        end

        it "returns the object's description for a matcher object that has a description" do
          expect(RSpec::Support.rspec_description_for_object(fake_matcher(nil))).to eq :fake_matcher
        end

        it "returns the object for a matcher that does not have a description" do
          matcher = matcher_with_no_description

          expect(matcher_with_no_description).not_to respond_to(:description)
          expect(RSpec::Support.is_a_matcher?(matcher_with_no_description)).to eq true

          expect(RSpec::Support.rspec_description_for_object(matcher)).to be matcher
        end
      end
    end
  end
end