rspec-expectations 2.14.5 → 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 -7
- data/Changelog.md +114 -31
- data/features/README.md +2 -1
- data/features/built_in_matchers/be.feature +40 -40
- data/features/step_definitions/additional_cli_steps.rb +10 -0
- data/features/test_frameworks/test_unit.feature +40 -0
- data/lib/rspec/expectations/caller_filter.rb +60 -0
- data/lib/rspec/{matchers → expectations}/configuration.rb +5 -3
- data/lib/rspec/expectations/deprecation.rb +11 -15
- data/lib/rspec/expectations/expectation_target.rb +75 -8
- data/lib/rspec/expectations/handler.rb +5 -1
- data/lib/rspec/expectations/syntax.rb +3 -5
- data/lib/rspec/expectations/version.rb +1 -2
- data/lib/rspec/expectations.rb +1 -1
- data/lib/rspec/matchers/be_close.rb +4 -1
- data/lib/rspec/matchers/built_in/base_matcher.rb +10 -5
- data/lib/rspec/matchers/built_in/be.rb +38 -9
- data/lib/rspec/matchers/built_in/be_within.rb +8 -2
- data/lib/rspec/matchers/built_in/change.rb +39 -1
- data/lib/rspec/matchers/built_in/has.rb +40 -7
- data/lib/rspec/matchers/built_in/have.rb +151 -2
- data/lib/rspec/matchers/built_in/include.rb +1 -1
- data/lib/rspec/matchers/built_in/match_array.rb +1 -1
- data/lib/rspec/matchers/built_in/raise_error.rb +7 -1
- 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 +25 -3
- 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 -70
- data/lib/rspec/matchers/pretty.rb +4 -0
- data/lib/rspec/matchers/test_unit_integration.rb +22 -5
- data/lib/rspec/matchers.rb +41 -7
- data/lib/rspec-expectations.rb +5 -0
- data/spec/rspec/{matchers → expectations}/configuration_spec.rb +21 -2
- data/spec/rspec/expectations/expectation_target_spec.rb +62 -0
- data/spec/rspec/expectations/extensions/kernel_spec.rb +4 -0
- data/spec/rspec/expectations/handler_spec.rb +1 -1
- data/spec/rspec/expectations/syntax_spec.rb +6 -6
- data/spec/rspec/expectations_spec.rb +22 -1
- data/spec/rspec/matchers/base_matcher_spec.rb +15 -21
- data/spec/rspec/matchers/be_close_spec.rb +4 -1
- data/spec/rspec/matchers/be_spec.rb +105 -10
- data/spec/rspec/matchers/change_spec.rb +76 -1
- data/spec/rspec/matchers/description_generation_spec.rb +22 -18
- 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/has_spec.rb +24 -0
- data/spec/rspec/matchers/have_spec.rb +399 -1
- data/spec/rspec/matchers/matcher_spec.rb +213 -24
- data/spec/rspec/matchers/operator_matcher_spec.rb +28 -9
- data/spec/rspec/matchers/pretty_spec.rb +23 -0
- data/spec/rspec/matchers/raise_error_spec.rb +3 -3
- data/spec/rspec/matchers/throw_symbol_spec.rb +14 -14
- data/spec/spec_helper.rb +4 -2
- data/spec/support/helper_methods.rb +42 -0
- data/spec/support/shared_examples.rb +42 -0
- metadata +85 -64
- data/spec/rspec/matchers/matchers_spec.rb +0 -37
|
@@ -33,8 +33,8 @@ module RSpec::Matchers::DSL
|
|
|
33
33
|
m1 = example_matcher(1)
|
|
34
34
|
m2 = example_matcher(2)
|
|
35
35
|
|
|
36
|
-
expect(m1.matches?(1)).to
|
|
37
|
-
expect(m2.matches?(2)).to
|
|
36
|
+
expect(m1.matches?(1)).to be_truthy
|
|
37
|
+
expect(m2.matches?(2)).to be_truthy
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
context "with an included module" do
|
|
@@ -66,6 +66,29 @@ module RSpec::Matchers::DSL
|
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
+
context "matching blocks" do
|
|
70
|
+
it 'warns when matching blocks by default' do
|
|
71
|
+
matcher = RSpec::Matchers::DSL::Matcher.new(:not_supporting_blocks) do
|
|
72
|
+
match { true }
|
|
73
|
+
end.for_expected
|
|
74
|
+
|
|
75
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 2, /block expectation/)
|
|
76
|
+
expect(3).to matcher
|
|
77
|
+
expect { 3 }.to matcher
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'does not when if it declares `supports_block_expectations`' do
|
|
81
|
+
matcher = RSpec::Matchers::DSL::Matcher.new(:supporting_blocks) do
|
|
82
|
+
match { true }
|
|
83
|
+
supports_block_expectations
|
|
84
|
+
end.for_expected
|
|
85
|
+
|
|
86
|
+
expect_no_deprecation
|
|
87
|
+
expect(3).to matcher
|
|
88
|
+
expect { 3 }.to matcher
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
69
92
|
context "without overrides" do
|
|
70
93
|
before(:each) do
|
|
71
94
|
@matcher = RSpec::Matchers::DSL::Matcher.new(:be_a_multiple_of) do |multiple|
|
|
@@ -104,13 +127,13 @@ module RSpec::Matchers::DSL
|
|
|
104
127
|
end
|
|
105
128
|
|
|
106
129
|
it "invokes the match_for_should block for #matches?" do
|
|
107
|
-
expect(matcher.matches?(77)).to
|
|
108
|
-
expect(matcher.matches?(18)).to
|
|
130
|
+
expect(matcher.matches?(77)).to be_truthy
|
|
131
|
+
expect(matcher.matches?(18)).to be_falsey
|
|
109
132
|
end
|
|
110
133
|
|
|
111
134
|
it "invokes the match_for_should_not block for #does_not_match?" do
|
|
112
|
-
expect(matcher.does_not_match?(77)).to
|
|
113
|
-
expect(matcher.does_not_match?(18)).to
|
|
135
|
+
expect(matcher.does_not_match?(77)).to be_falsey
|
|
136
|
+
expect(matcher.does_not_match?(18)).to be_truthy
|
|
114
137
|
end
|
|
115
138
|
|
|
116
139
|
it "provides a default failure message for #should_not" do
|
|
@@ -138,6 +161,19 @@ module RSpec::Matchers::DSL
|
|
|
138
161
|
end
|
|
139
162
|
|
|
140
163
|
it "provides expected" do
|
|
164
|
+
expect_no_deprecation
|
|
165
|
+
matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}.for_expected('expected', 'strings')
|
|
166
|
+
expect(matcher.expected).to eq %w[expected strings]
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "provides expected as an array" do
|
|
170
|
+
expect_no_deprecation
|
|
171
|
+
matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}.for_expected('expected string')
|
|
172
|
+
expect(matcher.expected_as_array).to eq ['expected string']
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it "warns of deprecation about expected when it's a single value" do
|
|
176
|
+
expect_deprecation_with_call_site __FILE__, __LINE__ + 2
|
|
141
177
|
matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}.for_expected('expected string')
|
|
142
178
|
expect(matcher.expected).to eq ['expected string']
|
|
143
179
|
end
|
|
@@ -159,7 +195,7 @@ module RSpec::Matchers::DSL
|
|
|
159
195
|
expect(actual).to eq expected
|
|
160
196
|
end
|
|
161
197
|
end.for_expected('value')
|
|
162
|
-
expect(matcher.matches?('value')).to
|
|
198
|
+
expect(matcher.matches?('value')).to be_truthy
|
|
163
199
|
end
|
|
164
200
|
|
|
165
201
|
it "returns false if the wrapped expectation fails" do
|
|
@@ -168,7 +204,7 @@ module RSpec::Matchers::DSL
|
|
|
168
204
|
expect(actual).to eq expected
|
|
169
205
|
end
|
|
170
206
|
end.for_expected('value')
|
|
171
|
-
expect(matcher.matches?('other value')).to
|
|
207
|
+
expect(matcher.matches?('other value')).to be_falsey
|
|
172
208
|
end
|
|
173
209
|
end
|
|
174
210
|
|
|
@@ -191,11 +227,11 @@ module RSpec::Matchers::DSL
|
|
|
191
227
|
end
|
|
192
228
|
|
|
193
229
|
it "does not hide result of match block when true" do
|
|
194
|
-
expect(@matcher.matches?(true)).to
|
|
230
|
+
expect(@matcher.matches?(true)).to be_truthy
|
|
195
231
|
end
|
|
196
232
|
|
|
197
233
|
it "does not hide result of match block when false" do
|
|
198
|
-
expect(@matcher.matches?(false)).to
|
|
234
|
+
expect(@matcher.matches?(false)).to be_falsey
|
|
199
235
|
end
|
|
200
236
|
|
|
201
237
|
it "overrides the description" do
|
|
@@ -220,7 +256,7 @@ module RSpec::Matchers::DSL
|
|
|
220
256
|
actual == 5
|
|
221
257
|
end
|
|
222
258
|
end.for_expected
|
|
223
|
-
expect(matcher.matches?(5)).to
|
|
259
|
+
expect(matcher.matches?(5)).to be_truthy
|
|
224
260
|
end
|
|
225
261
|
|
|
226
262
|
it "exposes arg submitted through #new to matcher block" do
|
|
@@ -229,7 +265,7 @@ module RSpec::Matchers::DSL
|
|
|
229
265
|
actual > expected
|
|
230
266
|
end
|
|
231
267
|
end.for_expected(4)
|
|
232
|
-
expect(matcher.matches?(5)).to
|
|
268
|
+
expect(matcher.matches?(5)).to be_truthy
|
|
233
269
|
end
|
|
234
270
|
end
|
|
235
271
|
|
|
@@ -243,7 +279,7 @@ module RSpec::Matchers::DSL
|
|
|
243
279
|
end
|
|
244
280
|
|
|
245
281
|
it "matches" do
|
|
246
|
-
expect(@matcher.matches?(5)).to
|
|
282
|
+
expect(@matcher.matches?(5)).to be_truthy
|
|
247
283
|
end
|
|
248
284
|
|
|
249
285
|
it "describes" do
|
|
@@ -261,7 +297,7 @@ module RSpec::Matchers::DSL
|
|
|
261
297
|
end
|
|
262
298
|
|
|
263
299
|
it "matches" do
|
|
264
|
-
expect(@matcher.matches?(5)).to
|
|
300
|
+
expect(@matcher.matches?(5)).to be_truthy
|
|
265
301
|
end
|
|
266
302
|
|
|
267
303
|
it "describes" do
|
|
@@ -279,7 +315,7 @@ module RSpec::Matchers::DSL
|
|
|
279
315
|
end
|
|
280
316
|
|
|
281
317
|
it "matches" do
|
|
282
|
-
expect(@matcher.matches?(10)).to
|
|
318
|
+
expect(@matcher.matches?(10)).to be_truthy
|
|
283
319
|
end
|
|
284
320
|
|
|
285
321
|
it "describes" do
|
|
@@ -298,7 +334,7 @@ module RSpec::Matchers::DSL
|
|
|
298
334
|
end
|
|
299
335
|
end.for_expected([1,2,3])
|
|
300
336
|
|
|
301
|
-
expect(matcher.matches?([2,3,1])).to
|
|
337
|
+
expect(matcher.matches?([2,3,1])).to be_truthy
|
|
302
338
|
end
|
|
303
339
|
|
|
304
340
|
it "supports fluent interface" do
|
|
@@ -324,7 +360,131 @@ module RSpec::Matchers::DSL
|
|
|
324
360
|
end
|
|
325
361
|
end.for_expected(3)
|
|
326
362
|
|
|
327
|
-
expect(matcher.matches?(8)).to
|
|
363
|
+
expect(matcher.matches?(8)).to be_truthy
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
shared_examples_for "accessing a singleton helper method" do
|
|
367
|
+
before { allow_deprecation }
|
|
368
|
+
|
|
369
|
+
it 'can access the helper method from `match`' do
|
|
370
|
+
expect([2, 3]).to matcher.for_expected(5)
|
|
371
|
+
expect([2, 3]).not_to matcher.for_expected(4)
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
it 'prints a deprecation warning when the helper method is accessed `match`' do
|
|
375
|
+
expect(RSpec).to receive(:deprecate).with(/sum_of/, an_instance_of(Hash))
|
|
376
|
+
matcher.for_expected(5).matches?([2, 3])
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
it 'includes the call site in the deprecation warning' do
|
|
380
|
+
expect_deprecation_with_call_site(__FILE__, line)
|
|
381
|
+
matcher.for_expected(5).matches?([2, 3])
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
it 'does not print a deprecation warning if the helper method is used as a macro' do
|
|
385
|
+
expect(RSpec).not_to receive(:deprecate)
|
|
386
|
+
matcher.for_expected(:use_as_macro).matches?([2, 3])
|
|
387
|
+
end
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
context "when a module of helper methods is extended" do
|
|
391
|
+
include_examples "accessing a singleton helper method" do
|
|
392
|
+
let(:matcher) do
|
|
393
|
+
RSpec::Matchers::DSL::Matcher.new(:sum_to) do |sum|
|
|
394
|
+
extend Module.new {
|
|
395
|
+
def sum_of(x, y) x + y end
|
|
396
|
+
def define_match() match {} end
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if sum == :use_as_macro
|
|
400
|
+
define_match
|
|
401
|
+
else
|
|
402
|
+
match { |summands| sum_of(*summands) == sum }
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
let(:line) { __LINE__ - 4 }
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
context "when a helper method is defined using `self.`" do
|
|
411
|
+
include_examples "accessing a singleton helper method" do
|
|
412
|
+
let(:matcher) do
|
|
413
|
+
RSpec::Matchers::DSL::Matcher.new(:sum_to) do |sum|
|
|
414
|
+
def self.sum_of(x, y) x + y end
|
|
415
|
+
def self.define_match() match {} end
|
|
416
|
+
|
|
417
|
+
if sum == :use_as_macro
|
|
418
|
+
define_match
|
|
419
|
+
else
|
|
420
|
+
match { |summands| sum_of(*summands) == sum }
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
let(:line) { __LINE__ - 4 }
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
shared_examples_for "accessing an instance helper method" do
|
|
429
|
+
before { allow_deprecation }
|
|
430
|
+
|
|
431
|
+
it 'can access the helper method from `match`' do
|
|
432
|
+
expect([2, 3]).to matcher.for_expected(5)
|
|
433
|
+
expect([2, 3]).not_to matcher.for_expected(4)
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
it 'does not print a deprecation warning when the helper method is accessed from `match`' do
|
|
437
|
+
expect(RSpec).not_to receive(:deprecate)
|
|
438
|
+
matcher.for_expected(5).matches?([2, 3])
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
it 'prints a deprecation warning if the helper method is used as a macro' do
|
|
442
|
+
expect(RSpec).to receive(:deprecate).with(/define_match/, an_instance_of(Hash))
|
|
443
|
+
matcher.for_expected(:use_as_macro).matches?([2, 3])
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
it 'includes the call site in the deprecation warning' do
|
|
447
|
+
expect_deprecation_with_call_site(__FILE__, line)
|
|
448
|
+
matcher.for_expected(:use_as_macro).matches?([2, 3])
|
|
449
|
+
end
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
context "when a module of helper methods is included" do
|
|
453
|
+
include_examples "accessing an instance helper method" do
|
|
454
|
+
let(:matcher) do
|
|
455
|
+
RSpec::Matchers::DSL::Matcher.new(:sum_to) do |sum|
|
|
456
|
+
include Module.new {
|
|
457
|
+
def sum_of(x, y) x + y end
|
|
458
|
+
def define_match() match {} end
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if sum == :use_as_macro
|
|
462
|
+
define_match
|
|
463
|
+
else
|
|
464
|
+
match { |summands| sum_of(*summands) == sum }
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
end
|
|
468
|
+
let(:line) { __LINE__ - 6 }
|
|
469
|
+
end
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
context "when a helper method is defined using `def foo`" do
|
|
473
|
+
include_examples "accessing an instance helper method" do
|
|
474
|
+
let(:matcher) do
|
|
475
|
+
RSpec::Matchers::DSL::Matcher.new(:sum_to) do |sum|
|
|
476
|
+
def sum_of(x, y) x + y end
|
|
477
|
+
def define_match() match {} end
|
|
478
|
+
|
|
479
|
+
if sum == :use_as_macro
|
|
480
|
+
define_match
|
|
481
|
+
else
|
|
482
|
+
match { |summands| sum_of(*summands) == sum }
|
|
483
|
+
end
|
|
484
|
+
end
|
|
485
|
+
end
|
|
486
|
+
let(:line) { __LINE__ - 6 }
|
|
487
|
+
end
|
|
328
488
|
end
|
|
329
489
|
|
|
330
490
|
context 'when multiple instances of the same matcher are used in the same example' do
|
|
@@ -377,7 +537,7 @@ module RSpec::Matchers::DSL
|
|
|
377
537
|
let(:matcher) do
|
|
378
538
|
m = mod
|
|
379
539
|
RSpec::Matchers::DSL::Matcher.new :equal do |expected|
|
|
380
|
-
|
|
540
|
+
include m
|
|
381
541
|
match_unless_raises UnexpectedError do
|
|
382
542
|
assert_equal expected, actual
|
|
383
543
|
end
|
|
@@ -386,13 +546,13 @@ module RSpec::Matchers::DSL
|
|
|
386
546
|
|
|
387
547
|
context "with passing assertion" do
|
|
388
548
|
it "passes" do
|
|
389
|
-
expect(matcher.matches?(4)).to
|
|
549
|
+
expect(matcher.matches?(4)).to be_truthy
|
|
390
550
|
end
|
|
391
551
|
end
|
|
392
552
|
|
|
393
553
|
context "with failing assertion" do
|
|
394
554
|
it "fails" do
|
|
395
|
-
expect(matcher.matches?(5)).to
|
|
555
|
+
expect(matcher.matches?(5)).to be_falsey
|
|
396
556
|
end
|
|
397
557
|
|
|
398
558
|
it "provides the raised exception" do
|
|
@@ -428,8 +588,8 @@ module RSpec::Matchers::DSL
|
|
|
428
588
|
match { |actual| actual == @expected_value }
|
|
429
589
|
end.for_expected
|
|
430
590
|
|
|
431
|
-
expect(matcher.expecting('value').matches?('value')).to
|
|
432
|
-
expect(matcher.expecting('value').matches?('other value')).to
|
|
591
|
+
expect(matcher.expecting('value').matches?('value')).to be_truthy
|
|
592
|
+
expect(matcher.expecting('value').matches?('other value')).to be_falsey
|
|
433
593
|
end
|
|
434
594
|
|
|
435
595
|
it "prevents name collisions on chainable methods from different matchers" do
|
|
@@ -445,7 +605,7 @@ module RSpec::Matchers::DSL
|
|
|
445
605
|
"method defined in the example"
|
|
446
606
|
end
|
|
447
607
|
|
|
448
|
-
it "can access methods in the running example" do
|
|
608
|
+
it "can access methods in the running example" do |example|
|
|
449
609
|
RSpec::Matchers.define(:__access_running_example) do
|
|
450
610
|
match do |actual|
|
|
451
611
|
a_method_in_the_example == "method defined in the example"
|
|
@@ -454,7 +614,7 @@ module RSpec::Matchers::DSL
|
|
|
454
614
|
expect(example).to __access_running_example
|
|
455
615
|
end
|
|
456
616
|
|
|
457
|
-
it "raises NoMethodError for methods not in the running_example" do
|
|
617
|
+
it "raises NoMethodError for methods not in the running_example" do |example|
|
|
458
618
|
RSpec::Matchers.define(:__raise_no_method_error) do
|
|
459
619
|
match do |actual|
|
|
460
620
|
a_method_not_in_the_example == "method defined in the example"
|
|
@@ -467,5 +627,34 @@ module RSpec::Matchers::DSL
|
|
|
467
627
|
end
|
|
468
628
|
end
|
|
469
629
|
|
|
630
|
+
describe "#matcher_execution_context" do
|
|
631
|
+
before { allow_deprecation }
|
|
632
|
+
|
|
633
|
+
let(:matcher) do
|
|
634
|
+
RSpec::Matchers::DSL::Matcher.new :foo do |expected|
|
|
635
|
+
end.for_expected(:bar)
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
it 'can be set' do
|
|
639
|
+
expect {
|
|
640
|
+
matcher.matcher_execution_context = :the_context
|
|
641
|
+
}.to change(matcher, :matcher_execution_context).to(:the_context)
|
|
642
|
+
end
|
|
643
|
+
|
|
644
|
+
it 'is the target of method_missing delegation' do
|
|
645
|
+
matcher.matcher_execution_context = double(:abcd => "efg")
|
|
646
|
+
expect(matcher.abcd).to eq("efg")
|
|
647
|
+
end
|
|
648
|
+
|
|
649
|
+
specify "the writer is deprecated" do
|
|
650
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /matcher_execution_context/)
|
|
651
|
+
matcher.matcher_execution_context = :the_context
|
|
652
|
+
end
|
|
653
|
+
|
|
654
|
+
specify "the reader is deprecated" do
|
|
655
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /matcher_execution_context/)
|
|
656
|
+
matcher.matcher_execution_context
|
|
657
|
+
end
|
|
658
|
+
end
|
|
470
659
|
end
|
|
471
660
|
end
|
|
@@ -24,7 +24,7 @@ describe "operator matchers", :uses_should do
|
|
|
24
24
|
|
|
25
25
|
it "returns true on success" do
|
|
26
26
|
subject = "apple"
|
|
27
|
-
(subject.should == "apple").should
|
|
27
|
+
(subject.should == "apple").should be_truthy
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it "fails when target.==(actual) returns false" do
|
|
@@ -44,7 +44,7 @@ describe "operator matchers", :uses_should do
|
|
|
44
44
|
obj = Object.new
|
|
45
45
|
|
|
46
46
|
myobj = MethodMissingObject.new(obj)
|
|
47
|
-
myobj.should == obj
|
|
47
|
+
(myobj.should == obj).nil? # just to avoid `useless use of == in void context` warning
|
|
48
48
|
myobj.should_not == Object.new
|
|
49
49
|
end
|
|
50
50
|
end
|
|
@@ -84,7 +84,7 @@ describe "operator matchers", :uses_should do
|
|
|
84
84
|
|
|
85
85
|
it "returns true on success" do
|
|
86
86
|
subject = "apple"
|
|
87
|
-
(subject.should_not == "orange").should
|
|
87
|
+
(subject.should_not == "orange").should be_falsey
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
it "fails when target.==(actual) returns false" do
|
|
@@ -211,21 +211,40 @@ describe "operator matchers", :uses_should do
|
|
|
211
211
|
let(:custom_subklass) { Class.new(custom_klass) }
|
|
212
212
|
|
|
213
213
|
after {
|
|
214
|
-
RSpec::Matchers::OperatorMatcher.unregister(custom_klass, "=~")
|
|
214
|
+
RSpec::Matchers::BuiltIn::OperatorMatcher.unregister(custom_klass, "=~")
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
it "allows operator matchers to be registered for types" do
|
|
218
|
-
RSpec::Matchers::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
|
|
219
|
-
expect(RSpec::Matchers::OperatorMatcher.get(custom_klass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
|
|
218
|
+
RSpec::Matchers::BuiltIn::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
|
|
219
|
+
expect(RSpec::Matchers::BuiltIn::OperatorMatcher.get(custom_klass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
|
|
220
220
|
end
|
|
221
221
|
|
|
222
222
|
it "considers ancestors when finding an operator matcher" do
|
|
223
|
-
RSpec::Matchers::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
|
|
224
|
-
expect(RSpec::Matchers::OperatorMatcher.get(custom_subklass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
|
|
223
|
+
RSpec::Matchers::BuiltIn::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
|
|
224
|
+
expect(RSpec::Matchers::BuiltIn::OperatorMatcher.get(custom_subklass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
|
|
225
225
|
end
|
|
226
226
|
|
|
227
227
|
it "returns nil if there is no matcher registered for a type" do
|
|
228
|
-
expect(RSpec::Matchers::OperatorMatcher.get(custom_klass, "=~")).to be_nil
|
|
228
|
+
expect(RSpec::Matchers::BuiltIn::OperatorMatcher.get(custom_klass, "=~")).to be_nil
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
context "when accessing it using the old 2.x const name" do
|
|
232
|
+
it 'returns the new constant scoped by `BuiltIn`' do
|
|
233
|
+
allow_deprecation
|
|
234
|
+
expect(RSpec::Matchers::OperatorMatcher).to be(RSpec::Matchers::BuiltIn::OperatorMatcher)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it 'issues a deprecation warning' do
|
|
238
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /OperatorMatcher/)
|
|
239
|
+
RSpec::Matchers::OperatorMatcher
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it 'allows other undefined constant to raise errors like normal' do
|
|
243
|
+
expect_no_deprecation
|
|
244
|
+
expect {
|
|
245
|
+
RSpec::Matchers::FooBarBazz
|
|
246
|
+
}.to raise_error(NameError, /RSpec::Matchers::FooBarBazz/)
|
|
247
|
+
end
|
|
229
248
|
end
|
|
230
249
|
end
|
|
231
250
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module RSpec
|
|
4
|
+
module Matchers
|
|
5
|
+
describe Pretty do
|
|
6
|
+
include Pretty
|
|
7
|
+
|
|
8
|
+
describe "#_pretty_print" do
|
|
9
|
+
it 'is deprecated' do
|
|
10
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /_pretty_print/)
|
|
11
|
+
_pretty_print([1, 2])
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "#expected_to_sentence" do
|
|
16
|
+
it 'is deprecated' do
|
|
17
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /expected_to_sentence/)
|
|
18
|
+
expected_to_sentence
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -61,7 +61,7 @@ describe "expect { ... }.to raise_error {|err| ... }" do
|
|
|
61
61
|
expect { non_existent_method }.to raise_error {|e|
|
|
62
62
|
ran = true
|
|
63
63
|
}
|
|
64
|
-
expect(ran).to
|
|
64
|
+
expect(ran).to be_truthy
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "passes the error to the block" do
|
|
@@ -409,8 +409,8 @@ describe "expect { ... }.to raise_error(NamedError, error_message) { |err| ... }
|
|
|
409
409
|
}
|
|
410
410
|
}.to fail_with(/expected: 4/m)
|
|
411
411
|
|
|
412
|
-
expect(ran).to
|
|
413
|
-
expect(passed).to
|
|
412
|
+
expect(ran).to be_truthy
|
|
413
|
+
expect(passed).to be_falsey
|
|
414
414
|
end
|
|
415
415
|
|
|
416
416
|
it "does NOT yield exception if no error was thrown" do
|
|
@@ -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
|
data/spec/spec_helper.rb
CHANGED
|
@@ -2,8 +2,8 @@ Dir['./spec/support/**/*'].each {|f| require f}
|
|
|
2
2
|
|
|
3
3
|
RSpec::configure do |config|
|
|
4
4
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
5
|
-
config.
|
|
6
|
-
config.filter_run :
|
|
5
|
+
config.color = true
|
|
6
|
+
config.filter_run :focus
|
|
7
7
|
config.run_all_when_everything_filtered = true
|
|
8
8
|
config.order = :random
|
|
9
9
|
|
|
@@ -11,6 +11,8 @@ RSpec::configure do |config|
|
|
|
11
11
|
$default_expectation_syntax = expectations.syntax
|
|
12
12
|
expectations.syntax = :expect
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
config.include DeprecationHelpers
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
shared_context "with #should enabled", :uses_should do
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module DeprecationHelpers
|
|
2
|
+
|
|
3
|
+
def expect_deprecation_with_call_site(file, line, snippet = //)
|
|
4
|
+
expect(RSpec.configuration.reporter).to receive(:deprecation) do |options|
|
|
5
|
+
matcher = include([file, line].join(':'))
|
|
6
|
+
call_site = options[:call_site] || options[:message]
|
|
7
|
+
|
|
8
|
+
unless matcher.matches?(call_site)
|
|
9
|
+
# RSpec::Expectations::ExpectationNotMetError is rescued in the `match` block
|
|
10
|
+
# of a custom matcher and returned as `false` from `matches?`. This would
|
|
11
|
+
# prevent an expectation failure here from surfacing in the test suite if
|
|
12
|
+
# it's triggered from within a `match` block, so we need to raise
|
|
13
|
+
# a different error class instead.
|
|
14
|
+
raise matcher.failure_message_for_should
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
deprecated = options[:deprecated] || options[:message]
|
|
18
|
+
expect(deprecated).to match(snippet)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def expect_deprecation_with_type(expression, message, type)
|
|
23
|
+
expect(RSpec).to receive(:deprecate).with(expression,
|
|
24
|
+
:replacement => message,
|
|
25
|
+
:type => type
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def expect_deprecation_with_replacement(snippet)
|
|
30
|
+
expect(RSpec).to receive(:deprecate) do |_, options|
|
|
31
|
+
expect(options[:replacement]).to match(snippet)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def allow_deprecation
|
|
36
|
+
allow(RSpec.configuration.reporter).to receive(:deprecation)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def expect_no_deprecation
|
|
40
|
+
expect(RSpec.configuration.reporter).not_to receive(:deprecation)
|
|
41
|
+
end
|
|
42
|
+
end
|