/usr/share/doc/ruby-rspec-expectations/features/built_in_matchers/comparisons.feature is in ruby-rspec-expectations 3.5.0c3e0m0s0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | Feature: Comparison matchers
RSpec provides a number of matchers that are based on Ruby's built-in operators. These
can be used for generalized comparison of values. E.g.
```ruby
expect(9).to be > 6
expect(3).to be <= 3
expect(1).to be < 6
expect('a').to be < 'b'
```
Scenario: numeric operator matchers
Given a file named "numeric_operator_matchers_spec.rb" with:
"""ruby
RSpec.describe 18 do
it { is_expected.to be < 20 }
it { is_expected.to be > 15 }
it { is_expected.to be <= 19 }
it { is_expected.to be >= 17 }
# deliberate failures
it { is_expected.to be < 15 }
it { is_expected.to be > 20 }
it { is_expected.to be <= 17 }
it { is_expected.to be >= 19 }
it { is_expected.to be < 'a' }
end
RSpec.describe 'a' do
it { is_expected.to be < 'b' }
# deliberate failures
it { is_expected.to be < 18 }
end
"""
When I run `rspec numeric_operator_matchers_spec.rb`
Then the output should contain "11 examples, 6 failures"
And the output should contain:
"""
Failure/Error: it { is_expected.to be < 15 }
expected: < 15
got: 18
"""
And the output should contain:
"""
Failure/Error: it { is_expected.to be > 20 }
expected: > 20
got: 18
"""
And the output should contain:
"""
Failure/Error: it { is_expected.to be <= 17 }
expected: <= 17
got: 18
"""
And the output should contain:
"""
Failure/Error: it { is_expected.to be >= 19 }
expected: >= 19
got: 18
"""
And the output should contain:
"""
Failure/Error: it { is_expected.to be < 'a' }
expected: < "a"
got: 18
"""
And the output should contain:
"""
Failure/Error: it { is_expected.to be < 18 }
expected: < 18
got: "a"
"""
Scenario: string operator matchers
Given a file named "string_operator_matchers_spec.rb" with:
"""ruby
RSpec.describe "Strawberry" do
it { is_expected.to be < "Tomato" }
it { is_expected.to be > "Apple" }
it { is_expected.to be <= "Turnip" }
it { is_expected.to be >= "Banana" }
# deliberate failures
it { is_expected.to be < "Cranberry" }
it { is_expected.to be > "Zuchini" }
it { is_expected.to be <= "Potato" }
it { is_expected.to be >= "Tomato" }
end
"""
When I run `rspec string_operator_matchers_spec.rb`
Then the output should contain "8 examples, 4 failures"
And the output should contain:
"""
Failure/Error: it { is_expected.to be < "Cranberry" }
expected: < "Cranberry"
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { is_expected.to be > "Zuchini" }
expected: > "Zuchini"
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { is_expected.to be <= "Potato" }
expected: <= "Potato"
got: "Strawberry"
"""
And the output should contain:
"""
Failure/Error: it { is_expected.to be >= "Tomato" }
expected: >= "Tomato"
got: "Strawberry"
"""
|