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
|
@@ -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
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
+
class MethodOverrideObject
|
|
4
|
+
def method
|
|
5
|
+
:foo
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class MethodMissingObject < Struct.new(:original)
|
|
10
|
+
undef ==
|
|
11
|
+
|
|
12
|
+
def method_missing(name, *args, &block)
|
|
13
|
+
original.__send__ name, *args, &block
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
3
17
|
describe "operator matchers", :uses_should do
|
|
4
18
|
describe "should ==" do
|
|
5
19
|
it "delegates message to target" do
|
|
@@ -10,7 +24,7 @@ describe "operator matchers", :uses_should do
|
|
|
10
24
|
|
|
11
25
|
it "returns true on success" do
|
|
12
26
|
subject = "apple"
|
|
13
|
-
(subject.should == "apple").should
|
|
27
|
+
(subject.should == "apple").should be_truthy
|
|
14
28
|
end
|
|
15
29
|
|
|
16
30
|
it "fails when target.==(actual) returns false" do
|
|
@@ -18,6 +32,21 @@ describe "operator matchers", :uses_should do
|
|
|
18
32
|
RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ==)], "orange", "apple")
|
|
19
33
|
subject.should == "orange"
|
|
20
34
|
end
|
|
35
|
+
|
|
36
|
+
it "works when #method is overriden" do
|
|
37
|
+
myobj = MethodOverrideObject.new
|
|
38
|
+
expect {
|
|
39
|
+
myobj.should == myobj
|
|
40
|
+
}.to_not raise_error
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "works when implemented via method_missing" do
|
|
44
|
+
obj = Object.new
|
|
45
|
+
|
|
46
|
+
myobj = MethodMissingObject.new(obj)
|
|
47
|
+
(myobj.should == obj).nil? # just to avoid `useless use of == in void context` warning
|
|
48
|
+
myobj.should_not == Object.new
|
|
49
|
+
end
|
|
21
50
|
end
|
|
22
51
|
|
|
23
52
|
describe "unsupported operators", :if => RUBY_VERSION.to_f == 1.9 do
|
|
@@ -55,7 +84,7 @@ describe "operator matchers", :uses_should do
|
|
|
55
84
|
|
|
56
85
|
it "returns true on success" do
|
|
57
86
|
subject = "apple"
|
|
58
|
-
(subject.should_not == "orange").should
|
|
87
|
+
(subject.should_not == "orange").should be_falsey
|
|
59
88
|
end
|
|
60
89
|
|
|
61
90
|
it "fails when target.==(actual) returns false" do
|
|
@@ -182,21 +211,40 @@ describe "operator matchers", :uses_should do
|
|
|
182
211
|
let(:custom_subklass) { Class.new(custom_klass) }
|
|
183
212
|
|
|
184
213
|
after {
|
|
185
|
-
RSpec::Matchers::OperatorMatcher.unregister(custom_klass, "=~")
|
|
214
|
+
RSpec::Matchers::BuiltIn::OperatorMatcher.unregister(custom_klass, "=~")
|
|
186
215
|
}
|
|
187
216
|
|
|
188
217
|
it "allows operator matchers to be registered for types" do
|
|
189
|
-
RSpec::Matchers::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
|
|
190
|
-
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)
|
|
191
220
|
end
|
|
192
221
|
|
|
193
222
|
it "considers ancestors when finding an operator matcher" do
|
|
194
|
-
RSpec::Matchers::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
|
|
195
|
-
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)
|
|
196
225
|
end
|
|
197
226
|
|
|
198
227
|
it "returns nil if there is no matcher registered for a type" do
|
|
199
|
-
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
|
|
200
248
|
end
|
|
201
249
|
end
|
|
202
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
|