rspec-expectations 3.13.6 → 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 +27 -9
- 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 +24 -39
- 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 -14
- 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 +3 -1
- 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 +5 -3
- data/lib/rspec/matchers.rb +11 -60
- data.tar.gz.sig +0 -0
- metadata +14 -16
- metadata.gz.sig +0 -0
- data/lib/rspec/expectations/syntax.rb +0 -132
- data/lib/rspec/matchers/built_in/operators.rb +0 -128
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'stringio'
|
|
2
4
|
|
|
3
5
|
module RSpec
|
|
@@ -16,20 +18,19 @@ module RSpec
|
|
|
16
18
|
|
|
17
19
|
def matches?(block)
|
|
18
20
|
@block = block
|
|
19
|
-
return false unless Proc === block
|
|
20
21
|
@actual = @stream_capturer.capture(block)
|
|
21
22
|
@expected ? values_match?(@expected, @actual) : captured?
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def does_not_match?(block)
|
|
25
|
-
!matches?(block)
|
|
26
|
+
!matches?(block)
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
# @api public
|
|
29
30
|
# Tells the matcher to match against stdout.
|
|
30
31
|
# Works only when the main Ruby process prints to stdout
|
|
31
32
|
def to_stdout
|
|
32
|
-
@stream_capturer = CaptureStdout
|
|
33
|
+
@stream_capturer = CaptureStdout.new
|
|
33
34
|
self
|
|
34
35
|
end
|
|
35
36
|
|
|
@@ -37,7 +38,7 @@ module RSpec
|
|
|
37
38
|
# Tells the matcher to match against stderr.
|
|
38
39
|
# Works only when the main Ruby process prints to stderr
|
|
39
40
|
def to_stderr
|
|
40
|
-
@stream_capturer = CaptureStderr
|
|
41
|
+
@stream_capturer = CaptureStderr.new
|
|
41
42
|
self
|
|
42
43
|
end
|
|
43
44
|
|
|
@@ -59,6 +60,27 @@ module RSpec
|
|
|
59
60
|
self
|
|
60
61
|
end
|
|
61
62
|
|
|
63
|
+
# @api public
|
|
64
|
+
# Tells the matcher to simulate the output stream being a TTY.
|
|
65
|
+
# This is useful to test code like `puts '...' if $stdout.tty?`.
|
|
66
|
+
def as_tty
|
|
67
|
+
raise ArgumentError, '`as_tty` can only be used after `to_stdout` or `to_stderr`' unless @stream_capturer.respond_to?(:as_tty=)
|
|
68
|
+
|
|
69
|
+
@stream_capturer.as_tty = true
|
|
70
|
+
self
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @api public
|
|
74
|
+
# Tells the matcher to simulate the output stream not being a TTY.
|
|
75
|
+
# Note that that's the default behaviour if you don't call `as_tty`
|
|
76
|
+
# (since `StringIO` is not a TTY).
|
|
77
|
+
def as_not_tty
|
|
78
|
+
raise ArgumentError, '`as_not_tty` can only be used after `to_stdout` or `to_stderr`' unless @stream_capturer.respond_to?(:as_tty=)
|
|
79
|
+
|
|
80
|
+
@stream_capturer.as_tty = false
|
|
81
|
+
self
|
|
82
|
+
end
|
|
83
|
+
|
|
62
84
|
# @api private
|
|
63
85
|
# @return [String]
|
|
64
86
|
def failure_message
|
|
@@ -108,13 +130,11 @@ module RSpec
|
|
|
108
130
|
end
|
|
109
131
|
|
|
110
132
|
def positive_failure_reason
|
|
111
|
-
return "was not a block" unless Proc === @block
|
|
112
133
|
return "output #{actual_output_description}" if @expected
|
|
113
134
|
"did not"
|
|
114
135
|
end
|
|
115
136
|
|
|
116
137
|
def negative_failure_reason
|
|
117
|
-
return "was not a block" unless Proc === @block
|
|
118
138
|
"output #{actual_output_description}"
|
|
119
139
|
end
|
|
120
140
|
|
|
@@ -136,13 +156,26 @@ module RSpec
|
|
|
136
156
|
end
|
|
137
157
|
|
|
138
158
|
# @private
|
|
139
|
-
|
|
140
|
-
|
|
159
|
+
class CapturedStream < StringIO
|
|
160
|
+
attr_accessor :as_tty
|
|
161
|
+
|
|
162
|
+
def tty?
|
|
163
|
+
return super if as_tty.nil?
|
|
164
|
+
as_tty
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# @private
|
|
169
|
+
class CaptureStdout
|
|
170
|
+
attr_accessor :as_tty
|
|
171
|
+
|
|
172
|
+
def name
|
|
141
173
|
'stdout'
|
|
142
174
|
end
|
|
143
175
|
|
|
144
|
-
def
|
|
145
|
-
captured_stream =
|
|
176
|
+
def capture(block)
|
|
177
|
+
captured_stream = CapturedStream.new
|
|
178
|
+
captured_stream.as_tty = as_tty
|
|
146
179
|
|
|
147
180
|
original_stream = $stdout
|
|
148
181
|
$stdout = captured_stream
|
|
@@ -156,13 +189,16 @@ module RSpec
|
|
|
156
189
|
end
|
|
157
190
|
|
|
158
191
|
# @private
|
|
159
|
-
|
|
160
|
-
|
|
192
|
+
class CaptureStderr
|
|
193
|
+
attr_accessor :as_tty
|
|
194
|
+
|
|
195
|
+
def name
|
|
161
196
|
'stderr'
|
|
162
197
|
end
|
|
163
198
|
|
|
164
|
-
def
|
|
165
|
-
captured_stream =
|
|
199
|
+
def capture(block)
|
|
200
|
+
captured_stream = CapturedStream.new
|
|
201
|
+
captured_stream.as_tty = as_tty
|
|
166
202
|
|
|
167
203
|
original_stream = $stderr
|
|
168
204
|
$stderr = captured_stream
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -23,10 +25,10 @@ module RSpec
|
|
|
23
25
|
@block = block
|
|
24
26
|
@actual_error = nil
|
|
25
27
|
@warn_about_bare_error = UndefinedValue === expected_error_or_message
|
|
26
|
-
|
|
28
|
+
raise_nil_argument_error! if expected_error_or_message.nil?
|
|
27
29
|
|
|
28
30
|
case expected_error_or_message
|
|
29
|
-
when
|
|
31
|
+
when UndefinedValue
|
|
30
32
|
@expected_error = Exception
|
|
31
33
|
@expected_message = expected_message
|
|
32
34
|
when String, Regexp
|
|
@@ -57,8 +59,6 @@ module RSpec
|
|
|
57
59
|
@eval_block = false
|
|
58
60
|
@eval_block_passed = false
|
|
59
61
|
|
|
60
|
-
return false unless Proc === given_proc
|
|
61
|
-
|
|
62
62
|
begin
|
|
63
63
|
given_proc.call
|
|
64
64
|
rescue Exception => @actual_error
|
|
@@ -71,7 +71,6 @@ module RSpec
|
|
|
71
71
|
|
|
72
72
|
unless negative_expectation
|
|
73
73
|
warn_about_bare_error! if warn_about_bare_error?
|
|
74
|
-
warn_about_nil_error! if warn_about_nil_error?
|
|
75
74
|
eval_block if ready_to_eval_block?
|
|
76
75
|
end
|
|
77
76
|
|
|
@@ -82,7 +81,7 @@ module RSpec
|
|
|
82
81
|
# @private
|
|
83
82
|
def does_not_match?(given_proc)
|
|
84
83
|
warn_for_negative_false_positives!
|
|
85
|
-
!matches?(given_proc, :negative_expectation)
|
|
84
|
+
!matches?(given_proc, :negative_expectation)
|
|
86
85
|
end
|
|
87
86
|
|
|
88
87
|
# @private
|
|
@@ -164,8 +163,6 @@ module RSpec
|
|
|
164
163
|
"`expect { }.not_to raise_error(SpecificErrorClass)`"
|
|
165
164
|
elsif @expected_message
|
|
166
165
|
"`expect { }.not_to raise_error(message)`"
|
|
167
|
-
elsif @warn_about_nil_error
|
|
168
|
-
"`expect { }.not_to raise_error(nil)`"
|
|
169
166
|
end
|
|
170
167
|
|
|
171
168
|
return unless expression
|
|
@@ -181,34 +178,28 @@ module RSpec
|
|
|
181
178
|
@warn_about_bare_error && @block.nil?
|
|
182
179
|
end
|
|
183
180
|
|
|
184
|
-
def warn_about_nil_error?
|
|
185
|
-
@warn_about_nil_error
|
|
186
|
-
end
|
|
187
|
-
|
|
188
181
|
def warn_about_bare_error!
|
|
189
182
|
handle_warning("Using the `raise_error` matcher without providing a specific " \
|
|
190
183
|
"error or message risks false positives, since `raise_error` " \
|
|
191
184
|
"will match when Ruby raises a `NoMethodError`, `NameError` or " \
|
|
192
185
|
"`ArgumentError`, potentially allowing the expectation to pass " \
|
|
193
186
|
"without even executing the method you are intending to call. " \
|
|
194
|
-
"#{warning}"\
|
|
187
|
+
"#{warning}" \
|
|
195
188
|
"Instead consider providing a specific error class or message. " \
|
|
196
189
|
"This message can be suppressed by setting: " \
|
|
197
190
|
"`RSpec::Expectations.configuration.on_potential_false" \
|
|
198
191
|
"_positives = :nothing`")
|
|
199
192
|
end
|
|
200
193
|
|
|
201
|
-
def
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
"`RSpec::Expectations.configuration.on_potential_false" \
|
|
211
|
-
"_positives = :nothing`")
|
|
194
|
+
def raise_nil_argument_error!
|
|
195
|
+
raise ArgumentError, "Using the `raise_error` matcher with a `nil` " \
|
|
196
|
+
"value is probably unintentional, it risks false positives, " \
|
|
197
|
+
"since `raise_error` will match when Ruby raises a " \
|
|
198
|
+
"`NoMethodError`, `NameError` or `ArgumentError`, potentially " \
|
|
199
|
+
"allowing the expectation to pass without even executing the " \
|
|
200
|
+
"method you are intending to call. " \
|
|
201
|
+
"#{warning}" \
|
|
202
|
+
"Instead provide a specific error class or message."
|
|
212
203
|
end
|
|
213
204
|
|
|
214
205
|
def warn_about_negative_false_positive!(expression)
|
|
@@ -244,7 +235,6 @@ module RSpec
|
|
|
244
235
|
end
|
|
245
236
|
|
|
246
237
|
def given_error
|
|
247
|
-
return " but was not given a block" unless Proc === @given_proc
|
|
248
238
|
return " but nothing was raised" unless @actual_error
|
|
249
239
|
|
|
250
240
|
backtrace = format_backtrace(@actual_error.backtrace)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
RSpec::Support.require_rspec_support "method_signature_verifier"
|
|
2
4
|
|
|
3
5
|
module RSpec
|
|
@@ -92,7 +94,7 @@ module RSpec
|
|
|
92
94
|
# @api private
|
|
93
95
|
# @return [String]
|
|
94
96
|
def failure_message_when_negated
|
|
95
|
-
failure_message.sub(
|
|
97
|
+
failure_message.sub('to respond to', 'not to respond to')
|
|
96
98
|
end
|
|
97
99
|
|
|
98
100
|
# @api private
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -54,12 +56,6 @@ module RSpec
|
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
|
|
57
|
-
# For RSpec 3.1, the base class was named `StartAndEndWith`. For SemVer reasons,
|
|
58
|
-
# we still provide this constant until 4.0.
|
|
59
|
-
# @deprecated Use StartOrEndWith instead.
|
|
60
|
-
# @private
|
|
61
|
-
StartAndEndWith = StartOrEndWith
|
|
62
|
-
|
|
63
59
|
# @api private
|
|
64
60
|
# Provides the implementation for `start_with`.
|
|
65
61
|
# Not intended to be instantiated directly.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -17,7 +19,6 @@ module RSpec
|
|
|
17
19
|
# @private
|
|
18
20
|
def matches?(given_proc)
|
|
19
21
|
@block = given_proc
|
|
20
|
-
return false unless Proc === given_proc
|
|
21
22
|
|
|
22
23
|
begin
|
|
23
24
|
if @expected_symbol.nil?
|
|
@@ -36,10 +37,7 @@ module RSpec
|
|
|
36
37
|
@caught_symbol = @expected_symbol
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
|
-
|
|
40
|
-
# Ruby 1.8 uses NameError with `symbol'
|
|
41
|
-
# Ruby 1.9 uses ArgumentError with :symbol
|
|
42
|
-
rescue NameError, ArgumentError => e
|
|
40
|
+
rescue ArgumentError => e
|
|
43
41
|
unless (match_data = e.message.match(/uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/))
|
|
44
42
|
other_exception = e
|
|
45
43
|
raise
|
|
@@ -66,7 +64,7 @@ module RSpec
|
|
|
66
64
|
# rubocop:enable Metrics/MethodLength
|
|
67
65
|
|
|
68
66
|
def does_not_match?(given_proc)
|
|
69
|
-
!matches?(given_proc)
|
|
67
|
+
!matches?(given_proc)
|
|
70
68
|
end
|
|
71
69
|
|
|
72
70
|
# @api private
|
|
@@ -107,7 +105,6 @@ module RSpec
|
|
|
107
105
|
private
|
|
108
106
|
|
|
109
107
|
def actual_result
|
|
110
|
-
return "but was not a block" unless Proc === @block
|
|
111
108
|
"got #{caught}"
|
|
112
109
|
end
|
|
113
110
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rspec/matchers/built_in/count_expectation'
|
|
2
4
|
|
|
3
5
|
RSpec::Support.require_rspec_support 'method_signature_verifier'
|
|
@@ -12,7 +14,6 @@ module RSpec
|
|
|
12
14
|
class YieldProbe
|
|
13
15
|
def self.probe(block, &callback)
|
|
14
16
|
probe = new(block, &callback)
|
|
15
|
-
return probe unless probe.has_block?
|
|
16
17
|
probe.probe
|
|
17
18
|
end
|
|
18
19
|
|
|
@@ -26,10 +27,6 @@ module RSpec
|
|
|
26
27
|
self.yielded_args = []
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
def has_block?
|
|
30
|
-
Proc === @block
|
|
31
|
-
end
|
|
32
|
-
|
|
33
30
|
def probe
|
|
34
31
|
assert_valid_expect_block!
|
|
35
32
|
@block.call(self)
|
|
@@ -74,24 +71,11 @@ module RSpec
|
|
|
74
71
|
'are.'
|
|
75
72
|
end
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
'matcher. Pass the argument as a block on to the method you are testing.'
|
|
83
|
-
end
|
|
84
|
-
else
|
|
85
|
-
# :nocov:
|
|
86
|
-
# On 1.8.7, `lambda { }.arity` and `lambda { |*a| }.arity` both return -1,
|
|
87
|
-
# so we can't distinguish between accepting no args and an arg splat.
|
|
88
|
-
# It's OK to skip, this, though; it just provides a nice error message
|
|
89
|
-
# when the user forgets to accept an arg in their block. They'll still get
|
|
90
|
-
# the `assert_used!` error message from above, which is sufficient.
|
|
91
|
-
def assert_valid_expect_block!
|
|
92
|
-
# nothing to do
|
|
93
|
-
end
|
|
94
|
-
# :nocov:
|
|
74
|
+
def assert_valid_expect_block!
|
|
75
|
+
block_signature = RSpec::Support::BlockSignature.new(@block)
|
|
76
|
+
return if RSpec::Support::StrictSignatureVerifier.new(block_signature, [self]).valid?
|
|
77
|
+
raise 'Your expect block must accept an argument to be used with this ' \
|
|
78
|
+
'matcher. Pass the argument as a block on to the method you are testing.'
|
|
95
79
|
end
|
|
96
80
|
end
|
|
97
81
|
|
|
@@ -100,16 +84,16 @@ module RSpec
|
|
|
100
84
|
# Not intended to be instantiated directly.
|
|
101
85
|
class YieldControl < BaseMatcher
|
|
102
86
|
include CountExpectation
|
|
87
|
+
|
|
103
88
|
# @private
|
|
104
89
|
def matches?(block)
|
|
105
90
|
@probe = YieldProbe.probe(block)
|
|
106
|
-
return false unless @probe.has_block?
|
|
107
91
|
expected_count_matches?(@probe.num_yields)
|
|
108
92
|
end
|
|
109
93
|
|
|
110
94
|
# @private
|
|
111
95
|
def does_not_match?(block)
|
|
112
|
-
!matches?(block)
|
|
96
|
+
!matches?(block)
|
|
113
97
|
end
|
|
114
98
|
|
|
115
99
|
# @api private
|
|
@@ -137,7 +121,6 @@ module RSpec
|
|
|
137
121
|
private
|
|
138
122
|
|
|
139
123
|
def failure_reason
|
|
140
|
-
return ' but was not a block' unless @probe.has_block?
|
|
141
124
|
return "#{count_expectation_description} but did not yield" if @probe.num_yields == 0
|
|
142
125
|
count_failure_reason('yielded')
|
|
143
126
|
end
|
|
@@ -150,13 +133,12 @@ module RSpec
|
|
|
150
133
|
# @private
|
|
151
134
|
def matches?(block)
|
|
152
135
|
@probe = YieldProbe.probe(block)
|
|
153
|
-
return false unless @probe.has_block?
|
|
154
136
|
@probe.yielded_once?(:yield_with_no_args) && @probe.single_yield_args.empty?
|
|
155
137
|
end
|
|
156
138
|
|
|
157
139
|
# @private
|
|
158
140
|
def does_not_match?(block)
|
|
159
|
-
!matches?(block)
|
|
141
|
+
!matches?(block)
|
|
160
142
|
end
|
|
161
143
|
|
|
162
144
|
# @private
|
|
@@ -182,13 +164,11 @@ module RSpec
|
|
|
182
164
|
private
|
|
183
165
|
|
|
184
166
|
def positive_failure_reason
|
|
185
|
-
return 'was not a block' unless @probe.has_block?
|
|
186
167
|
return 'did not yield' if @probe.num_yields.zero?
|
|
187
168
|
"yielded with arguments: #{description_of @probe.single_yield_args}"
|
|
188
169
|
end
|
|
189
170
|
|
|
190
171
|
def negative_failure_reason
|
|
191
|
-
return 'was not a block' unless @probe.has_block?
|
|
192
172
|
'did'
|
|
193
173
|
end
|
|
194
174
|
end
|
|
@@ -209,14 +189,13 @@ module RSpec
|
|
|
209
189
|
@actual_formatted = actual_formatted
|
|
210
190
|
@args_matched_when_yielded &&= args_currently_match?
|
|
211
191
|
end
|
|
212
|
-
return false unless @probe.has_block?
|
|
213
192
|
@probe.probe
|
|
214
193
|
@probe.yielded_once?(:yield_with_args) && @args_matched_when_yielded
|
|
215
194
|
end
|
|
216
195
|
|
|
217
196
|
# @private
|
|
218
197
|
def does_not_match?(block)
|
|
219
|
-
!matches?(block)
|
|
198
|
+
!matches?(block)
|
|
220
199
|
end
|
|
221
200
|
|
|
222
201
|
# @private
|
|
@@ -249,7 +228,6 @@ module RSpec
|
|
|
249
228
|
private
|
|
250
229
|
|
|
251
230
|
def positive_failure_reason
|
|
252
|
-
return 'was not a block' unless @probe.has_block?
|
|
253
231
|
return 'did not yield' if @probe.num_yields.zero?
|
|
254
232
|
@positive_args_failure
|
|
255
233
|
end
|
|
@@ -259,9 +237,7 @@ module RSpec
|
|
|
259
237
|
end
|
|
260
238
|
|
|
261
239
|
def negative_failure_reason
|
|
262
|
-
if !@
|
|
263
|
-
'was not a block'
|
|
264
|
-
elsif @args_matched_when_yielded && !@expected.empty?
|
|
240
|
+
if @args_matched_when_yielded && !@expected.empty?
|
|
265
241
|
'yielded with expected arguments' \
|
|
266
242
|
"\nexpected not: #{surface_descriptions_in(@expected).inspect}" \
|
|
267
243
|
"\n got: #{@actual_formatted}"
|
|
@@ -278,8 +254,8 @@ module RSpec
|
|
|
278
254
|
|
|
279
255
|
unless (match = all_args_match?)
|
|
280
256
|
@positive_args_failure = 'yielded with unexpected arguments' \
|
|
281
|
-
|
|
282
|
-
|
|
257
|
+
"\nexpected: #{surface_descriptions_in(@expected).inspect}" \
|
|
258
|
+
"\n got: #{@actual_formatted}"
|
|
283
259
|
end
|
|
284
260
|
|
|
285
261
|
match
|
|
@@ -313,24 +289,23 @@ module RSpec
|
|
|
313
289
|
yield_count += 1
|
|
314
290
|
end
|
|
315
291
|
|
|
316
|
-
return false unless @probe.has_block?
|
|
317
292
|
args_matched_when_yielded && yield_count == @expected.length
|
|
318
293
|
end
|
|
319
294
|
|
|
320
295
|
def does_not_match?(block)
|
|
321
|
-
!matches?(block)
|
|
296
|
+
!matches?(block)
|
|
322
297
|
end
|
|
323
298
|
|
|
324
299
|
# @private
|
|
325
300
|
def failure_message
|
|
326
301
|
'expected given block to yield successively with arguments, ' \
|
|
327
|
-
|
|
302
|
+
"but #{positive_failure_reason}"
|
|
328
303
|
end
|
|
329
304
|
|
|
330
305
|
# @private
|
|
331
306
|
def failure_message_when_negated
|
|
332
307
|
'expected given block not to yield successively with arguments, ' \
|
|
333
|
-
|
|
308
|
+
"but #{negative_failure_reason}"
|
|
334
309
|
end
|
|
335
310
|
|
|
336
311
|
# @private
|
|
@@ -355,19 +330,15 @@ module RSpec
|
|
|
355
330
|
end
|
|
356
331
|
|
|
357
332
|
def positive_failure_reason
|
|
358
|
-
return 'was not a block' unless @probe.has_block?
|
|
359
|
-
|
|
360
333
|
'yielded with unexpected arguments' \
|
|
361
|
-
|
|
362
|
-
|
|
334
|
+
"\nexpected: #{surface_descriptions_in(@expected).inspect}" \
|
|
335
|
+
"\n got: [#{@actual_formatted.join(", ")}]"
|
|
363
336
|
end
|
|
364
337
|
|
|
365
338
|
def negative_failure_reason
|
|
366
|
-
return 'was not a block' unless @probe.has_block?
|
|
367
|
-
|
|
368
339
|
'yielded with expected arguments' \
|
|
369
|
-
|
|
370
|
-
|
|
340
|
+
"\nexpected not: #{surface_descriptions_in(@expected).inspect}" \
|
|
341
|
+
"\n got: [#{@actual_formatted.join(", ")}]"
|
|
371
342
|
end
|
|
372
343
|
end
|
|
373
344
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
RSpec::Support.require_rspec_matchers "built_in/base_matcher"
|
|
2
4
|
|
|
3
5
|
module RSpec
|
|
@@ -35,10 +37,7 @@ module RSpec
|
|
|
35
37
|
autoload :Include, 'rspec/matchers/built_in/include'
|
|
36
38
|
autoload :All, 'rspec/matchers/built_in/all'
|
|
37
39
|
autoload :Match, 'rspec/matchers/built_in/match'
|
|
38
|
-
autoload :NegativeOperatorMatcher, 'rspec/matchers/built_in/operators'
|
|
39
|
-
autoload :OperatorMatcher, 'rspec/matchers/built_in/operators'
|
|
40
40
|
autoload :Output, 'rspec/matchers/built_in/output'
|
|
41
|
-
autoload :PositiveOperatorMatcher, 'rspec/matchers/built_in/operators'
|
|
42
41
|
autoload :RaiseError, 'rspec/matchers/built_in/raise_error'
|
|
43
42
|
autoload :RespondTo, 'rspec/matchers/built_in/respond_to'
|
|
44
43
|
autoload :Satisfy, 'rspec/matchers/built_in/satisfy'
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
RSpec::Support.require_rspec_support "fuzzy_matcher"
|
|
2
4
|
|
|
3
5
|
module RSpec
|
|
@@ -152,7 +154,6 @@ module RSpec
|
|
|
152
154
|
true
|
|
153
155
|
end
|
|
154
156
|
module_function :surface_descriptions_in, :should_enumerate?, :unreadable_io?
|
|
155
|
-
|
|
156
157
|
# Wraps an item in order to surface its `description` via `inspect`.
|
|
157
158
|
# @api private
|
|
158
159
|
DescribableItem = Struct.new(:item) do
|