Sha256: 3c65e03eeb18e6c404e1ab12cdf787bd3c0a5e6eac35cf6afb4da69bc84eda8c

Contents?: true

Size: 1.95 KB

Versions: 44

Compression:

Stored size: 1.95 KB

Contents

require 'spec_helper'

if (1..2).respond_to?(:cover?)
  describe "expect(...).to cover(expected)" do
    it_behaves_like "an RSpec matcher", :valid_value => (1..10), :invalid_value => (20..30) do
      let(:matcher) { cover(5) }
    end

    context "for a range target" do
      it "passes if target covers expected" do
        expect((1..10)).to cover(5)
      end

      it "fails if target does not cover expected" do
        expect {
          expect((1..10)).to cover(11)
        }.to fail_with("expected 1..10 to cover 11")
      end
    end
  end

  describe "expect(...).to cover(with, multiple, args)" do
    context "for a range target" do
      it "passes if target covers all items" do
        expect((1..10)).to cover(4, 6)
      end

      it "fails if target does not cover any one of the items" do
        expect {
          expect((1..10)).to cover(4, 6, 11)
        }.to fail_with("expected 1..10 to cover 4, 6, and 11")
      end
    end
  end

  describe "expect(...).not_to cover(expected)" do
    context "for a range target" do
      it "passes if target does not cover expected" do
        expect((1..10)).not_to cover(11)
      end

      it "fails if target covers expected" do
        expect {
          expect((1..10)).not_to cover(5)
        }.to fail_with("expected 1..10 not to cover 5")
      end
    end
  end

  describe "expect(...).not_to cover(with, multiple, args)" do
    context "for a range target" do
      it "passes if the target does not cover any of the expected" do
        expect((1..10)).not_to cover(11, 12, 13)
      end

      it "fails if the target covers all of the expected" do
        expect {
          expect((1..10)).not_to cover(4, 6)
        }.to fail_with("expected 1..10 not to cover 4 and 6")
      end

      it "fails if the target covers some (but not all) of the expected" do
        expect {
          expect((1..10)).not_to cover(5, 11)
        }.to fail_with("expected 1..10 not to cover 5 and 11")
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 12 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/cover_spec.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/cover_spec.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/cover_spec.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/cover_spec.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/cover_spec.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/cover_spec.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/cover_spec.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/cover_spec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-expectations-2.14.5/spec/rspec/matchers/cover_spec.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-expectations-2.13.0/spec/rspec/matchers/cover_spec.rb
rspec-expectations-2.99.2 spec/rspec/matchers/cover_spec.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-expectations-2.14.4/spec/rspec/matchers/cover_spec.rb
rspec-expectations-2.99.1 spec/rspec/matchers/cover_spec.rb
rspec-expectations-2.99.0 spec/rspec/matchers/cover_spec.rb
rspec-expectations-2.99.0.rc1 spec/rspec/matchers/cover_spec.rb
rspec-expectations-3.0.0.beta2 spec/rspec/matchers/built_in/cover_spec.rb
rspec-expectations-2.99.0.beta2 spec/rspec/matchers/cover_spec.rb
rspec-expectations-2.14.5 spec/rspec/matchers/cover_spec.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/cover_spec.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/cover_spec.rb