File: define_matcher_with_fluent_interface.feature

package info (click to toggle)
ruby-rspec 3.9.0c2e2m1s3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,612 kB
  • sloc: ruby: 67,456; sh: 1,572; makefile: 98
file content (70 lines) | stat: -rw-r--r-- 2,306 bytes parent folder | download | duplicates (2)
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
Feature: define matcher with fluent interface

  Use the `chain` method to define matchers with a fluent interface.

  Scenario: chained method with argument
    Given a file named "between_spec.rb" with:
      """ruby
      RSpec::Matchers.define :be_bigger_than do |first|
        match do |actual|
          (actual > first) && (actual < @second)
        end

        chain :and_smaller_than do |second|
          @second = second
        end
      end

      RSpec.describe 5 do
        it { is_expected.to be_bigger_than(4).and_smaller_than(6) }
      end
      """
    When I run `rspec between_spec.rb --format documentation`
    Then the output should contain "1 example, 0 failures"
    And  the output should contain "is expected to be bigger than 4"

  Scenario: chained setter
    Given a file named "between_spec.rb" with:
      """ruby
      RSpec::Matchers.define :be_bigger_than do |first|
        match do |actual|
          (actual > first) && (actual < second)
        end

        chain :and_smaller_than, :second
      end

      RSpec.describe 5 do
        it { is_expected.to be_bigger_than(4).and_smaller_than(6) }
      end
      """
    When I run `rspec between_spec.rb --format documentation`
    Then the output should contain "1 example, 0 failures"
    And  the output should contain "is expected to be bigger than 4"

    Scenario: include_chain_clauses_in_custom_matcher_descriptions configured to true, and chained method with argument
      Given a file named "between_spec.rb" with:
        """ruby
        RSpec.configure do |config|
          config.expect_with :rspec do |c|
            c.include_chain_clauses_in_custom_matcher_descriptions = true
          end
        end

        RSpec::Matchers.define :be_bigger_than do |first|
          match do |actual|
            (actual > first) && (actual < @second)
          end

          chain :and_smaller_than do |second|
            @second = second
          end
        end

        RSpec.describe 5 do
          it { is_expected.to be_bigger_than(4).and_smaller_than(6) }
        end
        """
      When I run `rspec between_spec.rb --format documentation`
      Then the output should contain "1 example, 0 failures"
      And  the output should contain "is expected to be bigger than 4 and smaller than 6"