| 1 | if (1..2).respond_to?(:cover?) |
| 2 | RSpec.describe "expect(...).to cover(expected)" do |
| 3 | it_behaves_like "an RSpec value matcher", :valid_value => (1..10), :invalid_value => (20..30) do |
| 4 | let(:matcher) { cover(5) } |
| 5 | end |
| 6 | |
| 7 | context "for a range target" do |
| 8 | it "passes if target covers expected" do |
| 9 | expect((1..10)).to cover(5) |
| 10 | end |
| 11 | |
| 12 | it "fails if target does not cover expected" do |
| 13 | expect { |
| 14 | expect((1..10)).to cover(11) |
| 15 | }.to fail_with("expected 1..10 to cover 11") |
| 16 | end |
| 17 | end |
| 18 | end |
| 19 | |
| 20 | RSpec.describe "expect(...).to cover(with, multiple, args)" do |
| 21 | context "for a range target" do |
| 22 | it "passes if target covers all items" do |
| 23 | expect((1..10)).to cover(4, 6) |
| 24 | end |
| 25 | |
| 26 | it "fails if target does not cover any one of the items" do |
| 27 | expect { |
| 28 | expect((1..10)).to cover(4, 6, 11) |
| 29 | }.to fail_with("expected 1..10 to cover 4, 6, and 11") |
| 30 | end |
| 31 | end |
| 32 | end |
| 33 | |
| 34 | RSpec.describe "expect(...).not_to cover(expected)" do |
| 35 | context "for a range target" do |
| 36 | it "passes if target does not cover expected" do |
| 37 | expect((1..10)).not_to cover(11) |
| 38 | end |
| 39 | |
| 40 | it "fails if target covers expected" do |
| 41 | expect { |
| 42 | expect((1..10)).not_to cover(5) |
| 43 | }.to fail_with("expected 1..10 not to cover 5") |
| 44 | end |
| 45 | end |
| 46 | end |
| 47 | |
| 48 | RSpec.describe "expect(...).not_to cover(with, multiple, args)" do |
| 49 | context "for a range target" do |
| 50 | it "passes if the target does not cover any of the expected" do |
| 51 | expect((1..10)).not_to cover(11, 12, 13) |
| 52 | end |
| 53 | |
| 54 | it "fails if the target covers all of the expected" do |
| 55 | expect { |
| 56 | expect((1..10)).not_to cover(4, 6) |
| 57 | }.to fail_with("expected 1..10 not to cover 4 and 6") |
| 58 | end |
| 59 | |
| 60 | it "fails if the target covers some (but not all) of the expected" do |
| 61 | expect { |
| 62 | expect((1..10)).not_to cover(5, 11) |
| 63 | }.to fail_with("expected 1..10 not to cover 5 and 11") |
| 64 | end |
| 65 | end |
| 66 | end |
| 67 | end |