File: cover.feature

package info (click to toggle)
ruby-rspec 3.13.0c0e0m0s1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,856 kB
  • sloc: ruby: 70,868; sh: 1,423; makefile: 99
file content (47 lines) | stat: -rw-r--r-- 1,666 bytes parent folder | download
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
@ruby-1.9
Feature: `cover` matcher

  Use the `cover` matcher to specify that a range covers one or more
  expected objects. This works on any object that responds to `#cover?`
  (such as a `Range`):

  ```ruby
    expect(1..10).to cover(5)
    expect(1..10).to cover(4, 6)
    expect(1..10).not_to cover(11)
  ```

  Scenario: Range usage
    Given a file named "range_cover_matcher_spec.rb" with:
      """ruby
      RSpec.describe (1..10) do
        it { is_expected.to cover(4) }
        it { is_expected.to cover(6) }
        it { is_expected.to cover(8) }
        it { is_expected.to cover(4, 6) }
        it { is_expected.to cover(4, 6, 8) }
        it { is_expected.not_to cover(11) }
        it { is_expected.not_to cover(11, 12) }

        # deliberate failures
        it { is_expected.to cover(11) }
        it { is_expected.not_to cover(4) }
        it { is_expected.not_to cover(6) }
        it { is_expected.not_to cover(8) }
        it { is_expected.not_to cover(4, 6, 8) }

        # both of these should fail since it covers 5 but not 11
        it { is_expected.to cover(5, 11) }
        it { is_expected.not_to cover(5, 11) }
      end
      """
    When I run `rspec range_cover_matcher_spec.rb`
    Then the output should contain all of these:
      | 14 examples, 7 failures                 |
      | expected 1..10 to cover 11              |
      | expected 1..10 not to cover 4           |
      | expected 1..10 not to cover 6           |
      | expected 1..10 not to cover 8           |
      | expected 1..10 not to cover 4, 6, and 8 |
      | expected 1..10 to cover 5 and 11        |
      | expected 1..10 not to cover 5 and 11    |