rspec-expectations 3.13.5 → 4.0.0.beta1
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +28 -1
- data/LICENSE.md +1 -0
- data/README.md +7 -67
- data/lib/rspec/expectations/block_snippet_extractor.rb +3 -1
- data/lib/rspec/expectations/configuration.rb +2 -99
- data/lib/rspec/expectations/expectation_target.rb +11 -12
- data/lib/rspec/expectations/fail_with.rb +2 -0
- data/lib/rspec/expectations/failure_aggregator.rb +4 -2
- data/lib/rspec/expectations/handler.rb +2 -103
- data/lib/rspec/expectations/minitest_integration.rb +2 -0
- data/lib/rspec/expectations/version.rb +3 -1
- data/lib/rspec/expectations.rb +5 -0
- data/lib/rspec/matchers/aliased_matcher.rb +2 -0
- data/lib/rspec/matchers/built_in/all.rb +2 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +10 -30
- data/lib/rspec/matchers/built_in/be.rb +4 -2
- data/lib/rspec/matchers/built_in/be_between.rb +2 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +2 -0
- data/lib/rspec/matchers/built_in/be_kind_of.rb +2 -0
- data/lib/rspec/matchers/built_in/be_within.rb +2 -0
- data/lib/rspec/matchers/built_in/change.rb +22 -37
- data/lib/rspec/matchers/built_in/compound.rb +16 -12
- data/lib/rspec/matchers/built_in/contain_exactly.rb +6 -15
- data/lib/rspec/matchers/built_in/count_expectation.rb +7 -17
- data/lib/rspec/matchers/built_in/cover.rb +2 -0
- data/lib/rspec/matchers/built_in/eq.rb +2 -0
- data/lib/rspec/matchers/built_in/eql.rb +2 -0
- data/lib/rspec/matchers/built_in/equal.rb +2 -0
- data/lib/rspec/matchers/built_in/exist.rb +4 -2
- data/lib/rspec/matchers/built_in/has.rb +9 -40
- data/lib/rspec/matchers/built_in/have_attributes.rb +2 -0
- data/lib/rspec/matchers/built_in/include.rb +8 -13
- data/lib/rspec/matchers/built_in/match.rb +3 -39
- data/lib/rspec/matchers/built_in/output.rb +50 -14
- data/lib/rspec/matchers/built_in/raise_error.rb +15 -25
- data/lib/rspec/matchers/built_in/respond_to.rb +5 -3
- data/lib/rspec/matchers/built_in/satisfy.rb +2 -0
- data/lib/rspec/matchers/built_in/start_or_end_with.rb +2 -6
- data/lib/rspec/matchers/built_in/throw_symbol.rb +4 -7
- data/lib/rspec/matchers/built_in/yield.rb +21 -50
- data/lib/rspec/matchers/built_in.rb +2 -3
- data/lib/rspec/matchers/composable.rb +2 -1
- data/lib/rspec/matchers/dsl.rb +19 -71
- data/lib/rspec/matchers/english_phrasing.rb +2 -18
- data/lib/rspec/matchers/fail_matchers.rb +2 -0
- data/lib/rspec/matchers/generated_descriptions.rb +2 -0
- data/lib/rspec/matchers/matcher_delegator.rb +9 -13
- data/lib/rspec/matchers/matcher_protocol.rb +2 -0
- data/lib/rspec/matchers/multi_matcher_diff.rb +6 -4
- data/lib/rspec/matchers.rb +11 -60
- data.tar.gz.sig +0 -0
- metadata +28 -30
- metadata.gz.sig +0 -0
- data/lib/rspec/expectations/syntax.rb +0 -132
- data/lib/rspec/matchers/built_in/operators.rb +0 -128
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b78a4094b1fd15d87c6a618fc428f08ea410c54cebf06fea64c4e8e39a3e4ad2
|
|
4
|
+
data.tar.gz: 85703b7d9b962af5dfc36c45e3929a503e586196869149b2be9fd2a6fd0a59c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8cd51f99521deb1b7b5fc4d87bdd2d34bb4ec5e008266b123e6271368b9baa59e517abf0c2dbc33f7ae4f7d3351e131ea9c7015fdad4af48e1af3dac294d2861
|
|
7
|
+
data.tar.gz: 39ed32f6c8cb479260abf1755837c96af70eddf496de9d754beca732ea51e990cc2501449d2ccfd2011169d0df8e0df6149811ecd1e2ec8891ab1b1b8bac5e9e
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/Changelog.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
### Development
|
|
2
|
-
[Full Changelog](https://github.com/rspec/rspec/compare/rspec-expectations-v3.13.4...
|
|
2
|
+
[Full Changelog](https://github.com/rspec/rspec/compare/rspec-expectations-v3.13.4...main)
|
|
3
|
+
|
|
4
|
+
# 4.0.0.beta1 / 2026-02-18
|
|
5
|
+
|
|
6
|
+
Breaking Changes:
|
|
7
|
+
|
|
8
|
+
* Ruby < 3.0 is no longer supported. (Phil Pirozhkov, Jon Rowe, rspec/rspec-expectations#1231, rspec/rspec#258)
|
|
9
|
+
* Remove `should` and `should_not` syntax (including one-liners). (Phil Pirozhkov, rspec/rspec-expectations#1245)
|
|
10
|
+
* Turn `strict_predicate_matchers` on by default. (Phil Pirozhkov, rspec/rspec-expectations#1277)
|
|
11
|
+
* Remove support for legacy RSpec matchers (pre 3). (Phil Pirozhkov, rspec/rspec-expectations#1253)
|
|
12
|
+
* Remove `include_chain_clauses_in_custom_matcher_descriptions` option
|
|
13
|
+
and make it the default. (Phil Pirozhkov, rspec/rspec-expectations#1279)
|
|
14
|
+
* Remove support for present-tense dynamic predicate. (Phil Pirozhkov, rspec/rspec-expectations#1286)
|
|
15
|
+
* Prevent implicit blocks (e.g blocks as values) from being used with block matchers.
|
|
16
|
+
(Phil Pirozhkov, rspec/rspec-expectations#1285)
|
|
17
|
+
* Remove deprecated `match_regex` matcher. (Phil Pirozhkov, rspec/rspec-expectations#1288)
|
|
18
|
+
* Remove deprecated `StartAndEndWith` matcher base class. (Phil Pirozhkov, rspec/rspec-expectations#1288)
|
|
19
|
+
* Raise `ArgumentError` when a `nil` is passed as the first argument to `raise_error`.
|
|
20
|
+
(Phil Pirozhkov, rspec/rspec-expectations#1389)
|
|
21
|
+
* Remove deprecated `RSpec::Expectations::Config#warn_about_potential_false_positives`.
|
|
22
|
+
(Anthony Clark, Phil Pirozhkov, rspec/rspec#260)
|
|
23
|
+
|
|
24
|
+
Enhancements:
|
|
25
|
+
|
|
26
|
+
* Improve the IO emulation in the output capture matchers (`output(...).to_stdout` et al)
|
|
27
|
+
by adding `as_tty` and `as_not_tty` to change the `tty?` flags. (Sergio Gil Pérez de la Manga, rspec/rspec-expectations#1459)
|
|
28
|
+
* Improve the error message when using constraints with a negated `change` matcher.
|
|
29
|
+
(Qingyu Chai, rspec/rspec#177)
|
|
3
30
|
|
|
4
31
|
### 3.13.5 / 2025-05-27
|
|
5
32
|
[Full Changelog](https://github.com/rspec/rspec/compare/rspec-expectations-v3.13.4...rspec-expectations-v3.13.5)
|
data/LICENSE.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
=====================
|
|
3
3
|
|
|
4
|
+
* Copyright © 2013 David Chelimsky, Myron Marston, Jon Rowe, Sam Phippen, Xavier Shay, Bradley Schaefer
|
|
4
5
|
* Copyright © 2012 David Chelimsky, Myron Marston
|
|
5
6
|
* Copyright © 2006 David Chelimsky, The RSpec Development Team
|
|
6
7
|
* Copyright © 2005 Steven Baker
|
data/README.md
CHANGED
|
@@ -1,51 +1,11 @@
|
|
|
1
|
-
# RSpec
|
|
1
|
+
# RSpec::Expectations
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
example.
|
|
3
|
+
This is the detailed readme for `rspec-expectations`, see also:
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Install
|
|
11
|
-
|
|
12
|
-
If you want to use rspec-expectations with rspec, just install the rspec gem
|
|
13
|
-
and RubyGems will also install rspec-expectations for you (along with
|
|
14
|
-
rspec-core and rspec-mocks):
|
|
15
|
-
|
|
16
|
-
```shell
|
|
17
|
-
gem install rspec
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Want to run against the `main` branch? You'll need to include the dependent
|
|
21
|
-
RSpec repos as well. Add the following to your `Gemfile`:
|
|
22
|
-
|
|
23
|
-
```ruby
|
|
24
|
-
%w[rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
|
|
25
|
-
gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'main'
|
|
26
|
-
end
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
If you want to use rspec-expectations with another tool, like Test::Unit,
|
|
30
|
-
Minitest, or Cucumber, you can install it directly:
|
|
31
|
-
|
|
32
|
-
```shell
|
|
33
|
-
gem install rspec-expectations
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Contributing
|
|
37
|
-
|
|
38
|
-
Once you've set up the environment, you'll need to cd into the working
|
|
39
|
-
directory of whichever repo you want to work in. From there you can run the
|
|
40
|
-
specs and cucumber features, and make patches.
|
|
41
|
-
|
|
42
|
-
NOTE: You do not need to use rspec-dev to work on a specific RSpec repo. You
|
|
43
|
-
can treat each RSpec repo as an independent project.
|
|
44
|
-
|
|
45
|
-
- [Build details](BUILD_DETAIL.md)
|
|
46
|
-
- [Code of Conduct](CODE_OF_CONDUCT.md)
|
|
47
|
-
- [Detailed contributing guide](CONTRIBUTING.md)
|
|
48
|
-
- [Development setup guide](DEVELOPMENT.md)
|
|
5
|
+
* [The combined readme](../README.md)
|
|
6
|
+
* [rspec-core](../rspec-core/README.md)
|
|
7
|
+
* [rspec-mocks](../rspec-mocks/README.md)
|
|
8
|
+
* [rspec-support](../rspec-support/README.md)
|
|
49
9
|
|
|
50
10
|
## Basic usage
|
|
51
11
|
|
|
@@ -172,7 +132,7 @@ expect(actual).to be_xxx # passes if actual.xxx?
|
|
|
172
132
|
expect(actual).to have_xxx(:arg) # passes if actual.has_xxx?(:arg)
|
|
173
133
|
```
|
|
174
134
|
|
|
175
|
-
### Ranges
|
|
135
|
+
### Ranges
|
|
176
136
|
|
|
177
137
|
```ruby
|
|
178
138
|
expect(1..10).to cover(3)
|
|
@@ -222,19 +182,6 @@ expect(
|
|
|
222
182
|
).to match([a_hash_including(:a => 'hash'), a_hash_including(:a => 'another')])
|
|
223
183
|
```
|
|
224
184
|
|
|
225
|
-
## `should` syntax
|
|
226
|
-
|
|
227
|
-
In addition to the `expect` syntax, rspec-expectations continues to support the
|
|
228
|
-
`should` syntax:
|
|
229
|
-
|
|
230
|
-
```ruby
|
|
231
|
-
actual.should eq expected
|
|
232
|
-
actual.should be > 3
|
|
233
|
-
[1, 2, 3].should_not include 4
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
See [detailed information on the `should` syntax and its usage.](https://github.com/rspec/rspec-expectations/blob/main/Should.md)
|
|
237
|
-
|
|
238
185
|
## Compound Matcher Expressions
|
|
239
186
|
|
|
240
187
|
You can also create compound matcher expressions using `and` or `or`:
|
|
@@ -317,10 +264,3 @@ class MyClass
|
|
|
317
264
|
end
|
|
318
265
|
end
|
|
319
266
|
```
|
|
320
|
-
|
|
321
|
-
## Also see
|
|
322
|
-
|
|
323
|
-
* [https://github.com/rspec/rspec](https://github.com/rspec/rspec)
|
|
324
|
-
* [https://github.com/rspec/rspec-core](https://github.com/rspec/rspec-core)
|
|
325
|
-
* [https://github.com/rspec/rspec-mocks](https://github.com/rspec/rspec-mocks)
|
|
326
|
-
* [https://github.com/rspec/rspec-rails](https://github.com/rspec/rspec-rails)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module RSpec
|
|
4
4
|
module Expectations
|
|
@@ -28,33 +28,7 @@ module RSpec
|
|
|
28
28
|
|
|
29
29
|
def initialize
|
|
30
30
|
@on_potential_false_positives = :warn
|
|
31
|
-
@strict_predicate_matchers =
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Configures the supported syntax.
|
|
35
|
-
# @param [Array<Symbol>, Symbol] values the syntaxes to enable
|
|
36
|
-
# @example
|
|
37
|
-
# RSpec.configure do |rspec|
|
|
38
|
-
# rspec.expect_with :rspec do |c|
|
|
39
|
-
# c.syntax = :should
|
|
40
|
-
# # or
|
|
41
|
-
# c.syntax = :expect
|
|
42
|
-
# # or
|
|
43
|
-
# c.syntax = [:should, :expect]
|
|
44
|
-
# end
|
|
45
|
-
# end
|
|
46
|
-
def syntax=(values)
|
|
47
|
-
if Array(values).include?(:expect)
|
|
48
|
-
Expectations::Syntax.enable_expect
|
|
49
|
-
else
|
|
50
|
-
Expectations::Syntax.disable_expect
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
if Array(values).include?(:should)
|
|
54
|
-
Expectations::Syntax.enable_should
|
|
55
|
-
else
|
|
56
|
-
Expectations::Syntax.disable_should
|
|
57
|
-
end
|
|
31
|
+
@strict_predicate_matchers = true
|
|
58
32
|
end
|
|
59
33
|
|
|
60
34
|
# Configures the maximum character length that RSpec will print while
|
|
@@ -71,19 +45,6 @@ module RSpec
|
|
|
71
45
|
RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = length
|
|
72
46
|
end
|
|
73
47
|
|
|
74
|
-
# The list of configured syntaxes.
|
|
75
|
-
# @return [Array<Symbol>] the list of configured syntaxes.
|
|
76
|
-
# @example
|
|
77
|
-
# unless RSpec::Matchers.configuration.syntax.include?(:expect)
|
|
78
|
-
# raise "this RSpec extension gem requires the rspec-expectations `:expect` syntax"
|
|
79
|
-
# end
|
|
80
|
-
def syntax
|
|
81
|
-
syntaxes = []
|
|
82
|
-
syntaxes << :should if Expectations::Syntax.should_enabled?
|
|
83
|
-
syntaxes << :expect if Expectations::Syntax.expect_enabled?
|
|
84
|
-
syntaxes
|
|
85
|
-
end
|
|
86
|
-
|
|
87
48
|
if ::RSpec.respond_to?(:configuration)
|
|
88
49
|
def color?
|
|
89
50
|
::RSpec.configuration.color_enabled?
|
|
@@ -104,22 +65,6 @@ module RSpec
|
|
|
104
65
|
# :nocov:
|
|
105
66
|
end
|
|
106
67
|
|
|
107
|
-
# :nocov: Because this is only really _useful_ on 1.8, and hard to test elsewhere.
|
|
108
|
-
#
|
|
109
|
-
# Adds `should` and `should_not` to the given classes
|
|
110
|
-
# or modules. This can be used to ensure `should` works
|
|
111
|
-
# properly on things like proxy objects (particular
|
|
112
|
-
# `Delegator`-subclassed objects on 1.8).
|
|
113
|
-
#
|
|
114
|
-
# @param [Array<Module>] modules the list of classes or modules
|
|
115
|
-
# to add `should` and `should_not` to.
|
|
116
|
-
def add_should_and_should_not_to(*modules)
|
|
117
|
-
modules.each do |mod|
|
|
118
|
-
Expectations::Syntax.enable_should(mod)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
# :nocov:
|
|
122
|
-
|
|
123
68
|
# Sets or gets the backtrace formatter. The backtrace formatter should
|
|
124
69
|
# implement `#format_backtrace(Array<String>)`. This is used
|
|
125
70
|
# to format backtraces of errors handled by the `raise_error`
|
|
@@ -139,24 +84,6 @@ module RSpec
|
|
|
139
84
|
end
|
|
140
85
|
end
|
|
141
86
|
|
|
142
|
-
# Sets if custom matcher descriptions and failure messages
|
|
143
|
-
# should include clauses from methods defined using `chain`.
|
|
144
|
-
# @param value [Boolean]
|
|
145
|
-
attr_writer :include_chain_clauses_in_custom_matcher_descriptions
|
|
146
|
-
|
|
147
|
-
# Indicates whether or not custom matcher descriptions and failure messages
|
|
148
|
-
# should include clauses from methods defined using `chain`. It is
|
|
149
|
-
# false by default for backwards compatibility.
|
|
150
|
-
def include_chain_clauses_in_custom_matcher_descriptions?
|
|
151
|
-
@include_chain_clauses_in_custom_matcher_descriptions ||= false
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
# @private
|
|
155
|
-
def reset_syntaxes_to_default
|
|
156
|
-
self.syntax = [:should, :expect]
|
|
157
|
-
RSpec::Expectations::Syntax.warn_about_should!
|
|
158
|
-
end
|
|
159
|
-
|
|
160
87
|
# @api private
|
|
161
88
|
# Null implementation of a backtrace formatter used by default
|
|
162
89
|
# when rspec-core is not loaded. Does no filtering.
|
|
@@ -166,20 +93,6 @@ module RSpec
|
|
|
166
93
|
end
|
|
167
94
|
end
|
|
168
95
|
|
|
169
|
-
# Configures whether RSpec will warn about matcher use which will
|
|
170
|
-
# potentially cause false positives in tests.
|
|
171
|
-
#
|
|
172
|
-
# @param [Boolean] boolean
|
|
173
|
-
def warn_about_potential_false_positives=(boolean)
|
|
174
|
-
if boolean
|
|
175
|
-
self.on_potential_false_positives = :warn
|
|
176
|
-
elsif warn_about_potential_false_positives?
|
|
177
|
-
self.on_potential_false_positives = :nothing
|
|
178
|
-
else
|
|
179
|
-
# no-op, handler is something else
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
96
|
# Configures what RSpec will do about matcher use which would potentially cause
|
|
184
97
|
# false positives in tests. Defaults to `:warn` since this is generally the desired behavior,
|
|
185
98
|
# but can also be set to `:raise` or `:nothing`.
|
|
@@ -219,13 +132,6 @@ module RSpec
|
|
|
219
132
|
@strict_predicate_matchers
|
|
220
133
|
end
|
|
221
134
|
|
|
222
|
-
# Indicates whether RSpec will warn about matcher use which will
|
|
223
|
-
# potentially cause false positives in tests, generally you want to
|
|
224
|
-
# avoid such scenarios so this defaults to `true`.
|
|
225
|
-
def warn_about_potential_false_positives?
|
|
226
|
-
on_potential_false_positives == :warn
|
|
227
|
-
end
|
|
228
|
-
|
|
229
135
|
# @private
|
|
230
136
|
def false_positives_handler
|
|
231
137
|
FALSE_POSITIVE_BEHAVIOURS.fetch(@on_potential_false_positives)
|
|
@@ -237,8 +143,5 @@ module RSpec
|
|
|
237
143
|
def self.configuration
|
|
238
144
|
@configuration ||= Configuration.new
|
|
239
145
|
end
|
|
240
|
-
|
|
241
|
-
# set default syntax
|
|
242
|
-
configuration.reset_syntaxes_to_default
|
|
243
146
|
end
|
|
244
147
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Expectations
|
|
3
5
|
# Wraps the target of an expectation.
|
|
@@ -111,16 +113,13 @@ module RSpec
|
|
|
111
113
|
def enforce_value_expectation(matcher)
|
|
112
114
|
return if supports_value_expectations?(matcher)
|
|
113
115
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
"#{RSpec::Support::ObjectFormatter.format(matcher)}` not " \
|
|
122
|
-
"`expect(value).to #{RSpec::Support::ObjectFormatter.format(matcher)}`"
|
|
123
|
-
)
|
|
116
|
+
raise ArgumentError,
|
|
117
|
+
"The implicit block expectation syntax is not supported, 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)}`"
|
|
124
123
|
end
|
|
125
124
|
|
|
126
125
|
def supports_value_expectations?(matcher)
|
|
@@ -151,8 +150,8 @@ module RSpec
|
|
|
151
150
|
return if supports_block_expectations?(matcher)
|
|
152
151
|
|
|
153
152
|
raise ExpectationNotMetError, "You must pass an argument rather than a block to `expect` to use the provided " \
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
"matcher (#{RSpec::Support::ObjectFormatter.format(matcher)}), or the matcher must implement " \
|
|
154
|
+
"`supports_block_expectations?`."
|
|
156
155
|
end
|
|
157
156
|
|
|
158
157
|
def supports_block_expectations?(matcher)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Expectations
|
|
3
5
|
# @private
|
|
@@ -144,7 +146,7 @@ module RSpec
|
|
|
144
146
|
# @return [String] A summary of the failure, including the block label and a count of failures.
|
|
145
147
|
def summary
|
|
146
148
|
"Got #{exception_count_description} from failure aggregation " \
|
|
147
|
-
|
|
149
|
+
"block#{block_description}"
|
|
148
150
|
end
|
|
149
151
|
|
|
150
152
|
# return [String] A description of the failure/error counts.
|
|
@@ -194,7 +196,7 @@ module RSpec
|
|
|
194
196
|
|
|
195
197
|
# It changes the current path that is relative to
|
|
196
198
|
# system root to be relative to the project root.
|
|
197
|
-
line.sub(/(\A|\s)#{File.expand_path('.')}(#{File::SEPARATOR}|\s|\Z)/, '\\1.\\2'
|
|
199
|
+
line.sub(/(\A|\s)#{File.expand_path('.')}(#{File::SEPARATOR}|\s|\Z)/, '\\1.\\2').sub(/\A([^:]+:\d+)$/, '\\1')
|
|
198
200
|
end
|
|
199
201
|
|
|
200
202
|
def enumerated_failures
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Expectations
|
|
3
5
|
# @private
|
|
@@ -11,18 +13,8 @@ module RSpec
|
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
|
|
14
|
-
# Returns an RSpec-3+ compatible matcher, wrapping a legacy one
|
|
15
|
-
# in an adapter if necessary.
|
|
16
|
-
#
|
|
17
|
-
# @private
|
|
18
|
-
def self.modern_matcher_from(matcher)
|
|
19
|
-
LegacyMatcherAdapter::RSpec2.wrap(matcher) ||
|
|
20
|
-
LegacyMatcherAdapter::RSpec1.wrap(matcher) || matcher
|
|
21
|
-
end
|
|
22
|
-
|
|
23
16
|
def self.with_matcher(handler, matcher, message)
|
|
24
17
|
check_message(message)
|
|
25
|
-
matcher = modern_matcher_from(matcher)
|
|
26
18
|
yield matcher
|
|
27
19
|
ensure
|
|
28
20
|
::RSpec::Matchers.last_expectation_handler = handler
|
|
@@ -45,8 +37,6 @@ module RSpec
|
|
|
45
37
|
class PositiveExpectationHandler
|
|
46
38
|
def self.handle_matcher(actual, initial_matcher, custom_message=nil, &block)
|
|
47
39
|
ExpectationHelper.with_matcher(self, initial_matcher, custom_message) do |matcher|
|
|
48
|
-
return ::RSpec::Matchers::BuiltIn::PositiveOperatorMatcher.new(actual) unless initial_matcher
|
|
49
|
-
|
|
50
40
|
match_result = matcher.matches?(actual, &block)
|
|
51
41
|
if custom_message && match_result.respond_to?(:error_generator)
|
|
52
42
|
match_result.error_generator.opts[:message] = custom_message
|
|
@@ -59,22 +49,12 @@ module RSpec
|
|
|
59
49
|
def self.verb
|
|
60
50
|
'is expected to'
|
|
61
51
|
end
|
|
62
|
-
|
|
63
|
-
def self.should_method
|
|
64
|
-
:should
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def self.opposite_should_method
|
|
68
|
-
:should_not
|
|
69
|
-
end
|
|
70
52
|
end
|
|
71
53
|
|
|
72
54
|
# @private
|
|
73
55
|
class NegativeExpectationHandler
|
|
74
56
|
def self.handle_matcher(actual, initial_matcher, custom_message=nil, &block)
|
|
75
57
|
ExpectationHelper.with_matcher(self, initial_matcher, custom_message) do |matcher|
|
|
76
|
-
return ::RSpec::Matchers::BuiltIn::NegativeOperatorMatcher.new(actual) unless initial_matcher
|
|
77
|
-
|
|
78
58
|
negated_match_result = does_not_match?(matcher, actual, &block)
|
|
79
59
|
if custom_message && negated_match_result.respond_to?(:error_generator)
|
|
80
60
|
negated_match_result.error_generator.opts[:message] = custom_message
|
|
@@ -95,87 +75,6 @@ module RSpec
|
|
|
95
75
|
def self.verb
|
|
96
76
|
'is expected not to'
|
|
97
77
|
end
|
|
98
|
-
|
|
99
|
-
def self.should_method
|
|
100
|
-
:should_not
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def self.opposite_should_method
|
|
104
|
-
:should
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# Wraps a matcher written against one of the legacy protocols in
|
|
109
|
-
# order to present the current protocol.
|
|
110
|
-
#
|
|
111
|
-
# @private
|
|
112
|
-
class LegacyMatcherAdapter < Matchers::MatcherDelegator
|
|
113
|
-
def initialize(matcher)
|
|
114
|
-
super
|
|
115
|
-
::RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, ''), :type => "legacy_matcher")
|
|
116
|
-
|#{matcher.class.name || matcher.inspect} implements a legacy RSpec matcher
|
|
117
|
-
|protocol. For the current protocol you should expose the failure messages
|
|
118
|
-
|via the `failure_message` and `failure_message_when_negated` methods.
|
|
119
|
-
|(Used from #{CallerFilter.first_non_rspec_line})
|
|
120
|
-
EOS
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def self.wrap(matcher)
|
|
124
|
-
new(matcher) if interface_matches?(matcher)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
# Starting in RSpec 1.2 (and continuing through all 2.x releases),
|
|
128
|
-
# the failure message protocol was:
|
|
129
|
-
# * `failure_message_for_should`
|
|
130
|
-
# * `failure_message_for_should_not`
|
|
131
|
-
# @private
|
|
132
|
-
class RSpec2 < self
|
|
133
|
-
def failure_message
|
|
134
|
-
base_matcher.failure_message_for_should
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def failure_message_when_negated
|
|
138
|
-
base_matcher.failure_message_for_should_not
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def self.interface_matches?(matcher)
|
|
142
|
-
(
|
|
143
|
-
!matcher.respond_to?(:failure_message) &&
|
|
144
|
-
matcher.respond_to?(:failure_message_for_should)
|
|
145
|
-
) || (
|
|
146
|
-
!matcher.respond_to?(:failure_message_when_negated) &&
|
|
147
|
-
matcher.respond_to?(:failure_message_for_should_not)
|
|
148
|
-
)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
# Before RSpec 1.2, the failure message protocol was:
|
|
153
|
-
# * `failure_message`
|
|
154
|
-
# * `negative_failure_message`
|
|
155
|
-
# @private
|
|
156
|
-
class RSpec1 < self
|
|
157
|
-
def failure_message
|
|
158
|
-
base_matcher.failure_message
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def failure_message_when_negated
|
|
162
|
-
base_matcher.negative_failure_message
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
# Note: `failure_message` is part of the RSpec 3 protocol
|
|
166
|
-
# (paired with `failure_message_when_negated`), so we don't check
|
|
167
|
-
# for `failure_message` here.
|
|
168
|
-
def self.interface_matches?(matcher)
|
|
169
|
-
!matcher.respond_to?(:failure_message_when_negated) &&
|
|
170
|
-
matcher.respond_to?(:negative_failure_message)
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
78
|
end
|
|
174
|
-
|
|
175
|
-
# RSpec 3.0 was released with the class name misspelled. For SemVer compatibility,
|
|
176
|
-
# we will provide this misspelled alias until 4.0.
|
|
177
|
-
# @deprecated Use LegacyMatcherAdapter instead.
|
|
178
|
-
# @private
|
|
179
|
-
LegacyMacherAdapter = LegacyMatcherAdapter
|
|
180
79
|
end
|
|
181
80
|
end
|
data/lib/rspec/expectations.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rspec/support'
|
|
2
4
|
RSpec::Support.require_rspec_support "caller_filter"
|
|
3
5
|
RSpec::Support.require_rspec_support "warnings"
|
|
@@ -58,6 +60,8 @@ module RSpec
|
|
|
58
60
|
# built-in matchers that ship with rspec-expectations, and how to write your
|
|
59
61
|
# own custom matchers.
|
|
60
62
|
module Expectations
|
|
63
|
+
# rubocop:disable Lint/InheritException
|
|
64
|
+
|
|
61
65
|
# Exception raised when an expectation fails.
|
|
62
66
|
#
|
|
63
67
|
# @note We subclass Exception so that in a stub implementation if
|
|
@@ -66,6 +70,7 @@ module RSpec
|
|
|
66
70
|
# @api public
|
|
67
71
|
class ExpectationNotMetError < Exception
|
|
68
72
|
end
|
|
73
|
+
# rubocop:enable Lint/InheritException
|
|
69
74
|
|
|
70
75
|
# Exception raised from `aggregate_failures` when multiple expectations fail.
|
|
71
76
|
#
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -149,39 +151,17 @@ module RSpec
|
|
|
149
151
|
# @return [Boolean] True if the actual and expected string encoding are different.
|
|
150
152
|
# i.e. the failure may be related to encoding differences and the encoding
|
|
151
153
|
# should be shown to the user. false otherwise.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
actual.is_a?(String) && expected.is_a?(String) && actual.encoding != expected.encoding
|
|
155
|
-
end
|
|
156
|
-
else
|
|
157
|
-
# @api private
|
|
158
|
-
# @return [Boolean] False always as the curent Ruby version does not support String encoding
|
|
159
|
-
# :nocov:
|
|
160
|
-
def string_encoding_differs?
|
|
161
|
-
false
|
|
162
|
-
end
|
|
163
|
-
# :nocov:
|
|
154
|
+
def string_encoding_differs?
|
|
155
|
+
actual.is_a?(String) && expected.is_a?(String) && actual.encoding != expected.encoding
|
|
164
156
|
end
|
|
165
157
|
module_function :string_encoding_differs?
|
|
166
158
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
"#<Encoding:#{value.encoding.name}>"
|
|
174
|
-
end
|
|
175
|
-
else
|
|
176
|
-
# @api private
|
|
177
|
-
# Formats a String's encoding as a human readable string
|
|
178
|
-
# @param _value [String]
|
|
179
|
-
# @return [nil] nil as the curent Ruby version does not support String encoding
|
|
180
|
-
# :nocov:
|
|
181
|
-
def format_encoding(_value)
|
|
182
|
-
nil
|
|
183
|
-
end
|
|
184
|
-
# :nocov:
|
|
159
|
+
# @api private
|
|
160
|
+
# Formats a String's encoding as a human readable string
|
|
161
|
+
# @param value [String]
|
|
162
|
+
# @return [String]
|
|
163
|
+
def format_encoding(value)
|
|
164
|
+
"#<Encoding:#{value.encoding.name}>"
|
|
185
165
|
end
|
|
186
166
|
module_function :format_encoding
|
|
187
167
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -157,8 +159,8 @@ module RSpec
|
|
|
157
159
|
# @api private
|
|
158
160
|
# @return [String]
|
|
159
161
|
def failure_message
|
|
160
|
-
"expected: #{@operator} #{expected_formatted}\n" \
|
|
161
|
-
|
|
162
|
+
"expected: #{@operator} #{expected_formatted}\n " \
|
|
163
|
+
"got: #{@operator.to_s.gsub(/./, ' ')} #{actual_formatted}"
|
|
162
164
|
end
|
|
163
165
|
|
|
164
166
|
# @api private
|