rspec-expectations 3.8.4 → 3.8.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3287d393bfe1d8bb47a19be373b09d965c86541f96844a6ee20666eac8e3b22
4
- data.tar.gz: 498320228bbe272e0b1c41e86f15b3c434e418c0c3d1f5afcb3630e6f450cdaf
3
+ metadata.gz: 58597a62f47f10ecd74eda0086bcee4ca68878120d63cc670ebae37f9db1d252
4
+ data.tar.gz: 7443ec753991ae3c88ac9be2e8a22aab784b7e10bd2be481bf8a83daf3b85778
5
5
  SHA512:
6
- metadata.gz: cc82b0fde107519cd587adc48435e9cdd11d563bae144a4a45ac78b625eb0ea36bad76a7c0d7cfb4514d81d78f9029087b76ef4a89cd208f0610c53ee0a887e4
7
- data.tar.gz: 2b5c42079a2f100d9ce9b0e6046b392350df1064977d4a56c78696459deecd279ab85a3b9d5b392828d60b44ba0aad1de9ee320c5bcb040d4bcf7bd079756c5f
6
+ metadata.gz: 36dab83e0399bbf5c58f17f3302c865ca4ec92123c97cc6eea1f9bf80a5466e643adfbd3056e46a653c5bbc08fc93f5d804bc9ca4a2e841468b22f09e2a140ec
7
+ data.tar.gz: f4b9263c27571536fa276eefee5a2c115a9f1f3d070f1abcaf4fba9e5e2cd2f11e04f48d146c870b26d019f6fb8533b3e2b605ff422ab32832f51d1531743515
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,11 @@
1
+ ### 3.8.5 / 2019-10-02
2
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.8.4...v3.8.5)
3
+
4
+ Bug Fixes:
5
+
6
+ * Prevent unsupported implicit block expectation syntax from being used.
7
+ (Phil Pirozhkov, #1125)
8
+
1
9
  ### 3.8.4 / 2019-06-10
2
10
  [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.8.3...v3.8.4)
3
11
 
@@ -14,7 +22,7 @@ Bug Fixes:
14
22
  * Prevent composed `all` matchers from leaking into their siblings leading to duplicate
15
23
  failures. (Jamie English, #1086)
16
24
  * Prevent objects which change their hash on comparison from failing change checks.
17
- (Phil Pirozhkov, #1110)
25
+ (Phil Pirozhkov, #1100)
18
26
  * Issue an `ArgumentError` rather than a `NoMethodError` when `be_an_instance_of` and
19
27
  `be_kind_of` matchers encounter objects not supporting those methods.
20
28
  (Taichi Ishitani, #1107)
@@ -33,16 +33,16 @@ module RSpec
33
33
  end
34
34
 
35
35
  # @private
36
- def self.for(value, block)
36
+ def self.for(value, &block)
37
37
  if UndefinedValue.equal?(value)
38
- unless block
38
+ unless block_given?
39
39
  raise ArgumentError, "You must pass either an argument or a block to `expect`."
40
40
  end
41
41
  BlockExpectationTarget.new(block)
42
- elsif block
42
+ elsif block_given?
43
43
  raise ArgumentError, "You cannot pass both an argument and a block to `expect`."
44
44
  else
45
- new(value)
45
+ ValueExpectationTarget.new(value)
46
46
  end
47
47
  end
48
48
 
@@ -90,6 +90,40 @@ module RSpec
90
90
  include InstanceMethods
91
91
  end
92
92
 
93
+ # @private
94
+ # Validates the provided matcher to ensure it supports block
95
+ # expectations, in order to avoid user confusion when they
96
+ # use a block thinking the expectation will be on the return
97
+ # value of the block rather than the block itself.
98
+ class ValueExpectationTarget < ExpectationTarget
99
+ def to(matcher=nil, message=nil, &block)
100
+ enforce_value_expectation(matcher)
101
+ super
102
+ end
103
+
104
+ def not_to(matcher=nil, message=nil, &block)
105
+ enforce_value_expectation(matcher)
106
+ super
107
+ end
108
+
109
+ private
110
+
111
+ def enforce_value_expectation(matcher)
112
+ return if supports_value_expectations?(matcher)
113
+
114
+ raise ExpectationNotMetError, "You must pass a block rather than an argument to `expect` to use the provided " \
115
+ "block expectation matcher (#{RSpec::Support::ObjectFormatter.format(matcher)})."
116
+ end
117
+
118
+ def supports_value_expectations?(matcher)
119
+ if matcher.respond_to?(:supports_value_expectations?)
120
+ matcher.supports_value_expectations?
121
+ else
122
+ true
123
+ end
124
+ end
125
+ end
126
+
93
127
  # @private
94
128
  # Validates the provided matcher to ensure it supports block
95
129
  # expectations, in order to avoid user confusion when they
@@ -118,9 +152,11 @@ module RSpec
118
152
  end
119
153
 
120
154
  def supports_block_expectations?(matcher)
121
- matcher.supports_block_expectations?
122
- rescue NoMethodError
123
- false
155
+ if matcher.respond_to?(:supports_block_expectations?)
156
+ matcher.supports_block_expectations?
157
+ else
158
+ false
159
+ end
124
160
  end
125
161
  end
126
162
  end
@@ -70,7 +70,7 @@ module RSpec
70
70
 
71
71
  syntax_host.module_exec do
72
72
  def expect(value=::RSpec::Expectations::ExpectationTarget::UndefinedValue, &block)
73
- ::RSpec::Expectations::ExpectationTarget.for(value, block)
73
+ ::RSpec::Expectations::ExpectationTarget.for(value, &block)
74
74
  end
75
75
  end
76
76
  end
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '3.8.4'
5
+ STRING = '3.8.5'
6
6
  end
7
7
  end
8
8
  end
@@ -266,9 +266,9 @@ module RSpec
266
266
  # @example
267
267
  # expect(actual).to eq(expected)
268
268
  # expect(actual).not_to eq(expected)
269
- # @return [ExpectationTarget]
270
- # @see ExpectationTarget#to
271
- # @see ExpectationTarget#not_to
269
+ # @return [Expectations::ExpectationTarget]
270
+ # @see Expectations::ExpectationTarget#to
271
+ # @see Expectations::ExpectationTarget#not_to
272
272
 
273
273
  # Allows multiple expectations in the provided block to fail, and then
274
274
  # aggregates them into a single exception, rather than aborting on the
@@ -78,6 +78,11 @@ module RSpec
78
78
  false
79
79
  end
80
80
 
81
+ # @private
82
+ def supports_value_expectations?
83
+ true
84
+ end
85
+
81
86
  # @api private
82
87
  def expects_call_stack_jump?
83
88
  false
@@ -77,6 +77,11 @@ module RSpec
77
77
  true
78
78
  end
79
79
 
80
+ # @private
81
+ def supports_value_expectations?
82
+ false
83
+ end
84
+
80
85
  private
81
86
 
82
87
  def initialize(receiver=nil, message=nil, &block)
@@ -107,12 +112,10 @@ module RSpec
107
112
  end
108
113
 
109
114
  def positive_failure_reason
110
- return "was not given a block" unless Proc === @event_proc
111
115
  "is still #{@actual_before_description}"
112
116
  end
113
117
 
114
118
  def negative_failure_reason
115
- return "was not given a block" unless Proc === @event_proc
116
119
  "did change from #{@actual_before_description} " \
117
120
  "to #{description_of change_details.actual_after}"
118
121
  end
@@ -158,10 +161,14 @@ module RSpec
158
161
  true
159
162
  end
160
163
 
164
+ # @private
165
+ def supports_value_expectations?
166
+ false
167
+ end
168
+
161
169
  private
162
170
 
163
171
  def failure_reason
164
- return "was not given a block" unless Proc === @event_proc
165
172
  "was changed by #{description_of @change_details.actual_delta}"
166
173
  end
167
174
  end
@@ -190,7 +197,6 @@ module RSpec
190
197
 
191
198
  # @private
192
199
  def failure_message
193
- return not_given_a_block_failure unless Proc === @event_proc
194
200
  return before_value_failure unless @matches_before
195
201
  return did_not_change_failure unless @change_details.changed?
196
202
  after_value_failure
@@ -201,6 +207,11 @@ module RSpec
201
207
  true
202
208
  end
203
209
 
210
+ # @private
211
+ def supports_value_expectations?
212
+ false
213
+ end
214
+
204
215
  private
205
216
 
206
217
  def perform_change(event_proc)
@@ -242,11 +253,6 @@ module RSpec
242
253
  "did change from #{@actual_before_description} " \
243
254
  "to #{description_of @change_details.actual_after}"
244
255
  end
245
-
246
- def not_given_a_block_failure
247
- "expected #{@change_details.value_representation} to have changed " \
248
- "#{change_description}, but was not given a block"
249
- end
250
256
  end
251
257
 
252
258
  # @api private
@@ -278,7 +284,6 @@ module RSpec
278
284
 
279
285
  # @private
280
286
  def failure_message_when_negated
281
- return not_given_a_block_failure unless Proc === @event_proc
282
287
  return before_value_failure unless @matches_before
283
288
  did_change_failure
284
289
  end
@@ -26,11 +26,19 @@ module RSpec
26
26
  "#{matcher_1.description} #{conjunction} #{matcher_2.description}"
27
27
  end
28
28
 
29
+ # @api private
29
30
  def supports_block_expectations?
30
31
  matcher_supports_block_expectations?(matcher_1) &&
31
32
  matcher_supports_block_expectations?(matcher_2)
32
33
  end
33
34
 
35
+ # @api private
36
+ def supports_value_expectations?
37
+ matcher_supports_value_expectations?(matcher_1) &&
38
+ matcher_supports_value_expectations?(matcher_2)
39
+ end
40
+
41
+ # @api private
34
42
  def expects_call_stack_jump?
35
43
  NestedEvaluator.matcher_expects_call_stack_jump?(matcher_1) ||
36
44
  NestedEvaluator.matcher_expects_call_stack_jump?(matcher_2)
@@ -102,6 +110,12 @@ module RSpec
102
110
  false
103
111
  end
104
112
 
113
+ def matcher_supports_value_expectations?(matcher)
114
+ matcher.supports_value_expectations?
115
+ rescue NoMethodError
116
+ true
117
+ end
118
+
105
119
  def matcher_is_diffable?(matcher)
106
120
  matcher.diffable?
107
121
  rescue NoMethodError
@@ -94,6 +94,13 @@ module RSpec
94
94
  true
95
95
  end
96
96
 
97
+ # @api private
98
+ # Indicates this matcher matches against a block only.
99
+ # @return [False]
100
+ def supports_value_expectations?
101
+ false
102
+ end
103
+
97
104
  private
98
105
 
99
106
  def captured?
@@ -101,13 +108,11 @@ module RSpec
101
108
  end
102
109
 
103
110
  def positive_failure_reason
104
- return "was not a block" unless Proc === @block
105
111
  return "output #{actual_output_description}" if @expected
106
112
  "did not"
107
113
  end
108
114
 
109
115
  def negative_failure_reason
110
- return "was not a block" unless Proc === @block
111
116
  "output #{actual_output_description}"
112
117
  end
113
118
 
@@ -76,6 +76,12 @@ module RSpec
76
76
  true
77
77
  end
78
78
 
79
+ # @private
80
+ def supports_value_expectations?
81
+ false
82
+ end
83
+
84
+ # @private
79
85
  def expects_call_stack_jump?
80
86
  true
81
87
  end
@@ -199,7 +205,6 @@ module RSpec
199
205
  end
200
206
 
201
207
  def given_error
202
- return " but was not given a block" unless Proc === @given_proc
203
208
  return " but nothing was raised" unless @actual_error
204
209
 
205
210
  backtrace = format_backtrace(@actual_error.backtrace)
@@ -88,12 +88,16 @@ module RSpec
88
88
  end
89
89
 
90
90
  # @api private
91
- # Indicates this matcher matches against a block.
92
- # @return [True]
93
91
  def supports_block_expectations?
94
92
  true
95
93
  end
96
94
 
95
+ # @api private
96
+ def supports_value_expectations?
97
+ false
98
+ end
99
+
100
+ # @api private
97
101
  def expects_call_stack_jump?
98
102
  true
99
103
  end
@@ -101,7 +105,6 @@ module RSpec
101
105
  private
102
106
 
103
107
  def actual_result
104
- return "but was not a block" unless Proc === @block
105
108
  "got #{caught}"
106
109
  end
107
110
 
@@ -10,7 +10,6 @@ module RSpec
10
10
  class YieldProbe
11
11
  def self.probe(block, &callback)
12
12
  probe = new(block, &callback)
13
- return probe unless probe.has_block?
14
13
  probe.probe
15
14
  end
16
15
 
@@ -24,10 +23,6 @@ module RSpec
24
23
  self.yielded_args = []
25
24
  end
26
25
 
27
- def has_block?
28
- Proc === @block
29
- end
30
-
31
26
  def probe
32
27
  assert_valid_expect_block!
33
28
  @block.call(self)
@@ -152,14 +147,12 @@ module RSpec
152
147
  # @private
153
148
  def matches?(block)
154
149
  @probe = YieldProbe.probe(block)
155
- return false unless @probe.has_block?
156
-
157
150
  @probe.num_yields.__send__(@expectation_type, @expected_yields_count)
158
151
  end
159
152
 
160
153
  # @private
161
154
  def does_not_match?(block)
162
- !matches?(block) && @probe.has_block?
155
+ !matches?(block)
163
156
  end
164
157
 
165
158
  # @api private
@@ -179,6 +172,11 @@ module RSpec
179
172
  true
180
173
  end
181
174
 
175
+ # @private
176
+ def supports_value_expectations?
177
+ false
178
+ end
179
+
182
180
  private
183
181
 
184
182
  def set_expected_yields_count(relativity, n)
@@ -192,7 +190,6 @@ module RSpec
192
190
  end
193
191
 
194
192
  def failure_reason
195
- return ' but was not a block' unless @probe.has_block?
196
193
  return '' unless @expected_yields_count
197
194
  " #{human_readable_expectation_type}#{human_readable_count(@expected_yields_count)}" \
198
195
  " but yielded #{human_readable_count(@probe.num_yields)}"
@@ -222,13 +219,12 @@ module RSpec
222
219
  # @private
223
220
  def matches?(block)
224
221
  @probe = YieldProbe.probe(block)
225
- return false unless @probe.has_block?
226
222
  @probe.yielded_once?(:yield_with_no_args) && @probe.single_yield_args.empty?
227
223
  end
228
224
 
229
225
  # @private
230
226
  def does_not_match?(block)
231
- !matches?(block) && @probe.has_block?
227
+ !matches?(block)
232
228
  end
233
229
 
234
230
  # @private
@@ -246,16 +242,19 @@ module RSpec
246
242
  true
247
243
  end
248
244
 
245
+ # @private
246
+ def supports_value_expectations?
247
+ false
248
+ end
249
+
249
250
  private
250
251
 
251
252
  def positive_failure_reason
252
- return 'was not a block' unless @probe.has_block?
253
253
  return 'did not yield' if @probe.num_yields.zero?
254
254
  "yielded with arguments: #{description_of @probe.single_yield_args}"
255
255
  end
256
256
 
257
257
  def negative_failure_reason
258
- return 'was not a block' unless @probe.has_block?
259
258
  'did'
260
259
  end
261
260
  end
@@ -276,14 +275,13 @@ module RSpec
276
275
  @actual_formatted = actual_formatted
277
276
  @args_matched_when_yielded &&= args_currently_match?
278
277
  end
279
- return false unless @probe.has_block?
280
278
  @probe.probe
281
279
  @probe.yielded_once?(:yield_with_args) && @args_matched_when_yielded
282
280
  end
283
281
 
284
282
  # @private
285
283
  def does_not_match?(block)
286
- !matches?(block) && @probe.has_block?
284
+ !matches?(block)
287
285
  end
288
286
 
289
287
  # @private
@@ -308,10 +306,14 @@ module RSpec
308
306
  true
309
307
  end
310
308
 
309
+ # @private
310
+ def supports_value_expectations?
311
+ false
312
+ end
313
+
311
314
  private
312
315
 
313
316
  def positive_failure_reason
314
- return 'was not a block' unless @probe.has_block?
315
317
  return 'did not yield' if @probe.num_yields.zero?
316
318
  @positive_args_failure
317
319
  end
@@ -321,9 +323,7 @@ module RSpec
321
323
  end
322
324
 
323
325
  def negative_failure_reason
324
- if !@probe.has_block?
325
- 'was not a block'
326
- elsif @args_matched_when_yielded && !@expected.empty?
326
+ if @args_matched_when_yielded && !@expected.empty?
327
327
  'yielded with expected arguments' \
328
328
  "\nexpected not: #{surface_descriptions_in(@expected).inspect}" \
329
329
  "\n got: #{@actual_formatted}"
@@ -375,12 +375,11 @@ module RSpec
375
375
  yield_count += 1
376
376
  end
377
377
 
378
- return false unless @probe.has_block?
379
378
  args_matched_when_yielded && yield_count == @expected.length
380
379
  end
381
380
 
382
381
  def does_not_match?(block)
383
- !matches?(block) && @probe.has_block?
382
+ !matches?(block)
384
383
  end
385
384
 
386
385
  # @private
@@ -405,6 +404,11 @@ module RSpec
405
404
  true
406
405
  end
407
406
 
407
+ # @private
408
+ def supports_value_expectations?
409
+ false
410
+ end
411
+
408
412
  private
409
413
 
410
414
  def expected_arg_description
@@ -412,16 +416,12 @@ module RSpec
412
416
  end
413
417
 
414
418
  def positive_failure_reason
415
- return 'was not a block' unless @probe.has_block?
416
-
417
419
  'yielded with unexpected arguments' \
418
420
  "\nexpected: #{surface_descriptions_in(@expected).inspect}" \
419
421
  "\n got: [#{@actual_formatted.join(", ")}]"
420
422
  end
421
423
 
422
424
  def negative_failure_reason
423
- return 'was not a block' unless @probe.has_block?
424
-
425
425
  'yielded with expected arguments' \
426
426
  "\nexpected not: #{surface_descriptions_in(@expected).inspect}" \
427
427
  "\n got: [#{@actual_formatted.join(", ")}]"
@@ -394,6 +394,10 @@ module RSpec
394
394
  false
395
395
  end
396
396
 
397
+ def supports_value_expectations?
398
+ true
399
+ end
400
+
397
401
  # Most matchers do not expect call stack jumps.
398
402
  def expects_call_stack_jump?
399
403
  false
@@ -60,6 +60,12 @@ module RSpec
60
60
  # @return [Boolean] true if this matcher can be used in block expressions.
61
61
  # @note If not defined, RSpec assumes a value of `false` for this method.
62
62
 
63
+ # @!method supports_value_expectations?
64
+ # Indicates that this matcher can be used in a value expectation expression,
65
+ # such as `expect(foo).to eq(bar)`.
66
+ # @return [Boolean] true if this matcher can be used in value expressions.
67
+ # @note If not defined, RSpec assumes a value of `true` for this method.
68
+
63
69
  # @!method expects_call_stack_jump?
64
70
  # Indicates that when this matcher is used in a block expectation
65
71
  # expression, it expects the block to use a ruby construct that causes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.4
4
+ version: 3.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -45,7 +45,7 @@ cert_chain:
45
45
  ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
46
46
  F3MdtaDehhjC
47
47
  -----END CERTIFICATE-----
48
- date: 2019-06-10 00:00:00.000000000 Z
48
+ date: 2019-10-02 00:00:00.000000000 Z
49
49
  dependencies:
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rspec-support
@@ -82,19 +82,19 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '2.0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: rake
85
+ name: aruba
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: 10.0.0
90
+ version: 0.14.10
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: 10.0.0
97
+ version: 0.14.10
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: cucumber
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -109,20 +109,6 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '1.3'
112
- - !ruby/object:Gem::Dependency
113
- name: aruba
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - "~>"
117
- - !ruby/object:Gem::Version
118
- version: 0.6.2
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - "~>"
124
- - !ruby/object:Gem::Version
125
- version: 0.6.2
126
112
  - !ruby/object:Gem::Dependency
127
113
  name: minitest
128
114
  requirement: !ruby/object:Gem::Requirement
@@ -202,7 +188,7 @@ licenses:
202
188
  - MIT
203
189
  metadata:
204
190
  bug_tracker_uri: https://github.com/rspec/rspec-expectations/issues
205
- changelog_uri: https://github.com/rspec/rspec-expectations/blob/v3.8.4/Changelog.md
191
+ changelog_uri: https://github.com/rspec/rspec-expectations/blob/v3.8.5/Changelog.md
206
192
  documentation_uri: https://rspec.info/documentation/
207
193
  mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
208
194
  source_code_uri: https://github.com/rspec/rspec-expectations
@@ -222,8 +208,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
208
  - !ruby/object:Gem::Version
223
209
  version: '0'
224
210
  requirements: []
225
- rubygems_version: 3.0.3
211
+ rubygems_version: 3.0.6
226
212
  signing_key:
227
213
  specification_version: 4
228
- summary: rspec-expectations-3.8.4
214
+ summary: rspec-expectations-3.8.5
229
215
  test_files: []
metadata.gz.sig CHANGED
Binary file