rspec-expectations 3.12.3 → 3.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +25 -1
- data/README.md +10 -4
- data/lib/rspec/expectations/fail_with.rb +1 -1
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers/built_in/base_matcher.rb +41 -0
- data/lib/rspec/matchers/built_in/compound.rb +2 -2
- data/lib/rspec/matchers/built_in/eq.rb +5 -1
- data/lib/rspec/matchers/built_in/eql.rb +5 -1
- data/lib/rspec/matchers/built_in/raise_error.rb +5 -1
- data/lib/rspec/matchers/matcher_delegator.rb +27 -1
- data/lib/rspec/matchers/{expecteds_for_multiple_diffs.rb → multi_matcher_diff.rb} +16 -16
- data/lib/rspec/matchers.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +7 -7
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de739c3ced3dfe0c29aad887b8aefef44b04b826a0315265289f21f7a9bcf4de
|
4
|
+
data.tar.gz: 969d3de594cc6061f2f197df757abb248359d139594ce23087c10f5c565ba88d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fde1836ea6689705e559d087433f4f7f3d239555e79e6f9d5f65b3c3d1cccb671e8dd40e60b88ae223fba347d59afc1e502c48f7ccceccb6dfbcf875abd46a7
|
7
|
+
data.tar.gz: f68303aaa957bdd48e2062bc0b00c43810740712879a8e93343eb602e58218958133cd9b55a25c4f006fb10fad295b204b404b1b5bf428a945bf5b3c719624ff
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
### Development
|
2
|
-
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.13.1...3-13-maintenance)
|
3
|
+
|
4
|
+
### 3.13.1 / 2024-06-13
|
5
|
+
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.13.0...v3.13.1)
|
6
|
+
|
7
|
+
Bug Fixes:
|
8
|
+
|
9
|
+
* Fix the "false positive" warning message when using a negated `raise_error` matcher
|
10
|
+
with a `RegExp` instance. (Eric Mueller, #1456)
|
11
|
+
|
12
|
+
### 3.13.0 / 2024-02-04
|
13
|
+
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.12.4...v3.13.0)
|
14
|
+
|
15
|
+
Enhancements:
|
16
|
+
|
17
|
+
* Update `eq` and `eql` matchers to better highlight difference in string encoding.
|
18
|
+
(Alan Foster, #1425)
|
19
|
+
|
20
|
+
### 3.12.4 / 2024-02-04
|
21
|
+
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.12.3...v3.12.4)
|
22
|
+
|
23
|
+
Bug Fixes:
|
24
|
+
|
25
|
+
* Fix the diff for redefined `actual` and reassigned `@actual` in compound
|
26
|
+
expectations failure messages. (Phil Pirozhkov, #1440)
|
3
27
|
|
4
28
|
### 3.12.3 / 2023-04-20
|
5
29
|
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.12.2...v3.12.3)
|
data/README.md
CHANGED
@@ -13,7 +13,9 @@ If you want to use rspec-expectations with rspec, just install the rspec gem
|
|
13
13
|
and RubyGems will also install rspec-expectations for you (along with
|
14
14
|
rspec-core and rspec-mocks):
|
15
15
|
|
16
|
-
|
16
|
+
```shell
|
17
|
+
gem install rspec
|
18
|
+
```
|
17
19
|
|
18
20
|
Want to run against the `main` branch? You'll need to include the dependent
|
19
21
|
RSpec repos as well. Add the following to your `Gemfile`:
|
@@ -27,7 +29,9 @@ end
|
|
27
29
|
If you want to use rspec-expectations with another tool, like Test::Unit,
|
28
30
|
Minitest, or Cucumber, you can install it directly:
|
29
31
|
|
30
|
-
|
32
|
+
```shell
|
33
|
+
gem install rspec-expectations
|
34
|
+
```
|
31
35
|
|
32
36
|
## Contributing
|
33
37
|
|
@@ -67,8 +71,10 @@ The `describe` and `it` methods come from rspec-core. The `Order`, `LineItem`,
|
|
67
71
|
expresses an expected outcome. If `order.total == Money.new(5.55, :USD)`, then
|
68
72
|
the example passes. If not, it fails with a message like:
|
69
73
|
|
70
|
-
|
71
|
-
|
74
|
+
```
|
75
|
+
expected: #<Money @value=5.55 @currency=:USD>
|
76
|
+
got: #<Money @value=1.11 @currency=:USD>
|
77
|
+
```
|
72
78
|
|
73
79
|
## Built-in matchers
|
74
80
|
|
@@ -30,7 +30,7 @@ module RSpec
|
|
30
30
|
"appropriate failure_message[_when_negated] method to return a string?"
|
31
31
|
end
|
32
32
|
|
33
|
-
message = ::RSpec::Matchers::
|
33
|
+
message = ::RSpec::Matchers::MultiMatcherDiff.from(expected, actual).message_with_diff(message, differ)
|
34
34
|
|
35
35
|
RSpec::Support.notify_failure(RSpec::Expectations::ExpectationNotMetError.new message)
|
36
36
|
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
|
@@ -51,10 +51,10 @@ module RSpec
|
|
51
51
|
end
|
52
52
|
|
53
53
|
# @api private
|
54
|
-
# @return [RSpec::Matchers::
|
54
|
+
# @return [RSpec::Matchers::MultiMatcherDiff]
|
55
55
|
def expected
|
56
56
|
return nil unless evaluator
|
57
|
-
::RSpec::Matchers::
|
57
|
+
::RSpec::Matchers::MultiMatcherDiff.for_many_matchers(diffable_matcher_list)
|
58
58
|
end
|
59
59
|
|
60
60
|
protected
|
@@ -8,7 +8,11 @@ module RSpec
|
|
8
8
|
# @api private
|
9
9
|
# @return [String]
|
10
10
|
def failure_message
|
11
|
-
|
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
|
-
|
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
|
@@ -13,6 +13,10 @@ module RSpec
|
|
13
13
|
# argument. We can't use `nil` for that because we need to warn when `nil` is
|
14
14
|
# passed in a different way. It's an Object, not a Module, since Module's `===`
|
15
15
|
# does not evaluate to true when compared to itself.
|
16
|
+
#
|
17
|
+
# Note; this _is_ the default value supplied for expected_error_or_message, but
|
18
|
+
# because there are two method-calls involved, that default is actually supplied
|
19
|
+
# in the definition of the _matcher_ method, `RSpec::Matchers#raise_error`
|
16
20
|
UndefinedValue = Object.new.freeze
|
17
21
|
|
18
22
|
def initialize(expected_error_or_message, expected_message, &block)
|
@@ -25,7 +29,7 @@ module RSpec
|
|
25
29
|
when nil, UndefinedValue
|
26
30
|
@expected_error = Exception
|
27
31
|
@expected_message = expected_message
|
28
|
-
when String
|
32
|
+
when String, Regexp
|
29
33
|
@expected_error = Exception
|
30
34
|
@expected_message = expected_error_or_message
|
31
35
|
else
|
@@ -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
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Matchers
|
3
3
|
# @api private
|
4
|
-
# Handles list of expected
|
5
|
-
# multiple diffs. Also can handle one
|
6
|
-
class
|
4
|
+
# Handles list of expected and actual value pairs when there is a need
|
5
|
+
# to render multiple diffs. Also can handle one pair.
|
6
|
+
class MultiMatcherDiff
|
7
7
|
# @private
|
8
8
|
# Default diff label when there is only one matcher in diff
|
9
9
|
# output
|
@@ -19,22 +19,23 @@ module RSpec
|
|
19
19
|
|
20
20
|
# @api private
|
21
21
|
# Wraps provided expected value in instance of
|
22
|
-
#
|
23
|
-
#
|
22
|
+
# MultiMatcherDiff. If provided value is already an
|
23
|
+
# MultiMatcherDiff then it just returns it.
|
24
24
|
# @param [Any] expected value to be wrapped
|
25
|
-
# @
|
26
|
-
|
25
|
+
# @param [Any] actual value
|
26
|
+
# @return [RSpec::Matchers::MultiMatcherDiff]
|
27
|
+
def self.from(expected, actual)
|
27
28
|
return expected if self === expected
|
28
|
-
new([[expected, DEFAULT_DIFF_LABEL]])
|
29
|
+
new([[expected, DEFAULT_DIFF_LABEL, actual]])
|
29
30
|
end
|
30
31
|
|
31
32
|
# @api private
|
32
33
|
# Wraps provided matcher list in instance of
|
33
|
-
#
|
34
|
+
# MultiMatcherDiff.
|
34
35
|
# @param [Array<Any>] matchers list of matchers to wrap
|
35
|
-
# @return [RSpec::Matchers::
|
36
|
+
# @return [RSpec::Matchers::MultiMatcherDiff]
|
36
37
|
def self.for_many_matchers(matchers)
|
37
|
-
new(matchers.map { |m| [m.expected, diff_label_for(m)] })
|
38
|
+
new(matchers.map { |m| [m.expected, diff_label_for(m), m.actual] })
|
38
39
|
end
|
39
40
|
|
40
41
|
# @api private
|
@@ -42,10 +43,9 @@ module RSpec
|
|
42
43
|
# factory and actual value if there are any
|
43
44
|
# @param [String] message original failure message
|
44
45
|
# @param [Proc] differ
|
45
|
-
# @param [Any] actual value
|
46
46
|
# @return [String]
|
47
|
-
def message_with_diff(message, differ
|
48
|
-
diff = diffs(differ
|
47
|
+
def message_with_diff(message, differ)
|
48
|
+
diff = diffs(differ)
|
49
49
|
message = "#{message}\n#{diff}" unless diff.empty?
|
50
50
|
message
|
51
51
|
end
|
@@ -65,8 +65,8 @@ module RSpec
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
def diffs(differ
|
69
|
-
@expected_list.map do |(expected, diff_label)|
|
68
|
+
def diffs(differ)
|
69
|
+
@expected_list.map do |(expected, diff_label, actual)|
|
70
70
|
diff = differ.diff(actual, expected)
|
71
71
|
next if diff.strip.empty?
|
72
72
|
if diff == "\e[0m\n\e[0m"
|
data/lib/rspec/matchers.rb
CHANGED
@@ -10,7 +10,7 @@ RSpec::Support.define_optimized_require_for_rspec(:matchers) { |f| require_relat
|
|
10
10
|
dsl
|
11
11
|
matcher_delegator
|
12
12
|
aliased_matcher
|
13
|
-
|
13
|
+
multi_matcher_diff
|
14
14
|
].each { |file| RSpec::Support.require_rspec_matchers(file) }
|
15
15
|
|
16
16
|
# RSpec's top level namespace. All of rspec-expectations is contained
|
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.
|
4
|
+
version: 3.13.1
|
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:
|
48
|
+
date: 2024-06-13 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.
|
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.
|
63
|
+
version: 3.13.0
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
65
|
name: diff-lcs
|
66
66
|
requirement: !ruby/object:Gem::Requirement
|
@@ -193,17 +193,17 @@ files:
|
|
193
193
|
- lib/rspec/matchers/composable.rb
|
194
194
|
- lib/rspec/matchers/dsl.rb
|
195
195
|
- lib/rspec/matchers/english_phrasing.rb
|
196
|
-
- lib/rspec/matchers/expecteds_for_multiple_diffs.rb
|
197
196
|
- lib/rspec/matchers/fail_matchers.rb
|
198
197
|
- lib/rspec/matchers/generated_descriptions.rb
|
199
198
|
- lib/rspec/matchers/matcher_delegator.rb
|
200
199
|
- lib/rspec/matchers/matcher_protocol.rb
|
200
|
+
- lib/rspec/matchers/multi_matcher_diff.rb
|
201
201
|
homepage: https://github.com/rspec/rspec-expectations
|
202
202
|
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.
|
206
|
+
changelog_uri: https://github.com/rspec/rspec-expectations/blob/v3.13.1/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.
|
229
|
+
summary: rspec-expectations-3.13.1
|
230
230
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|