rspec-expectations 3.10.1 → 3.11.0

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: 487ee657765cb954821ff9cdff9298e5442431c611eb83f380afe9151e865a01
4
- data.tar.gz: 5c6a1b5e7c99e1f58029cef0f0dce644d83d64fe265155aadb3f247b0b3fbe32
3
+ metadata.gz: e651e80dd869915779a72a9ea43b38d20327f3dbfaf94a4851eff7974d1f3d0a
4
+ data.tar.gz: e1788055c911b97cbad1b3747fe9b9be005a999e2e97e6c361df4c91fa4fda25
5
5
  SHA512:
6
- metadata.gz: a5f4383ba85185e8c59ccf2f1523835fb64e02e1828e37b2d5a93bd1be320c6152e0783b14fd524d753b8ef18d7dc7205fe25481a8adbadf2bf6b8c63acd3965
7
- data.tar.gz: 710360cfef64576512eab6a165cd6e54cde44648d20ff40598a047af2fbce20f88caf00bf695c74c53c78e404505a4bfa6f196f5481bc7a7a742c1898c98a398
6
+ metadata.gz: ec1b6b68b80fddae764dbf88312817c35c1e76228c29748e2b89d8d9a69d95384aa4fe9daf7b8a650dd307dd32aca13bae590d8960f0989beea67c54f7f6d7d5
7
+ data.tar.gz: 7a8a129e74ccec6299ab3af1c728cab2754a1cc98911507704c3f52a01c33b321250bfe715deef835b61963e22c66ec878500d10c6fea93d4fda7cc39b101676
checksums.yaml.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,3 +1,30 @@
1
+ ### Development
2
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.11.0...3-11-maintenance)
3
+
4
+ ### 3.11.0 / 2022-02-09
5
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.10.2...v3.11.0)
6
+
7
+ Enhancements:
8
+
9
+ * Return `true` from `aggregate_failures` when no exception occurs. (Jon Rowe, #1225)
10
+
11
+ Deprecations:
12
+
13
+ * Print a deprecation message when using the implicit block expectation syntax.
14
+ (Phil Pirozhkov, #1139)
15
+
16
+ ### 3.10.2 / 2022-01-14
17
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.10.1...v3.10.2)
18
+
19
+ Bug Fixes:
20
+
21
+ * Fix support for dynamic matchers for expectation target checks (Phil Pirozhkov, #1294)
22
+ * Fix `expect(array).to include(hash).times`, previously this would fail due to
23
+ matching the entire array as a single hash, rather than a member of the hash.
24
+ (Slava Kardakov, #1322)
25
+ * Ensure `raise_error` matches works with the `error_highlight` option from Ruby 3.1.
26
+ (Peter Goldstein, #1339)
27
+
1
28
  ### 3.10.1 / 2020-12-27
2
29
  [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.10.0...v3.10.1)
3
30
 
@@ -113,7 +140,7 @@ Bug Fixes:
113
140
  * Prevent composed `all` matchers from leaking into their siblings leading to duplicate
114
141
  failures. (Jamie English, #1086)
115
142
  * Prevent objects which change their hash on comparison from failing change checks.
116
- (Phil Pirozhkov, #1110)
143
+ (Phil Pirozhkov, #1100)
117
144
  * Issue an `ArgumentError` rather than a `NoMethodError` when `be_an_instance_of` and
118
145
  `be_kind_of` matchers encounter objects not supporting those methods.
119
146
  (Taichi Ishitani, #1107)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # RSpec Expectations [![Build Status](https://secure.travis-ci.org/rspec/rspec-expectations.svg?branch=main)](http://travis-ci.org/rspec/rspec-expectations) [![Code Climate](https://codeclimate.com/github/rspec/rspec-expectations.svg)](https://codeclimate.com/github/rspec/rspec-expectations)
1
+ # RSpec Expectations [![Build Status](https://github.com/rspec/rspec-expectations/workflows/RSpec%20CI/badge.svg)](https://github.com/rspec/rspec-expectations/actions) [![Code Climate](https://codeclimate.com/github/rspec/rspec-expectations.svg)](https://codeclimate.com/github/rspec/rspec-expectations)
2
2
 
3
3
  RSpec::Expectations lets you express expected outcomes on an object in an
4
4
  example.
@@ -42,7 +42,7 @@ module RSpec
42
42
  elsif block
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
 
@@ -57,7 +57,7 @@ module RSpec
57
57
  # expect { perform }.to raise_error
58
58
  # @param [Matcher]
59
59
  # matcher
60
- # @param [String or Proc] message optional message to display when the expectation fails
60
+ # @param [String, Proc] message optional message to display when the expectation fails
61
61
  # @return [Boolean] true if the expectation succeeds (else raises)
62
62
  # @see RSpec::Matchers
63
63
  def to(matcher=nil, message=nil, &block)
@@ -70,7 +70,7 @@ module RSpec
70
70
  # expect(value).not_to eq(5)
71
71
  # @param [Matcher]
72
72
  # matcher
73
- # @param [String or Proc] message optional message to display when the expectation fails
73
+ # @param [String, Proc] message optional message to display when the expectation fails
74
74
  # @return [Boolean] false if the negative expectation succeeds (else raises)
75
75
  # @see RSpec::Matchers
76
76
  def not_to(matcher=nil, message=nil, &block)
@@ -90,6 +90,44 @@ 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
+ RSpec.deprecate(
115
+ "expect(value).to #{RSpec::Support::ObjectFormatter.format(matcher)}",
116
+ :message =>
117
+ "The implicit block expectation syntax is deprecated, you should pass " \
118
+ "a block rather than an argument to `expect` to use the provided " \
119
+ "block expectation matcher or the matcher must implement " \
120
+ "`supports_value_expectations?`. e.g `expect { value }.to " \
121
+ "#{RSpec::Support::ObjectFormatter.format(matcher)}` not " \
122
+ "`expect(value).to #{RSpec::Support::ObjectFormatter.format(matcher)}`"
123
+ )
124
+ end
125
+
126
+ def supports_value_expectations?(matcher)
127
+ !matcher.respond_to?(:supports_value_expectations?) || matcher.supports_value_expectations?
128
+ end
129
+ end
130
+
93
131
  # @private
94
132
  # Validates the provided matcher to ensure it supports block
95
133
  # expectations, in order to avoid user confusion when they
@@ -118,9 +156,7 @@ module RSpec
118
156
  end
119
157
 
120
158
  def supports_block_expectations?(matcher)
121
- matcher.supports_block_expectations?
122
- rescue NoMethodError
123
- false
159
+ matcher.respond_to?(:supports_block_expectations?) && matcher.supports_block_expectations?
124
160
  end
125
161
  end
126
162
  end
@@ -80,7 +80,7 @@ module RSpec
80
80
  all_errors = failures + other_errors
81
81
 
82
82
  case all_errors.size
83
- when 0 then return nil
83
+ when 0 then return true
84
84
  when 1 then RSpec::Support.notify_failure all_errors.first
85
85
  else RSpec::Support.notify_failure MultipleExpectationsNotMetError.new(self)
86
86
  end
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '3.10.1'
5
+ STRING = '3.11.0'
6
6
  end
7
7
  end
8
8
  end
@@ -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)
@@ -158,6 +163,11 @@ module RSpec
158
163
  true
159
164
  end
160
165
 
166
+ # @private
167
+ def supports_value_expectations?
168
+ false
169
+ end
170
+
161
171
  private
162
172
 
163
173
  def failure_reason
@@ -201,6 +211,11 @@ module RSpec
201
211
  true
202
212
  end
203
213
 
214
+ # @private
215
+ def supports_value_expectations?
216
+ false
217
+ end
218
+
204
219
  private
205
220
 
206
221
  def perform_change(event_proc)
@@ -337,6 +352,8 @@ module RSpec
337
352
  class ChangeDetails
338
353
  attr_reader :actual_after
339
354
 
355
+ UNDEFINED = Module.new.freeze
356
+
340
357
  def initialize(matcher_name, receiver=nil, message=nil, &block)
341
358
  if receiver && !message
342
359
  raise(
@@ -351,6 +368,11 @@ module RSpec
351
368
  @receiver = receiver
352
369
  @message = message
353
370
  @value_proc = block
371
+ # TODO: temporary measure to mute warning of access to an initialized
372
+ # instance variable when a deprecated implicit block expectation
373
+ # syntax is used. This may be removed once `fail` is used, and the
374
+ # matcher never issues this warning.
375
+ @actual_after = UNDEFINED
354
376
  end
355
377
 
356
378
  def value_representation
@@ -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
@@ -182,7 +182,7 @@ module RSpec
182
182
  when String
183
183
  actual.scan(expected.first).length
184
184
  when Enumerable
185
- count_enumerable(expected.first)
185
+ count_enumerable(Hash === expected ? expected : expected.first)
186
186
  else
187
187
  raise NotImplementedError, 'Count constraints are implemented for Enumerable and String values only'
188
188
  end
@@ -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?
@@ -59,7 +59,7 @@ module RSpec
59
59
  given_proc.call
60
60
  rescue Exception => @actual_error
61
61
  if values_match?(@expected_error, @actual_error) ||
62
- values_match?(@expected_error, @actual_error.message)
62
+ values_match?(@expected_error, actual_error_message)
63
63
  @raised_expected_error = true
64
64
  @with_expected_message = verify_message
65
65
  end
@@ -86,6 +86,12 @@ module RSpec
86
86
  true
87
87
  end
88
88
 
89
+ # @private
90
+ def supports_value_expectations?
91
+ false
92
+ end
93
+
94
+ # @private
89
95
  def expects_call_stack_jump?
90
96
  true
91
97
  end
@@ -93,7 +99,7 @@ module RSpec
93
99
  # @api private
94
100
  # @return [String]
95
101
  def failure_message
96
- @eval_block ? @actual_error.message : "expected #{expected_error}#{given_error}"
102
+ @eval_block ? actual_error_message : "expected #{expected_error}#{given_error}"
97
103
  end
98
104
 
99
105
  # @api private
@@ -110,6 +116,12 @@ module RSpec
110
116
 
111
117
  private
112
118
 
119
+ def actual_error_message
120
+ return nil unless @actual_error
121
+
122
+ @actual_error.respond_to?(:original_message) ? @actual_error.original_message : @actual_error.message
123
+ end
124
+
113
125
  def expectation_matched?
114
126
  error_and_message_match? && block_matches?
115
127
  end
@@ -138,7 +150,7 @@ module RSpec
138
150
 
139
151
  def verify_message
140
152
  return true if @expected_message.nil?
141
- values_match?(@expected_message, @actual_error.message.to_s)
153
+ values_match?(@expected_message, actual_error_message.to_s)
142
154
  end
143
155
 
144
156
  def warn_for_negative_false_positives!
@@ -94,6 +94,12 @@ module RSpec
94
94
  true
95
95
  end
96
96
 
97
+ # @api private
98
+ def supports_value_expectations?
99
+ false
100
+ end
101
+
102
+ # @api private
97
103
  def expects_call_stack_jump?
98
104
  true
99
105
  end
@@ -129,6 +129,11 @@ module RSpec
129
129
  true
130
130
  end
131
131
 
132
+ # @private
133
+ def supports_value_expectations?
134
+ false
135
+ end
136
+
132
137
  private
133
138
 
134
139
  def failure_reason
@@ -169,6 +174,11 @@ module RSpec
169
174
  true
170
175
  end
171
176
 
177
+ # @private
178
+ def supports_value_expectations?
179
+ false
180
+ end
181
+
172
182
  private
173
183
 
174
184
  def positive_failure_reason
@@ -231,6 +241,11 @@ module RSpec
231
241
  true
232
242
  end
233
243
 
244
+ # @private
245
+ def supports_value_expectations?
246
+ false
247
+ end
248
+
234
249
  private
235
250
 
236
251
  def positive_failure_reason
@@ -328,6 +343,11 @@ module RSpec
328
343
  true
329
344
  end
330
345
 
346
+ # @private
347
+ def supports_value_expectations?
348
+ false
349
+ end
350
+
331
351
  private
332
352
 
333
353
  def expected_arg_description
@@ -403,6 +403,10 @@ module RSpec
403
403
  false
404
404
  end
405
405
 
406
+ def supports_value_expectations?
407
+ true
408
+ end
409
+
406
410
  # Most matchers do not expect call stack jumps.
407
411
  def expects_call_stack_jump?
408
412
  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
data.tar.gz.sig CHANGED
Binary file
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.10.1
4
+ version: 3.11.0
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: 2020-12-27 00:00:00.000000000 Z
48
+ date: 2022-02-09 00:00:00.000000000 Z
49
49
  dependencies:
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rspec-support
@@ -53,14 +53,14 @@ dependencies:
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 3.10.0
56
+ version: 3.11.0
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: 3.10.0
63
+ version: 3.11.0
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: diff-lcs
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -99,14 +99,14 @@ dependencies:
99
99
  name: cucumber
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - "~>"
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: '1.3'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - "~>"
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '1.3'
112
112
  - !ruby/object:Gem::Dependency
@@ -203,7 +203,7 @@ licenses:
203
203
  - MIT
204
204
  metadata:
205
205
  bug_tracker_uri: https://github.com/rspec/rspec-expectations/issues
206
- changelog_uri: https://github.com/rspec/rspec-expectations/blob/v3.10.1/Changelog.md
206
+ changelog_uri: https://github.com/rspec/rspec-expectations/blob/v3.11.0/Changelog.md
207
207
  documentation_uri: https://rspec.info/documentation/
208
208
  mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
209
209
  source_code_uri: https://github.com/rspec/rspec-expectations
@@ -223,8 +223,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  - !ruby/object:Gem::Version
224
224
  version: '0'
225
225
  requirements: []
226
- rubygems_version: 3.2.3
226
+ rubygems_version: 3.3.3
227
227
  signing_key:
228
228
  specification_version: 4
229
- summary: rspec-expectations-3.10.1
229
+ summary: rspec-expectations-3.11.0
230
230
  test_files: []
metadata.gz.sig CHANGED
Binary file