Sha256: 78bf489be1f97c30db08d5c6f0694e063a5789401a9ab53e524332ee45828491

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

Feature: Define negated matcher

  You can use `RSpec::Matchers.define_negated_matcher` to define a negated version of
  an existing matcher. This is particularly useful in composed matcher expressions.

  @skip-when-ripper-unsupported
  Scenario: Composed negated matcher expression
    Given a file named "composed_negated_expression_spec.rb" with:
      """ruby
      RSpec::Matchers.define_negated_matcher :an_array_excluding, :include

      RSpec.describe "A negated matcher" do
        let(:list) { 1.upto(10).to_a }

        it "can be used in a composed matcher expression" do
          expect { list.delete(5) }.to change { list }.to(an_array_excluding 5)
        end

        it "provides a good failure message based on the name" do
          # deliberate failure
          expect { list.delete(1) }.to change { list }.to(an_array_excluding 5)
        end
      end
      """
    When I run `rspec composed_negated_expression_spec.rb`
    Then the output should contain all of these:
      | 2 examples, 1 failure                                                                                  |
      |  1) A negated matcher provides a good failure message based on the name                                |
      |     Failure/Error: expect { list.delete(1) }.to change { list }.to(an_array_excluding 5)               |
      |       expected `list` to have changed to an array excluding 5, but is now [2, 3, 4, 5, 6, 7, 8, 9, 10] |

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opal-rspec-1.1.0.alpha3 rspec-expectations/upstream/features/define_negated_matcher.feature
opal-rspec-1.1.0.alpha2 rspec-expectations/upstream/features/define_negated_matcher.feature
opal-rspec-1.1.0.alpha1 rspec-expectations/upstream/features/define_negated_matcher.feature
opal-rspec-1.0.0 rspec-expectations/upstream/features/define_negated_matcher.feature
opal-rspec-1.0.0.alpha1 rspec-expectations/upstream/features/define_negated_matcher.feature