rspec-expectations 2.13.0 → 2.14.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +34 -0
- data/README.md +43 -87
- data/features/README.md +8 -9
- data/features/built_in_matchers/README.md +41 -41
- data/features/built_in_matchers/be_within.feature +3 -3
- data/features/built_in_matchers/expect_change.feature +6 -6
- data/features/built_in_matchers/expect_error.feature +2 -2
- data/features/built_in_matchers/start_with.feature +1 -1
- data/features/built_in_matchers/throw_symbol.feature +11 -11
- data/features/built_in_matchers/yield.feature +18 -3
- data/features/custom_matchers/define_diffable_matcher.feature +1 -1
- data/features/custom_matchers/define_matcher_outside_rspec.feature +6 -6
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
- data/features/customized_message.feature +1 -1
- data/features/support/env.rb +10 -1
- data/features/syntax_configuration.feature +3 -0
- data/features/test_frameworks/test_unit.feature +15 -17
- data/lib/rspec/expectations.rb +1 -1
- data/lib/rspec/expectations/deprecation.rb +12 -33
- data/lib/rspec/expectations/differ.rb +25 -7
- data/lib/rspec/expectations/expectation_target.rb +7 -8
- data/lib/rspec/expectations/extensions/object.rb +2 -12
- data/lib/rspec/expectations/fail_with.rb +11 -1
- data/lib/rspec/expectations/handler.rb +11 -6
- data/lib/rspec/expectations/syntax.rb +2 -2
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +134 -144
- data/lib/rspec/matchers/be_close.rb +1 -1
- data/lib/rspec/matchers/built_in/be_within.rb +1 -1
- data/lib/rspec/matchers/built_in/have.rb +20 -4
- data/lib/rspec/matchers/built_in/raise_error.rb +23 -7
- data/lib/rspec/matchers/built_in/yield.rb +78 -3
- data/lib/rspec/matchers/operator_matcher.rb +1 -1
- data/lib/rspec/matchers/test_unit_integration.rb +11 -0
- data/spec/rspec/expectations/differ_spec.rb +27 -5
- data/spec/rspec/expectations/expectation_target_spec.rb +10 -3
- data/spec/rspec/expectations/extensions/kernel_spec.rb +5 -5
- data/spec/rspec/expectations/fail_with_spec.rb +19 -0
- data/spec/rspec/expectations/handler_spec.rb +42 -21
- data/spec/rspec/expectations/syntax_spec.rb +45 -3
- data/spec/rspec/matchers/be_close_spec.rb +6 -6
- data/spec/rspec/matchers/be_spec.rb +36 -36
- data/spec/rspec/matchers/be_within_spec.rb +4 -0
- data/spec/rspec/matchers/change_spec.rb +6 -6
- data/spec/rspec/matchers/configuration_spec.rb +57 -89
- data/spec/rspec/matchers/description_generation_spec.rb +1 -1
- data/spec/rspec/matchers/exist_spec.rb +9 -9
- data/spec/rspec/matchers/has_spec.rb +1 -1
- data/spec/rspec/matchers/have_spec.rb +12 -2
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +2 -2
- data/spec/rspec/matchers/include_spec.rb +4 -4
- data/spec/rspec/matchers/match_array_spec.rb +1 -1
- data/spec/rspec/matchers/match_spec.rb +1 -1
- data/spec/rspec/matchers/raise_error_spec.rb +189 -99
- data/spec/rspec/matchers/respond_to_spec.rb +4 -4
- data/spec/rspec/matchers/satisfy_spec.rb +1 -1
- data/spec/rspec/matchers/start_with_end_with_spec.rb +2 -2
- data/spec/rspec/matchers/yield_spec.rb +81 -4
- data/spec/spec_helper.rb +1 -1
- metadata +10 -12
@@ -171,6 +171,6 @@ describe "a Matcher with no description" do
|
|
171
171
|
|
172
172
|
it "provides a helpful message when used in a string-less example block" do
|
173
173
|
expect(5).to matcher
|
174
|
-
expect(RSpec::Matchers.generated_description).to match
|
174
|
+
expect(RSpec::Matchers.generated_description).to match(/When you call.*description method/m)
|
175
175
|
end
|
176
176
|
end
|
@@ -8,7 +8,7 @@ describe "exist matcher" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
context "when the object does not respond to #exist? or #exists?" do
|
11
|
-
subject {
|
11
|
+
subject { double }
|
12
12
|
|
13
13
|
[:to, :not_to].each do |expect_method|
|
14
14
|
describe "expect(...).#{expect_method} exist" do
|
@@ -25,12 +25,12 @@ describe "exist matcher" do
|
|
25
25
|
context "when the object responds to ##{predicate}" do
|
26
26
|
describe "expect(...).to exist" do
|
27
27
|
it "passes if #{predicate}" do
|
28
|
-
expect(
|
28
|
+
expect(double(predicate => true)).to exist
|
29
29
|
end
|
30
30
|
|
31
31
|
it "fails if not #{predicate}" do
|
32
32
|
expect {
|
33
|
-
expect(
|
33
|
+
expect(double(predicate => false)).to exist
|
34
34
|
}.to fail_with(/expected .* to exist/)
|
35
35
|
end
|
36
36
|
|
@@ -51,12 +51,12 @@ describe "exist matcher" do
|
|
51
51
|
|
52
52
|
describe "expect(...).not_to exist" do
|
53
53
|
it "passes if not #{predicate}" do
|
54
|
-
expect(
|
54
|
+
expect(double(predicate => false)).not_to exist
|
55
55
|
end
|
56
56
|
|
57
57
|
it "fails if #{predicate}" do
|
58
58
|
expect {
|
59
|
-
expect(
|
59
|
+
expect(double(predicate => true)).not_to exist
|
60
60
|
}.to fail_with(/expected .* not to exist/)
|
61
61
|
end
|
62
62
|
end
|
@@ -65,7 +65,7 @@ describe "exist matcher" do
|
|
65
65
|
|
66
66
|
context "when the object responds to #exist? and #exists?" do
|
67
67
|
context "when they both return falsey values" do
|
68
|
-
subject {
|
68
|
+
subject { double(:exist? => false, :exists? => nil) }
|
69
69
|
|
70
70
|
describe "expect(...).not_to exist" do
|
71
71
|
it "passes" do
|
@@ -83,7 +83,7 @@ describe "exist matcher" do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
context "when they both return truthy values" do
|
86
|
-
subject {
|
86
|
+
subject { double(:exist? => true, :exists? => "something true") }
|
87
87
|
|
88
88
|
describe "expect(...).not_to exist" do
|
89
89
|
it "fails" do
|
@@ -101,7 +101,7 @@ describe "exist matcher" do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
context "when they return values with different truthiness" do
|
104
|
-
subject {
|
104
|
+
subject { double(:exist? => true, :exists? => false) }
|
105
105
|
|
106
106
|
[:to, :not_to].each do |expect_method|
|
107
107
|
describe "expect(...).#{expect_method} exist" do
|
@@ -116,7 +116,7 @@ describe "exist matcher" do
|
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'passes any provided arguments to the call to #exist?' do
|
119
|
-
object =
|
119
|
+
object = double
|
120
120
|
object.should_receive(:exist?).with(:foo, :bar) { true }
|
121
121
|
|
122
122
|
expect(object).to exist(:foo, :bar)
|
@@ -326,13 +326,13 @@ EOF
|
|
326
326
|
|
327
327
|
describe "have(n).items(args, block)" do
|
328
328
|
it "passes args to target" do
|
329
|
-
target =
|
329
|
+
target = double("target")
|
330
330
|
target.should_receive(:items).with("arg1","arg2").and_return([1,2,3])
|
331
331
|
expect(target).to have(3).items("arg1","arg2")
|
332
332
|
end
|
333
333
|
|
334
334
|
it "passes block to target" do
|
335
|
-
target =
|
335
|
+
target = double("target")
|
336
336
|
block = lambda { 5 }
|
337
337
|
target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
|
338
338
|
expect(target).to have(3).items("arg1","arg2", block)
|
@@ -402,6 +402,16 @@ EOF
|
|
402
402
|
end
|
403
403
|
end
|
404
404
|
|
405
|
+
if RUBY_VERSION >= '2.0'
|
406
|
+
describe RSpec::Matchers::BuiltIn::Have, "for an Enumerator whose size is nil but count is supplied" do
|
407
|
+
let(:enumerator) { %w[a b c d].to_enum(:each) }
|
408
|
+
|
409
|
+
it 'works fine' do
|
410
|
+
expect(enumerator).to have(4).items
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
405
415
|
describe RSpec::Matchers::BuiltIn::Have do
|
406
416
|
it "has method_missing as private" do
|
407
417
|
expect(described_class.private_instance_methods).to include_method(:method_missing)
|
@@ -22,8 +22,8 @@ module RSpec
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "works with be_[some predicate]" do
|
25
|
-
expect([
|
26
|
-
expect([
|
25
|
+
expect([double("actual", :happy? => true)]).to include( be_happy )
|
26
|
+
expect([double("actual", :happy? => false)]).not_to include( be_happy )
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -137,7 +137,7 @@ describe "#include matcher" do
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
describe "expect(...).
|
140
|
+
describe "expect(...).not_to include(expected)" do
|
141
141
|
context "for a string target" do
|
142
142
|
it "passes if target does not include expected" do
|
143
143
|
expect("abc").not_to include("d")
|
@@ -188,7 +188,7 @@ describe "#include matcher" do
|
|
188
188
|
|
189
189
|
end
|
190
190
|
|
191
|
-
describe "expect(...).
|
191
|
+
describe "expect(...).not_to include(with, multiple, args)" do
|
192
192
|
context "for a string target" do
|
193
193
|
it "passes if the target does not include any of the expected" do
|
194
194
|
expect("abc").not_to include("d", "e", "f")
|
@@ -280,7 +280,7 @@ describe "#include matcher" do
|
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
283
|
-
describe "expect(...).
|
283
|
+
describe "expect(...).not_to include(:key => value)" do
|
284
284
|
context 'for a hash target' do
|
285
285
|
it "fails if target includes the key/value pair" do
|
286
286
|
expect {
|
@@ -364,7 +364,7 @@ describe "#include matcher" do
|
|
364
364
|
end
|
365
365
|
end
|
366
366
|
|
367
|
-
describe "expect(...).
|
367
|
+
describe "expect(...).not_to include(:key1 => value1, :key2 => value2)" do
|
368
368
|
context 'for a hash target' do
|
369
369
|
it "fails if target includes the key/value pairs" do
|
370
370
|
expect {
|
@@ -156,7 +156,7 @@ MESSAGE
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
describe "expect(...).
|
159
|
+
describe "expect(...).not_to match_array [:with, :multiple, :args]" do
|
160
160
|
it "is not supported" do
|
161
161
|
expect {
|
162
162
|
expect([1,2,3]).not_to match_array [1,2,3]
|
@@ -32,7 +32,7 @@ describe "expect(...).to match(expected)" do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe "expect(...).
|
35
|
+
describe "expect(...).not_to match(expected)" do
|
36
36
|
it "passes when target (String) matches does not match (Regexp)" do
|
37
37
|
expect("string").not_to match(/rings/)
|
38
38
|
end
|
@@ -10,6 +10,25 @@ describe "expect { ... }.to raise_error" do
|
|
10
10
|
expect {raise}.to raise_error
|
11
11
|
end
|
12
12
|
|
13
|
+
it "passes if an error instance is expected" do
|
14
|
+
s = StandardError.new
|
15
|
+
expect {raise s}.to raise_error(s)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "fails if a different error instance is thrown from the one that is expected" do
|
19
|
+
s = StandardError.new :bees
|
20
|
+
to_raise = StandardError.new(:faces)
|
21
|
+
expect do
|
22
|
+
expect {raise to_raise}.to raise_error(s)
|
23
|
+
end.to fail_with(Regexp.new("expected #{s.inspect}, got #{to_raise.inspect} with backtrace"))
|
24
|
+
end
|
25
|
+
|
26
|
+
it "passes if an error class is expected and an instance of that class is thrown" do
|
27
|
+
s = StandardError.new :bees
|
28
|
+
|
29
|
+
expect { raise s }.to raise_error(StandardError)
|
30
|
+
end
|
31
|
+
|
13
32
|
it "fails if nothing is raised" do
|
14
33
|
expect {
|
15
34
|
expect {}.to raise_error
|
@@ -41,36 +60,53 @@ describe "expect { ... }.to raise_error {|err| ... }" do
|
|
41
60
|
end
|
42
61
|
end
|
43
62
|
|
44
|
-
describe "expect { ... }.
|
45
|
-
it "passes if nothing is raised" do
|
46
|
-
expect {}.to_not raise_error
|
47
|
-
end
|
63
|
+
describe "expect { ... }.not_to raise_error" do
|
48
64
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
65
|
+
context "with a specific error class" do
|
66
|
+
it "is deprecated" do
|
67
|
+
RSpec.should_receive :deprecate
|
68
|
+
expect {"bees"}.not_to raise_error(RuntimeError)
|
69
|
+
end
|
53
70
|
end
|
54
71
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
expect(
|
61
|
-
|
62
|
-
end
|
72
|
+
context "with no specific error class" do
|
73
|
+
it "is not deprecated" do
|
74
|
+
run = nil
|
75
|
+
allow(RSpec).to receive(:deprecate) { run = true }
|
76
|
+
expect {"bees"}.not_to raise_error
|
77
|
+
expect(run).to be_nil
|
78
|
+
end
|
63
79
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
and_return("formatted-backtrace")
|
80
|
+
it "passes if nothing is raised" do
|
81
|
+
expect {}.not_to raise_error
|
82
|
+
end
|
68
83
|
|
69
|
-
|
70
|
-
expect {
|
71
|
-
|
72
|
-
|
73
|
-
|
84
|
+
it "fails if anything is raised" do
|
85
|
+
expect {
|
86
|
+
expect { raise RuntimeError, "example message" }.not_to raise_error
|
87
|
+
}.to fail_with(/expected no Exception, got #<RuntimeError: example message>/)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'includes the backtrace of the error that was raised in the error message' do
|
91
|
+
expect {
|
92
|
+
expect { raise "boom" }.not_to raise_error
|
93
|
+
}.to raise_error { |e|
|
94
|
+
backtrace_line = "#{File.basename(__FILE__)}:#{__LINE__ - 2}"
|
95
|
+
expect(e.message).to include("with backtrace", backtrace_line)
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'formats the backtrace using the configured backtrace formatter' do
|
100
|
+
RSpec::Matchers.configuration.backtrace_formatter.
|
101
|
+
stub(:format_backtrace).
|
102
|
+
and_return("formatted-backtrace")
|
103
|
+
|
104
|
+
expect {
|
105
|
+
expect { raise "boom" }.not_to raise_error
|
106
|
+
}.to raise_error { |e|
|
107
|
+
expect(e.message).to include("with backtrace", "formatted-backtrace")
|
108
|
+
}
|
109
|
+
end
|
74
110
|
end
|
75
111
|
end
|
76
112
|
|
@@ -109,24 +145,33 @@ describe "expect { ... }.to raise_error(message)" do
|
|
109
145
|
end
|
110
146
|
end
|
111
147
|
|
112
|
-
describe "expect { ... }.
|
148
|
+
describe "expect { ... }.not_to raise_error(message)" do
|
149
|
+
before do
|
150
|
+
allow(RSpec).to receive(:deprecate)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "is deprecated" do
|
154
|
+
expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(message\)/, :replacement =>"`expect { }.not_to raise_error()`")
|
155
|
+
expect {raise 'blarg'}.not_to raise_error('blah')
|
156
|
+
end
|
157
|
+
|
113
158
|
it "passes if RuntimeError error is raised with the different message" do
|
114
|
-
expect {raise 'blarg'}.
|
159
|
+
expect {raise 'blarg'}.not_to raise_error('blah')
|
115
160
|
end
|
116
161
|
|
117
162
|
it "passes if any other error is raised with the wrong message" do
|
118
|
-
expect {raise NameError.new('blarg')}.
|
163
|
+
expect {raise NameError.new('blarg')}.not_to raise_error('blah')
|
119
164
|
end
|
120
165
|
|
121
166
|
it "fails if RuntimeError is raised with message" do
|
122
167
|
expect do
|
123
|
-
expect {raise 'blah'}.
|
168
|
+
expect {raise 'blah'}.not_to raise_error('blah')
|
124
169
|
end.to fail_with(/expected no Exception with "blah", got #<RuntimeError: blah>/)
|
125
170
|
end
|
126
171
|
|
127
172
|
it "fails if any other error is raised with message" do
|
128
173
|
expect do
|
129
|
-
expect {raise NameError.new('blah')}.
|
174
|
+
expect {raise NameError.new('blah')}.not_to raise_error('blah')
|
130
175
|
end.to fail_with(/expected no Exception with "blah", got #<NameError: blah>/)
|
131
176
|
end
|
132
177
|
end
|
@@ -155,18 +200,27 @@ describe "expect { ... }.to raise_error(NamedError)" do
|
|
155
200
|
end
|
156
201
|
end
|
157
202
|
|
158
|
-
describe "expect { ... }.
|
203
|
+
describe "expect { ... }.not_to raise_error(NamedError)" do
|
204
|
+
before do
|
205
|
+
allow(RSpec).to receive(:deprecate)
|
206
|
+
end
|
207
|
+
|
208
|
+
it "is deprecated" do
|
209
|
+
expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(SpecificErrorClass\)/, :replacement => "`expect { }.not_to raise_error()`")
|
210
|
+
expect { }.not_to raise_error(NameError)
|
211
|
+
end
|
212
|
+
|
159
213
|
it "passes if nothing is raised" do
|
160
|
-
expect { }.
|
214
|
+
expect { }.not_to raise_error(NameError)
|
161
215
|
end
|
162
216
|
|
163
217
|
it "passes if another error is raised" do
|
164
|
-
expect { raise }.
|
218
|
+
expect { raise }.not_to raise_error(NameError)
|
165
219
|
end
|
166
220
|
|
167
221
|
it "fails if named error is raised" do
|
168
222
|
expect {
|
169
|
-
expect { 1 + 'b' }.
|
223
|
+
expect { 1 + 'b' }.not_to raise_error(TypeError)
|
170
224
|
}.to fail_with(/expected no TypeError, got #<TypeError: String can't be/)
|
171
225
|
end
|
172
226
|
end
|
@@ -195,6 +249,88 @@ describe "expect { ... }.to raise_error(NamedError, error_message) with String"
|
|
195
249
|
end
|
196
250
|
end
|
197
251
|
|
252
|
+
describe "expect { ... }.not_to raise_error(NamedError, error_message) with String" do
|
253
|
+
before do
|
254
|
+
allow(RSpec).to receive(:deprecate)
|
255
|
+
end
|
256
|
+
|
257
|
+
it "is deprecated" do
|
258
|
+
expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(SpecificErrorClass, message\)/, :replacement =>"`expect { }.not_to raise_error()`")
|
259
|
+
expect {}.not_to raise_error(RuntimeError, "example message")
|
260
|
+
end
|
261
|
+
|
262
|
+
it "passes if nothing is raised" do
|
263
|
+
expect {}.not_to raise_error(RuntimeError, "example message")
|
264
|
+
end
|
265
|
+
|
266
|
+
it "passes if a different error is raised" do
|
267
|
+
expect { raise }.not_to raise_error(NameError, "example message")
|
268
|
+
end
|
269
|
+
|
270
|
+
it "passes if same error is raised with different message" do
|
271
|
+
expect { raise RuntimeError.new("not the example message") }.not_to raise_error(RuntimeError, "example message")
|
272
|
+
end
|
273
|
+
|
274
|
+
it "fails if named error is raised with same message" do
|
275
|
+
expect {
|
276
|
+
expect { raise "example message" }.not_to raise_error(RuntimeError, "example message")
|
277
|
+
}.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe "expect { ... }.to raise_error(NamedError, error_message) with Regexp" do
|
282
|
+
it "passes if named error is raised with matching message" do
|
283
|
+
expect { raise "example message" }.to raise_error(RuntimeError, /ample mess/)
|
284
|
+
end
|
285
|
+
|
286
|
+
it "fails if nothing is raised" do
|
287
|
+
expect {
|
288
|
+
expect {}.to raise_error(RuntimeError, /ample mess/)
|
289
|
+
}.to fail_with(/expected RuntimeError with message matching \/ample mess\/ but nothing was raised/)
|
290
|
+
end
|
291
|
+
|
292
|
+
it "fails if incorrect error is raised" do
|
293
|
+
expect {
|
294
|
+
expect { raise RuntimeError, "example message" }.to raise_error(NameError, /ample mess/)
|
295
|
+
}.to fail_with(/expected NameError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
|
296
|
+
end
|
297
|
+
|
298
|
+
it "fails if correct error is raised with incorrect message" do
|
299
|
+
expect {
|
300
|
+
expect { raise RuntimeError.new("not the example message") }.to raise_error(RuntimeError, /less than ample mess/)
|
301
|
+
}.to fail_with(/expected RuntimeError with message matching \/less than ample mess\/, got #<RuntimeError: not the example message>/)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
describe "expect { ... }.not_to raise_error(NamedError, error_message) with Regexp" do
|
306
|
+
before do
|
307
|
+
allow(RSpec).to receive(:deprecate)
|
308
|
+
end
|
309
|
+
|
310
|
+
it "is deprecated" do
|
311
|
+
expect(RSpec).to receive(:deprecate)
|
312
|
+
expect {}.not_to raise_error(RuntimeError, /ample mess/)
|
313
|
+
end
|
314
|
+
|
315
|
+
it "passes if nothing is raised" do
|
316
|
+
expect {}.not_to raise_error(RuntimeError, /ample mess/)
|
317
|
+
end
|
318
|
+
|
319
|
+
it "passes if a different error is raised" do
|
320
|
+
expect { raise }.not_to raise_error(NameError, /ample mess/)
|
321
|
+
end
|
322
|
+
|
323
|
+
it "passes if same error is raised with non-matching message" do
|
324
|
+
expect { raise RuntimeError.new("non matching message") }.not_to raise_error(RuntimeError, /ample mess/)
|
325
|
+
end
|
326
|
+
|
327
|
+
it "fails if named error is raised with matching message" do
|
328
|
+
expect {
|
329
|
+
expect { raise "example message" }.not_to raise_error(RuntimeError, /ample mess/)
|
330
|
+
}.to fail_with(/expected no RuntimeError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
198
334
|
describe "expect { ... }.to raise_error(NamedError, error_message) { |err| ... }" do
|
199
335
|
it "yields exception if named error is raised with same message" do
|
200
336
|
ran = false
|
@@ -268,11 +404,20 @@ describe "expect { ... }.to raise_error(NamedError, error_message) { |err| ... }
|
|
268
404
|
end
|
269
405
|
end
|
270
406
|
|
271
|
-
describe "expect { ... }.
|
407
|
+
describe "expect { ... }.not_to raise_error(NamedError, error_message) { |err| ... }" do
|
408
|
+
before do
|
409
|
+
allow(RSpec).to receive(:deprecate)
|
410
|
+
end
|
411
|
+
|
412
|
+
it "is deprecated" do
|
413
|
+
expect(RSpec).to receive(:deprecate)
|
414
|
+
expect {}.not_to raise_error(RuntimeError, "example message") { |err| }
|
415
|
+
end
|
416
|
+
|
272
417
|
it "passes if nothing is raised" do
|
273
418
|
ran = false
|
274
419
|
|
275
|
-
expect {}.
|
420
|
+
expect {}.not_to raise_error(RuntimeError, "example message") { |err|
|
276
421
|
ran = true
|
277
422
|
}
|
278
423
|
|
@@ -282,7 +427,7 @@ describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| .
|
|
282
427
|
it "passes if a different error is raised" do
|
283
428
|
ran = false
|
284
429
|
|
285
|
-
expect { raise }.
|
430
|
+
expect { raise }.not_to raise_error(NameError, "example message") { |err|
|
286
431
|
ran = true
|
287
432
|
}
|
288
433
|
|
@@ -294,7 +439,7 @@ describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| .
|
|
294
439
|
|
295
440
|
expect {
|
296
441
|
raise RuntimeError.new("not the example message")
|
297
|
-
}.
|
442
|
+
}.not_to raise_error(RuntimeError, "example message") { |err|
|
298
443
|
ran = true
|
299
444
|
}
|
300
445
|
|
@@ -307,7 +452,7 @@ describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| .
|
|
307
452
|
expect {
|
308
453
|
expect {
|
309
454
|
raise "example message"
|
310
|
-
}.
|
455
|
+
}.not_to raise_error(RuntimeError, "example message") { |err|
|
311
456
|
ran = true
|
312
457
|
}
|
313
458
|
}.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
|
@@ -330,66 +475,11 @@ describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| .
|
|
330
475
|
end
|
331
476
|
end
|
332
477
|
|
333
|
-
describe "
|
334
|
-
it "
|
335
|
-
|
336
|
-
end
|
337
|
-
|
338
|
-
it "passes if a different error is raised" do
|
339
|
-
expect { raise }.to_not raise_error(NameError, "example message")
|
340
|
-
end
|
341
|
-
|
342
|
-
it "passes if same error is raised with different message" do
|
343
|
-
expect { raise RuntimeError.new("not the example message") }.to_not raise_error(RuntimeError, "example message")
|
344
|
-
end
|
345
|
-
|
346
|
-
it "fails if named error is raised with same message" do
|
347
|
-
expect {
|
348
|
-
expect { raise "example message" }.to_not raise_error(RuntimeError, "example message")
|
349
|
-
}.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
describe "expect { ... }.to raise_error(NamedError, error_message) with Regexp" do
|
354
|
-
it "passes if named error is raised with matching message" do
|
355
|
-
expect { raise "example message" }.to raise_error(RuntimeError, /ample mess/)
|
356
|
-
end
|
357
|
-
|
358
|
-
it "fails if nothing is raised" do
|
359
|
-
expect {
|
360
|
-
expect {}.to raise_error(RuntimeError, /ample mess/)
|
361
|
-
}.to fail_with(/expected RuntimeError with message matching \/ample mess\/ but nothing was raised/)
|
362
|
-
end
|
363
|
-
|
364
|
-
it "fails if incorrect error is raised" do
|
365
|
-
expect {
|
366
|
-
expect { raise RuntimeError, "example message" }.to raise_error(NameError, /ample mess/)
|
367
|
-
}.to fail_with(/expected NameError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
|
368
|
-
end
|
369
|
-
|
370
|
-
it "fails if correct error is raised with incorrect message" do
|
371
|
-
expect {
|
372
|
-
expect { raise RuntimeError.new("not the example message") }.to raise_error(RuntimeError, /less than ample mess/)
|
373
|
-
}.to fail_with(/expected RuntimeError with message matching \/less than ample mess\/, got #<RuntimeError: not the example message>/)
|
374
|
-
end
|
375
|
-
end
|
376
|
-
|
377
|
-
describe "expect { ... }.to_not raise_error(NamedError, error_message) with Regexp" do
|
378
|
-
it "passes if nothing is raised" do
|
379
|
-
expect {}.to_not raise_error(RuntimeError, /ample mess/)
|
380
|
-
end
|
381
|
-
|
382
|
-
it "passes if a different error is raised" do
|
383
|
-
expect { raise }.to_not raise_error(NameError, /ample mess/)
|
384
|
-
end
|
385
|
-
|
386
|
-
it "passes if same error is raised with non-matching message" do
|
387
|
-
expect { raise RuntimeError.new("non matching message") }.to_not raise_error(RuntimeError, /ample mess/)
|
388
|
-
end
|
389
|
-
|
390
|
-
it "fails if named error is raised with matching message" do
|
478
|
+
describe "misuse of raise_error, with (), not {}" do
|
479
|
+
it "fails with warning" do
|
480
|
+
::Kernel.should_receive(:warn).with(/`raise_error` was called with non-proc object 1\.7/)
|
391
481
|
expect {
|
392
|
-
expect
|
393
|
-
}.to fail_with(/
|
482
|
+
expect(Math.sqrt(3)).to raise_error
|
483
|
+
}.to fail_with(/nothing was raised/)
|
394
484
|
end
|
395
485
|
end
|