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.
- checksums.yaml +15 -0
- data/Changelog.md +204 -23
- data/README.md +43 -87
- data/features/README.md +10 -10
- data/features/built_in_matchers/README.md +41 -41
- data/features/built_in_matchers/be.feature +40 -40
- 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/diffing.feature +1 -1
- data/features/step_definitions/additional_cli_steps.rb +10 -0
- data/features/support/env.rb +10 -1
- data/features/support/rubinius.rb +6 -0
- data/features/syntax_configuration.feature +3 -0
- data/features/test_frameworks/test_unit.feature +55 -17
- data/lib/rspec/expectations/caller_filter.rb +60 -0
- data/lib/rspec/{matchers → expectations}/configuration.rb +5 -3
- data/lib/rspec/expectations/deprecation.rb +20 -31
- data/lib/rspec/expectations/differ.rb +48 -9
- data/lib/rspec/expectations/expectation_target.rb +81 -15
- data/lib/rspec/expectations/extensions/object.rb +2 -12
- data/lib/rspec/expectations/fail_with.rb +11 -1
- data/lib/rspec/expectations/handler.rb +16 -7
- data/lib/rspec/expectations/syntax.rb +5 -7
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +28 -2
- data/lib/rspec/matchers/be_close.rb +4 -1
- data/lib/rspec/matchers/built_in/base_matcher.rb +17 -10
- data/lib/rspec/matchers/built_in/be.rb +69 -32
- data/lib/rspec/matchers/built_in/be_within.rb +9 -3
- data/lib/rspec/matchers/built_in/change.rb +49 -3
- data/lib/rspec/matchers/built_in/has.rb +40 -7
- data/lib/rspec/matchers/built_in/have.rb +170 -5
- data/lib/rspec/matchers/built_in/include.rb +3 -11
- data/lib/rspec/matchers/built_in/match.rb +5 -0
- data/lib/rspec/matchers/built_in/match_array.rb +1 -1
- data/lib/rspec/matchers/built_in/raise_error.rb +34 -8
- data/lib/rspec/matchers/built_in/respond_to.rb +7 -1
- data/lib/rspec/matchers/built_in/satisfy.rb +7 -1
- data/lib/rspec/matchers/built_in/throw_symbol.rb +10 -2
- data/lib/rspec/matchers/built_in/yield.rb +102 -5
- data/lib/rspec/matchers/built_in.rb +2 -2
- data/lib/rspec/matchers/differentiate_block_method_types.rb +55 -0
- data/lib/rspec/matchers/dsl.rb +2 -1
- data/lib/rspec/matchers/match_aliases.rb +22 -0
- data/lib/rspec/matchers/matcher.rb +131 -10
- data/lib/rspec/matchers/operator_matcher.rb +70 -66
- data/lib/rspec/matchers/pretty.rb +11 -1
- data/lib/rspec/matchers/test_unit_integration.rb +28 -0
- data/lib/rspec/matchers.rb +175 -146
- data/lib/rspec-expectations.rb +5 -0
- data/spec/rspec/{matchers → expectations}/configuration_spec.rb +78 -91
- data/spec/rspec/expectations/differ_spec.rb +65 -6
- data/spec/rspec/expectations/expectation_target_spec.rb +72 -3
- data/spec/rspec/expectations/extensions/kernel_spec.rb +9 -5
- data/spec/rspec/expectations/fail_with_spec.rb +19 -0
- data/spec/rspec/expectations/handler_spec.rb +43 -22
- data/spec/rspec/expectations/syntax_spec.rb +51 -9
- data/spec/rspec/expectations_spec.rb +71 -0
- data/spec/rspec/matchers/base_matcher_spec.rb +33 -18
- data/spec/rspec/matchers/be_close_spec.rb +9 -6
- data/spec/rspec/matchers/be_spec.rb +146 -45
- data/spec/rspec/matchers/be_within_spec.rb +8 -0
- data/spec/rspec/matchers/change_spec.rb +107 -7
- data/spec/rspec/matchers/description_generation_spec.rb +38 -20
- data/spec/rspec/matchers/differentiate_block_method_types_spec.rb +39 -0
- data/spec/rspec/matchers/eq_spec.rb +1 -1
- data/spec/rspec/matchers/equal_spec.rb +26 -0
- data/spec/rspec/matchers/exist_spec.rb +9 -9
- data/spec/rspec/matchers/has_spec.rb +25 -1
- data/spec/rspec/matchers/have_spec.rb +411 -3
- 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 +14 -1
- data/spec/rspec/matchers/matcher_spec.rb +213 -24
- data/spec/rspec/matchers/operator_matcher_spec.rb +56 -8
- data/spec/rspec/matchers/pretty_spec.rb +23 -0
- data/spec/rspec/matchers/raise_error_spec.rb +242 -102
- 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/throw_symbol_spec.rb +14 -14
- data/spec/rspec/matchers/yield_spec.rb +81 -4
- data/spec/spec_helper.rb +5 -3
- data/spec/support/helper_methods.rb +42 -0
- data/spec/support/shared_examples.rb +42 -0
- metadata +40 -44
- 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
|
|
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 { ... }.
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
expect(
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
and_return("formatted-backtrace")
|
|
93
|
+
it "passes if nothing is raised" do
|
|
94
|
+
expect {}.not_to raise_error
|
|
95
|
+
end
|
|
68
96
|
|
|
69
|
-
|
|
70
|
-
expect {
|
|
71
|
-
|
|
72
|
-
|
|
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 { ... }.
|
|
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'}.
|
|
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')}.
|
|
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'}.
|
|
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')}.
|
|
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 { ... }.
|
|
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 { }.
|
|
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 }.
|
|
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' }.
|
|
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
|
|
227
|
-
expect(passed).to
|
|
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 { ... }.
|
|
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 {}.
|
|
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 }.
|
|
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
|
-
}.
|
|
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
|
-
}.
|
|
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 "
|
|
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
|
|
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
|
|
393
|
-
}.to fail_with(/
|
|
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(...).
|
|
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(...).
|
|
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(...).
|
|
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(...).
|
|
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(...).
|
|
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(...).
|
|
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(...).
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|