rspec-expectations 2.99.0.beta2 → 2.99.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/Changelog.md +55 -32
  3. data/features/README.md +2 -1
  4. data/lib/rspec-expectations.rb +5 -0
  5. data/lib/rspec/expectations.rb +1 -1
  6. data/lib/rspec/{matchers → expectations}/configuration.rb +5 -3
  7. data/lib/rspec/expectations/expectation_target.rb +75 -8
  8. data/lib/rspec/expectations/syntax.rb +3 -5
  9. data/lib/rspec/expectations/version.rb +1 -1
  10. data/lib/rspec/matchers.rb +12 -5
  11. data/lib/rspec/matchers/built_in/base_matcher.rb +11 -3
  12. data/lib/rspec/matchers/built_in/be.rb +15 -4
  13. data/lib/rspec/matchers/built_in/be_within.rb +6 -1
  14. data/lib/rspec/matchers/built_in/change.rb +4 -2
  15. data/lib/rspec/matchers/built_in/has.rb +38 -6
  16. data/lib/rspec/matchers/built_in/include.rb +1 -1
  17. data/lib/rspec/matchers/built_in/match_array.rb +1 -1
  18. data/lib/rspec/matchers/built_in/raise_error.rb +5 -0
  19. data/lib/rspec/matchers/built_in/respond_to.rb +5 -0
  20. data/lib/rspec/matchers/built_in/satisfy.rb +5 -0
  21. data/lib/rspec/matchers/built_in/throw_symbol.rb +8 -1
  22. data/lib/rspec/matchers/built_in/yield.rb +21 -1
  23. data/lib/rspec/matchers/dsl.rb +2 -1
  24. data/lib/rspec/matchers/matcher.rb +28 -7
  25. data/lib/rspec/matchers/pretty.rb +4 -0
  26. data/spec/rspec/{matchers → expectations}/configuration_spec.rb +21 -2
  27. data/spec/rspec/expectations/expectation_target_spec.rb +62 -0
  28. data/spec/rspec/expectations/extensions/kernel_spec.rb +4 -0
  29. data/spec/rspec/expectations_spec.rb +7 -0
  30. data/spec/rspec/matchers/be_spec.rb +21 -0
  31. data/spec/rspec/matchers/description_generation_spec.rb +1 -1
  32. data/spec/rspec/matchers/has_spec.rb +24 -0
  33. data/spec/rspec/matchers/matcher_spec.rb +52 -0
  34. data/spec/rspec/matchers/pretty_spec.rb +23 -0
  35. data/spec/spec_helper.rb +2 -2
  36. data/spec/support/helper_methods.rb +6 -0
  37. metadata +64 -75
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6638fae315b3f230a14e4e9a58b845016e1f2cd1
4
+ data.tar.gz: 7f54fd6c65671705178edae5454c4b7c6712aac2
5
+ SHA512:
6
+ metadata.gz: dc9c8cc98c5d0863ba78a930e14866fed155ff606f83b96eac184ae2beeec7077d5a17613f7a49b79d7809bbf359e49289f6730ab9736ced587338769f5720bc
7
+ data.tar.gz: 4cef0dcd237b8853ef730e171d333e325d141826f13e4c721a92c5e9bd71a136ea7e375c4d01d808a529dc0d209b710993ed2e949c3a3bc5e4d43b0a082ad511
@@ -1,5 +1,28 @@
1
+ ### 2.99.0.rc1 / 2014-05-18
2
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.99.0.beta2...2.99.0.rc1)
3
+
4
+ Deprecations:
5
+
6
+ * Deprecate `matcher_execution_context` attribute on DSL-defined
7
+ custom matchers. (Myron Marston)
8
+ * Deprecate `RSpec::Matchers::Pretty#_pretty_print`. (Myron Marston)
9
+ * Deprecate `RSpec::Matchers::Pretty#expected_to_sentence`. (Myron Marston)
10
+ * Deprecate `RSpec::Matchers::Configuration` in favor of
11
+ `RSpec::Expectations::Configuration`. (Myron Marston)
12
+ * Deprecate `be_xyz` predicate matcher on an object that doesn't respond to
13
+ `xyz?` or `xyzs?`. (Daniel Fone)
14
+ * Deprecate `have_xyz` matcher on an object that doesn't respond to `has_xyz?`.
15
+ (Daniel Fone)
16
+ * Deprecate `have_xyz` matcher on an object that has a private method `has_xyz?`.
17
+ (Jon Rowe)
18
+ * Issue a deprecation warning when a block expectation expression is
19
+ used with a matcher that doesn't explicitly support block expectations
20
+ via `supports_block_expectations?`. (Myron Marston)
21
+ * Deprecate `require 'rspec-expectations'`. Use
22
+ `require 'rspec/expectations'` instead. (Myron Marston)
23
+
1
24
  ### 2.99.0.beta2 / 2014-02-17
2
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.99.0.beta1...v2.99.0.beta2)
25
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.99.0.beta1...v2.99.0.beta2)
3
26
 
4
27
  Deprecations:
5
28
 
@@ -25,7 +48,7 @@ Deprecations:
25
48
  work properly. (Jon Rowe)
26
49
 
27
50
  ### 2.99.0.beta1 / 2013-11-07
28
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.4...v2.99.0.beta1)
51
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.4...v2.99.0.beta1)
29
52
 
30
53
  Deprecations:
31
54
 
@@ -50,7 +73,7 @@ Deprecations:
50
73
  either purpose, but RSpec 3.0 will not.
51
74
 
52
75
  ### 2.14.5 / 2014-02-01
53
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.4...v2.14.5)
76
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.4...v2.14.5)
54
77
 
55
78
  Bug fixes
56
79
 
@@ -58,7 +81,7 @@ Bug fixes
58
81
  (yujinakayama)
59
82
 
60
83
  ### 2.14.4 / 2013-11-06
61
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.3...v2.14.4)
84
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.3...v2.14.4)
62
85
 
63
86
  Bug fixes
64
87
 
@@ -67,7 +90,7 @@ Bug fixes
67
90
  back to default internal encoding with replacing characters. (Jon Rowe)
68
91
 
69
92
  ### 2.14.3 / 2013-09-22
70
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.2...v2.14.3)
93
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.2...v2.14.3)
71
94
 
72
95
  Bug fixes
73
96
 
@@ -78,7 +101,7 @@ Bug fixes
78
101
  `method_missing` (Jon Rowe)
79
102
 
80
103
  ### 2.14.2 / 2013-08-14
81
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.1...v2.14.2)
104
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.1...v2.14.2)
82
105
 
83
106
  Bug fixes
84
107
 
@@ -94,7 +117,7 @@ Bug fixes
94
117
  `SomeClass === SomeClass` returns false. (Myron Marston)
95
118
 
96
119
  ### 2.14.1 / 2013-08-08
97
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.0...2.14.1)
120
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.0...2.14.1)
98
121
 
99
122
  Bug fixes
100
123
 
@@ -103,7 +126,7 @@ Bug fixes
103
126
  errors (Jon Rowe).
104
127
 
105
128
  ### 2.14.0 / 2013-07-06
106
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.0.rc1...v2.14.0)
129
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.0.rc1...v2.14.0)
107
130
 
108
131
  Bug fixes
109
132
 
@@ -115,7 +138,7 @@ Bug fixes
115
138
  change...` (Sam Phippen).
116
139
 
117
140
  ### 2.14.0.rc1 / 2013-05-27
118
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.13.0...v2.14.0.rc1)
141
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.13.0...v2.14.0.rc1)
119
142
 
120
143
  Enhancements
121
144
 
@@ -149,7 +172,7 @@ Deprecations
149
172
  error_ to pass. (Sam Phippen and David Chelimsky)
150
173
 
151
174
  ### 2.13.0 / 2013-02-23
152
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.12.1...v2.13.0)
175
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.12.1...v2.13.0)
153
176
 
154
177
  Enhancements
155
178
 
@@ -180,7 +203,7 @@ Bug fixes
180
203
  printed for empty diffs (Myron Marston).
181
204
 
182
205
  ### 2.12.1 / 2012-12-15
183
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.12.0...v2.12.1)
206
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.12.0...v2.12.1)
184
207
 
185
208
  Bug fixes
186
209
 
@@ -192,7 +215,7 @@ Bug fixes
192
215
  (Steven Harman)
193
216
 
194
217
  ### 2.12.0 / 2012-11-12
195
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.3...v2.12.0)
218
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.3...v2.12.0)
196
219
 
197
220
  Enhancements
198
221
 
@@ -215,7 +238,7 @@ Bug fixes
215
238
  (Tom Stuart)
216
239
 
217
240
  ### 2.11.3 / 2012-09-04
218
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.2...v2.11.3)
241
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.2...v2.11.3)
219
242
 
220
243
  Bug fixes
221
244
 
@@ -231,7 +254,7 @@ Bug fixes
231
254
  }.to change { user.last_emailed_at }.to be_within(1.second).of(Time.zone.now)
232
255
 
233
256
  ### 2.11.2 / 2012-07-25
234
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.1...v2.11.2)
257
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.1...v2.11.2)
235
258
 
236
259
  Bug fixes
237
260
 
@@ -240,7 +263,7 @@ Bug fixes
240
263
  of the object hierarchy. (Gabriel Gilder)
241
264
 
242
265
  ### 2.11.1 / 2012-07-08
243
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.0...v2.11.1)
266
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.0...v2.11.1)
244
267
 
245
268
  Bug fixes
246
269
 
@@ -249,7 +272,7 @@ Bug fixes
249
272
  * `Time`, for example, is a legit alternative.
250
273
 
251
274
  ### 2.11.0 / 2012-07-07
252
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.10.0...v2.11.0)
275
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.10.0...v2.11.0)
253
276
 
254
277
  Enhancements
255
278
 
@@ -272,7 +295,7 @@ Bug fixes
272
295
  Marston)
273
296
 
274
297
  ### 2.10.0 / 2012-05-03
275
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.9.1...v2.10.0)
298
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.9.1...v2.10.0)
276
299
 
277
300
  Enhancements
278
301
 
@@ -290,7 +313,7 @@ Bug fixes
290
313
  * Fix message-specific specs to pass on Rubinius (John Firebaugh)
291
314
 
292
315
  ### 2.9.1 / 2012-04-03
293
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.9.0...v2.9.1)
316
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.9.0...v2.9.1)
294
317
 
295
318
  Bug fixes
296
319
 
@@ -301,7 +324,7 @@ Bug fixes
301
324
  * Fix using execution context methods in nested DSL matchers (mirasrael)
302
325
 
303
326
  ### 2.9.0 / 2012-03-17
304
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.8.0...v2.9.0)
327
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.8.0...v2.9.0)
305
328
 
306
329
  Enhancements
307
330
 
@@ -321,7 +344,7 @@ Bug fixes
321
344
 
322
345
  ### 2.8.0 / 2012-01-04
323
346
 
324
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.8.0.rc2...v2.8.0)
347
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.8.0.rc2...v2.8.0)
325
348
 
326
349
  Enhancements
327
350
 
@@ -330,13 +353,13 @@ Enhancements
330
353
 
331
354
  ### 2.8.0.rc2 / 2011-12-19
332
355
 
333
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.8.0.rc1...v2.8.0.rc2)
356
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.8.0.rc1...v2.8.0.rc2)
334
357
 
335
358
  No changes for this release. Just releasing with the other rspec gems.
336
359
 
337
360
  ### 2.8.0.rc1 / 2011-11-06
338
361
 
339
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.7.0...v2.8.0.rc1)
362
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.7.0...v2.8.0.rc1)
340
363
 
341
364
  Enhancements
342
365
 
@@ -345,7 +368,7 @@ Enhancements
345
368
 
346
369
  ### 2.7.0 / 2011-10-16
347
370
 
348
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.6.0...v2.7.0)
371
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.6.0...v2.7.0)
349
372
 
350
373
  Enhancements
351
374
 
@@ -363,7 +386,7 @@ Bug fixes
363
386
 
364
387
  ### 2.6.0 / 2011-05-12
365
388
 
366
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.5.0...v2.6.0)
389
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.5.0...v2.6.0)
367
390
 
368
391
  Enhancements
369
392
 
@@ -381,7 +404,7 @@ Bug fixes
381
404
 
382
405
  ### 2.5.0 / 2011-02-05
383
406
 
384
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.4.0...v2.5.0)
407
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.4.0...v2.5.0)
385
408
 
386
409
  Enhancements
387
410
 
@@ -394,7 +417,7 @@ Documentation
394
417
 
395
418
  ### 2.4.0 / 2011-01-02
396
419
 
397
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.3.0...v2.4.0)
420
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.3.0...v2.4.0)
398
421
 
399
422
  No functional changes in this release, which was made to align with the
400
423
  rspec-core-2.4.0 release.
@@ -405,7 +428,7 @@ Enhancements
405
428
 
406
429
  ### 2.3.0 / 2010-12-12
407
430
 
408
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.2.1...v2.3.0)
431
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.2.1...v2.3.0)
409
432
 
410
433
  Enhancements
411
434
 
@@ -413,11 +436,11 @@ Enhancements
413
436
 
414
437
  ### 2.2.0 / 2010-11-28
415
438
 
416
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.1.0...v2.2.0)
439
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.1.0...v2.2.0)
417
440
 
418
441
  ### 2.1.0 / 2010-11-07
419
442
 
420
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.1...v2.1.0)
443
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.1...v2.1.0)
421
444
 
422
445
  Enhancements
423
446
 
@@ -436,7 +459,7 @@ Bug fixes
436
459
 
437
460
  ### 2.0.0 / 2010-10-10
438
461
 
439
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.rc...v2.0.0)
462
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.rc...v2.0.0)
440
463
 
441
464
  Enhancements
442
465
 
@@ -451,7 +474,7 @@ Bug fixes
451
474
 
452
475
  ### 2.0.0.rc / 2010-10-05
453
476
 
454
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.22...v2.0.0.rc)
477
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.22...v2.0.0.rc)
455
478
 
456
479
  Enhancements
457
480
 
@@ -464,7 +487,7 @@ Bug fixes
464
487
 
465
488
  ### 2.0.0.beta.22 / 2010-09-12
466
489
 
467
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.20...v2.0.0.beta.22)
490
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.20...v2.0.0.beta.22)
468
491
 
469
492
  Enhancements
470
493
 
@@ -23,7 +23,7 @@ Note: You can also use `expect(..).to_not` instead of `expect(..).not_to`.
23
23
 
24
24
  ## What is a matcher?
25
25
 
26
- A Matcher is any object that responds to the following methods:
26
+ A matcher is any object that responds to the following methods:
27
27
 
28
28
  matches?(actual)
29
29
  failure_message_for_should
@@ -33,6 +33,7 @@ These methods are also part of the matcher protocol, but are optional:
33
33
  does_not_match?(actual)
34
34
  failure_message_for_should_not
35
35
  description
36
+ supports_block_expectations?
36
37
 
37
38
  RSpec ships with a number of built-in matchers and a DSL for writing custom
38
39
  matchers.
@@ -1 +1,6 @@
1
1
  require "rspec/expectations"
2
+
3
+ RSpec.deprecate("`require 'rspec-expectations'`",
4
+ :replacement => "`require 'rspec/expectations'`",
5
+ # we explcitly pass a caller because CallerFilter ignores this file
6
+ :call_site => caller[RUBY_PLATFORM == 'java' ? 2 : 0])
@@ -1,7 +1,7 @@
1
1
  require 'rspec/expectations/extensions'
2
2
  require 'rspec/matchers'
3
3
  require 'rspec/expectations/expectation_target'
4
- require 'rspec/matchers/configuration'
4
+ require 'rspec/expectations/configuration'
5
5
  require 'rspec/expectations/fail_with'
6
6
  require 'rspec/expectations/errors'
7
7
  require 'rspec/expectations/deprecation'
@@ -1,7 +1,7 @@
1
1
  require 'rspec/expectations/syntax'
2
2
 
3
3
  module RSpec
4
- module Matchers
4
+ module Expectations
5
5
  # Provides configuration options for rspec-expectations.
6
6
  class Configuration
7
7
  # Configures the supported syntax.
@@ -94,11 +94,13 @@ module RSpec
94
94
  end
95
95
  end
96
96
  end
97
+ end
97
98
 
99
+ module Matchers
98
100
  # The configuration object
99
- # @return [RSpec::Matchers::Configuration] the configuration object
101
+ # @return [RSpec::Expectations::Configuration] the configuration object
100
102
  def self.configuration
101
- @configuration ||= Configuration.new
103
+ @configuration ||= Expectations::Configuration.new
102
104
  end
103
105
 
104
106
  # set default syntax
@@ -1,23 +1,48 @@
1
1
  module RSpec
2
2
  module Expectations
3
3
  # Wraps the target of an expectation.
4
+ #
4
5
  # @example
5
- # expect(something) # => ExpectationTarget wrapping something
6
+ # expect(something) # => ExpectationTarget wrapping something
7
+ # expect { do_something } # => ExpectationTarget wrapping the block
6
8
  #
7
9
  # # used with `to`
8
10
  # expect(actual).to eq(3)
9
11
  #
10
12
  # # with `not_to`
11
13
  # expect(actual).not_to eq(3)
14
+ #
15
+ # @note `ExpectationTarget` is not intended to be instantiated
16
+ # directly by users. Use `expect` instead.
12
17
  class ExpectationTarget
13
18
  class << self
14
19
  attr_accessor :deprecated_should_enabled
15
20
  alias deprecated_should_enabled? deprecated_should_enabled
16
21
  end
17
22
 
23
+ # @private
24
+ # Used as a sentinel value to be able to tell when the user
25
+ # did not pass an argument. We can't use `nil` for that because
26
+ # `nil` is a valid value to pass.
27
+ UndefinedValue = Module.new
28
+
18
29
  # @api private
19
- def initialize(target)
20
- @target = target
30
+ def initialize(value)
31
+ @target = value
32
+ end
33
+
34
+ # @private
35
+ def self.for(value, block)
36
+ if UndefinedValue.equal?(value)
37
+ unless block
38
+ raise ArgumentError, "You must pass either an argument or a block to `expect`."
39
+ end
40
+ BlockExpectationTarget.new(block)
41
+ elsif block
42
+ raise ArgumentError, "You cannot pass both an argument and a block to `expect`."
43
+ else
44
+ new(value)
45
+ end
21
46
  end
22
47
 
23
48
  # Runs the given expectation, passing if `matcher` returns true.
@@ -30,7 +55,7 @@ module RSpec
30
55
  # @return [Boolean] true if the expectation succeeds (else raises)
31
56
  # @see RSpec::Matchers
32
57
  def to(matcher=nil, message=nil, &block)
33
- prevent_operator_matchers(:to, matcher)
58
+ prevent_operator_matchers(:to) unless matcher
34
59
  RSpec::Expectations::PositiveExpectationHandler.handle_matcher(@target, matcher, message, &block)
35
60
  end
36
61
 
@@ -43,7 +68,7 @@ module RSpec
43
68
  # @return [Boolean] false if the negative expectation succeeds (else raises)
44
69
  # @see RSpec::Matchers
45
70
  def not_to(matcher=nil, message=nil, &block)
46
- prevent_operator_matchers(:not_to, matcher)
71
+ prevent_operator_matchers(:not_to) unless matcher
47
72
  RSpec::Expectations::NegativeExpectationHandler.handle_matcher(@target, matcher, message, &block)
48
73
  end
49
74
  alias to_not not_to
@@ -75,13 +100,55 @@ module RSpec
75
100
 
76
101
  private
77
102
 
78
- def prevent_operator_matchers(verb, matcher)
79
- return if matcher
80
-
103
+ def prevent_operator_matchers(verb)
81
104
  raise ArgumentError, "The expect syntax does not support operator matchers, " +
82
105
  "so you must pass a matcher to `##{verb}`."
83
106
  end
84
107
  end
108
+
109
+ # @private
110
+ # Validates the provided matcher to ensure it supports block
111
+ # expectations, in order to avoid user confusion when they
112
+ # use a block thinking the expectation will be on the return
113
+ # value of the block rather than the block itself.
114
+ class BlockExpectationTarget < ExpectationTarget
115
+ def to(matcher, message=nil, &block)
116
+ enforce_block_expectation(matcher)
117
+ super
118
+ end
119
+
120
+ def not_to(matcher, message=nil, &block)
121
+ enforce_block_expectation(matcher)
122
+ super
123
+ end
124
+ alias to_not not_to
125
+
126
+ private
127
+
128
+ def enforce_block_expectation(matcher)
129
+ return if supports_block_expectations?(matcher)
130
+
131
+ RSpec.deprecate("Using a matcher in a block expectation expression " +
132
+ "(e.g. `expect { }.to matcher`) that does not implement " +
133
+ "`supports_block_expectations?`",
134
+ :replacement => "a value expectation expression " +
135
+ "(e.g. `expect(value).to matcher`) or implement " +
136
+ "`supports_block_expectations?` on the provided matcher " +
137
+ "(#{description_of matcher})")
138
+ end
139
+
140
+ def supports_block_expectations?(matcher)
141
+ matcher.supports_block_expectations?
142
+ rescue NoMethodError
143
+ false
144
+ end
145
+
146
+ def description_of(matcher)
147
+ matcher.description
148
+ rescue NoMethodError
149
+ matcher.inspect
150
+ end
151
+ end
85
152
  end
86
153
  end
87
154