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
@@ -1,55 +1,55 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "expect { ... }.to raise_error" do
|
4
4
|
it_behaves_like("an RSpec matcher", :valid_value => lambda { raise "boom" },
|
5
5
|
:invalid_value => lambda { }) do
|
6
6
|
let(:matcher) { raise_error(/boom/) }
|
7
7
|
end
|
8
8
|
|
9
9
|
it "passes if anything is raised" do
|
10
|
-
|
10
|
+
expect {raise}.to raise_error
|
11
11
|
end
|
12
12
|
|
13
13
|
it "fails if nothing is raised" do
|
14
|
-
|
15
|
-
|
16
|
-
}.
|
14
|
+
expect {
|
15
|
+
expect {}.to raise_error
|
16
|
+
}.to fail_with("expected Exception but nothing was raised")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "raise_exception aliased to raise_error" do
|
21
21
|
it "passes if anything is raised" do
|
22
|
-
|
22
|
+
expect {raise}.to raise_exception
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe "
|
26
|
+
describe "expect { ... }.to raise_error {|err| ... }" do
|
27
27
|
it "passes if there is an error" do
|
28
28
|
ran = false
|
29
|
-
|
29
|
+
expect { non_existent_method }.to raise_error {|e|
|
30
30
|
ran = true
|
31
31
|
}
|
32
|
-
ran.
|
32
|
+
expect(ran).to be_true
|
33
33
|
end
|
34
34
|
|
35
35
|
it "passes the error to the block" do
|
36
36
|
error = nil
|
37
|
-
|
37
|
+
expect { non_existent_method }.to raise_error {|e|
|
38
38
|
error = e
|
39
39
|
}
|
40
|
-
error.
|
40
|
+
expect(error).to be_kind_of(NameError)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
describe "
|
44
|
+
describe "expect { ... }.to_not raise_error" do
|
45
45
|
it "passes if nothing is raised" do
|
46
|
-
|
46
|
+
expect {}.to_not raise_error
|
47
47
|
end
|
48
48
|
|
49
49
|
it "fails if anything is raised" do
|
50
|
-
|
51
|
-
|
52
|
-
}.
|
50
|
+
expect {
|
51
|
+
expect { raise RuntimeError, "example message" }.to_not raise_error
|
52
|
+
}.to fail_with(/expected no Exception, got #<RuntimeError: example message>/)
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'includes the backtrace of the error that was raised in the error message' do
|
@@ -57,7 +57,7 @@ describe "should_not raise_error" do
|
|
57
57
|
expect { raise "boom" }.not_to raise_error
|
58
58
|
}.to raise_error { |e|
|
59
59
|
backtrace_line = "#{File.basename(__FILE__)}:#{__LINE__ - 2}"
|
60
|
-
e.message.
|
60
|
+
expect(e.message).to include("with backtrace", backtrace_line)
|
61
61
|
}
|
62
62
|
end
|
63
63
|
|
@@ -69,34 +69,34 @@ describe "should_not raise_error" do
|
|
69
69
|
expect {
|
70
70
|
expect { raise "boom" }.not_to raise_error
|
71
71
|
}.to raise_error { |e|
|
72
|
-
e.message.
|
72
|
+
expect(e.message).to include("with backtrace", "formatted-backtrace")
|
73
73
|
}
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
describe "
|
77
|
+
describe "expect { ... }.to raise_error(message)" do
|
78
78
|
it "passes if RuntimeError is raised with the right message" do
|
79
|
-
|
79
|
+
expect {raise 'blah'}.to raise_error('blah')
|
80
80
|
end
|
81
81
|
|
82
82
|
it "passes if RuntimeError is raised with a matching message" do
|
83
|
-
|
83
|
+
expect {raise 'blah'}.to raise_error(/blah/)
|
84
84
|
end
|
85
85
|
|
86
86
|
it "passes if any other error is raised with the right message" do
|
87
|
-
|
87
|
+
expect {raise NameError.new('blah')}.to raise_error('blah')
|
88
88
|
end
|
89
89
|
|
90
90
|
it "fails if RuntimeError error is raised with the wrong message" do
|
91
|
-
|
92
|
-
|
93
|
-
end.
|
91
|
+
expect do
|
92
|
+
expect {raise 'blarg'}.to raise_error('blah')
|
93
|
+
end.to fail_with(/expected Exception with \"blah\", got #<RuntimeError: blarg>/)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "fails if any other error is raised with the wrong message" do
|
97
|
-
|
98
|
-
|
99
|
-
end.
|
97
|
+
expect do
|
98
|
+
expect {raise NameError.new('blarg')}.to raise_error('blah')
|
99
|
+
end.to fail_with(/expected Exception with \"blah\", got #<NameError: blarg>/)
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'includes the backtrace of any other error in the failure message' do
|
@@ -104,215 +104,215 @@ describe "should raise_error(message)" do
|
|
104
104
|
expect { raise "boom" }.to raise_error(ArgumentError)
|
105
105
|
}.to raise_error { |e|
|
106
106
|
backtrace_line = "#{File.basename(__FILE__)}:#{__LINE__ - 2}"
|
107
|
-
e.message.
|
107
|
+
expect(e.message).to include("with backtrace", backtrace_line)
|
108
108
|
}
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
describe "
|
112
|
+
describe "expect { ... }.to_not raise_error(message)" do
|
113
113
|
it "passes if RuntimeError error is raised with the different message" do
|
114
|
-
|
114
|
+
expect {raise 'blarg'}.to_not raise_error('blah')
|
115
115
|
end
|
116
116
|
|
117
117
|
it "passes if any other error is raised with the wrong message" do
|
118
|
-
|
118
|
+
expect {raise NameError.new('blarg')}.to_not raise_error('blah')
|
119
119
|
end
|
120
120
|
|
121
121
|
it "fails if RuntimeError is raised with message" do
|
122
|
-
|
123
|
-
|
124
|
-
end.
|
122
|
+
expect do
|
123
|
+
expect {raise 'blah'}.to_not raise_error('blah')
|
124
|
+
end.to fail_with(/expected no Exception with "blah", got #<RuntimeError: blah>/)
|
125
125
|
end
|
126
126
|
|
127
127
|
it "fails if any other error is raised with message" do
|
128
|
-
|
129
|
-
|
130
|
-
end.
|
128
|
+
expect do
|
129
|
+
expect {raise NameError.new('blah')}.to_not raise_error('blah')
|
130
|
+
end.to fail_with(/expected no Exception with "blah", got #<NameError: blah>/)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
describe "
|
134
|
+
describe "expect { ... }.to raise_error(NamedError)" do
|
135
135
|
it "passes if named error is raised" do
|
136
|
-
|
136
|
+
expect { non_existent_method }.to raise_error(NameError)
|
137
137
|
end
|
138
138
|
|
139
139
|
it "fails if nothing is raised" do
|
140
|
-
|
141
|
-
|
142
|
-
}.
|
140
|
+
expect {
|
141
|
+
expect { }.to raise_error(NameError)
|
142
|
+
}.to fail_with(/expected NameError but nothing was raised/)
|
143
143
|
end
|
144
144
|
|
145
145
|
it "fails if another error is raised (NameError)" do
|
146
|
-
|
147
|
-
|
148
|
-
}.
|
146
|
+
expect {
|
147
|
+
expect { raise RuntimeError, "example message" }.to raise_error(NameError)
|
148
|
+
}.to fail_with(/expected NameError, got #<RuntimeError: example message>/)
|
149
149
|
end
|
150
150
|
|
151
151
|
it "fails if another error is raised (NameError)" do
|
152
|
-
|
153
|
-
|
154
|
-
}.
|
152
|
+
expect {
|
153
|
+
expect { load "non/existent/file" }.to raise_error(NameError)
|
154
|
+
}.to fail_with(/expected NameError, got #<LoadError/)
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
describe "
|
158
|
+
describe "expect { ... }.to_not raise_error(NamedError)" do
|
159
159
|
it "passes if nothing is raised" do
|
160
|
-
|
160
|
+
expect { }.to_not raise_error(NameError)
|
161
161
|
end
|
162
162
|
|
163
163
|
it "passes if another error is raised" do
|
164
|
-
|
164
|
+
expect { raise }.to_not raise_error(NameError)
|
165
165
|
end
|
166
166
|
|
167
167
|
it "fails if named error is raised" do
|
168
|
-
|
169
|
-
|
170
|
-
}.
|
168
|
+
expect {
|
169
|
+
expect { 1 + 'b' }.to_not raise_error(TypeError)
|
170
|
+
}.to fail_with(/expected no TypeError, got #<TypeError: String can't be/)
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
-
describe "
|
174
|
+
describe "expect { ... }.to raise_error(NamedError, error_message) with String" do
|
175
175
|
it "passes if named error is raised with same message" do
|
176
|
-
|
176
|
+
expect { raise "example message" }.to raise_error(RuntimeError, "example message")
|
177
177
|
end
|
178
178
|
|
179
179
|
it "fails if nothing is raised" do
|
180
|
-
|
181
|
-
|
182
|
-
}.
|
180
|
+
expect {
|
181
|
+
expect {}.to raise_error(RuntimeError, "example message")
|
182
|
+
}.to fail_with(/expected RuntimeError with \"example message\" but nothing was raised/)
|
183
183
|
end
|
184
184
|
|
185
185
|
it "fails if incorrect error is raised" do
|
186
|
-
|
187
|
-
|
188
|
-
}.
|
186
|
+
expect {
|
187
|
+
expect { raise RuntimeError, "example message" }.to raise_error(NameError, "example message")
|
188
|
+
}.to fail_with(/expected NameError with \"example message\", got #<RuntimeError: example message>/)
|
189
189
|
end
|
190
190
|
|
191
191
|
it "fails if correct error is raised with incorrect message" do
|
192
|
-
|
193
|
-
|
194
|
-
}.
|
192
|
+
expect {
|
193
|
+
expect { raise RuntimeError.new("not the example message") }.to raise_error(RuntimeError, "example message")
|
194
|
+
}.to fail_with(/expected RuntimeError with \"example message\", got #<RuntimeError: not the example message/)
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
|
-
describe "
|
198
|
+
describe "expect { ... }.to raise_error(NamedError, error_message) { |err| ... }" do
|
199
199
|
it "yields exception if named error is raised with same message" do
|
200
200
|
ran = false
|
201
201
|
|
202
|
-
|
202
|
+
expect {
|
203
203
|
raise "example message"
|
204
|
-
}.
|
204
|
+
}.to raise_error(RuntimeError, "example message") { |err|
|
205
205
|
ran = true
|
206
|
-
err.class.
|
207
|
-
err.message.
|
206
|
+
expect(err.class).to eq RuntimeError
|
207
|
+
expect(err.message).to eq "example message"
|
208
208
|
}
|
209
209
|
|
210
|
-
ran.
|
210
|
+
expect(ran).to be(true)
|
211
211
|
end
|
212
212
|
|
213
213
|
it "yielded block fails on it's own right" do
|
214
214
|
ran, passed = false, false
|
215
215
|
|
216
|
-
|
217
|
-
|
216
|
+
expect {
|
217
|
+
expect {
|
218
218
|
raise "example message"
|
219
|
-
}.
|
219
|
+
}.to raise_error(RuntimeError, "example message") { |err|
|
220
220
|
ran = true
|
221
|
-
5.
|
221
|
+
expect(5).to eq 4
|
222
222
|
passed = true
|
223
223
|
}
|
224
|
-
}.
|
224
|
+
}.to fail_with(/expected: 4/m)
|
225
225
|
|
226
|
-
ran.
|
227
|
-
passed.
|
226
|
+
expect(ran).to be_true
|
227
|
+
expect(passed).to be_false
|
228
228
|
end
|
229
229
|
|
230
230
|
it "does NOT yield exception if no error was thrown" do
|
231
231
|
ran = false
|
232
232
|
|
233
|
-
|
234
|
-
|
233
|
+
expect {
|
234
|
+
expect {}.to raise_error(RuntimeError, "example message") { |err|
|
235
235
|
ran = true
|
236
236
|
}
|
237
|
-
}.
|
237
|
+
}.to fail_with(/expected RuntimeError with \"example message\" but nothing was raised/)
|
238
238
|
|
239
|
-
ran.
|
239
|
+
expect(ran).to eq false
|
240
240
|
end
|
241
241
|
|
242
242
|
it "does not yield exception if error class is not matched" do
|
243
243
|
ran = false
|
244
244
|
|
245
|
-
|
246
|
-
|
245
|
+
expect {
|
246
|
+
expect {
|
247
247
|
raise "example message"
|
248
|
-
}.
|
248
|
+
}.to raise_error(SyntaxError, "example message") { |err|
|
249
249
|
ran = true
|
250
250
|
}
|
251
|
-
}.
|
251
|
+
}.to fail_with(/expected SyntaxError with \"example message\", got #<RuntimeError: example message>/)
|
252
252
|
|
253
|
-
ran.
|
253
|
+
expect(ran).to eq false
|
254
254
|
end
|
255
255
|
|
256
256
|
it "does NOT yield exception if error message is not matched" do
|
257
257
|
ran = false
|
258
258
|
|
259
|
-
|
260
|
-
|
259
|
+
expect {
|
260
|
+
expect {
|
261
261
|
raise "example message"
|
262
|
-
}.
|
262
|
+
}.to raise_error(RuntimeError, "different message") { |err|
|
263
263
|
ran = true
|
264
264
|
}
|
265
|
-
}.
|
265
|
+
}.to fail_with(/expected RuntimeError with \"different message\", got #<RuntimeError: example message>/)
|
266
266
|
|
267
|
-
ran.
|
267
|
+
expect(ran).to eq false
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
271
|
-
describe "
|
271
|
+
describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| ... }" do
|
272
272
|
it "passes if nothing is raised" do
|
273
273
|
ran = false
|
274
274
|
|
275
|
-
|
275
|
+
expect {}.to_not raise_error(RuntimeError, "example message") { |err|
|
276
276
|
ran = true
|
277
277
|
}
|
278
278
|
|
279
|
-
ran.
|
279
|
+
expect(ran).to eq false
|
280
280
|
end
|
281
281
|
|
282
282
|
it "passes if a different error is raised" do
|
283
283
|
ran = false
|
284
284
|
|
285
|
-
|
285
|
+
expect { raise }.to_not raise_error(NameError, "example message") { |err|
|
286
286
|
ran = true
|
287
287
|
}
|
288
288
|
|
289
|
-
ran.
|
289
|
+
expect(ran).to eq false
|
290
290
|
end
|
291
291
|
|
292
292
|
it "passes if same error is raised with different message" do
|
293
293
|
ran = false
|
294
294
|
|
295
|
-
|
295
|
+
expect {
|
296
296
|
raise RuntimeError.new("not the example message")
|
297
|
-
}.
|
297
|
+
}.to_not raise_error(RuntimeError, "example message") { |err|
|
298
298
|
ran = true
|
299
299
|
}
|
300
300
|
|
301
|
-
ran.
|
301
|
+
expect(ran).to eq false
|
302
302
|
end
|
303
303
|
|
304
304
|
it "fails if named error is raised with same message" do
|
305
305
|
ran = false
|
306
306
|
|
307
|
-
|
308
|
-
|
307
|
+
expect {
|
308
|
+
expect {
|
309
309
|
raise "example message"
|
310
|
-
}.
|
310
|
+
}.to_not raise_error(RuntimeError, "example message") { |err|
|
311
311
|
ran = true
|
312
312
|
}
|
313
|
-
}.
|
313
|
+
}.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
|
314
314
|
|
315
|
-
ran.
|
315
|
+
expect(ran).to eq false
|
316
316
|
end
|
317
317
|
|
318
318
|
it 'skips the error verification block when using the expect {...}.to syntax' do
|
@@ -326,70 +326,70 @@ describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
|
|
326
326
|
}
|
327
327
|
}.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
|
328
328
|
|
329
|
-
ran.
|
329
|
+
expect(ran).to eq false
|
330
330
|
end
|
331
331
|
end
|
332
332
|
|
333
|
-
describe "
|
333
|
+
describe "expect { ... }.to_not raise_error(NamedError, error_message) with String" do
|
334
334
|
it "passes if nothing is raised" do
|
335
|
-
|
335
|
+
expect {}.to_not raise_error(RuntimeError, "example message")
|
336
336
|
end
|
337
337
|
|
338
338
|
it "passes if a different error is raised" do
|
339
|
-
|
339
|
+
expect { raise }.to_not raise_error(NameError, "example message")
|
340
340
|
end
|
341
341
|
|
342
342
|
it "passes if same error is raised with different message" do
|
343
|
-
|
343
|
+
expect { raise RuntimeError.new("not the example message") }.to_not raise_error(RuntimeError, "example message")
|
344
344
|
end
|
345
345
|
|
346
346
|
it "fails if named error is raised with same message" do
|
347
|
-
|
348
|
-
|
349
|
-
}.
|
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
350
|
end
|
351
351
|
end
|
352
352
|
|
353
|
-
describe "
|
353
|
+
describe "expect { ... }.to raise_error(NamedError, error_message) with Regexp" do
|
354
354
|
it "passes if named error is raised with matching message" do
|
355
|
-
|
355
|
+
expect { raise "example message" }.to raise_error(RuntimeError, /ample mess/)
|
356
356
|
end
|
357
357
|
|
358
358
|
it "fails if nothing is raised" do
|
359
|
-
|
360
|
-
|
361
|
-
}.
|
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
362
|
end
|
363
363
|
|
364
364
|
it "fails if incorrect error is raised" do
|
365
|
-
|
366
|
-
|
367
|
-
}.
|
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
368
|
end
|
369
369
|
|
370
370
|
it "fails if correct error is raised with incorrect message" do
|
371
|
-
|
372
|
-
|
373
|
-
}.
|
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
374
|
end
|
375
375
|
end
|
376
376
|
|
377
|
-
describe "
|
377
|
+
describe "expect { ... }.to_not raise_error(NamedError, error_message) with Regexp" do
|
378
378
|
it "passes if nothing is raised" do
|
379
|
-
|
379
|
+
expect {}.to_not raise_error(RuntimeError, /ample mess/)
|
380
380
|
end
|
381
381
|
|
382
382
|
it "passes if a different error is raised" do
|
383
|
-
|
383
|
+
expect { raise }.to_not raise_error(NameError, /ample mess/)
|
384
384
|
end
|
385
385
|
|
386
386
|
it "passes if same error is raised with non-matching message" do
|
387
|
-
|
387
|
+
expect { raise RuntimeError.new("non matching message") }.to_not raise_error(RuntimeError, /ample mess/)
|
388
388
|
end
|
389
389
|
|
390
390
|
it "fails if named error is raised with matching message" do
|
391
|
-
|
392
|
-
|
393
|
-
}.
|
391
|
+
expect {
|
392
|
+
expect { raise "example message" }.to_not raise_error(RuntimeError, /ample mess/)
|
393
|
+
}.to fail_with(/expected no RuntimeError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
|
394
394
|
end
|
395
395
|
end
|