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.
Files changed (76) hide show
  1. data/Changelog.md +31 -0
  2. data/README.md +1 -1
  3. data/features/built_in_matchers/be.feature +6 -4
  4. data/features/built_in_matchers/be_within.feature +3 -1
  5. data/features/built_in_matchers/cover.feature +2 -0
  6. data/features/built_in_matchers/end_with.feature +2 -0
  7. data/features/built_in_matchers/equality.feature +9 -15
  8. data/features/built_in_matchers/exist.feature +2 -0
  9. data/features/built_in_matchers/expect_error.feature +14 -8
  10. data/features/built_in_matchers/have.feature +11 -5
  11. data/features/built_in_matchers/include.feature +53 -0
  12. data/features/built_in_matchers/match.feature +2 -0
  13. data/features/built_in_matchers/operators.feature +17 -11
  14. data/features/built_in_matchers/predicates.feature +21 -13
  15. data/features/built_in_matchers/respond_to.feature +7 -1
  16. data/features/built_in_matchers/satisfy.feature +2 -0
  17. data/features/built_in_matchers/start_with.feature +2 -0
  18. data/features/built_in_matchers/throw_symbol.feature +6 -0
  19. data/features/built_in_matchers/types.feature +8 -6
  20. data/lib/rspec/expectations/deprecation.rb +1 -1
  21. data/lib/rspec/expectations/differ.rb +8 -8
  22. data/lib/rspec/expectations/fail_with.rb +17 -3
  23. data/lib/rspec/expectations/syntax.rb +46 -0
  24. data/lib/rspec/expectations/version.rb +1 -1
  25. data/lib/rspec/matchers/built_in/be.rb +7 -3
  26. data/lib/rspec/matchers/built_in/be_within.rb +13 -4
  27. data/lib/rspec/matchers/built_in/change.rb +2 -2
  28. data/lib/rspec/matchers/built_in/equal.rb +5 -1
  29. data/lib/rspec/matchers/built_in/exist.rb +1 -1
  30. data/lib/rspec/matchers/built_in/have.rb +8 -8
  31. data/lib/rspec/matchers/built_in/include.rb +19 -3
  32. data/lib/rspec/matchers/built_in/respond_to.rb +1 -1
  33. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +1 -1
  34. data/lib/rspec/matchers/matcher.rb +4 -3
  35. data/lib/rspec/matchers/operator_matcher.rb +1 -1
  36. data/lib/rspec/matchers/pretty.rb +5 -1
  37. data/spec/rspec/expectations/differ_spec.rb +8 -15
  38. data/spec/rspec/expectations/expectation_target_spec.rb +18 -8
  39. data/spec/rspec/expectations/extensions/kernel_spec.rb +15 -15
  40. data/spec/rspec/expectations/fail_with_spec.rb +41 -16
  41. data/spec/rspec/expectations/handler_spec.rb +13 -13
  42. data/spec/rspec/expectations/syntax_spec.rb +70 -8
  43. data/spec/rspec/matchers/base_matcher_spec.rb +14 -12
  44. data/spec/rspec/matchers/be_close_spec.rb +1 -1
  45. data/spec/rspec/matchers/be_instance_of_spec.rb +14 -8
  46. data/spec/rspec/matchers/be_kind_of_spec.rb +12 -8
  47. data/spec/rspec/matchers/be_spec.rb +212 -148
  48. data/spec/rspec/matchers/be_within_spec.rb +91 -42
  49. data/spec/rspec/matchers/change_spec.rb +52 -38
  50. data/spec/rspec/matchers/configuration_spec.rb +19 -15
  51. data/spec/rspec/matchers/cover_spec.rb +19 -19
  52. data/spec/rspec/matchers/description_generation_spec.rb +86 -86
  53. data/spec/rspec/matchers/dsl_spec.rb +7 -7
  54. data/spec/rspec/matchers/eq_spec.rb +17 -11
  55. data/spec/rspec/matchers/eql_spec.rb +10 -10
  56. data/spec/rspec/matchers/equal_spec.rb +27 -9
  57. data/spec/rspec/matchers/exist_spec.rb +35 -21
  58. data/spec/rspec/matchers/has_spec.rb +33 -29
  59. data/spec/rspec/matchers/have_spec.rb +165 -151
  60. data/spec/rspec/matchers/include_matcher_integration_spec.rb +30 -0
  61. data/spec/rspec/matchers/include_spec.rb +282 -124
  62. data/spec/rspec/matchers/match_array_spec.rb +90 -49
  63. data/spec/rspec/matchers/match_spec.rb +21 -21
  64. data/spec/rspec/matchers/matcher_spec.rb +85 -48
  65. data/spec/rspec/matchers/matchers_spec.rb +12 -6
  66. data/spec/rspec/matchers/method_missing_spec.rb +5 -1
  67. data/spec/rspec/matchers/operator_matcher_spec.rb +216 -237
  68. data/spec/rspec/matchers/raise_error_spec.rb +132 -132
  69. data/spec/rspec/matchers/respond_to_spec.rb +109 -112
  70. data/spec/rspec/matchers/satisfy_spec.rb +16 -16
  71. data/spec/rspec/matchers/start_with_end_with_spec.rb +36 -32
  72. data/spec/rspec/matchers/throw_symbol_spec.rb +24 -24
  73. data/spec/rspec/matchers/yield_spec.rb +7 -7
  74. data/spec/spec_helper.rb +46 -19
  75. data/spec/support/in_sub_process.rb +27 -20
  76. metadata +81 -83
@@ -1,55 +1,55 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "should raise_error" do
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
- lambda {raise}.should raise_error
10
+ expect {raise}.to raise_error
11
11
  end
12
12
 
13
13
  it "fails if nothing is raised" do
14
- lambda {
15
- lambda {}.should raise_error
16
- }.should fail_with("expected Exception but nothing was raised")
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
- lambda {raise}.should raise_exception
22
+ expect {raise}.to raise_exception
23
23
  end
24
24
  end
25
25
 
26
- describe "should raise_error {|err| ... }" do
26
+ describe "expect { ... }.to raise_error {|err| ... }" do
27
27
  it "passes if there is an error" do
28
28
  ran = false
29
- lambda { non_existent_method }.should raise_error {|e|
29
+ expect { non_existent_method }.to raise_error {|e|
30
30
  ran = true
31
31
  }
32
- ran.should be_true
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
- lambda { non_existent_method }.should raise_error {|e|
37
+ expect { non_existent_method }.to raise_error {|e|
38
38
  error = e
39
39
  }
40
- error.should be_kind_of(NameError)
40
+ expect(error).to be_kind_of(NameError)
41
41
  end
42
42
  end
43
43
 
44
- describe "should_not raise_error" do
44
+ describe "expect { ... }.to_not raise_error" do
45
45
  it "passes if nothing is raised" do
46
- lambda {}.should_not raise_error
46
+ expect {}.to_not raise_error
47
47
  end
48
48
 
49
49
  it "fails if anything is raised" do
50
- lambda {
51
- lambda { raise RuntimeError, "example message" }.should_not raise_error
52
- }.should fail_with(/expected no Exception, got #<RuntimeError: example message>/)
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.should include("with backtrace", backtrace_line)
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.should include("with backtrace", "formatted-backtrace")
72
+ expect(e.message).to include("with backtrace", "formatted-backtrace")
73
73
  }
74
74
  end
75
75
  end
76
76
 
77
- describe "should raise_error(message)" do
77
+ describe "expect { ... }.to raise_error(message)" do
78
78
  it "passes if RuntimeError is raised with the right message" do
79
- lambda {raise 'blah'}.should raise_error('blah')
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
- lambda {raise 'blah'}.should raise_error(/blah/)
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
- lambda {raise NameError.new('blah')}.should raise_error('blah')
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
- lambda do
92
- lambda {raise 'blarg'}.should raise_error('blah')
93
- end.should fail_with(/expected Exception with \"blah\", got #<RuntimeError: blarg>/)
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
- lambda do
98
- lambda {raise NameError.new('blarg')}.should raise_error('blah')
99
- end.should fail_with(/expected Exception with \"blah\", got #<NameError: blarg>/)
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.should include("with backtrace", backtrace_line)
107
+ expect(e.message).to include("with backtrace", backtrace_line)
108
108
  }
109
109
  end
110
110
  end
111
111
 
112
- describe "should_not raise_error(message)" do
112
+ describe "expect { ... }.to_not raise_error(message)" do
113
113
  it "passes if RuntimeError error is raised with the different message" do
114
- lambda {raise 'blarg'}.should_not raise_error('blah')
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
- lambda {raise NameError.new('blarg')}.should_not raise_error('blah')
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
- lambda do
123
- lambda {raise 'blah'}.should_not raise_error('blah')
124
- end.should fail_with(/expected no Exception with "blah", got #<RuntimeError: blah>/)
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
- lambda do
129
- lambda {raise NameError.new('blah')}.should_not raise_error('blah')
130
- end.should fail_with(/expected no Exception with "blah", got #<NameError: blah>/)
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 "should raise_error(NamedError)" do
134
+ describe "expect { ... }.to raise_error(NamedError)" do
135
135
  it "passes if named error is raised" do
136
- lambda { non_existent_method }.should raise_error(NameError)
136
+ expect { non_existent_method }.to raise_error(NameError)
137
137
  end
138
138
 
139
139
  it "fails if nothing is raised" do
140
- lambda {
141
- lambda { }.should raise_error(NameError)
142
- }.should fail_with(/expected NameError but nothing was raised/)
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
- lambda {
147
- lambda { raise RuntimeError, "example message" }.should raise_error(NameError)
148
- }.should fail_with(/expected NameError, got #<RuntimeError: example message>/)
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
- lambda {
153
- lambda { load "non/existent/file" }.should raise_error(NameError)
154
- }.should fail_with(/expected NameError, got #<LoadError/)
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 "should_not raise_error(NamedError)" do
158
+ describe "expect { ... }.to_not raise_error(NamedError)" do
159
159
  it "passes if nothing is raised" do
160
- lambda { }.should_not raise_error(NameError)
160
+ expect { }.to_not raise_error(NameError)
161
161
  end
162
162
 
163
163
  it "passes if another error is raised" do
164
- lambda { raise }.should_not raise_error(NameError)
164
+ expect { raise }.to_not raise_error(NameError)
165
165
  end
166
166
 
167
167
  it "fails if named error is raised" do
168
- lambda {
169
- lambda { 1 + 'b' }.should_not raise_error(TypeError)
170
- }.should fail_with(/expected no TypeError, got #<TypeError: String can't be/)
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 "should raise_error(NamedError, error_message) with String" do
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
- lambda { raise "example message" }.should raise_error(RuntimeError, "example message")
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
- lambda {
181
- lambda {}.should raise_error(RuntimeError, "example message")
182
- }.should fail_with(/expected RuntimeError with \"example message\" but nothing was raised/)
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
- lambda {
187
- lambda { raise RuntimeError, "example message" }.should raise_error(NameError, "example message")
188
- }.should fail_with(/expected NameError with \"example message\", got #<RuntimeError: example message>/)
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
- lambda {
193
- lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, "example message")
194
- }.should fail_with(/expected RuntimeError with \"example message\", got #<RuntimeError: not the example message/)
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 "should raise_error(NamedError, error_message) { |err| ... }" do
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
- lambda {
202
+ expect {
203
203
  raise "example message"
204
- }.should raise_error(RuntimeError, "example message") { |err|
204
+ }.to raise_error(RuntimeError, "example message") { |err|
205
205
  ran = true
206
- err.class.should eq RuntimeError
207
- err.message.should eq "example message"
206
+ expect(err.class).to eq RuntimeError
207
+ expect(err.message).to eq "example message"
208
208
  }
209
209
 
210
- ran.should be(true)
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
- lambda {
217
- lambda {
216
+ expect {
217
+ expect {
218
218
  raise "example message"
219
- }.should raise_error(RuntimeError, "example message") { |err|
219
+ }.to raise_error(RuntimeError, "example message") { |err|
220
220
  ran = true
221
- 5.should eq 4
221
+ expect(5).to eq 4
222
222
  passed = true
223
223
  }
224
- }.should fail_with(/expected: 4/m)
224
+ }.to fail_with(/expected: 4/m)
225
225
 
226
- ran.should be_true
227
- passed.should be_false
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
- lambda {
234
- lambda {}.should raise_error(RuntimeError, "example message") { |err|
233
+ expect {
234
+ expect {}.to raise_error(RuntimeError, "example message") { |err|
235
235
  ran = true
236
236
  }
237
- }.should fail_with(/expected RuntimeError with \"example message\" but nothing was raised/)
237
+ }.to fail_with(/expected RuntimeError with \"example message\" but nothing was raised/)
238
238
 
239
- ran.should == false
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
- lambda {
246
- lambda {
245
+ expect {
246
+ expect {
247
247
  raise "example message"
248
- }.should raise_error(SyntaxError, "example message") { |err|
248
+ }.to raise_error(SyntaxError, "example message") { |err|
249
249
  ran = true
250
250
  }
251
- }.should fail_with(/expected SyntaxError with \"example message\", got #<RuntimeError: example message>/)
251
+ }.to fail_with(/expected SyntaxError with \"example message\", got #<RuntimeError: example message>/)
252
252
 
253
- ran.should == false
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
- lambda {
260
- lambda {
259
+ expect {
260
+ expect {
261
261
  raise "example message"
262
- }.should raise_error(RuntimeError, "different message") { |err|
262
+ }.to raise_error(RuntimeError, "different message") { |err|
263
263
  ran = true
264
264
  }
265
- }.should fail_with(/expected RuntimeError with \"different message\", got #<RuntimeError: example message>/)
265
+ }.to fail_with(/expected RuntimeError with \"different message\", got #<RuntimeError: example message>/)
266
266
 
267
- ran.should == false
267
+ expect(ran).to eq false
268
268
  end
269
269
  end
270
270
 
271
- describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
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
- lambda {}.should_not raise_error(RuntimeError, "example message") { |err|
275
+ expect {}.to_not raise_error(RuntimeError, "example message") { |err|
276
276
  ran = true
277
277
  }
278
278
 
279
- ran.should == false
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
- lambda { raise }.should_not raise_error(NameError, "example message") { |err|
285
+ expect { raise }.to_not raise_error(NameError, "example message") { |err|
286
286
  ran = true
287
287
  }
288
288
 
289
- ran.should == false
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
- lambda {
295
+ expect {
296
296
  raise RuntimeError.new("not the example message")
297
- }.should_not raise_error(RuntimeError, "example message") { |err|
297
+ }.to_not raise_error(RuntimeError, "example message") { |err|
298
298
  ran = true
299
299
  }
300
300
 
301
- ran.should == false
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
- lambda {
308
- lambda {
307
+ expect {
308
+ expect {
309
309
  raise "example message"
310
- }.should_not raise_error(RuntimeError, "example message") { |err|
310
+ }.to_not raise_error(RuntimeError, "example message") { |err|
311
311
  ran = true
312
312
  }
313
- }.should fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
313
+ }.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
314
314
 
315
- ran.should == false
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.should == false
329
+ expect(ran).to eq false
330
330
  end
331
331
  end
332
332
 
333
- describe "should_not raise_error(NamedError, error_message) with String" do
333
+ describe "expect { ... }.to_not raise_error(NamedError, error_message) with String" do
334
334
  it "passes if nothing is raised" do
335
- lambda {}.should_not raise_error(RuntimeError, "example message")
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
- lambda { raise }.should_not raise_error(NameError, "example message")
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
- lambda { raise RuntimeError.new("not the example message") }.should_not raise_error(RuntimeError, "example message")
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
- lambda {
348
- lambda { raise "example message" }.should_not raise_error(RuntimeError, "example message")
349
- }.should fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
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 "should raise_error(NamedError, error_message) with Regexp" do
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
- lambda { raise "example message" }.should raise_error(RuntimeError, /ample mess/)
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
- lambda {
360
- lambda {}.should raise_error(RuntimeError, /ample mess/)
361
- }.should fail_with(/expected RuntimeError with message matching \/ample mess\/ but nothing was raised/)
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
- lambda {
366
- lambda { raise RuntimeError, "example message" }.should raise_error(NameError, /ample mess/)
367
- }.should fail_with(/expected NameError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
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
- lambda {
372
- lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, /less than ample mess/)
373
- }.should fail_with(/expected RuntimeError with message matching \/less than ample mess\/, got #<RuntimeError: not the example message>/)
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 "should_not raise_error(NamedError, error_message) with Regexp" do
377
+ describe "expect { ... }.to_not raise_error(NamedError, error_message) with Regexp" do
378
378
  it "passes if nothing is raised" do
379
- lambda {}.should_not raise_error(RuntimeError, /ample mess/)
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
- lambda { raise }.should_not raise_error(NameError, /ample mess/)
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
- lambda { raise RuntimeError.new("non matching message") }.should_not raise_error(RuntimeError, /ample mess/)
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
- lambda {
392
- lambda { raise "example message" }.should_not raise_error(RuntimeError, /ample mess/)
393
- }.should fail_with(/expected no RuntimeError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
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