File: cover_spec.rb

package info (click to toggle)
ruby-rspec-expectations 2.14.2-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 920 kB
  • sloc: ruby: 8,202; makefile: 4
file content (69 lines) | stat: -rw-r--r-- 2,000 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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