rspec-expectations 2.12.1 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +31 -0
- data/README.md +1 -1
- data/features/built_in_matchers/be.feature +6 -4
- data/features/built_in_matchers/be_within.feature +3 -1
- data/features/built_in_matchers/cover.feature +2 -0
- data/features/built_in_matchers/end_with.feature +2 -0
- data/features/built_in_matchers/equality.feature +9 -15
- data/features/built_in_matchers/exist.feature +2 -0
- data/features/built_in_matchers/expect_error.feature +14 -8
- data/features/built_in_matchers/have.feature +11 -5
- data/features/built_in_matchers/include.feature +53 -0
- data/features/built_in_matchers/match.feature +2 -0
- data/features/built_in_matchers/operators.feature +17 -11
- data/features/built_in_matchers/predicates.feature +21 -13
- data/features/built_in_matchers/respond_to.feature +7 -1
- data/features/built_in_matchers/satisfy.feature +2 -0
- data/features/built_in_matchers/start_with.feature +2 -0
- data/features/built_in_matchers/throw_symbol.feature +6 -0
- data/features/built_in_matchers/types.feature +8 -6
- data/lib/rspec/expectations/deprecation.rb +1 -1
- data/lib/rspec/expectations/differ.rb +8 -8
- data/lib/rspec/expectations/fail_with.rb +17 -3
- data/lib/rspec/expectations/syntax.rb +46 -0
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers/built_in/be.rb +7 -3
- data/lib/rspec/matchers/built_in/be_within.rb +13 -4
- data/lib/rspec/matchers/built_in/change.rb +2 -2
- data/lib/rspec/matchers/built_in/equal.rb +5 -1
- data/lib/rspec/matchers/built_in/exist.rb +1 -1
- data/lib/rspec/matchers/built_in/have.rb +8 -8
- data/lib/rspec/matchers/built_in/include.rb +19 -3
- data/lib/rspec/matchers/built_in/respond_to.rb +1 -1
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +1 -1
- data/lib/rspec/matchers/matcher.rb +4 -3
- data/lib/rspec/matchers/operator_matcher.rb +1 -1
- data/lib/rspec/matchers/pretty.rb +5 -1
- data/spec/rspec/expectations/differ_spec.rb +8 -15
- data/spec/rspec/expectations/expectation_target_spec.rb +18 -8
- data/spec/rspec/expectations/extensions/kernel_spec.rb +15 -15
- data/spec/rspec/expectations/fail_with_spec.rb +41 -16
- data/spec/rspec/expectations/handler_spec.rb +13 -13
- data/spec/rspec/expectations/syntax_spec.rb +70 -8
- data/spec/rspec/matchers/base_matcher_spec.rb +14 -12
- data/spec/rspec/matchers/be_close_spec.rb +1 -1
- data/spec/rspec/matchers/be_instance_of_spec.rb +14 -8
- data/spec/rspec/matchers/be_kind_of_spec.rb +12 -8
- data/spec/rspec/matchers/be_spec.rb +212 -148
- data/spec/rspec/matchers/be_within_spec.rb +91 -42
- data/spec/rspec/matchers/change_spec.rb +52 -38
- data/spec/rspec/matchers/configuration_spec.rb +19 -15
- data/spec/rspec/matchers/cover_spec.rb +19 -19
- data/spec/rspec/matchers/description_generation_spec.rb +86 -86
- data/spec/rspec/matchers/dsl_spec.rb +7 -7
- data/spec/rspec/matchers/eq_spec.rb +17 -11
- data/spec/rspec/matchers/eql_spec.rb +10 -10
- data/spec/rspec/matchers/equal_spec.rb +27 -9
- data/spec/rspec/matchers/exist_spec.rb +35 -21
- data/spec/rspec/matchers/has_spec.rb +33 -29
- data/spec/rspec/matchers/have_spec.rb +165 -151
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +30 -0
- data/spec/rspec/matchers/include_spec.rb +282 -124
- data/spec/rspec/matchers/match_array_spec.rb +90 -49
- data/spec/rspec/matchers/match_spec.rb +21 -21
- data/spec/rspec/matchers/matcher_spec.rb +85 -48
- data/spec/rspec/matchers/matchers_spec.rb +12 -6
- data/spec/rspec/matchers/method_missing_spec.rb +5 -1
- data/spec/rspec/matchers/operator_matcher_spec.rb +216 -237
- data/spec/rspec/matchers/raise_error_spec.rb +132 -132
- data/spec/rspec/matchers/respond_to_spec.rb +109 -112
- data/spec/rspec/matchers/satisfy_spec.rb +16 -16
- data/spec/rspec/matchers/start_with_end_with_spec.rb +36 -32
- data/spec/rspec/matchers/throw_symbol_spec.rb +24 -24
- data/spec/rspec/matchers/yield_spec.rb +7 -7
- data/spec/spec_helper.rb +46 -19
- data/spec/support/in_sub_process.rb +27 -20
- metadata +81 -83
@@ -11,17 +11,23 @@ module RSpec
|
|
11
11
|
end
|
12
12
|
|
13
13
|
context "once required" do
|
14
|
+
include TestUnitIntegrationSupport
|
15
|
+
|
14
16
|
it "includes itself in Test::Unit::TestCase" do
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
with_test_unit_loaded do
|
18
|
+
test_unit_case = Test::Unit::TestCase.allocate
|
19
|
+
sample_matchers.each do |sample_matcher|
|
20
|
+
expect(test_unit_case).to respond_to(sample_matcher)
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
25
|
it "includes itself in MiniTest::Unit::TestCase", :if => defined?(MiniTest) do
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
with_test_unit_loaded do
|
27
|
+
minitest_case = MiniTest::Unit::TestCase.allocate
|
28
|
+
sample_matchers.each do |sample_matcher|
|
29
|
+
expect(minitest_case).to respond_to(sample_matcher)
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
shared_examples_for "a well-behaved method_missing hook" do
|
4
|
+
include TestUnitIntegrationSupport
|
5
|
+
|
4
6
|
it "raises a NoMethodError (and not SystemStackError) for an undefined method" do
|
5
|
-
|
7
|
+
with_test_unit_loaded do
|
8
|
+
expect { subject.some_undefined_method }.to raise_error(NoMethodError)
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
8
12
|
|
@@ -1,244 +1,223 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
describe "operator matchers", :uses_should do
|
4
|
+
describe "should ==" do
|
5
|
+
it "delegates message to target" do
|
6
|
+
subject = "apple"
|
7
|
+
subject.should_receive(:==).with("apple").and_return(true)
|
8
|
+
subject.should == "apple"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns true on success" do
|
12
|
+
subject = "apple"
|
13
|
+
(subject.should == "apple").should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "fails when target.==(actual) returns false" do
|
17
|
+
subject = "apple"
|
18
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ==)], "orange", "apple")
|
19
|
+
subject.should == "orange"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "unsupported operators", :if => RUBY_VERSION.to_f == 1.9 do
|
24
|
+
it "raises an appropriate error for should != expected" do
|
25
|
+
expect {
|
26
|
+
"apple".should != "pear"
|
27
|
+
}.to raise_error(/does not support `should != expected`. Use `should_not == expected`/)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises an appropriate error for should_not != expected" do
|
31
|
+
expect {
|
32
|
+
"apple".should_not != "pear"
|
33
|
+
}.to raise_error(/does not support `should_not != expected`. Use `should == expected`/)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises an appropriate error for should !~ expected" do
|
37
|
+
expect {
|
38
|
+
"apple".should !~ /regex/
|
39
|
+
}.to raise_error(/does not support `should !~ expected`. Use `should_not =~ expected`/)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises an appropriate error for should_not !~ expected" do
|
43
|
+
expect {
|
44
|
+
"apple".should_not !~ /regex/
|
45
|
+
}.to raise_error(/does not support `should_not !~ expected`. Use `should =~ expected`/)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "should_not ==" do
|
50
|
+
it "delegates message to target" do
|
51
|
+
subject = "orange"
|
52
|
+
subject.should_receive(:==).with("apple").and_return(false)
|
53
|
+
subject.should_not == "apple"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns true on success" do
|
57
|
+
subject = "apple"
|
58
|
+
(subject.should_not == "orange").should be_false
|
59
|
+
end
|
60
|
+
|
61
|
+
it "fails when target.==(actual) returns false" do
|
62
|
+
subject = "apple"
|
63
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: == "apple"\n got: "apple"], "apple", "apple")
|
64
|
+
subject.should_not == "apple"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "should ===" do
|
69
|
+
it "delegates message to target" do
|
70
|
+
subject = "apple"
|
71
|
+
subject.should_receive(:===).with("apple").and_return(true)
|
72
|
+
subject.should === "apple"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "fails when target.===(actual) returns false" do
|
76
|
+
subject = "apple"
|
77
|
+
subject.should_receive(:===).with("orange").and_return(false)
|
78
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ===)], "orange", "apple")
|
79
|
+
subject.should === "orange"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "should_not ===" do
|
84
|
+
it "delegates message to target" do
|
85
|
+
subject = "orange"
|
86
|
+
subject.should_receive(:===).with("apple").and_return(false)
|
87
|
+
subject.should_not === "apple"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "fails when target.===(actual) returns false" do
|
91
|
+
subject = "apple"
|
92
|
+
subject.should_receive(:===).with("apple").and_return(true)
|
93
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: === "apple"\n got: "apple"], "apple", "apple")
|
94
|
+
subject.should_not === "apple"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "should =~" do
|
99
|
+
it "delegates message to target" do
|
100
|
+
subject = "foo"
|
101
|
+
subject.should_receive(:=~).with(/oo/).and_return(true)
|
102
|
+
subject.should =~ /oo/
|
103
|
+
end
|
104
|
+
|
105
|
+
it "fails when target.=~(actual) returns false" do
|
106
|
+
subject = "fu"
|
107
|
+
subject.should_receive(:=~).with(/oo/).and_return(false)
|
108
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: /oo/\n got: "fu" (using =~)], /oo/, "fu")
|
109
|
+
subject.should =~ /oo/
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "should_not =~" do
|
114
|
+
it "delegates message to target" do
|
115
|
+
subject = "fu"
|
116
|
+
subject.should_receive(:=~).with(/oo/).and_return(false)
|
117
|
+
subject.should_not =~ /oo/
|
118
|
+
end
|
119
|
+
|
120
|
+
it "fails when target.=~(actual) returns false" do
|
121
|
+
subject = "foo"
|
122
|
+
subject.should_receive(:=~).with(/oo/).and_return(true)
|
123
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: =~ /oo/\n got: "foo"], /oo/, "foo")
|
124
|
+
subject.should_not =~ /oo/
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "should >" do
|
129
|
+
it "passes if > passes" do
|
130
|
+
4.should > 3
|
131
|
+
end
|
132
|
+
|
133
|
+
it "fails if > fails" do
|
134
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: > 5\n got: 4], 5, 4)
|
135
|
+
4.should > 5
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "should >=" do
|
140
|
+
it "passes if actual == expected" do
|
141
|
+
4.should >= 4
|
142
|
+
end
|
143
|
+
|
144
|
+
it "passes if actual > expected" do
|
145
|
+
4.should >= 3
|
146
|
+
end
|
147
|
+
|
148
|
+
it "fails if > fails" do
|
149
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: >= 5\n got: 4], 5, 4)
|
150
|
+
4.should >= 5
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "should <" do
|
155
|
+
it "passes if < passes" do
|
156
|
+
4.should < 5
|
157
|
+
end
|
158
|
+
|
159
|
+
it "fails if > fails" do
|
160
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: < 3\n got: 4], 3, 4)
|
161
|
+
4.should < 3
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "should <=" do
|
166
|
+
it "passes if actual == expected" do
|
167
|
+
4.should <= 4
|
168
|
+
end
|
169
|
+
|
170
|
+
it "passes if actual < expected" do
|
171
|
+
4.should <= 5
|
172
|
+
end
|
173
|
+
|
174
|
+
it "fails if > fails" do
|
175
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: <= 3\n got: 4], 3, 4)
|
176
|
+
4.should <= 3
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "OperatorMatcher registry" do
|
181
|
+
let(:custom_klass) { Class.new }
|
182
|
+
let(:custom_subklass) { Class.new(custom_klass) }
|
183
|
+
|
184
|
+
after {
|
185
|
+
RSpec::Matchers::OperatorMatcher.unregister(custom_klass, "=~")
|
186
|
+
}
|
187
|
+
|
188
|
+
it "allows operator matchers to be registered for types" do
|
189
|
+
RSpec::Matchers::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
|
190
|
+
expect(RSpec::Matchers::OperatorMatcher.get(custom_klass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
|
191
|
+
end
|
192
|
+
|
193
|
+
it "considers ancestors when finding an operator matcher" do
|
194
|
+
RSpec::Matchers::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
|
195
|
+
expect(RSpec::Matchers::OperatorMatcher.get(custom_subklass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
|
196
|
+
end
|
197
|
+
|
198
|
+
it "returns nil if there is no matcher registered for a type" do
|
199
|
+
expect(RSpec::Matchers::OperatorMatcher.get(custom_klass, "=~")).to be_nil
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe RSpec::Matchers::BuiltIn::PositiveOperatorMatcher do
|
204
|
+
it "works when the target has implemented #send" do
|
205
|
+
o = Object.new
|
206
|
+
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
207
|
+
expect {
|
208
|
+
o.should == o
|
209
|
+
}.not_to raise_error
|
210
|
+
end
|
9
211
|
end
|
10
|
-
|
11
|
-
it "returns true on success" do
|
12
|
-
subject = "apple"
|
13
|
-
(subject.should == "apple").should be_true
|
14
|
-
end
|
15
|
-
|
16
|
-
it "fails when target.==(actual) returns false" do
|
17
|
-
subject = "apple"
|
18
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ==)], "orange", "apple")
|
19
|
-
subject.should == "orange"
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "unsupported operators", :if => RUBY_VERSION.to_f == 1.9 do
|
25
|
-
it "raises an appropriate error for should != expected" do
|
26
|
-
expect {
|
27
|
-
"apple".should != "pear"
|
28
|
-
}.to raise_error(/does not support `should != expected`. Use `should_not == expected`/)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "raises an appropriate error for should_not != expected" do
|
32
|
-
expect {
|
33
|
-
"apple".should_not != "pear"
|
34
|
-
}.to raise_error(/does not support `should_not != expected`. Use `should == expected`/)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "raises an appropriate error for should !~ expected" do
|
38
|
-
expect {
|
39
|
-
"apple".should !~ /regex/
|
40
|
-
}.to raise_error(/does not support `should !~ expected`. Use `should_not =~ expected`/)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "raises an appropriate error for should_not !~ expected" do
|
44
|
-
expect {
|
45
|
-
"apple".should_not !~ /regex/
|
46
|
-
}.to raise_error(/does not support `should_not !~ expected`. Use `should =~ expected`/)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "should_not ==" do
|
51
|
-
|
52
|
-
it "delegates message to target" do
|
53
|
-
subject = "orange"
|
54
|
-
subject.should_receive(:==).with("apple").and_return(false)
|
55
|
-
subject.should_not == "apple"
|
56
|
-
end
|
57
|
-
|
58
|
-
it "returns true on success" do
|
59
|
-
subject = "apple"
|
60
|
-
(subject.should_not == "orange").should be_false
|
61
|
-
end
|
62
|
-
|
63
|
-
it "fails when target.==(actual) returns false" do
|
64
|
-
subject = "apple"
|
65
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: == "apple"\n got: "apple"], "apple", "apple")
|
66
|
-
subject.should_not == "apple"
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "should ===" do
|
72
|
-
|
73
|
-
it "delegates message to target" do
|
74
|
-
subject = "apple"
|
75
|
-
subject.should_receive(:===).with("apple").and_return(true)
|
76
|
-
subject.should === "apple"
|
77
|
-
end
|
78
|
-
|
79
|
-
it "fails when target.===(actual) returns false" do
|
80
|
-
subject = "apple"
|
81
|
-
subject.should_receive(:===).with("orange").and_return(false)
|
82
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ===)], "orange", "apple")
|
83
|
-
subject.should === "orange"
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "should_not ===" do
|
89
|
-
|
90
|
-
it "delegates message to target" do
|
91
|
-
subject = "orange"
|
92
|
-
subject.should_receive(:===).with("apple").and_return(false)
|
93
|
-
subject.should_not === "apple"
|
94
|
-
end
|
95
|
-
|
96
|
-
it "fails when target.===(actual) returns false" do
|
97
|
-
subject = "apple"
|
98
|
-
subject.should_receive(:===).with("apple").and_return(true)
|
99
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: === "apple"\n got: "apple"], "apple", "apple")
|
100
|
-
subject.should_not === "apple"
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "should =~" do
|
106
|
-
|
107
|
-
it "delegates message to target" do
|
108
|
-
subject = "foo"
|
109
|
-
subject.should_receive(:=~).with(/oo/).and_return(true)
|
110
|
-
subject.should =~ /oo/
|
111
|
-
end
|
112
|
-
|
113
|
-
it "fails when target.=~(actual) returns false" do
|
114
|
-
subject = "fu"
|
115
|
-
subject.should_receive(:=~).with(/oo/).and_return(false)
|
116
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: /oo/\n got: "fu" (using =~)], /oo/, "fu")
|
117
|
-
subject.should =~ /oo/
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "should_not =~" do
|
123
|
-
|
124
|
-
it "delegates message to target" do
|
125
|
-
subject = "fu"
|
126
|
-
subject.should_receive(:=~).with(/oo/).and_return(false)
|
127
|
-
subject.should_not =~ /oo/
|
128
|
-
end
|
129
|
-
|
130
|
-
it "fails when target.=~(actual) returns false" do
|
131
|
-
subject = "foo"
|
132
|
-
subject.should_receive(:=~).with(/oo/).and_return(true)
|
133
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: =~ /oo/\n got: "foo"], /oo/, "foo")
|
134
|
-
subject.should_not =~ /oo/
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
describe "should >" do
|
140
|
-
|
141
|
-
it "passes if > passes" do
|
142
|
-
4.should > 3
|
143
|
-
end
|
144
|
-
|
145
|
-
it "fails if > fails" do
|
146
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: > 5\n got: 4], 5, 4)
|
147
|
-
4.should > 5
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "should >=" do
|
153
|
-
|
154
|
-
it "passes if actual == expected" do
|
155
|
-
4.should >= 4
|
156
|
-
end
|
157
|
-
|
158
|
-
it "passes if actual > expected" do
|
159
|
-
4.should >= 3
|
160
|
-
end
|
161
|
-
|
162
|
-
it "fails if > fails" do
|
163
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: >= 5\n got: 4], 5, 4)
|
164
|
-
4.should >= 5
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "should <" do
|
170
|
-
|
171
|
-
it "passes if < passes" do
|
172
|
-
4.should < 5
|
173
|
-
end
|
174
|
-
|
175
|
-
it "fails if > fails" do
|
176
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: < 3\n got: 4], 3, 4)
|
177
|
-
4.should < 3
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "should <=" do
|
183
|
-
|
184
|
-
it "passes if actual == expected" do
|
185
|
-
4.should <= 4
|
186
|
-
end
|
187
|
-
|
188
|
-
it "passes if actual < expected" do
|
189
|
-
4.should <= 5
|
190
|
-
end
|
191
|
-
|
192
|
-
it "fails if > fails" do
|
193
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: <= 3\n got: 4], 3, 4)
|
194
|
-
4.should <= 3
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
describe "OperatorMatcher registry" do
|
200
|
-
let(:custom_klass) { Class.new }
|
201
|
-
let(:custom_subklass) { Class.new(custom_klass) }
|
202
|
-
|
203
|
-
after {
|
204
|
-
RSpec::Matchers::OperatorMatcher.unregister(custom_klass, "=~")
|
205
|
-
}
|
206
|
-
|
207
|
-
it "allows operator matchers to be registered for types" do
|
208
|
-
RSpec::Matchers::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
|
209
|
-
expect(RSpec::Matchers::OperatorMatcher.get(custom_klass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
|
210
|
-
end
|
211
|
-
|
212
|
-
it "considers ancestors when finding an operator matcher" do
|
213
|
-
RSpec::Matchers::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
|
214
|
-
expect(RSpec::Matchers::OperatorMatcher.get(custom_subklass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
|
215
|
-
end
|
216
|
-
|
217
|
-
it "returns nil if there is no matcher registered for a type" do
|
218
|
-
expect(RSpec::Matchers::OperatorMatcher.get(custom_klass, "=~")).to be_nil
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
describe RSpec::Matchers::BuiltIn::PositiveOperatorMatcher do
|
223
212
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
213
|
+
describe RSpec::Matchers::BuiltIn::NegativeOperatorMatcher do
|
214
|
+
it "works when the target has implemented #send" do
|
215
|
+
o = Object.new
|
216
|
+
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
217
|
+
expect {
|
218
|
+
o.should_not == :foo
|
219
|
+
}.not_to raise_error
|
220
|
+
end
|
230
221
|
end
|
231
|
-
|
232
222
|
end
|
233
223
|
|
234
|
-
describe RSpec::Matchers::BuiltIn::NegativeOperatorMatcher do
|
235
|
-
|
236
|
-
it "works when the target has implemented #send" do
|
237
|
-
o = Object.new
|
238
|
-
def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
239
|
-
lambda {
|
240
|
-
o.should_not == :foo
|
241
|
-
}.should_not raise_error
|
242
|
-
end
|
243
|
-
|
244
|
-
end
|