File: define_matcher_outside_rspec.feature

package info (click to toggle)
ruby-rspec 3.13.0c0e0m0s1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,856 kB
  • sloc: ruby: 70,868; sh: 1,423; makefile: 99
file content (32 lines) | stat: -rw-r--r-- 972 bytes parent folder | download
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
Feature: Defining a matcher outside rspec

  You can define custom matchers when using rspec-expectations outside of rspec-core.

  Scenario: Define a matcher with default messages
    Given a file named "test_multiples.rb" with:
      """ruby
      require "minitest/autorun"
      require "rspec/expectations/minitest_integration"

      RSpec::Matchers.define :be_a_multiple_of do |expected|
        match do |actual|
          actual % expected == 0
        end
      end

      class TestMultiples < Minitest::Test

        def test_9_should_be_a_multiple_of_3
          expect(9).to be_a_multiple_of(3)
        end

        def test_9_should_be_a_multiple_of_4
          expect(9).to be_a_multiple_of(4)
        end

      end
      """
    When I run `ruby test_multiples.rb`
    Then the exit status should not be 0
    And the output should contain "expected 9 to be a multiple of 4"
    And the output should contain "2 runs, 2 assertions, 1 failures, 0 errors"