rspec-expectations 3.12.4 → 3.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a4b2b9ff3e6aa95cb68edc11fb142d4ed9af33134ece089bb4fa2f524b4fed9
4
- data.tar.gz: cde69140cecbddef69efa9a51148983786cec5023695c56686ef4141490dd657
3
+ metadata.gz: f09f6ee084c32b2e2090849e672c3f71479b002183e0a3731ee6dd72c08352bf
4
+ data.tar.gz: 997ea963ec0460e393ac82075843e67aaf47513d9de082c88c083ad38da49a6d
5
5
  SHA512:
6
- metadata.gz: a391ea2eb336a05f2cabaea19ddd759499dac7f0ca1578504ad9668752d0c758f83f75281b4ba041db55ff62695e99368fb37576566068baf0ad95de43f16b1a
7
- data.tar.gz: 1f2b528c2073230317a0557b371a28be61a35895b8849f310f6696ce6cf6cc7074878ea8657a8e137cae9da5f7c58219716946fe56229b49eb91a60ae2125dfc
6
+ metadata.gz: 58cb3644c01f1771f2109faf971acba2bdc04c6e528ff68a55765ea850666ab27bec8ffcaf39e23b72b194f936e09de263136b5ac8cbc2cbc3d51d7e2d1dddee
7
+ data.tar.gz: 73204c1e6f84100a10e27f78ea853e1282ca26daf39927dd5a72f3c8294ff0555ea49ca01fcf5626faedc9af972a56f8641a7496e765eedd7936b647dcb28b5a
checksums.yaml.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ### Development
2
- [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.12.4...3-12-maintenance)
2
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.12.3...main)
3
+
4
+ ### 3.13.0 / 2024-02-04
5
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.12.4...v3.13.0)
6
+
7
+ Enhancements:
8
+
9
+ * Update `eq` and `eql` matchers to better highlight difference in string encoding.
10
+ (Alan Foster, #1425)
3
11
 
4
12
  ### 3.12.4 / 2024-02-04
5
13
  [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.12.3...v3.12.4)
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '3.12.4'
5
+ STRING = '3.13.0'
6
6
  end
7
7
  end
8
8
  end
@@ -161,6 +161,47 @@ module RSpec
161
161
 
162
162
  include HashFormatting
163
163
 
164
+ # @private
165
+ module StringEncodingFormatting
166
+ # @api private
167
+ # @return [Boolean] True if the actual and expected string encoding are different.
168
+ # i.e. the failure may be related to encoding differences and the encoding
169
+ # should be shown to the user. false otherwise.
170
+ if String.method_defined?(:encoding)
171
+ def string_encoding_differs?
172
+ actual.is_a?(String) && expected.is_a?(String) && actual.encoding != expected.encoding
173
+ end
174
+ else
175
+ # @api private
176
+ # @return [Boolean] False always as the curent Ruby version does not support String encoding
177
+ def string_encoding_differs?
178
+ false
179
+ end
180
+ end
181
+ module_function :string_encoding_differs?
182
+
183
+ if String.method_defined?(:encoding)
184
+ # @api private
185
+ # Formats a String's encoding as a human readable string
186
+ # @param value [String]
187
+ # @return [String]
188
+ def format_encoding(value)
189
+ "#<Encoding:#{value.encoding.name}>"
190
+ end
191
+ else
192
+ # @api private
193
+ # Formats a String's encoding as a human readable string
194
+ # @param _value [String]
195
+ # @return [nil] nil as the curent Ruby version does not support String encoding
196
+ def format_encoding(_value)
197
+ nil
198
+ end
199
+ end
200
+ module_function :format_encoding
201
+ end
202
+
203
+ include StringEncodingFormatting
204
+
164
205
  # @api private
165
206
  # Provides default implementations of failure messages, based on the `description`.
166
207
  module DefaultFailureMessages
@@ -8,7 +8,11 @@ module RSpec
8
8
  # @api private
9
9
  # @return [String]
10
10
  def failure_message
11
- "\nexpected: #{expected_formatted}\n got: #{actual_formatted}\n\n(compared using ==)\n"
11
+ if string_encoding_differs?
12
+ "\nexpected: #{format_encoding(expected)} #{expected_formatted}\n got: #{format_encoding(actual)} #{actual_formatted}\n\n(compared using ==)\n"
13
+ else
14
+ "\nexpected: #{expected_formatted}\n got: #{actual_formatted}\n\n(compared using ==)\n"
15
+ end
12
16
  end
13
17
 
14
18
  # @api private
@@ -8,7 +8,11 @@ module RSpec
8
8
  # @api private
9
9
  # @return [String]
10
10
  def failure_message
11
- "\nexpected: #{expected_formatted}\n got: #{actual_formatted}\n\n(compared using eql?)\n"
11
+ if string_encoding_differs?
12
+ "\nexpected: #{format_encoding(expected)} #{expected_formatted}\n got: #{format_encoding(actual)} #{actual_formatted}\n\n(compared using eql?)\n"
13
+ else
14
+ "\nexpected: #{expected_formatted}\n got: #{actual_formatted}\n\n(compared using eql?)\n"
15
+ end
12
16
  end
13
17
 
14
18
  # @api private
@@ -1,8 +1,34 @@
1
1
  module RSpec
2
2
  module Matchers
3
+ # Provides a base class with as little methods as possible, so that
4
+ # most methods can be delegated via `method_missing`.
5
+ #
6
+ # On Ruby 2.0+ BasicObject could be used for this purpose, but it
7
+ # introduce some extra complexity with constant resolution, so the
8
+ # BlankSlate pattern was prefered.
9
+ # @private
10
+ class BaseDelegator
11
+ kept_methods = [
12
+ # Methods that raise warnings if removed.
13
+ :__id__, :__send__, :object_id,
14
+
15
+ # Methods that are explicitly undefined in some subclasses.
16
+ :==, :===,
17
+
18
+ # Methods we keep on purpose.
19
+ :class, :respond_to?, :__method__, :method, :dup,
20
+ :clone, :initialize_dup, :initialize_copy, :initialize_clone,
21
+ ]
22
+ instance_methods.each do |method|
23
+ unless kept_methods.include?(method.to_sym)
24
+ undef_method(method)
25
+ end
26
+ end
27
+ end
28
+
3
29
  # Provides the necessary plumbing to wrap a matcher with a decorator.
4
30
  # @private
5
- class MatcherDelegator
31
+ class MatcherDelegator < BaseDelegator
6
32
  include Composable
7
33
  attr_reader :base_matcher
8
34
 
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.12.4
4
+ version: 3.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -53,14 +53,14 @@ dependencies:
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 3.12.0
56
+ version: 3.13.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.12.0
63
+ version: 3.13.0
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: diff-lcs
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -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.12.4/Changelog.md
206
+ changelog_uri: https://github.com/rspec/rspec-expectations/blob/v3.13.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
@@ -226,5 +226,5 @@ requirements: []
226
226
  rubygems_version: 3.3.26
227
227
  signing_key:
228
228
  specification_version: 4
229
- summary: rspec-expectations-3.12.4
229
+ summary: rspec-expectations-3.13.0
230
230
  test_files: []
metadata.gz.sig CHANGED
Binary file