Sha256: 3bfc422abc306af77190c5363390c8b8142d29894ec411b86a5aa1539d322587

Contents?: true

Size: 1.59 KB

Versions: 12

Compression:

Stored size: 1.59 KB

Contents

Feature: Compound Expectations

  Matchers can be composed using `and` or `or` to make compound expectations.

  Scenario: Use `and` to chain expectations
    Given a file named "compound_and_matcher_spec.rb" with:
      """ruby
      RSpec.describe "A compound `and` matcher" do
        let(:string) { "foo bar bazz" }

        it "passes when both are true" do
          expect(string).to start_with("foo").and end_with("bazz")
        end

        it "passes when using boolean AND `&` alias" do
          expect(string).to start_with("foo") & end_with("bazz")
        end

        it "fails when the first matcher fails" do
          expect(string).to start_with("bar").and end_with("bazz")
        end

        it "fails when the second matcher fails" do
          expect(string).to start_with("foo").and end_with("bar")
        end
      end
      """
    When I run `rspec compound_and_matcher_spec.rb`
    Then the output should contain "4 examples, 2 failures"

  Scenario: Use `or` to chain expectations
    Given a file named "stoplight_spec.rb" with:
      """ruby
      class StopLight
        def color
          %w[ green yellow red ].shuffle.first
        end
      end

      RSpec.describe StopLight, "#color" do
        let(:light) { StopLight.new }
        it "is green, yellow or red" do
          expect(light.color).to eq("green").or eq("yellow").or eq("red")
        end

        it "passes when using boolean OR `|` alias" do
          expect(light.color).to eq("green") | eq("yellow") | eq("red")
        end
      end
      """
    When I run `rspec stoplight_spec.rb`
    Then the example should pass

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
opal-rspec-1.1.0.alpha3 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-1.1.0.alpha2 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-1.1.0.alpha1 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-1.0.0 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-1.0.0.alpha1 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-0.8.0 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-0.8.0.alpha3 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-0.8.0.alpha2 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-0.8.0.alpha1 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-0.7.1 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-0.7.0 rspec-expectations/upstream/features/compound_expectations.feature
opal-rspec-0.7.0.rc.2 rspec-expectations/upstream/features/compound_expectations.feature