rspec-expectations 2.99.0.beta1 → 2.99.0.beta2
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.
- data/Changelog.md +35 -1
- 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 +50 -45
- data/lib/rspec/expectations/deprecation.rb +8 -0
- data/lib/rspec/expectations/handler.rb +5 -1
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +10 -1
- data/lib/rspec/matchers/be_close.rb +4 -1
- data/lib/rspec/matchers/built_in/base_matcher.rb +8 -9
- data/lib/rspec/matchers/built_in/be_within.rb +2 -1
- data/lib/rspec/matchers/built_in/change.rb +37 -1
- data/lib/rspec/matchers/built_in/has.rb +2 -1
- data/lib/rspec/matchers/built_in/have.rb +6 -2
- data/lib/rspec/matchers/built_in/raise_error.rb +2 -1
- data/lib/rspec/matchers/built_in/respond_to.rb +2 -1
- data/lib/rspec/matchers/built_in/satisfy.rb +2 -1
- data/lib/rspec/matchers/built_in/throw_symbol.rb +2 -1
- data/lib/rspec/matchers/built_in/yield.rb +4 -2
- data/lib/rspec/matchers/match_aliases.rb +22 -0
- data/lib/rspec/matchers/matcher.rb +18 -1
- data/lib/rspec/matchers/operator_matcher.rb +70 -70
- data/lib/rspec/matchers/test_unit_integration.rb +22 -5
- data/spec/rspec/expectations_spec.rb +1 -1
- data/spec/rspec/matchers/base_matcher_spec.rb +27 -12
- data/spec/rspec/matchers/be_close_spec.rb +4 -1
- data/spec/rspec/matchers/be_spec.rb +2 -2
- data/spec/rspec/matchers/change_spec.rb +76 -1
- data/spec/rspec/matchers/equal_spec.rb +26 -0
- data/spec/rspec/matchers/have_spec.rb +26 -18
- data/spec/rspec/matchers/matcher_spec.rb +13 -0
- data/spec/rspec/matchers/operator_matcher_spec.rb +25 -6
- data/spec/spec_helper.rb +0 -21
- data/spec/support/helper_methods.rb +28 -3
- data/spec/support/shared_examples.rb +42 -0
- metadata +20 -8
- checksums.yaml +0 -15
- data/spec/rspec/matchers/matchers_spec.rb +0 -37
@@ -193,7 +193,8 @@ end
|
|
193
193
|
|
194
194
|
describe "expect { ... }.to change { block }" do
|
195
195
|
o = SomethingExpected.new
|
196
|
-
|
196
|
+
o.some_value = 1
|
197
|
+
it_behaves_like "an RSpec matcher", :valid_value => lambda { o.some_value += 1 },
|
197
198
|
:invalid_value => lambda { } do
|
198
199
|
let(:matcher) { change { o.some_value } }
|
199
200
|
end
|
@@ -247,6 +248,80 @@ describe "expect { ... }.not_to change { block }" do
|
|
247
248
|
end
|
248
249
|
end
|
249
250
|
|
251
|
+
describe "expect { ... }.not_to change { }.from" do
|
252
|
+
context 'when the value starts at the from value' do
|
253
|
+
it 'passes when the value does not change' do
|
254
|
+
k = 5
|
255
|
+
expect { }.not_to change { k }.from(5)
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'fails when the value does change' do
|
259
|
+
expect {
|
260
|
+
k = 5
|
261
|
+
expect { k += 1 }.not_to change { k }.from(5)
|
262
|
+
}.to fail_with(/but did change from 5 to 6/)
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'does not issue a deprecation warning' do
|
266
|
+
expect(RSpec.configuration.reporter).not_to receive(:deprecation)
|
267
|
+
k = 5
|
268
|
+
expect { }.not_to change { k }.from(5)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context 'when the value starts at a different value' do
|
273
|
+
before { allow_deprecation }
|
274
|
+
|
275
|
+
it 'passes when the value does not change' do
|
276
|
+
k = 6
|
277
|
+
expect { }.not_to change { k }.from(5)
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'passes when the value does change' do
|
281
|
+
k = 6
|
282
|
+
expect { k += 1 }.not_to change { k }.from(5)
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'issues a deprecation warning' do
|
286
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 2, /#{Regexp.escape("expect { }.not_to change { }.from()")}/)
|
287
|
+
k = 6
|
288
|
+
expect { }.not_to change { k }.from(5)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
describe "expect { ... }.not_to change { }.to" do
|
294
|
+
it 'issues a deprecation warning' do
|
295
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{Regexp.escape("expect { }.not_to change { }.to()")}/)
|
296
|
+
expect {
|
297
|
+
}.not_to change { }.to(3)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
describe "expect { ... }.not_to change { }.by" do
|
302
|
+
it 'issues a deprecation warning' do
|
303
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{Regexp.escape("expect { }.not_to change { }.by()")}/)
|
304
|
+
expect {
|
305
|
+
}.not_to change { }.by(3)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
describe "expect { ... }.not_to change { }.by_at_least" do
|
310
|
+
it 'issues a deprecation warning' do
|
311
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{Regexp.escape("expect { }.not_to change { }.by_at_least()")}/)
|
312
|
+
expect {
|
313
|
+
}.not_to change { }.by_at_least(3)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
describe "expect { ... }.not_to change { }.by_at_most" do
|
318
|
+
it 'issues a deprecation warning' do
|
319
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{Regexp.escape("expect { }.not_to change { }.by_at_most()")}/)
|
320
|
+
expect {
|
321
|
+
}.not_to change { }.by_at_most(3)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
250
325
|
describe "expect { ... }.to change(actual, message).by(expected)" do
|
251
326
|
before(:each) do
|
252
327
|
@instance = SomethingExpected.new
|
@@ -24,6 +24,32 @@ module RSpec
|
|
24
24
|
expect(matcher.description).to eq "equal 1"
|
25
25
|
end
|
26
26
|
|
27
|
+
context "when the expected object is falsey in conditinal semantics" do
|
28
|
+
it "describes itself with the expected object" do
|
29
|
+
matcher = equal(nil)
|
30
|
+
matcher.matches?(nil)
|
31
|
+
expect(matcher.description).to eq "equal nil"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when the expected object's #equal? always returns true" do
|
36
|
+
let(:strange_string) do
|
37
|
+
string = "foo"
|
38
|
+
|
39
|
+
def string.equal?(other)
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
string
|
44
|
+
end
|
45
|
+
|
46
|
+
it "describes itself with the expected object" do
|
47
|
+
matcher = equal(strange_string)
|
48
|
+
matcher.matches?(strange_string)
|
49
|
+
expect(matcher.description).to eq 'equal "foo"'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
27
53
|
it "suggests the `eq` matcher on failure" do
|
28
54
|
expected, actual = "1", "1"
|
29
55
|
expect {
|
@@ -15,6 +15,14 @@ describe "have matcher" do
|
|
15
15
|
allow_deprecation
|
16
16
|
end
|
17
17
|
|
18
|
+
def expect_have_deprecation(expression, message)
|
19
|
+
expect_deprecation_with_type(
|
20
|
+
"`#{expression}`",
|
21
|
+
message,
|
22
|
+
'the have matcher'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
18
26
|
def create_collection_owner_with(n)
|
19
27
|
owner = RSpec::Expectations::Helper::CollectionOwner.new
|
20
28
|
(1..n).each do |number|
|
@@ -470,7 +478,7 @@ EOF
|
|
470
478
|
"or replace your expectation with something like " +
|
471
479
|
"`expect(collection.size).to eq(3)`"
|
472
480
|
|
473
|
-
|
481
|
+
expect_have_deprecation(expectation_expression, message)
|
474
482
|
|
475
483
|
expect([1, 2, 3]).to have(3).items
|
476
484
|
end
|
@@ -482,7 +490,7 @@ EOF
|
|
482
490
|
"or replace your expectation with something like " +
|
483
491
|
"`expect(collection.size).to_not eq(4)`"
|
484
492
|
|
485
|
-
|
493
|
+
expect_have_deprecation(expectation_expression, message)
|
486
494
|
|
487
495
|
expect([1, 2, 3]).to_not have(4).items
|
488
496
|
end
|
@@ -504,7 +512,7 @@ EOF
|
|
504
512
|
"or replace your expectation with something like " +
|
505
513
|
"`expect(collection_owner.words.size).to eq(3)`"
|
506
514
|
|
507
|
-
|
515
|
+
expect_have_deprecation(expectation_expression, message)
|
508
516
|
|
509
517
|
target = BagOfWords.new(%w[foo bar baz])
|
510
518
|
expect(target).to have(3).words
|
@@ -517,7 +525,7 @@ EOF
|
|
517
525
|
"or replace your expectation with something like " +
|
518
526
|
"`expect(collection_owner.words.size).to_not eq(4)`"
|
519
527
|
|
520
|
-
|
528
|
+
expect_have_deprecation(expectation_expression, message)
|
521
529
|
|
522
530
|
target = BagOfWords.new(%w[foo bar baz])
|
523
531
|
expect(target).to_not have(4).words
|
@@ -534,7 +542,7 @@ EOF
|
|
534
542
|
"or replace your expectation with something like " +
|
535
543
|
"`expect(collection.count).to eq(3)`"
|
536
544
|
|
537
|
-
|
545
|
+
expect_have_deprecation(expectation_expression, message)
|
538
546
|
|
539
547
|
expect(target).to have(3).letters
|
540
548
|
end
|
@@ -548,7 +556,7 @@ EOF
|
|
548
556
|
"or replace your expectation with something like " +
|
549
557
|
"`expect(collection.count).to_not eq(4)`"
|
550
558
|
|
551
|
-
|
559
|
+
expect_have_deprecation(expectation_expression, message)
|
552
560
|
|
553
561
|
expect(target).to_not have(4).letters
|
554
562
|
end
|
@@ -569,7 +577,7 @@ EOF
|
|
569
577
|
"or replace your expectation with something like " +
|
570
578
|
"`expect(collection.size).to be <= 3`"
|
571
579
|
|
572
|
-
|
580
|
+
expect_have_deprecation(expectation_expression, message)
|
573
581
|
|
574
582
|
expect([1, 2, 3]).to have_at_most(3).items
|
575
583
|
end
|
@@ -581,7 +589,7 @@ EOF
|
|
581
589
|
"or replace your expectation with something like " +
|
582
590
|
"`expect(collection.size).to be > 2`"
|
583
591
|
|
584
|
-
|
592
|
+
expect_have_deprecation(expectation_expression, message)
|
585
593
|
|
586
594
|
expect([1, 2, 3]).to_not have_at_most(2).items
|
587
595
|
end
|
@@ -603,7 +611,7 @@ EOF
|
|
603
611
|
"or replace your expectation with something like " +
|
604
612
|
"`expect(collection_owner.words.size).to be <= 3`"
|
605
613
|
|
606
|
-
|
614
|
+
expect_have_deprecation(expectation_expression, message)
|
607
615
|
|
608
616
|
target = BagOfWords.new(%w[foo bar baz])
|
609
617
|
expect(target).to have_at_most(3).words
|
@@ -616,7 +624,7 @@ EOF
|
|
616
624
|
"or replace your expectation with something like " +
|
617
625
|
"`expect(collection_owner.words.size).to be > 2`"
|
618
626
|
|
619
|
-
|
627
|
+
expect_have_deprecation(expectation_expression, message)
|
620
628
|
|
621
629
|
target = BagOfWords.new(%w[foo bar baz])
|
622
630
|
expect(target).to_not have_at_most(2).words
|
@@ -633,7 +641,7 @@ EOF
|
|
633
641
|
"or replace your expectation with something like " +
|
634
642
|
"`expect(collection.count).to be <= 3`"
|
635
643
|
|
636
|
-
|
644
|
+
expect_have_deprecation(expectation_expression, message)
|
637
645
|
|
638
646
|
expect(target).to have_at_most(3).letters
|
639
647
|
end
|
@@ -647,7 +655,7 @@ EOF
|
|
647
655
|
"or replace your expectation with something like " +
|
648
656
|
"`expect(collection.count).to be > 2`"
|
649
657
|
|
650
|
-
|
658
|
+
expect_have_deprecation(expectation_expression, message)
|
651
659
|
|
652
660
|
expect(target).to_not have_at_most(2).letters
|
653
661
|
end
|
@@ -668,7 +676,7 @@ EOF
|
|
668
676
|
"or replace your expectation with something like " +
|
669
677
|
"`expect(collection.size).to be >= 3`"
|
670
678
|
|
671
|
-
|
679
|
+
expect_have_deprecation(expectation_expression, message)
|
672
680
|
|
673
681
|
expect([1, 2, 3]).to have_at_least(3).items
|
674
682
|
end
|
@@ -680,7 +688,7 @@ EOF
|
|
680
688
|
"or replace your expectation with something like " +
|
681
689
|
"`expect(collection.size).to be < 4`"
|
682
690
|
|
683
|
-
|
691
|
+
expect_have_deprecation(expectation_expression, message)
|
684
692
|
|
685
693
|
expect([1, 2, 3]).to_not have_at_least(4).items
|
686
694
|
end
|
@@ -702,7 +710,7 @@ EOF
|
|
702
710
|
"or replace your expectation with something like " +
|
703
711
|
"`expect(collection_owner.words.size).to be >= 3`"
|
704
712
|
|
705
|
-
|
713
|
+
expect_have_deprecation(expectation_expression, message)
|
706
714
|
|
707
715
|
target = BagOfWords.new(%w[foo bar baz])
|
708
716
|
expect(target).to have_at_least(3).words
|
@@ -715,7 +723,7 @@ EOF
|
|
715
723
|
"or replace your expectation with something like " +
|
716
724
|
"`expect(collection_owner.words.size).to be < 4`"
|
717
725
|
|
718
|
-
|
726
|
+
expect_have_deprecation(expectation_expression, message)
|
719
727
|
|
720
728
|
target = BagOfWords.new(%w[foo bar baz])
|
721
729
|
expect(target).to_not have_at_least(4).words
|
@@ -732,7 +740,7 @@ EOF
|
|
732
740
|
"or replace your expectation with something like " +
|
733
741
|
"`expect(collection.count).to be >= 3`"
|
734
742
|
|
735
|
-
|
743
|
+
expect_have_deprecation(expectation_expression, message)
|
736
744
|
|
737
745
|
expect(target).to have_at_least(3).letters
|
738
746
|
end
|
@@ -746,7 +754,7 @@ EOF
|
|
746
754
|
"or replace your expectation with something like " +
|
747
755
|
"`expect(collection.count).to be < 4`"
|
748
756
|
|
749
|
-
|
757
|
+
expect_have_deprecation(expectation_expression, message)
|
750
758
|
|
751
759
|
expect(target).to_not have_at_least(4).letters
|
752
760
|
end
|
@@ -138,6 +138,19 @@ module RSpec::Matchers::DSL
|
|
138
138
|
end
|
139
139
|
|
140
140
|
it "provides expected" do
|
141
|
+
expect_no_deprecation
|
142
|
+
matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}.for_expected('expected', 'strings')
|
143
|
+
expect(matcher.expected).to eq %w[expected strings]
|
144
|
+
end
|
145
|
+
|
146
|
+
it "provides expected as an array" do
|
147
|
+
expect_no_deprecation
|
148
|
+
matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}.for_expected('expected string')
|
149
|
+
expect(matcher.expected_as_array).to eq ['expected string']
|
150
|
+
end
|
151
|
+
|
152
|
+
it "warns of deprecation about expected when it's a single value" do
|
153
|
+
expect_deprecation_with_call_site __FILE__, __LINE__ + 2
|
141
154
|
matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}.for_expected('expected string')
|
142
155
|
expect(matcher.expected).to eq ['expected string']
|
143
156
|
end
|
@@ -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
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,25 +1,5 @@
|
|
1
1
|
Dir['./spec/support/**/*'].each {|f| require f}
|
2
2
|
|
3
|
-
module DeprecationHelpers
|
4
|
-
def allow_deprecation
|
5
|
-
allow(RSpec.configuration.reporter).to receive(:deprecation)
|
6
|
-
end
|
7
|
-
|
8
|
-
def expect_deprecation_with_call_site(file, line)
|
9
|
-
expect(RSpec.configuration.reporter).to receive(:deprecation) do |options|
|
10
|
-
matcher = include([file, line].join(':'))
|
11
|
-
unless matcher.matches?(options[:call_site])
|
12
|
-
# RSpec::Expectations::ExpectationNotMetError is rescued in the `match` block
|
13
|
-
# of a custom matcher and returned as `false` from `matches?`. This would
|
14
|
-
# prevent an expectation failure here from surfacing in the test suite if
|
15
|
-
# it's triggered from within a `match` block, so we need to raise
|
16
|
-
# a different error class instead.
|
17
|
-
raise matcher.failure_message_for_should
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
3
|
RSpec::configure do |config|
|
24
4
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
25
5
|
config.color_enabled = true
|
@@ -32,7 +12,6 @@ RSpec::configure do |config|
|
|
32
12
|
expectations.syntax = :expect
|
33
13
|
end
|
34
14
|
|
35
|
-
config.include SpecHelperMethods
|
36
15
|
config.include DeprecationHelpers
|
37
16
|
end
|
38
17
|
|
@@ -1,11 +1,36 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module DeprecationHelpers
|
2
|
+
|
3
|
+
def expect_deprecation_with_call_site(file, line, snippet = //)
|
3
4
|
expect(RSpec.configuration.reporter).to receive(:deprecation) do |options|
|
4
|
-
|
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)
|
5
19
|
end
|
6
20
|
end
|
7
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
|
+
|
8
29
|
def allow_deprecation
|
9
30
|
allow(RSpec.configuration.reporter).to receive(:deprecation)
|
10
31
|
end
|
32
|
+
|
33
|
+
def expect_no_deprecation
|
34
|
+
expect(RSpec.configuration.reporter).not_to receive(:deprecation)
|
35
|
+
end
|
11
36
|
end
|
@@ -1,13 +1,55 @@
|
|
1
1
|
shared_examples_for "an RSpec matcher" do |options|
|
2
2
|
let(:valid_value) { options.fetch(:valid_value) }
|
3
3
|
let(:invalid_value) { options.fetch(:invalid_value) }
|
4
|
+
let(:deprecations) { [] }
|
5
|
+
|
6
|
+
def matched_deprecations
|
7
|
+
deprecations.select { |opts| opts[:deprecated] =~ /matcher == value/ }
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
allow(RSpec.configuration.reporter).to receive(:deprecation) do |opts|
|
12
|
+
deprecations << opts
|
13
|
+
end
|
14
|
+
end
|
4
15
|
|
5
16
|
it 'matches a valid value when using #== so it can be composed' do
|
6
17
|
expect(matcher).to eq(valid_value)
|
7
18
|
end
|
8
19
|
|
20
|
+
it 'matches a valid value when using #=== so it can be composed' do
|
21
|
+
expect(matcher).to be === valid_value
|
22
|
+
end
|
23
|
+
|
9
24
|
it 'does not match an invalid value when using #== so it can be composed' do
|
10
25
|
expect(matcher).not_to eq(invalid_value)
|
11
26
|
end
|
27
|
+
|
28
|
+
it 'does not match an invalid value when using #=== so it can be composed' do
|
29
|
+
expect(matcher).not_to be === invalid_value
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'does not print a deprecation warning when using #===' do
|
33
|
+
matcher === valid_value
|
34
|
+
matcher === invalid_value
|
35
|
+
expect(matched_deprecations).to eq([])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'does not print a deprecation warning when using #== if it returns false' do
|
39
|
+
(matcher == invalid_value).nil? # calling a method to avoid a warning
|
40
|
+
expect(matched_deprecations).to eq([])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'does not print a deprecation warning when using #== if it returns true because it was given the same object' do
|
44
|
+
expect(matcher).to be == matcher
|
45
|
+
expect(matched_deprecations).to eq([])
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'prints a deprecation warning for #== when given a valid value since' do
|
49
|
+
(matcher == valid_value).nil? # calling a method to avoid a warning
|
50
|
+
expect(matched_deprecations.count).to eq(1)
|
51
|
+
deprecation = matched_deprecations.first
|
52
|
+
expect(deprecation[:call_site]).to include([__FILE__, __LINE__ - 3].join(':'))
|
53
|
+
end
|
12
54
|
end
|
13
55
|
|