rspec-expectations 2.13.0 → 2.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +15 -0
  2. data/Changelog.md +204 -23
  3. data/README.md +43 -87
  4. data/features/README.md +10 -10
  5. data/features/built_in_matchers/README.md +41 -41
  6. data/features/built_in_matchers/be.feature +40 -40
  7. data/features/built_in_matchers/be_within.feature +3 -3
  8. data/features/built_in_matchers/expect_change.feature +6 -6
  9. data/features/built_in_matchers/expect_error.feature +2 -2
  10. data/features/built_in_matchers/start_with.feature +1 -1
  11. data/features/built_in_matchers/throw_symbol.feature +11 -11
  12. data/features/built_in_matchers/yield.feature +18 -3
  13. data/features/custom_matchers/define_diffable_matcher.feature +1 -1
  14. data/features/custom_matchers/define_matcher_outside_rspec.feature +6 -6
  15. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
  16. data/features/customized_message.feature +1 -1
  17. data/features/diffing.feature +1 -1
  18. data/features/step_definitions/additional_cli_steps.rb +10 -0
  19. data/features/support/env.rb +10 -1
  20. data/features/support/rubinius.rb +6 -0
  21. data/features/syntax_configuration.feature +3 -0
  22. data/features/test_frameworks/test_unit.feature +55 -17
  23. data/lib/rspec/expectations/caller_filter.rb +60 -0
  24. data/lib/rspec/{matchers → expectations}/configuration.rb +5 -3
  25. data/lib/rspec/expectations/deprecation.rb +20 -31
  26. data/lib/rspec/expectations/differ.rb +48 -9
  27. data/lib/rspec/expectations/expectation_target.rb +81 -15
  28. data/lib/rspec/expectations/extensions/object.rb +2 -12
  29. data/lib/rspec/expectations/fail_with.rb +11 -1
  30. data/lib/rspec/expectations/handler.rb +16 -7
  31. data/lib/rspec/expectations/syntax.rb +5 -7
  32. data/lib/rspec/expectations/version.rb +1 -1
  33. data/lib/rspec/expectations.rb +28 -2
  34. data/lib/rspec/matchers/be_close.rb +4 -1
  35. data/lib/rspec/matchers/built_in/base_matcher.rb +17 -10
  36. data/lib/rspec/matchers/built_in/be.rb +69 -32
  37. data/lib/rspec/matchers/built_in/be_within.rb +9 -3
  38. data/lib/rspec/matchers/built_in/change.rb +49 -3
  39. data/lib/rspec/matchers/built_in/has.rb +40 -7
  40. data/lib/rspec/matchers/built_in/have.rb +170 -5
  41. data/lib/rspec/matchers/built_in/include.rb +3 -11
  42. data/lib/rspec/matchers/built_in/match.rb +5 -0
  43. data/lib/rspec/matchers/built_in/match_array.rb +1 -1
  44. data/lib/rspec/matchers/built_in/raise_error.rb +34 -8
  45. data/lib/rspec/matchers/built_in/respond_to.rb +7 -1
  46. data/lib/rspec/matchers/built_in/satisfy.rb +7 -1
  47. data/lib/rspec/matchers/built_in/throw_symbol.rb +10 -2
  48. data/lib/rspec/matchers/built_in/yield.rb +102 -5
  49. data/lib/rspec/matchers/built_in.rb +2 -2
  50. data/lib/rspec/matchers/differentiate_block_method_types.rb +55 -0
  51. data/lib/rspec/matchers/dsl.rb +2 -1
  52. data/lib/rspec/matchers/match_aliases.rb +22 -0
  53. data/lib/rspec/matchers/matcher.rb +131 -10
  54. data/lib/rspec/matchers/operator_matcher.rb +70 -66
  55. data/lib/rspec/matchers/pretty.rb +11 -1
  56. data/lib/rspec/matchers/test_unit_integration.rb +28 -0
  57. data/lib/rspec/matchers.rb +175 -146
  58. data/lib/rspec-expectations.rb +5 -0
  59. data/spec/rspec/{matchers → expectations}/configuration_spec.rb +78 -91
  60. data/spec/rspec/expectations/differ_spec.rb +65 -6
  61. data/spec/rspec/expectations/expectation_target_spec.rb +72 -3
  62. data/spec/rspec/expectations/extensions/kernel_spec.rb +9 -5
  63. data/spec/rspec/expectations/fail_with_spec.rb +19 -0
  64. data/spec/rspec/expectations/handler_spec.rb +43 -22
  65. data/spec/rspec/expectations/syntax_spec.rb +51 -9
  66. data/spec/rspec/expectations_spec.rb +71 -0
  67. data/spec/rspec/matchers/base_matcher_spec.rb +33 -18
  68. data/spec/rspec/matchers/be_close_spec.rb +9 -6
  69. data/spec/rspec/matchers/be_spec.rb +146 -45
  70. data/spec/rspec/matchers/be_within_spec.rb +8 -0
  71. data/spec/rspec/matchers/change_spec.rb +107 -7
  72. data/spec/rspec/matchers/description_generation_spec.rb +38 -20
  73. data/spec/rspec/matchers/differentiate_block_method_types_spec.rb +39 -0
  74. data/spec/rspec/matchers/eq_spec.rb +1 -1
  75. data/spec/rspec/matchers/equal_spec.rb +26 -0
  76. data/spec/rspec/matchers/exist_spec.rb +9 -9
  77. data/spec/rspec/matchers/has_spec.rb +25 -1
  78. data/spec/rspec/matchers/have_spec.rb +411 -3
  79. data/spec/rspec/matchers/include_matcher_integration_spec.rb +2 -2
  80. data/spec/rspec/matchers/include_spec.rb +4 -4
  81. data/spec/rspec/matchers/match_array_spec.rb +1 -1
  82. data/spec/rspec/matchers/match_spec.rb +14 -1
  83. data/spec/rspec/matchers/matcher_spec.rb +213 -24
  84. data/spec/rspec/matchers/operator_matcher_spec.rb +56 -8
  85. data/spec/rspec/matchers/pretty_spec.rb +23 -0
  86. data/spec/rspec/matchers/raise_error_spec.rb +242 -102
  87. data/spec/rspec/matchers/respond_to_spec.rb +4 -4
  88. data/spec/rspec/matchers/satisfy_spec.rb +1 -1
  89. data/spec/rspec/matchers/start_with_end_with_spec.rb +2 -2
  90. data/spec/rspec/matchers/throw_symbol_spec.rb +14 -14
  91. data/spec/rspec/matchers/yield_spec.rb +81 -4
  92. data/spec/spec_helper.rb +5 -3
  93. data/spec/support/helper_methods.rb +42 -0
  94. data/spec/support/shared_examples.rb +42 -0
  95. metadata +40 -44
  96. data/spec/rspec/matchers/matchers_spec.rb +0 -37
@@ -1,5 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
+ module WrapDeprecationCallSite
4
+ def expect_deprecation_with_call_site(file, line)
5
+ actual_call_site = nil
6
+ allow(RSpec.configuration.reporter).to receive(:deprecation) do |options|
7
+ actual_call_site = options[:call_site]
8
+ end
9
+
10
+ yield
11
+
12
+ expect(actual_call_site).to match([file, line].join(':'))
13
+ end
14
+ end
15
+
3
16
  describe "expect { ... }.to raise_error" do
4
17
  it_behaves_like("an RSpec matcher", :valid_value => lambda { raise "boom" },
5
18
  :invalid_value => lambda { }) do
@@ -10,6 +23,25 @@ describe "expect { ... }.to raise_error" do
10
23
  expect {raise}.to raise_error
11
24
  end
12
25
 
26
+ it "passes if an error instance is expected" do
27
+ s = StandardError.new
28
+ expect {raise s}.to raise_error(s)
29
+ end
30
+
31
+ it "fails if a different error instance is thrown from the one that is expected" do
32
+ s = StandardError.new("Error 1")
33
+ to_raise = StandardError.new("Error 2")
34
+ expect do
35
+ expect {raise to_raise}.to raise_error(s)
36
+ end.to fail_with(Regexp.new("expected #{s.inspect}, got #{to_raise.inspect} with backtrace"))
37
+ end
38
+
39
+ it "passes if an error class is expected and an instance of that class is thrown" do
40
+ s = StandardError.new :bees
41
+
42
+ expect { raise s }.to raise_error(StandardError)
43
+ end
44
+
13
45
  it "fails if nothing is raised" do
14
46
  expect {
15
47
  expect {}.to raise_error
@@ -29,7 +61,7 @@ describe "expect { ... }.to raise_error {|err| ... }" do
29
61
  expect { non_existent_method }.to raise_error {|e|
30
62
  ran = true
31
63
  }
32
- expect(ran).to be_true
64
+ expect(ran).to be_truthy
33
65
  end
34
66
 
35
67
  it "passes the error to the block" do
@@ -41,36 +73,53 @@ describe "expect { ... }.to raise_error {|err| ... }" do
41
73
  end
42
74
  end
43
75
 
44
- describe "expect { ... }.to_not raise_error" do
45
- it "passes if nothing is raised" do
46
- expect {}.to_not raise_error
47
- end
76
+ describe "expect { ... }.not_to raise_error" do
48
77
 
49
- it "fails if anything is raised" do
50
- expect {
51
- expect { raise RuntimeError, "example message" }.to_not raise_error
52
- }.to fail_with(/expected no Exception, got #<RuntimeError: example message>/)
78
+ context "with a specific error class" do
79
+ it "is deprecated" do
80
+ RSpec.should_receive :deprecate
81
+ expect {"bees"}.not_to raise_error(RuntimeError)
82
+ end
53
83
  end
54
84
 
55
- it 'includes the backtrace of the error that was raised in the error message' do
56
- expect {
57
- expect { raise "boom" }.not_to raise_error
58
- }.to raise_error { |e|
59
- backtrace_line = "#{File.basename(__FILE__)}:#{__LINE__ - 2}"
60
- expect(e.message).to include("with backtrace", backtrace_line)
61
- }
62
- end
85
+ context "with no specific error class" do
86
+ it "is not deprecated" do
87
+ run = nil
88
+ allow(RSpec).to receive(:deprecate) { run = true }
89
+ expect {"bees"}.not_to raise_error
90
+ expect(run).to be_nil
91
+ end
63
92
 
64
- it 'formats the backtrace using the configured backtrace formatter' do
65
- RSpec::Matchers.configuration.backtrace_formatter.
66
- stub(:format_backtrace).
67
- and_return("formatted-backtrace")
93
+ it "passes if nothing is raised" do
94
+ expect {}.not_to raise_error
95
+ end
68
96
 
69
- expect {
70
- expect { raise "boom" }.not_to raise_error
71
- }.to raise_error { |e|
72
- expect(e.message).to include("with backtrace", "formatted-backtrace")
73
- }
97
+ it "fails if anything is raised" do
98
+ expect {
99
+ expect { raise RuntimeError, "example message" }.not_to raise_error
100
+ }.to fail_with(/expected no Exception, got #<RuntimeError: example message>/)
101
+ end
102
+
103
+ it 'includes the backtrace of the error that was raised in the error message' do
104
+ expect {
105
+ expect { raise "boom" }.not_to raise_error
106
+ }.to raise_error { |e|
107
+ backtrace_line = "#{File.basename(__FILE__)}:#{__LINE__ - 2}"
108
+ expect(e.message).to include("with backtrace", backtrace_line)
109
+ }
110
+ end
111
+
112
+ it 'formats the backtrace using the configured backtrace formatter' do
113
+ RSpec::Matchers.configuration.backtrace_formatter.
114
+ stub(:format_backtrace).
115
+ and_return("formatted-backtrace")
116
+
117
+ expect {
118
+ expect { raise "boom" }.not_to raise_error
119
+ }.to raise_error { |e|
120
+ expect(e.message).to include("with backtrace", "formatted-backtrace")
121
+ }
122
+ end
74
123
  end
75
124
  end
76
125
 
@@ -109,24 +158,46 @@ describe "expect { ... }.to raise_error(message)" do
109
158
  end
110
159
  end
111
160
 
112
- describe "expect { ... }.to_not raise_error(message)" do
161
+ describe "expect { ... }.not_to raise_error(message)" do
162
+ include WrapDeprecationCallSite
163
+
164
+ before do
165
+ allow(RSpec).to receive(:deprecate)
166
+ end
167
+
168
+ it "is deprecated" do
169
+ expect(RSpec).to receive(:deprecate).with(
170
+ /not_to raise_error\(message\)/,
171
+ :replacement =>"`expect { }.not_to raise_error` (with no args)"
172
+ )
173
+ expect {raise 'blarg'}.not_to raise_error('blah')
174
+ end
175
+
176
+ it 'reports the line number of the deprecated syntax' do
177
+ allow(RSpec).to receive(:deprecate).and_call_original
178
+
179
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1) do
180
+ expect {raise 'blarg'}.not_to raise_error('blah')
181
+ end
182
+ end
183
+
113
184
  it "passes if RuntimeError error is raised with the different message" do
114
- expect {raise 'blarg'}.to_not raise_error('blah')
185
+ expect {raise 'blarg'}.not_to raise_error('blah')
115
186
  end
116
187
 
117
188
  it "passes if any other error is raised with the wrong message" do
118
- expect {raise NameError.new('blarg')}.to_not raise_error('blah')
189
+ expect {raise NameError.new('blarg')}.not_to raise_error('blah')
119
190
  end
120
191
 
121
192
  it "fails if RuntimeError is raised with message" do
122
193
  expect do
123
- expect {raise 'blah'}.to_not raise_error('blah')
194
+ expect {raise 'blah'}.not_to raise_error('blah')
124
195
  end.to fail_with(/expected no Exception with "blah", got #<RuntimeError: blah>/)
125
196
  end
126
197
 
127
198
  it "fails if any other error is raised with message" do
128
199
  expect do
129
- expect {raise NameError.new('blah')}.to_not raise_error('blah')
200
+ expect {raise NameError.new('blah')}.not_to raise_error('blah')
130
201
  end.to fail_with(/expected no Exception with "blah", got #<NameError: blah>/)
131
202
  end
132
203
  end
@@ -155,18 +226,39 @@ describe "expect { ... }.to raise_error(NamedError)" do
155
226
  end
156
227
  end
157
228
 
158
- describe "expect { ... }.to_not raise_error(NamedError)" do
229
+ describe "expect { ... }.not_to raise_error(NamedError)" do
230
+ include WrapDeprecationCallSite
231
+
232
+ before do
233
+ allow(RSpec).to receive(:deprecate)
234
+ end
235
+
236
+ it "is deprecated" do
237
+ expect(RSpec).to receive(:deprecate).with(
238
+ /not_to raise_error\(SpecificErrorClass\)/,
239
+ :replacement =>"`expect { }.not_to raise_error` (with no args)"
240
+ )
241
+ expect { }.not_to raise_error(NameError)
242
+ end
243
+
244
+ it 'reports the line number of the deprecated syntax' do
245
+ allow(RSpec).to receive(:deprecate).and_call_original
246
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1) do
247
+ expect { }.not_to raise_error(NameError)
248
+ end
249
+ end
250
+
159
251
  it "passes if nothing is raised" do
160
- expect { }.to_not raise_error(NameError)
252
+ expect { }.not_to raise_error(NameError)
161
253
  end
162
254
 
163
255
  it "passes if another error is raised" do
164
- expect { raise }.to_not raise_error(NameError)
256
+ expect { raise }.not_to raise_error(NameError)
165
257
  end
166
258
 
167
259
  it "fails if named error is raised" do
168
260
  expect {
169
- expect { 1 + 'b' }.to_not raise_error(TypeError)
261
+ expect { 1 + 'b' }.not_to raise_error(TypeError)
170
262
  }.to fail_with(/expected no TypeError, got #<TypeError: String can't be/)
171
263
  end
172
264
  end
@@ -195,6 +287,100 @@ describe "expect { ... }.to raise_error(NamedError, error_message) with String"
195
287
  end
196
288
  end
197
289
 
290
+ describe "expect { ... }.not_to raise_error(NamedError, error_message) with String" do
291
+ include WrapDeprecationCallSite
292
+
293
+ before do
294
+ allow(RSpec).to receive(:deprecate)
295
+ end
296
+
297
+ it "is deprecated" do
298
+ expect(RSpec).to receive(:deprecate).with(
299
+ /not_to raise_error\(SpecificErrorClass, message\)/,
300
+ :replacement =>"`expect { }.not_to raise_error` (with no args)"
301
+ )
302
+ expect {}.not_to raise_error(RuntimeError, "example message")
303
+ end
304
+
305
+ it 'reports the line number of the deprecated syntax' do
306
+ allow(RSpec).to receive(:deprecate).and_call_original
307
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1) do
308
+ expect {}.not_to raise_error(RuntimeError, "example message")
309
+ end
310
+ end
311
+
312
+ it "passes if nothing is raised" do
313
+ expect {}.not_to raise_error(RuntimeError, "example message")
314
+ end
315
+
316
+ it "passes if a different error is raised" do
317
+ expect { raise }.not_to raise_error(NameError, "example message")
318
+ end
319
+
320
+ it "passes if same error is raised with different message" do
321
+ expect { raise RuntimeError.new("not the example message") }.not_to raise_error(RuntimeError, "example message")
322
+ end
323
+
324
+ it "fails if named error is raised with same message" do
325
+ expect {
326
+ expect { raise "example message" }.not_to raise_error(RuntimeError, "example message")
327
+ }.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
328
+ end
329
+ end
330
+
331
+ describe "expect { ... }.to raise_error(NamedError, error_message) with Regexp" do
332
+ it "passes if named error is raised with matching message" do
333
+ expect { raise "example message" }.to raise_error(RuntimeError, /ample mess/)
334
+ end
335
+
336
+ it "fails if nothing is raised" do
337
+ expect {
338
+ expect {}.to raise_error(RuntimeError, /ample mess/)
339
+ }.to fail_with(/expected RuntimeError with message matching \/ample mess\/ but nothing was raised/)
340
+ end
341
+
342
+ it "fails if incorrect error is raised" do
343
+ expect {
344
+ expect { raise RuntimeError, "example message" }.to raise_error(NameError, /ample mess/)
345
+ }.to fail_with(/expected NameError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
346
+ end
347
+
348
+ it "fails if correct error is raised with incorrect message" do
349
+ expect {
350
+ expect { raise RuntimeError.new("not the example message") }.to raise_error(RuntimeError, /less than ample mess/)
351
+ }.to fail_with(/expected RuntimeError with message matching \/less than ample mess\/, got #<RuntimeError: not the example message>/)
352
+ end
353
+ end
354
+
355
+ describe "expect { ... }.not_to raise_error(NamedError, error_message) with Regexp" do
356
+ before do
357
+ allow(RSpec).to receive(:deprecate)
358
+ end
359
+
360
+ it "is deprecated" do
361
+ expect(RSpec).to receive(:deprecate)
362
+ expect {}.not_to raise_error(RuntimeError, /ample mess/)
363
+ end
364
+
365
+ it "passes if nothing is raised" do
366
+ expect {}.not_to raise_error(RuntimeError, /ample mess/)
367
+ end
368
+
369
+ it "passes if a different error is raised" do
370
+ expect { raise }.not_to raise_error(NameError, /ample mess/)
371
+ end
372
+
373
+ it "passes if same error is raised with non-matching message" do
374
+ expect { raise RuntimeError.new("non matching message") }.not_to raise_error(RuntimeError, /ample mess/)
375
+ end
376
+
377
+ it "fails if named error is raised with matching message" do
378
+ expect {
379
+ expect { raise "example message" }.not_to raise_error(RuntimeError, /ample mess/)
380
+ }.to fail_with(/expected no RuntimeError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
381
+ end
382
+ end
383
+
198
384
  describe "expect { ... }.to raise_error(NamedError, error_message) { |err| ... }" do
199
385
  it "yields exception if named error is raised with same message" do
200
386
  ran = false
@@ -223,8 +409,8 @@ describe "expect { ... }.to raise_error(NamedError, error_message) { |err| ... }
223
409
  }
224
410
  }.to fail_with(/expected: 4/m)
225
411
 
226
- expect(ran).to be_true
227
- expect(passed).to be_false
412
+ expect(ran).to be_truthy
413
+ expect(passed).to be_falsey
228
414
  end
229
415
 
230
416
  it "does NOT yield exception if no error was thrown" do
@@ -268,11 +454,20 @@ describe "expect { ... }.to raise_error(NamedError, error_message) { |err| ... }
268
454
  end
269
455
  end
270
456
 
271
- describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| ... }" do
457
+ describe "expect { ... }.not_to raise_error(NamedError, error_message) { |err| ... }" do
458
+ before do
459
+ allow(RSpec).to receive(:deprecate)
460
+ end
461
+
462
+ it "is deprecated" do
463
+ expect(RSpec).to receive(:deprecate)
464
+ expect {}.not_to raise_error(RuntimeError, "example message") { |err| }
465
+ end
466
+
272
467
  it "passes if nothing is raised" do
273
468
  ran = false
274
469
 
275
- expect {}.to_not raise_error(RuntimeError, "example message") { |err|
470
+ expect {}.not_to raise_error(RuntimeError, "example message") { |err|
276
471
  ran = true
277
472
  }
278
473
 
@@ -282,7 +477,7 @@ describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| .
282
477
  it "passes if a different error is raised" do
283
478
  ran = false
284
479
 
285
- expect { raise }.to_not raise_error(NameError, "example message") { |err|
480
+ expect { raise }.not_to raise_error(NameError, "example message") { |err|
286
481
  ran = true
287
482
  }
288
483
 
@@ -294,7 +489,7 @@ describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| .
294
489
 
295
490
  expect {
296
491
  raise RuntimeError.new("not the example message")
297
- }.to_not raise_error(RuntimeError, "example message") { |err|
492
+ }.not_to raise_error(RuntimeError, "example message") { |err|
298
493
  ran = true
299
494
  }
300
495
 
@@ -307,7 +502,7 @@ describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| .
307
502
  expect {
308
503
  expect {
309
504
  raise "example message"
310
- }.to_not raise_error(RuntimeError, "example message") { |err|
505
+ }.not_to raise_error(RuntimeError, "example message") { |err|
311
506
  ran = true
312
507
  }
313
508
  }.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
@@ -330,66 +525,11 @@ describe "expect { ... }.to_not raise_error(NamedError, error_message) { |err| .
330
525
  end
331
526
  end
332
527
 
333
- describe "expect { ... }.to_not raise_error(NamedError, error_message) with String" do
334
- it "passes if nothing is raised" do
335
- expect {}.to_not raise_error(RuntimeError, "example message")
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
528
+ describe "misuse of raise_error, with (), not {}" do
529
+ it "fails with warning" do
530
+ ::Kernel.should_receive(:warn).with(/`raise_error` was called with non-proc object 1\.7/)
391
531
  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>/)
532
+ expect(Math.sqrt(3)).to raise_error
533
+ }.to fail_with(/nothing was raised/)
394
534
  end
395
535
  end
@@ -148,7 +148,7 @@ describe "expect(...).to respond_to(:sym).with(2).arguments" do
148
148
  end
149
149
  end
150
150
 
151
- describe "expect(...).to_not respond_to(:sym)" do
151
+ describe "expect(...).not_to respond_to(:sym)" do
152
152
  it "passes if target does not respond to :sym" do
153
153
  expect(Object.new).not_to respond_to(:some_method)
154
154
  end
@@ -160,7 +160,7 @@ describe "expect(...).to_not respond_to(:sym)" do
160
160
  end
161
161
  end
162
162
 
163
- describe "expect(...).to_not respond_to(:sym).with(1).argument" do
163
+ describe "expect(...).not_to respond_to(:sym).with(1).argument" do
164
164
  it "fails if target responds to :sym with 1 arg" do
165
165
  obj = Object.new
166
166
  def obj.foo(arg); end
@@ -209,7 +209,7 @@ describe "expect(...).to_not respond_to(:sym).with(1).argument" do
209
209
  end
210
210
  end
211
211
 
212
- describe "expect(...).to_not respond_to(message1, message2)" do
212
+ describe "expect(...).not_to respond_to(message1, message2)" do
213
213
  it "passes if target does not respond to either message1 or message2" do
214
214
  expect(Object.new).not_to respond_to(:some_method, :some_other_method)
215
215
  end
@@ -233,7 +233,7 @@ describe "expect(...).to_not respond_to(message1, message2)" do
233
233
  end
234
234
  end
235
235
 
236
- describe "expect(...).to_not respond_to(:sym).with(2).arguments" do
236
+ describe "expect(...).not_to respond_to(:sym).with(2).arguments" do
237
237
  it "fails if target responds to :sym with 2 args" do
238
238
  obj = Object.new
239
239
  def obj.foo(a1, a2); end
@@ -28,7 +28,7 @@ describe "expect(...).to satisfy { block }" do
28
28
  end
29
29
  end
30
30
 
31
- describe "expect(...).to_not satisfy { block }" do
31
+ describe "expect(...).not_to satisfy { block }" do
32
32
  it "passes if block returns false" do
33
33
  expect(false).not_to satisfy { |val| val }
34
34
  expect(false).not_to satisfy do |val|
@@ -56,7 +56,7 @@ describe "expect(...).to start_with" do
56
56
  end
57
57
  end
58
58
 
59
- describe "expect(...).to_not start_with" do
59
+ describe "expect(...).not_to start_with" do
60
60
  context "with a string" do
61
61
  it "passes if it does not match the start of the actual string" do
62
62
  expect("this string").not_to start_with "that str"
@@ -149,7 +149,7 @@ describe "expect(...).to end_with" do
149
149
 
150
150
  end
151
151
 
152
- describe "expect(...).to_not end_with" do
152
+ describe "expect(...).not_to end_with" do
153
153
  context "with a sting" do
154
154
  it "passes if it does not match the end of the actual string" do
155
155
  expect("this string").not_to end_with "stringy"
@@ -11,13 +11,13 @@ module RSpec::Matchers::BuiltIn
11
11
  before(:each) { @matcher = throw_symbol }
12
12
 
13
13
  it "matches if any Symbol is thrown" do
14
- expect(@matcher.matches?(lambda{ throw :sym })).to be_true
14
+ expect(@matcher.matches?(lambda{ throw :sym })).to be_truthy
15
15
  end
16
16
  it "matches if any Symbol is thrown with an arg" do
17
- expect(@matcher.matches?(lambda{ throw :sym, "argument" })).to be_true
17
+ expect(@matcher.matches?(lambda{ throw :sym, "argument" })).to be_truthy
18
18
  end
19
19
  it "does not match if no Symbol is thrown" do
20
- expect(@matcher.matches?(lambda{ })).to be_false
20
+ expect(@matcher.matches?(lambda{ })).to be_falsey
21
21
  end
22
22
  it "provides a failure message" do
23
23
  @matcher.matches?(lambda{})
@@ -33,16 +33,16 @@ module RSpec::Matchers::BuiltIn
33
33
  before(:each) { @matcher = throw_symbol(:sym) }
34
34
 
35
35
  it "matches if correct Symbol is thrown" do
36
- expect(@matcher.matches?(lambda{ throw :sym })).to be_true
36
+ expect(@matcher.matches?(lambda{ throw :sym })).to be_truthy
37
37
  end
38
38
  it "matches if correct Symbol is thrown with an arg" do
39
- expect(@matcher.matches?(lambda{ throw :sym, "argument" })).to be_true
39
+ expect(@matcher.matches?(lambda{ throw :sym, "argument" })).to be_truthy
40
40
  end
41
41
  it "does not match if no Symbol is thrown" do
42
- expect(@matcher.matches?(lambda{ })).to be_false
42
+ expect(@matcher.matches?(lambda{ })).to be_falsey
43
43
  end
44
44
  it "does not match if correct Symbol is thrown" do
45
- expect(@matcher.matches?(lambda{ throw :other_sym })).to be_false
45
+ expect(@matcher.matches?(lambda{ throw :other_sym })).to be_falsey
46
46
  end
47
47
  it "provides a failure message when no Symbol is thrown" do
48
48
  @matcher.matches?(lambda{})
@@ -58,7 +58,7 @@ module RSpec::Matchers::BuiltIn
58
58
  end
59
59
  it "only matches NameErrors raised by uncaught throws" do
60
60
  expect {
61
- expect(@matcher.matches?(lambda{ sym })).to be_false
61
+ expect(@matcher.matches?(lambda{ sym })).to be_falsey
62
62
  }.to raise_error(NameError)
63
63
  end
64
64
  end
@@ -67,19 +67,19 @@ module RSpec::Matchers::BuiltIn
67
67
  before(:each) { @matcher = throw_symbol(:sym, "a") }
68
68
 
69
69
  it "matches if correct Symbol and args are thrown" do
70
- expect(@matcher.matches?(lambda{ throw :sym, "a" })).to be_true
70
+ expect(@matcher.matches?(lambda{ throw :sym, "a" })).to be_truthy
71
71
  end
72
72
  it "does not match if nothing is thrown" do
73
- expect(@matcher.matches?(lambda{ })).to be_false
73
+ expect(@matcher.matches?(lambda{ })).to be_falsey
74
74
  end
75
75
  it "does not match if other Symbol is thrown" do
76
- expect(@matcher.matches?(lambda{ throw :other_sym, "a" })).to be_false
76
+ expect(@matcher.matches?(lambda{ throw :other_sym, "a" })).to be_falsey
77
77
  end
78
78
  it "does not match if no arg is thrown" do
79
- expect(@matcher.matches?(lambda{ throw :sym })).to be_false
79
+ expect(@matcher.matches?(lambda{ throw :sym })).to be_falsey
80
80
  end
81
81
  it "does not match if wrong arg is thrown" do
82
- expect(@matcher.matches?(lambda{ throw :sym, "b" })).to be_false
82
+ expect(@matcher.matches?(lambda{ throw :sym, "b" })).to be_falsey
83
83
  end
84
84
  it "provides a failure message when no Symbol is thrown" do
85
85
  @matcher.matches?(lambda{})
@@ -103,7 +103,7 @@ module RSpec::Matchers::BuiltIn
103
103
  end
104
104
  it "only matches NameErrors raised by uncaught throws" do
105
105
  expect {
106
- expect(@matcher.matches?(lambda{ sym })).to be_false
106
+ expect(@matcher.matches?(lambda{ sym })).to be_falsey
107
107
  }.to raise_error(NameError)
108
108
  end
109
109
  it "raises other errors" do