rspec-expectations 2.11.3 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +1 -1
- data/Changelog.md +1026 -21
- data/{License.txt → LICENSE.md} +5 -3
- data/README.md +174 -78
- data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
- data/lib/rspec/expectations/configuration.rb +230 -0
- data/lib/rspec/expectations/expectation_target.rb +130 -55
- data/lib/rspec/expectations/fail_with.rb +17 -33
- data/lib/rspec/expectations/failure_aggregator.rb +212 -0
- data/lib/rspec/expectations/handler.rb +163 -29
- data/lib/rspec/expectations/minitest_integration.rb +58 -0
- data/lib/rspec/expectations/syntax.rb +68 -54
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +59 -24
- data/lib/rspec/matchers/aliased_matcher.rb +116 -0
- data/lib/rspec/matchers/built_in/all.rb +86 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +150 -20
- data/lib/rspec/matchers/built_in/be.rb +115 -109
- data/lib/rspec/matchers/built_in/be_between.rb +77 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
- data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
- data/lib/rspec/matchers/built_in/be_within.rb +43 -17
- data/lib/rspec/matchers/built_in/change.rb +392 -75
- data/lib/rspec/matchers/built_in/compound.rb +290 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -0
- data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +26 -8
- data/lib/rspec/matchers/built_in/eql.rb +19 -8
- data/lib/rspec/matchers/built_in/equal.rb +56 -19
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +141 -22
- data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
- data/lib/rspec/matchers/built_in/include.rb +175 -20
- data/lib/rspec/matchers/built_in/match.rb +95 -1
- data/lib/rspec/matchers/built_in/operators.rb +128 -0
- data/lib/rspec/matchers/built_in/output.rb +207 -0
- data/lib/rspec/matchers/built_in/raise_error.rb +212 -38
- data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
- data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
- data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
- data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
- data/lib/rspec/matchers/built_in/yield.rb +252 -98
- data/lib/rspec/matchers/built_in.rb +47 -33
- data/lib/rspec/matchers/composable.rb +171 -0
- data/lib/rspec/matchers/dsl.rb +530 -10
- data/lib/rspec/matchers/english_phrasing.rb +58 -0
- data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
- data/lib/rspec/matchers/fail_matchers.rb +42 -0
- data/lib/rspec/matchers/generated_descriptions.rb +15 -10
- data/lib/rspec/matchers/matcher_delegator.rb +35 -0
- data/lib/rspec/matchers/matcher_protocol.rb +105 -0
- data/lib/rspec/matchers.rb +604 -252
- data.tar.gz.sig +0 -0
- metadata +178 -278
- metadata.gz.sig +0 -0
- data/features/README.md +0 -49
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -90
- data/features/built_in_matchers/be.feature +0 -173
- data/features/built_in_matchers/be_within.feature +0 -46
- data/features/built_in_matchers/cover.feature +0 -45
- data/features/built_in_matchers/end_with.feature +0 -46
- data/features/built_in_matchers/equality.feature +0 -145
- data/features/built_in_matchers/exist.feature +0 -43
- data/features/built_in_matchers/expect_change.feature +0 -59
- data/features/built_in_matchers/expect_error.feature +0 -138
- data/features/built_in_matchers/have.feature +0 -103
- data/features/built_in_matchers/include.feature +0 -121
- data/features/built_in_matchers/match.feature +0 -50
- data/features/built_in_matchers/operators.feature +0 -221
- data/features/built_in_matchers/predicates.feature +0 -128
- data/features/built_in_matchers/respond_to.feature +0 -78
- data/features/built_in_matchers/satisfy.feature +0 -31
- data/features/built_in_matchers/start_with.feature +0 -46
- data/features/built_in_matchers/throw_symbol.feature +0 -85
- data/features/built_in_matchers/types.feature +0 -114
- data/features/built_in_matchers/yield.feature +0 -146
- data/features/custom_matchers/access_running_example.feature +0 -53
- data/features/custom_matchers/define_diffable_matcher.feature +0 -27
- data/features/custom_matchers/define_matcher.feature +0 -340
- data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -22
- data/features/diffing.feature +0 -85
- data/features/implicit_docstrings.feature +0 -52
- data/features/step_definitions/additional_cli_steps.rb +0 -22
- data/features/support/env.rb +0 -5
- data/features/syntax_configuration.feature +0 -68
- data/features/test_frameworks/test_unit.feature +0 -46
- data/lib/rspec/expectations/deprecation.rb +0 -38
- data/lib/rspec/expectations/differ.rb +0 -81
- data/lib/rspec/expectations/errors.rb +0 -9
- data/lib/rspec/expectations/extensions/array.rb +0 -9
- data/lib/rspec/expectations/extensions/object.rb +0 -39
- data/lib/rspec/expectations/extensions.rb +0 -2
- data/lib/rspec/matchers/be_close.rb +0 -9
- data/lib/rspec/matchers/built_in/have.rb +0 -108
- data/lib/rspec/matchers/built_in/match_array.rb +0 -45
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
- data/lib/rspec/matchers/compatibility.rb +0 -14
- data/lib/rspec/matchers/configuration.rb +0 -66
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
- data/lib/rspec/matchers/matcher.rb +0 -299
- data/lib/rspec/matchers/method_missing.rb +0 -12
- data/lib/rspec/matchers/operator_matcher.rb +0 -84
- data/lib/rspec/matchers/pretty.rb +0 -60
- data/lib/rspec-expectations.rb +0 -1
- data/spec/rspec/expectations/differ_spec.rb +0 -153
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -70
- data/spec/rspec/expectations/handler_spec.rb +0 -206
- data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
- data/spec/rspec/matchers/be_close_spec.rb +0 -22
- data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
- data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
- data/spec/rspec/matchers/be_spec.rb +0 -452
- data/spec/rspec/matchers/be_within_spec.rb +0 -80
- data/spec/rspec/matchers/change_spec.rb +0 -528
- data/spec/rspec/matchers/configuration_spec.rb +0 -202
- data/spec/rspec/matchers/cover_spec.rb +0 -69
- data/spec/rspec/matchers/description_generation_spec.rb +0 -176
- data/spec/rspec/matchers/dsl_spec.rb +0 -57
- data/spec/rspec/matchers/eq_spec.rb +0 -54
- data/spec/rspec/matchers/eql_spec.rb +0 -41
- data/spec/rspec/matchers/equal_spec.rb +0 -60
- data/spec/rspec/matchers/exist_spec.rb +0 -110
- data/spec/rspec/matchers/has_spec.rb +0 -118
- data/spec/rspec/matchers/have_spec.rb +0 -461
- data/spec/rspec/matchers/include_spec.rb +0 -367
- data/spec/rspec/matchers/match_array_spec.rb +0 -124
- data/spec/rspec/matchers/match_spec.rb +0 -61
- data/spec/rspec/matchers/matcher_spec.rb +0 -434
- data/spec/rspec/matchers/matchers_spec.rb +0 -31
- data/spec/rspec/matchers/method_missing_spec.rb +0 -24
- data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
- data/spec/rspec/matchers/raise_error_spec.rb +0 -344
- data/spec/rspec/matchers/respond_to_spec.rb +0 -295
- data/spec/rspec/matchers/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
- data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
- data/spec/rspec/matchers/yield_spec.rb +0 -402
- data/spec/spec_helper.rb +0 -27
- data/spec/support/classes.rb +0 -56
- data/spec/support/in_sub_process.rb +0 -31
- data/spec/support/matchers.rb +0 -22
- data/spec/support/ruby_version.rb +0 -10
- data/spec/support/shared_examples.rb +0 -13
@@ -1,29 +1,52 @@
|
|
1
|
+
require 'rspec/matchers/built_in/count_expectation'
|
2
|
+
|
3
|
+
RSpec::Support.require_rspec_support 'method_signature_verifier'
|
4
|
+
|
1
5
|
module RSpec
|
2
6
|
module Matchers
|
3
7
|
module BuiltIn
|
8
|
+
# @private
|
9
|
+
# Object that is yielded to `expect` when one of the
|
10
|
+
# yield matchers is used. Provides information about
|
11
|
+
# the yield behavior of the object-under-test.
|
4
12
|
class YieldProbe
|
5
|
-
def self.probe(block)
|
6
|
-
probe = new
|
7
|
-
|
8
|
-
|
9
|
-
probe.assert_used!
|
10
|
-
probe
|
13
|
+
def self.probe(block, &callback)
|
14
|
+
probe = new(block, &callback)
|
15
|
+
return probe unless probe.has_block?
|
16
|
+
probe.probe
|
11
17
|
end
|
12
18
|
|
13
19
|
attr_accessor :num_yields, :yielded_args
|
14
20
|
|
15
|
-
def initialize
|
21
|
+
def initialize(block, &callback)
|
22
|
+
@block = block
|
23
|
+
@callback = callback || Proc.new {}
|
16
24
|
@used = false
|
17
|
-
self.num_yields
|
25
|
+
self.num_yields = 0
|
26
|
+
self.yielded_args = []
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_block?
|
30
|
+
Proc === @block
|
31
|
+
end
|
32
|
+
|
33
|
+
def probe
|
34
|
+
assert_valid_expect_block!
|
35
|
+
@block.call(self)
|
36
|
+
assert_used!
|
37
|
+
self
|
18
38
|
end
|
19
39
|
|
20
40
|
def to_proc
|
21
41
|
@used = true
|
22
42
|
|
23
43
|
probe = self
|
44
|
+
callback = @callback
|
24
45
|
Proc.new do |*args|
|
25
46
|
probe.num_yields += 1
|
26
47
|
probe.yielded_args << args
|
48
|
+
callback.call(*args)
|
49
|
+
nil # to indicate the block does not return a meaningful value
|
27
50
|
end
|
28
51
|
end
|
29
52
|
|
@@ -36,186 +59,317 @@ module RSpec
|
|
36
59
|
when 1 then true
|
37
60
|
when 0 then false
|
38
61
|
else
|
39
|
-
raise "The #{matcher_name} matcher is not designed to be used with a "
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def successive_yield_args
|
46
|
-
yielded_args.map do |arg_array|
|
47
|
-
arg_array.size == 1 ? arg_array.first : arg_array
|
62
|
+
raise "The #{matcher_name} matcher is not designed to be used with a " \
|
63
|
+
'method that yields multiple times. Use the yield_successive_args ' \
|
64
|
+
'matcher for that case.'
|
48
65
|
end
|
49
66
|
end
|
50
67
|
|
51
68
|
def assert_used!
|
52
69
|
return if @used
|
53
|
-
raise
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
70
|
+
raise 'You must pass the argument yielded to your expect block on ' \
|
71
|
+
'to the method-under-test as a block. It acts as a probe that ' \
|
72
|
+
'allows the matcher to detect whether or not the method-under-test ' \
|
73
|
+
'yields, and, if so, how many times, and what the yielded arguments ' \
|
74
|
+
'are.'
|
58
75
|
end
|
59
76
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
77
|
+
if RUBY_VERSION.to_f > 1.8
|
78
|
+
def assert_valid_expect_block!
|
79
|
+
block_signature = RSpec::Support::BlockSignature.new(@block)
|
80
|
+
return if RSpec::Support::StrictSignatureVerifier.new(block_signature, [self]).valid?
|
81
|
+
raise 'Your expect block must accept an argument to be used with this ' \
|
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:
|
64
95
|
end
|
65
96
|
end
|
66
97
|
|
98
|
+
# @api private
|
99
|
+
# Provides the implementation for `yield_control`.
|
100
|
+
# Not intended to be instantiated directly.
|
67
101
|
class YieldControl < BaseMatcher
|
102
|
+
include CountExpectation
|
103
|
+
# @private
|
68
104
|
def matches?(block)
|
69
|
-
probe = YieldProbe.probe(block)
|
70
|
-
probe.
|
105
|
+
@probe = YieldProbe.probe(block)
|
106
|
+
return false unless @probe.has_block?
|
107
|
+
expected_count_matches?(@probe.num_yields)
|
108
|
+
end
|
109
|
+
|
110
|
+
# @private
|
111
|
+
def does_not_match?(block)
|
112
|
+
!matches?(block) && @probe.has_block?
|
113
|
+
end
|
114
|
+
|
115
|
+
# @api private
|
116
|
+
# @return [String]
|
117
|
+
def failure_message
|
118
|
+
'expected given block to yield control' + failure_reason
|
119
|
+
end
|
120
|
+
|
121
|
+
# @api private
|
122
|
+
# @return [String]
|
123
|
+
def failure_message_when_negated
|
124
|
+
'expected given block not to yield control' + failure_reason
|
71
125
|
end
|
72
126
|
|
73
|
-
|
74
|
-
|
127
|
+
# @private
|
128
|
+
def supports_block_expectations?
|
129
|
+
true
|
75
130
|
end
|
76
131
|
|
77
|
-
|
78
|
-
|
132
|
+
# @private
|
133
|
+
def supports_value_expectations?
|
134
|
+
false
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def failure_reason
|
140
|
+
return ' but was not a block' unless @probe.has_block?
|
141
|
+
return "#{count_expectation_description} but did not yield" if @probe.num_yields == 0
|
142
|
+
count_failure_reason('yielded')
|
79
143
|
end
|
80
144
|
end
|
81
145
|
|
146
|
+
# @api private
|
147
|
+
# Provides the implementation for `yield_with_no_args`.
|
148
|
+
# Not intended to be instantiated directly.
|
82
149
|
class YieldWithNoArgs < BaseMatcher
|
83
|
-
|
150
|
+
# @private
|
84
151
|
def matches?(block)
|
85
152
|
@probe = YieldProbe.probe(block)
|
86
|
-
|
153
|
+
return false unless @probe.has_block?
|
154
|
+
@probe.yielded_once?(:yield_with_no_args) && @probe.single_yield_args.empty?
|
155
|
+
end
|
156
|
+
|
157
|
+
# @private
|
158
|
+
def does_not_match?(block)
|
159
|
+
!matches?(block) && @probe.has_block?
|
87
160
|
end
|
88
161
|
|
89
|
-
|
90
|
-
|
162
|
+
# @private
|
163
|
+
def failure_message
|
164
|
+
"expected given block to yield with no arguments, but #{positive_failure_reason}"
|
91
165
|
end
|
92
166
|
|
93
|
-
|
94
|
-
|
167
|
+
# @private
|
168
|
+
def failure_message_when_negated
|
169
|
+
"expected given block not to yield with no arguments, but #{negative_failure_reason}"
|
170
|
+
end
|
171
|
+
|
172
|
+
# @private
|
173
|
+
def supports_block_expectations?
|
174
|
+
true
|
175
|
+
end
|
176
|
+
|
177
|
+
# @private
|
178
|
+
def supports_value_expectations?
|
179
|
+
false
|
95
180
|
end
|
96
181
|
|
97
182
|
private
|
98
183
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
184
|
+
def positive_failure_reason
|
185
|
+
return 'was not a block' unless @probe.has_block?
|
186
|
+
return 'did not yield' if @probe.num_yields.zero?
|
187
|
+
"yielded with arguments: #{description_of @probe.single_yield_args}"
|
188
|
+
end
|
189
|
+
|
190
|
+
def negative_failure_reason
|
191
|
+
return 'was not a block' unless @probe.has_block?
|
192
|
+
'did'
|
105
193
|
end
|
106
194
|
end
|
107
195
|
|
108
|
-
|
196
|
+
# @api private
|
197
|
+
# Provides the implementation for `yield_with_args`.
|
198
|
+
# Not intended to be instantiated directly.
|
199
|
+
class YieldWithArgs < BaseMatcher
|
109
200
|
def initialize(*args)
|
110
201
|
@expected = args
|
111
202
|
end
|
112
203
|
|
204
|
+
# @private
|
113
205
|
def matches?(block)
|
114
|
-
@
|
115
|
-
@
|
116
|
-
|
206
|
+
@args_matched_when_yielded = true
|
207
|
+
@probe = YieldProbe.new(block) do
|
208
|
+
@actual = @probe.single_yield_args
|
209
|
+
@actual_formatted = actual_formatted
|
210
|
+
@args_matched_when_yielded &&= args_currently_match?
|
211
|
+
end
|
212
|
+
return false unless @probe.has_block?
|
213
|
+
@probe.probe
|
214
|
+
@probe.yielded_once?(:yield_with_args) && @args_matched_when_yielded
|
117
215
|
end
|
118
|
-
alias == matches?
|
119
216
|
|
120
|
-
|
217
|
+
# @private
|
218
|
+
def does_not_match?(block)
|
219
|
+
!matches?(block) && @probe.has_block?
|
220
|
+
end
|
221
|
+
|
222
|
+
# @private
|
223
|
+
def failure_message
|
121
224
|
"expected given block to yield with arguments, but #{positive_failure_reason}"
|
122
225
|
end
|
123
226
|
|
124
|
-
|
227
|
+
# @private
|
228
|
+
def failure_message_when_negated
|
125
229
|
"expected given block not to yield with arguments, but #{negative_failure_reason}"
|
126
230
|
end
|
127
231
|
|
232
|
+
# @private
|
128
233
|
def description
|
129
|
-
desc =
|
130
|
-
desc
|
234
|
+
desc = 'yield with args'
|
235
|
+
desc = "#{desc}(#{expected_arg_description})" unless @expected.empty?
|
131
236
|
desc
|
132
237
|
end
|
133
238
|
|
239
|
+
# @private
|
240
|
+
def supports_block_expectations?
|
241
|
+
true
|
242
|
+
end
|
243
|
+
|
244
|
+
# @private
|
245
|
+
def supports_value_expectations?
|
246
|
+
false
|
247
|
+
end
|
248
|
+
|
134
249
|
private
|
135
250
|
|
136
251
|
def positive_failure_reason
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
252
|
+
return 'was not a block' unless @probe.has_block?
|
253
|
+
return 'did not yield' if @probe.num_yields.zero?
|
254
|
+
@positive_args_failure
|
255
|
+
end
|
256
|
+
|
257
|
+
def expected_arg_description
|
258
|
+
@expected.map { |e| description_of e }.join(', ')
|
142
259
|
end
|
143
260
|
|
144
261
|
def negative_failure_reason
|
145
|
-
if
|
146
|
-
|
147
|
-
|
148
|
-
|
262
|
+
if !@probe.has_block?
|
263
|
+
'was not a block'
|
264
|
+
elsif @args_matched_when_yielded && !@expected.empty?
|
265
|
+
'yielded with expected arguments' \
|
266
|
+
"\nexpected not: #{surface_descriptions_in(@expected).inspect}" \
|
267
|
+
"\n got: #{@actual_formatted}"
|
149
268
|
else
|
150
|
-
|
269
|
+
'did'
|
151
270
|
end
|
152
271
|
end
|
153
272
|
|
154
|
-
def
|
155
|
-
if @expected.
|
156
|
-
@positive_args_failure =
|
157
|
-
return
|
273
|
+
def args_currently_match?
|
274
|
+
if @expected.empty? # expect {...}.to yield_with_args
|
275
|
+
@positive_args_failure = 'yielded with no arguments' if @actual.empty?
|
276
|
+
return !@actual.empty?
|
158
277
|
end
|
159
278
|
|
160
|
-
unless match = all_args_match?
|
161
|
-
@positive_args_failure =
|
162
|
-
"\nexpected: #{@expected.inspect}"
|
163
|
-
"\n got: #{@
|
279
|
+
unless (match = all_args_match?)
|
280
|
+
@positive_args_failure = 'yielded with unexpected arguments' \
|
281
|
+
"\nexpected: #{surface_descriptions_in(@expected).inspect}" \
|
282
|
+
"\n got: #{@actual_formatted}"
|
164
283
|
end
|
165
284
|
|
166
285
|
match
|
167
286
|
end
|
168
287
|
|
169
288
|
def all_args_match?
|
170
|
-
|
171
|
-
|
172
|
-
@expected.zip(@actual).all? do |expected, actual|
|
173
|
-
expected === actual || actual == expected
|
174
|
-
end
|
289
|
+
values_match?(@expected, @actual)
|
175
290
|
end
|
176
291
|
end
|
177
292
|
|
178
|
-
|
293
|
+
# @api private
|
294
|
+
# Provides the implementation for `yield_successive_args`.
|
295
|
+
# Not intended to be instantiated directly.
|
296
|
+
class YieldSuccessiveArgs < BaseMatcher
|
179
297
|
def initialize(*args)
|
180
298
|
@expected = args
|
181
299
|
end
|
182
300
|
|
301
|
+
# @private
|
183
302
|
def matches?(block)
|
184
|
-
@
|
185
|
-
@actual =
|
186
|
-
|
303
|
+
@actual_formatted = []
|
304
|
+
@actual = []
|
305
|
+
args_matched_when_yielded = true
|
306
|
+
yield_count = 0
|
307
|
+
|
308
|
+
@probe = YieldProbe.probe(block) do |*arg_array|
|
309
|
+
arg_or_args = arg_array.size == 1 ? arg_array.first : arg_array
|
310
|
+
@actual_formatted << RSpec::Support::ObjectFormatter.format(arg_or_args)
|
311
|
+
@actual << arg_or_args
|
312
|
+
args_matched_when_yielded &&= values_match?(@expected[yield_count], arg_or_args)
|
313
|
+
yield_count += 1
|
314
|
+
end
|
315
|
+
|
316
|
+
return false unless @probe.has_block?
|
317
|
+
args_matched_when_yielded && yield_count == @expected.length
|
318
|
+
end
|
319
|
+
|
320
|
+
def does_not_match?(block)
|
321
|
+
!matches?(block) && @probe.has_block?
|
187
322
|
end
|
188
|
-
alias == matches?
|
189
323
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
324
|
+
# @private
|
325
|
+
def failure_message
|
326
|
+
'expected given block to yield successively with arguments, ' \
|
327
|
+
"but #{positive_failure_reason}"
|
194
328
|
end
|
195
329
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
330
|
+
# @private
|
331
|
+
def failure_message_when_negated
|
332
|
+
'expected given block not to yield successively with arguments, ' \
|
333
|
+
"but #{negative_failure_reason}"
|
200
334
|
end
|
201
335
|
|
336
|
+
# @private
|
202
337
|
def description
|
203
|
-
|
204
|
-
|
205
|
-
|
338
|
+
"yield successive args(#{expected_arg_description})"
|
339
|
+
end
|
340
|
+
|
341
|
+
# @private
|
342
|
+
def supports_block_expectations?
|
343
|
+
true
|
344
|
+
end
|
345
|
+
|
346
|
+
# @private
|
347
|
+
def supports_value_expectations?
|
348
|
+
false
|
206
349
|
end
|
207
350
|
|
208
351
|
private
|
209
352
|
|
210
|
-
def
|
211
|
-
|
353
|
+
def expected_arg_description
|
354
|
+
@expected.map { |e| description_of e }.join(', ')
|
355
|
+
end
|
212
356
|
|
213
|
-
|
214
|
-
|
215
|
-
|
357
|
+
def positive_failure_reason
|
358
|
+
return 'was not a block' unless @probe.has_block?
|
359
|
+
|
360
|
+
'yielded with unexpected arguments' \
|
361
|
+
"\nexpected: #{surface_descriptions_in(@expected).inspect}" \
|
362
|
+
"\n got: [#{@actual_formatted.join(", ")}]"
|
363
|
+
end
|
364
|
+
|
365
|
+
def negative_failure_reason
|
366
|
+
return 'was not a block' unless @probe.has_block?
|
367
|
+
|
368
|
+
'yielded with expected arguments' \
|
369
|
+
"\nexpected not: #{surface_descriptions_in(@expected).inspect}" \
|
370
|
+
"\n got: [#{@actual_formatted.join(", ")}]"
|
216
371
|
end
|
217
372
|
end
|
218
373
|
end
|
219
374
|
end
|
220
375
|
end
|
221
|
-
|
@@ -1,39 +1,53 @@
|
|
1
|
+
RSpec::Support.require_rspec_matchers "built_in/base_matcher"
|
2
|
+
|
1
3
|
module RSpec
|
2
4
|
module Matchers
|
5
|
+
# Container module for all built-in matchers. The matcher classes are here
|
6
|
+
# (rather than directly under `RSpec::Matchers`) in order to prevent name
|
7
|
+
# collisions, since `RSpec::Matchers` gets included into the user's namespace.
|
8
|
+
#
|
9
|
+
# Autoloading is used to delay when the matcher classes get loaded, allowing
|
10
|
+
# rspec-matchers to boot faster, and avoiding loading matchers the user is
|
11
|
+
# not using.
|
3
12
|
module BuiltIn
|
4
|
-
|
5
|
-
autoload :BeAnInstanceOf,
|
6
|
-
autoload :
|
7
|
-
autoload :
|
8
|
-
autoload :
|
9
|
-
autoload :
|
10
|
-
autoload :
|
11
|
-
autoload :
|
12
|
-
autoload :
|
13
|
-
autoload :
|
14
|
-
autoload :
|
15
|
-
autoload :
|
16
|
-
autoload :
|
17
|
-
autoload :
|
18
|
-
autoload :
|
19
|
-
autoload :
|
20
|
-
autoload :
|
21
|
-
autoload :
|
22
|
-
autoload :
|
23
|
-
autoload :
|
24
|
-
autoload :
|
25
|
-
autoload :
|
26
|
-
autoload :
|
27
|
-
autoload :
|
28
|
-
autoload :
|
29
|
-
autoload :
|
30
|
-
autoload :
|
31
|
-
autoload :
|
32
|
-
autoload :
|
33
|
-
autoload :
|
34
|
-
autoload :
|
13
|
+
autoload :BeAKindOf, 'rspec/matchers/built_in/be_kind_of'
|
14
|
+
autoload :BeAnInstanceOf, 'rspec/matchers/built_in/be_instance_of'
|
15
|
+
autoload :BeBetween, 'rspec/matchers/built_in/be_between'
|
16
|
+
autoload :Be, 'rspec/matchers/built_in/be'
|
17
|
+
autoload :BeComparedTo, 'rspec/matchers/built_in/be'
|
18
|
+
autoload :BeFalsey, 'rspec/matchers/built_in/be'
|
19
|
+
autoload :BeHelpers, 'rspec/matchers/built_in/be'
|
20
|
+
autoload :BeNil, 'rspec/matchers/built_in/be'
|
21
|
+
autoload :BePredicate, 'rspec/matchers/built_in/has'
|
22
|
+
autoload :BeTruthy, 'rspec/matchers/built_in/be'
|
23
|
+
autoload :BeWithin, 'rspec/matchers/built_in/be_within'
|
24
|
+
autoload :Change, 'rspec/matchers/built_in/change'
|
25
|
+
autoload :Compound, 'rspec/matchers/built_in/compound'
|
26
|
+
autoload :ContainExactly, 'rspec/matchers/built_in/contain_exactly'
|
27
|
+
autoload :Cover, 'rspec/matchers/built_in/cover'
|
28
|
+
autoload :EndWith, 'rspec/matchers/built_in/start_or_end_with'
|
29
|
+
autoload :Eq, 'rspec/matchers/built_in/eq'
|
30
|
+
autoload :Eql, 'rspec/matchers/built_in/eql'
|
31
|
+
autoload :Equal, 'rspec/matchers/built_in/equal'
|
32
|
+
autoload :Exist, 'rspec/matchers/built_in/exist'
|
33
|
+
autoload :Has, 'rspec/matchers/built_in/has'
|
34
|
+
autoload :HaveAttributes, 'rspec/matchers/built_in/have_attributes'
|
35
|
+
autoload :Include, 'rspec/matchers/built_in/include'
|
36
|
+
autoload :All, 'rspec/matchers/built_in/all'
|
37
|
+
autoload :Match, 'rspec/matchers/built_in/match'
|
38
|
+
autoload :NegativeOperatorMatcher, 'rspec/matchers/built_in/operators'
|
39
|
+
autoload :OperatorMatcher, 'rspec/matchers/built_in/operators'
|
40
|
+
autoload :Output, 'rspec/matchers/built_in/output'
|
41
|
+
autoload :PositiveOperatorMatcher, 'rspec/matchers/built_in/operators'
|
42
|
+
autoload :RaiseError, 'rspec/matchers/built_in/raise_error'
|
43
|
+
autoload :RespondTo, 'rspec/matchers/built_in/respond_to'
|
44
|
+
autoload :Satisfy, 'rspec/matchers/built_in/satisfy'
|
45
|
+
autoload :StartWith, 'rspec/matchers/built_in/start_or_end_with'
|
46
|
+
autoload :ThrowSymbol, 'rspec/matchers/built_in/throw_symbol'
|
47
|
+
autoload :YieldControl, 'rspec/matchers/built_in/yield'
|
48
|
+
autoload :YieldSuccessiveArgs, 'rspec/matchers/built_in/yield'
|
49
|
+
autoload :YieldWithArgs, 'rspec/matchers/built_in/yield'
|
50
|
+
autoload :YieldWithNoArgs, 'rspec/matchers/built_in/yield'
|
35
51
|
end
|
36
52
|
end
|
37
53
|
end
|
38
|
-
|
39
|
-
|