rspec-expectations 2.13.0 → 3.0.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 +15 -0
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +413 -23
- data/License.txt +1 -0
- data/README.md +109 -80
- data/lib/rspec/{matchers → expectations}/configuration.rb +44 -14
- data/lib/rspec/expectations/expectation_target.rb +71 -38
- data/lib/rspec/expectations/fail_with.rb +12 -44
- data/lib/rspec/expectations/handler.rb +135 -35
- data/lib/rspec/expectations/minitest_integration.rb +16 -0
- data/lib/rspec/expectations/syntax.rb +60 -94
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +46 -24
- data/lib/rspec/matchers/aliased_matcher.rb +41 -0
- data/lib/rspec/matchers/built_in/all.rb +78 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +63 -15
- data/lib/rspec/matchers/built_in/be.rb +170 -79
- data/lib/rspec/matchers/built_in/be_between.rb +77 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
- data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
- data/lib/rspec/matchers/built_in/be_within.rb +40 -16
- data/lib/rspec/matchers/built_in/change.rb +275 -74
- data/lib/rspec/matchers/built_in/compound.rb +122 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +256 -0
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +60 -6
- data/lib/rspec/matchers/built_in/eql.rb +17 -5
- data/lib/rspec/matchers/built_in/equal.rb +55 -21
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +71 -15
- data/lib/rspec/matchers/built_in/include.rb +58 -29
- data/lib/rspec/matchers/built_in/match.rb +19 -1
- data/lib/rspec/matchers/built_in/operators.rb +119 -0
- data/lib/rspec/matchers/built_in/output.rb +150 -0
- data/lib/rspec/matchers/built_in/raise_error.rb +91 -33
- data/lib/rspec/matchers/built_in/respond_to.rb +42 -20
- data/lib/rspec/matchers/built_in/satisfy.rb +19 -3
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +54 -18
- data/lib/rspec/matchers/built_in/throw_symbol.rb +38 -8
- data/lib/rspec/matchers/built_in/yield.rb +237 -55
- data/lib/rspec/matchers/built_in.rb +45 -33
- data/lib/rspec/matchers/composable.rb +179 -0
- data/lib/rspec/matchers/dsl.rb +362 -5
- data/lib/rspec/matchers/generated_descriptions.rb +13 -6
- data/lib/rspec/matchers/matcher_delegator.rb +37 -0
- data/lib/rspec/matchers/pretty.rb +33 -20
- data/lib/rspec/matchers.rb +450 -227
- data.tar.gz.sig +1 -0
- metadata +100 -215
- 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 -175
- data/features/built_in_matchers/be_within.feature +0 -48
- data/features/built_in_matchers/cover.feature +0 -47
- data/features/built_in_matchers/end_with.feature +0 -48
- data/features/built_in_matchers/equality.feature +0 -139
- data/features/built_in_matchers/exist.feature +0 -45
- data/features/built_in_matchers/expect_change.feature +0 -59
- data/features/built_in_matchers/expect_error.feature +0 -144
- data/features/built_in_matchers/have.feature +0 -109
- data/features/built_in_matchers/include.feature +0 -174
- data/features/built_in_matchers/match.feature +0 -52
- data/features/built_in_matchers/operators.feature +0 -227
- data/features/built_in_matchers/predicates.feature +0 -137
- data/features/built_in_matchers/respond_to.feature +0 -84
- data/features/built_in_matchers/satisfy.feature +0 -33
- data/features/built_in_matchers/start_with.feature +0 -48
- data/features/built_in_matchers/throw_symbol.feature +0 -91
- data/features/built_in_matchers/types.feature +0 -116
- 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 -368
- 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 -115
- 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 -51
- data/lib/rspec/matchers/compatibility.rb +0 -14
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
- data/lib/rspec/matchers/matcher.rb +0 -300
- data/lib/rspec/matchers/method_missing.rb +0 -12
- data/lib/rspec/matchers/operator_matcher.rb +0 -109
- data/lib/rspec-expectations.rb +0 -1
- data/spec/rspec/expectations/differ_spec.rb +0 -170
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -75
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -95
- data/spec/rspec/expectations/handler_spec.rb +0 -206
- data/spec/rspec/expectations/syntax_spec.rb +0 -97
- data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
- data/spec/rspec/matchers/be_close_spec.rb +0 -22
- data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
- data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
- data/spec/rspec/matchers/be_spec.rb +0 -516
- data/spec/rspec/matchers/be_within_spec.rb +0 -129
- data/spec/rspec/matchers/change_spec.rb +0 -542
- data/spec/rspec/matchers/configuration_spec.rb +0 -238
- 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 -60
- data/spec/rspec/matchers/eql_spec.rb +0 -41
- data/spec/rspec/matchers/equal_spec.rb +0 -78
- data/spec/rspec/matchers/exist_spec.rb +0 -124
- data/spec/rspec/matchers/has_spec.rb +0 -122
- data/spec/rspec/matchers/have_spec.rb +0 -445
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
- data/spec/rspec/matchers/include_spec.rb +0 -531
- data/spec/rspec/matchers/match_array_spec.rb +0 -194
- data/spec/rspec/matchers/match_spec.rb +0 -61
- data/spec/rspec/matchers/matcher_spec.rb +0 -471
- data/spec/rspec/matchers/matchers_spec.rb +0 -37
- data/spec/rspec/matchers/method_missing_spec.rb +0 -28
- data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
- data/spec/rspec/matchers/raise_error_spec.rb +0 -395
- data/spec/rspec/matchers/respond_to_spec.rb +0 -292
- data/spec/rspec/matchers/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
- data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
- data/spec/rspec/matchers/yield_spec.rb +0 -437
- data/spec/spec_helper.rb +0 -54
- data/spec/support/classes.rb +0 -56
- data/spec/support/in_sub_process.rb +0 -38
- data/spec/support/matchers.rb +0 -22
- data/spec/support/ruby_version.rb +0 -10
- data/spec/support/shared_examples.rb +0 -13
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
module RSpec
|
|
2
2
|
module Matchers
|
|
3
3
|
module BuiltIn
|
|
4
|
+
# @private
|
|
5
|
+
# Object that is yielded to `expect` when one of the
|
|
6
|
+
# yield matchers is used. Provides information about
|
|
7
|
+
# the yield behavior of the object-under-test.
|
|
4
8
|
class YieldProbe
|
|
5
9
|
def self.probe(block)
|
|
6
|
-
probe = new
|
|
7
|
-
|
|
10
|
+
probe = new(block)
|
|
11
|
+
return probe unless probe.has_block?
|
|
12
|
+
probe.assert_valid_expect_block!
|
|
8
13
|
block.call(probe)
|
|
9
14
|
probe.assert_used!
|
|
10
15
|
probe
|
|
@@ -12,11 +17,16 @@ module RSpec
|
|
|
12
17
|
|
|
13
18
|
attr_accessor :num_yields, :yielded_args
|
|
14
19
|
|
|
15
|
-
def initialize
|
|
20
|
+
def initialize(block)
|
|
21
|
+
@block = block
|
|
16
22
|
@used = false
|
|
17
23
|
self.num_yields, self.yielded_args = 0, []
|
|
18
24
|
end
|
|
19
25
|
|
|
26
|
+
def has_block?
|
|
27
|
+
Proc === @block
|
|
28
|
+
end
|
|
29
|
+
|
|
20
30
|
def to_proc
|
|
21
31
|
@used = true
|
|
22
32
|
|
|
@@ -24,6 +34,7 @@ module RSpec
|
|
|
24
34
|
Proc.new do |*args|
|
|
25
35
|
probe.num_yields += 1
|
|
26
36
|
probe.yielded_args << args
|
|
37
|
+
nil # to indicate the block does not return a meaningful value
|
|
27
38
|
end
|
|
28
39
|
end
|
|
29
40
|
|
|
@@ -57,95 +68,240 @@ module RSpec
|
|
|
57
68
|
"are."
|
|
58
69
|
end
|
|
59
70
|
|
|
60
|
-
def
|
|
61
|
-
return if block.arity == 1
|
|
71
|
+
def assert_valid_expect_block!
|
|
72
|
+
return if @block.arity == 1
|
|
62
73
|
raise "Your expect block must accept an argument to be used with this " +
|
|
63
74
|
"matcher. Pass the argument as a block on to the method you are testing."
|
|
64
75
|
end
|
|
65
76
|
end
|
|
66
77
|
|
|
78
|
+
# @api private
|
|
79
|
+
# Provides the implementation for `yield_control`.
|
|
80
|
+
# Not intended to be instantiated directly.
|
|
67
81
|
class YieldControl < BaseMatcher
|
|
82
|
+
def initialize
|
|
83
|
+
@expectation_type = nil
|
|
84
|
+
@expected_yields_count = nil
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# @api public
|
|
88
|
+
# Specifies that the method is expected to yield once.
|
|
89
|
+
def once
|
|
90
|
+
exactly(1)
|
|
91
|
+
self
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# @api public
|
|
95
|
+
# Specifies that the method is expected to yield once.
|
|
96
|
+
def twice
|
|
97
|
+
exactly(2)
|
|
98
|
+
self
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# @api public
|
|
102
|
+
# Specifies that the method is expected to yield the given number of times.
|
|
103
|
+
def exactly(number)
|
|
104
|
+
set_expected_yields_count(:==, number)
|
|
105
|
+
self
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# @api public
|
|
109
|
+
# Specifies the maximum number of times the method is expected to yield
|
|
110
|
+
def at_most(number)
|
|
111
|
+
set_expected_yields_count(:<=, number)
|
|
112
|
+
self
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# @api public
|
|
116
|
+
# Specifies the minimum number of times the method is expected to yield
|
|
117
|
+
def at_least(number)
|
|
118
|
+
set_expected_yields_count(:>=, number)
|
|
119
|
+
self
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# @api public
|
|
123
|
+
# No-op. Provides syntactic sugar.
|
|
124
|
+
def times
|
|
125
|
+
self
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# @private
|
|
68
129
|
def matches?(block)
|
|
69
|
-
probe = YieldProbe.probe(block)
|
|
70
|
-
probe.
|
|
130
|
+
@probe = YieldProbe.probe(block)
|
|
131
|
+
return false unless @probe.has_block?
|
|
132
|
+
|
|
133
|
+
if @expectation_type
|
|
134
|
+
@probe.num_yields.__send__(@expectation_type, @expected_yields_count)
|
|
135
|
+
else
|
|
136
|
+
@probe.yielded_once?(:yield_control)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# @private
|
|
141
|
+
def does_not_match?(block)
|
|
142
|
+
!matches?(block) && @probe.has_block?
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# @api private
|
|
146
|
+
# @return [String]
|
|
147
|
+
def failure_message
|
|
148
|
+
'expected given block to yield control' + failure_reason
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# @api private
|
|
152
|
+
# @return [String]
|
|
153
|
+
def failure_message_when_negated
|
|
154
|
+
'expected given block not to yield control' + failure_reason
|
|
71
155
|
end
|
|
72
156
|
|
|
73
|
-
|
|
74
|
-
|
|
157
|
+
# @private
|
|
158
|
+
def supports_block_expectations?
|
|
159
|
+
true
|
|
75
160
|
end
|
|
76
161
|
|
|
77
|
-
|
|
78
|
-
|
|
162
|
+
private
|
|
163
|
+
|
|
164
|
+
def set_expected_yields_count(relativity, n)
|
|
165
|
+
@expectation_type = relativity
|
|
166
|
+
@expected_yields_count = case n
|
|
167
|
+
when Numeric then n
|
|
168
|
+
when :once then 1
|
|
169
|
+
when :twice then 2
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def failure_reason
|
|
174
|
+
return " but was not a block" unless @probe.has_block?
|
|
175
|
+
return '' unless @expected_yields_count
|
|
176
|
+
" #{human_readable_expecation_type}#{human_readable_count}"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def human_readable_expecation_type
|
|
180
|
+
case @expectation_type
|
|
181
|
+
when :<= then 'at most '
|
|
182
|
+
when :>= then 'at least '
|
|
183
|
+
else ''
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def human_readable_count
|
|
188
|
+
case @expected_yields_count
|
|
189
|
+
when 1 then "once"
|
|
190
|
+
when 2 then "twice"
|
|
191
|
+
else "#{@expected_yields_count} times"
|
|
192
|
+
end
|
|
79
193
|
end
|
|
80
194
|
end
|
|
81
195
|
|
|
196
|
+
# @api private
|
|
197
|
+
# Provides the implementation for `yield_with_no_args`.
|
|
198
|
+
# Not intended to be instantiated directly.
|
|
82
199
|
class YieldWithNoArgs < BaseMatcher
|
|
83
|
-
|
|
200
|
+
# @private
|
|
84
201
|
def matches?(block)
|
|
85
202
|
@probe = YieldProbe.probe(block)
|
|
203
|
+
return false unless @probe.has_block?
|
|
86
204
|
@probe.yielded_once?(:yield_with_no_args) && @probe.single_yield_args.empty?
|
|
87
205
|
end
|
|
88
206
|
|
|
89
|
-
|
|
90
|
-
|
|
207
|
+
# @private
|
|
208
|
+
def does_not_match?(block)
|
|
209
|
+
!matches?(block) && @probe.has_block?
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# @private
|
|
213
|
+
def failure_message
|
|
214
|
+
"expected given block to yield with no arguments, but #{positive_failure_reason}"
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# @private
|
|
218
|
+
def failure_message_when_negated
|
|
219
|
+
"expected given block not to yield with no arguments, but #{negative_failure_reason}"
|
|
91
220
|
end
|
|
92
221
|
|
|
93
|
-
|
|
94
|
-
|
|
222
|
+
# @private
|
|
223
|
+
def supports_block_expectations?
|
|
224
|
+
true
|
|
95
225
|
end
|
|
96
226
|
|
|
97
227
|
private
|
|
98
228
|
|
|
99
|
-
def
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
229
|
+
def positive_failure_reason
|
|
230
|
+
return "was not a block" unless @probe.has_block?
|
|
231
|
+
return "did not yield" if @probe.num_yields.zero?
|
|
232
|
+
"yielded with arguments: #{@probe.single_yield_args.inspect}"
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def negative_failure_reason
|
|
236
|
+
return "was not a block" unless @probe.has_block?
|
|
237
|
+
"did"
|
|
105
238
|
end
|
|
106
239
|
end
|
|
107
240
|
|
|
241
|
+
# @api private
|
|
242
|
+
# Provides the implementation for `yield_with_args`.
|
|
243
|
+
# Not intended to be instantiated directly.
|
|
108
244
|
class YieldWithArgs
|
|
245
|
+
include Composable
|
|
246
|
+
|
|
109
247
|
def initialize(*args)
|
|
110
248
|
@expected = args
|
|
111
249
|
end
|
|
112
250
|
|
|
251
|
+
# @private
|
|
113
252
|
def matches?(block)
|
|
114
253
|
@probe = YieldProbe.probe(block)
|
|
254
|
+
return false unless @probe.has_block?
|
|
115
255
|
@actual = @probe.single_yield_args
|
|
116
256
|
@probe.yielded_once?(:yield_with_args) && args_match?
|
|
117
257
|
end
|
|
118
|
-
alias == matches?
|
|
119
258
|
|
|
120
|
-
|
|
259
|
+
# @private
|
|
260
|
+
def does_not_match?(block)
|
|
261
|
+
!matches?(block) && @probe.has_block?
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
# @private
|
|
265
|
+
def failure_message
|
|
121
266
|
"expected given block to yield with arguments, but #{positive_failure_reason}"
|
|
122
267
|
end
|
|
123
268
|
|
|
124
|
-
|
|
269
|
+
# @private
|
|
270
|
+
def failure_message_when_negated
|
|
125
271
|
"expected given block not to yield with arguments, but #{negative_failure_reason}"
|
|
126
272
|
end
|
|
127
273
|
|
|
274
|
+
# @private
|
|
128
275
|
def description
|
|
129
276
|
desc = "yield with args"
|
|
130
|
-
desc << "(
|
|
277
|
+
desc << "(#{expected_arg_description})" unless @expected.empty?
|
|
131
278
|
desc
|
|
132
279
|
end
|
|
133
280
|
|
|
281
|
+
# @private
|
|
282
|
+
def supports_block_expectations?
|
|
283
|
+
true
|
|
284
|
+
end
|
|
285
|
+
|
|
134
286
|
private
|
|
135
287
|
|
|
136
288
|
def positive_failure_reason
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
289
|
+
return "was not a block" unless @probe.has_block?
|
|
290
|
+
return "did not yield" if @probe.num_yields.zero?
|
|
291
|
+
@positive_args_failure
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
def expected_arg_description
|
|
295
|
+
@expected.map { |e| description_of e }.join(", ")
|
|
142
296
|
end
|
|
143
297
|
|
|
144
298
|
def negative_failure_reason
|
|
145
|
-
if
|
|
299
|
+
if !@probe.has_block?
|
|
300
|
+
"was not a block"
|
|
301
|
+
elsif all_args_match?
|
|
146
302
|
"yielded with expected arguments" +
|
|
147
|
-
"\nexpected not: #{@expected.inspect}" +
|
|
148
|
-
"\n got: #{@actual.inspect}
|
|
303
|
+
"\nexpected not: #{surface_descriptions_in(@expected).inspect}" +
|
|
304
|
+
"\n got: #{@actual.inspect}"
|
|
149
305
|
else
|
|
150
306
|
"did"
|
|
151
307
|
end
|
|
@@ -159,60 +315,86 @@ module RSpec
|
|
|
159
315
|
|
|
160
316
|
unless match = all_args_match?
|
|
161
317
|
@positive_args_failure = "yielded with unexpected arguments" +
|
|
162
|
-
"\nexpected: #{@expected.inspect}" +
|
|
163
|
-
"\n got: #{@actual.inspect}
|
|
318
|
+
"\nexpected: #{surface_descriptions_in(@expected).inspect}" +
|
|
319
|
+
"\n got: #{@actual.inspect}"
|
|
164
320
|
end
|
|
165
321
|
|
|
166
322
|
match
|
|
167
323
|
end
|
|
168
324
|
|
|
169
325
|
def all_args_match?
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
@expected.zip(@actual).all? do |expected, actual|
|
|
173
|
-
expected === actual || actual == expected
|
|
174
|
-
end
|
|
326
|
+
values_match?(@expected, @actual)
|
|
175
327
|
end
|
|
176
328
|
end
|
|
177
329
|
|
|
330
|
+
# @api private
|
|
331
|
+
# Provides the implementation for `yield_successive_args`.
|
|
332
|
+
# Not intended to be instantiated directly.
|
|
178
333
|
class YieldSuccessiveArgs
|
|
334
|
+
include Composable
|
|
335
|
+
|
|
179
336
|
def initialize(*args)
|
|
180
337
|
@expected = args
|
|
181
338
|
end
|
|
182
339
|
|
|
340
|
+
# @private
|
|
183
341
|
def matches?(block)
|
|
184
342
|
@probe = YieldProbe.probe(block)
|
|
343
|
+
return false unless @probe.has_block?
|
|
185
344
|
@actual = @probe.successive_yield_args
|
|
186
345
|
args_match?
|
|
187
346
|
end
|
|
188
|
-
alias == matches?
|
|
189
347
|
|
|
190
|
-
def
|
|
191
|
-
|
|
192
|
-
"\nexpected: #{@expected.inspect}" +
|
|
193
|
-
"\n got: #{@actual.inspect} (compared using === and ==)"
|
|
348
|
+
def does_not_match?(block)
|
|
349
|
+
!matches?(block) && @probe.has_block?
|
|
194
350
|
end
|
|
195
351
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
"\n got: #{@actual.inspect} (compared using === and ==)"
|
|
352
|
+
# @private
|
|
353
|
+
def failure_message
|
|
354
|
+
"expected given block to yield successively with arguments, but #{positive_failure_reason}"
|
|
200
355
|
end
|
|
201
356
|
|
|
357
|
+
# @private
|
|
358
|
+
def failure_message_when_negated
|
|
359
|
+
"expected given block not to yield successively with arguments, but #{negative_failure_reason}"
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
# @private
|
|
202
363
|
def description
|
|
203
364
|
desc = "yield successive args"
|
|
204
|
-
desc << "(
|
|
365
|
+
desc << "(#{expected_arg_description})"
|
|
205
366
|
desc
|
|
206
367
|
end
|
|
207
368
|
|
|
369
|
+
# @private
|
|
370
|
+
def supports_block_expectations?
|
|
371
|
+
true
|
|
372
|
+
end
|
|
373
|
+
|
|
208
374
|
private
|
|
209
375
|
|
|
210
376
|
def args_match?
|
|
211
|
-
|
|
377
|
+
values_match?(@expected, @actual)
|
|
378
|
+
end
|
|
212
379
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
380
|
+
def expected_arg_description
|
|
381
|
+
@expected.map { |e| description_of e }.join(", ")
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def positive_failure_reason
|
|
385
|
+
return "was not a block" unless @probe.has_block?
|
|
386
|
+
|
|
387
|
+
"yielded with unexpected arguments" +
|
|
388
|
+
"\nexpected: #{surface_descriptions_in(@expected).inspect}" +
|
|
389
|
+
"\n got: #{@actual.inspect}"
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
def negative_failure_reason
|
|
393
|
+
return "was not a block" unless @probe.has_block?
|
|
394
|
+
|
|
395
|
+
"yielded with expected arguments" +
|
|
396
|
+
"\nexpected not: #{surface_descriptions_in(@expected).inspect}" +
|
|
397
|
+
"\n got: #{@actual.inspect}"
|
|
216
398
|
end
|
|
217
399
|
end
|
|
218
400
|
end
|
|
@@ -1,39 +1,51 @@
|
|
|
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 :BePredicate,
|
|
12
|
-
autoload :
|
|
13
|
-
autoload :BeWithin,
|
|
14
|
-
autoload :Change,
|
|
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 :BeNil, 'rspec/matchers/built_in/be'
|
|
20
|
+
autoload :BePredicate, 'rspec/matchers/built_in/be'
|
|
21
|
+
autoload :BeTruthy, 'rspec/matchers/built_in/be'
|
|
22
|
+
autoload :BeWithin, 'rspec/matchers/built_in/be_within'
|
|
23
|
+
autoload :Change, 'rspec/matchers/built_in/change'
|
|
24
|
+
autoload :Compound, 'rspec/matchers/built_in/compound'
|
|
25
|
+
autoload :ContainExactly, 'rspec/matchers/built_in/contain_exactly'
|
|
26
|
+
autoload :Cover, 'rspec/matchers/built_in/cover'
|
|
27
|
+
autoload :EndWith, 'rspec/matchers/built_in/start_and_end_with'
|
|
28
|
+
autoload :Eq, 'rspec/matchers/built_in/eq'
|
|
29
|
+
autoload :Eql, 'rspec/matchers/built_in/eql'
|
|
30
|
+
autoload :Equal, 'rspec/matchers/built_in/equal'
|
|
31
|
+
autoload :Exist, 'rspec/matchers/built_in/exist'
|
|
32
|
+
autoload :Has, 'rspec/matchers/built_in/has'
|
|
33
|
+
autoload :Include, 'rspec/matchers/built_in/include'
|
|
34
|
+
autoload :All, 'rspec/matchers/built_in/all'
|
|
35
|
+
autoload :Match, 'rspec/matchers/built_in/match'
|
|
36
|
+
autoload :NegativeOperatorMatcher, 'rspec/matchers/built_in/operators'
|
|
37
|
+
autoload :OperatorMatcher, 'rspec/matchers/built_in/operators'
|
|
38
|
+
autoload :Output, 'rspec/matchers/built_in/output'
|
|
39
|
+
autoload :PositiveOperatorMatcher, 'rspec/matchers/built_in/operators'
|
|
40
|
+
autoload :RaiseError, 'rspec/matchers/built_in/raise_error'
|
|
41
|
+
autoload :RespondTo, 'rspec/matchers/built_in/respond_to'
|
|
42
|
+
autoload :Satisfy, 'rspec/matchers/built_in/satisfy'
|
|
43
|
+
autoload :StartWith, 'rspec/matchers/built_in/start_and_end_with'
|
|
44
|
+
autoload :ThrowSymbol, 'rspec/matchers/built_in/throw_symbol'
|
|
45
|
+
autoload :YieldControl, 'rspec/matchers/built_in/yield'
|
|
46
|
+
autoload :YieldSuccessiveArgs, 'rspec/matchers/built_in/yield'
|
|
47
|
+
autoload :YieldWithArgs, 'rspec/matchers/built_in/yield'
|
|
48
|
+
autoload :YieldWithNoArgs, 'rspec/matchers/built_in/yield'
|
|
35
49
|
end
|
|
36
50
|
end
|
|
37
51
|
end
|
|
38
|
-
|
|
39
|
-
|