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
|
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
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -42,12 +44,12 @@ module RSpec
|
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
# @private
|
|
45
|
-
def matches?(event_proc
|
|
47
|
+
def matches?(event_proc)
|
|
46
48
|
raise_block_syntax_error if block_given?
|
|
47
49
|
perform_change(event_proc) && change_details.changed?
|
|
48
50
|
end
|
|
49
51
|
|
|
50
|
-
def does_not_match?(event_proc
|
|
52
|
+
def does_not_match?(event_proc)
|
|
51
53
|
raise_block_syntax_error if block_given?
|
|
52
54
|
perform_change(event_proc) && !change_details.changed?
|
|
53
55
|
end
|
|
@@ -56,14 +58,14 @@ module RSpec
|
|
|
56
58
|
# @return [String]
|
|
57
59
|
def failure_message
|
|
58
60
|
"expected #{change_details.value_representation} to have changed, " \
|
|
59
|
-
|
|
61
|
+
"but #{positive_failure_reason}"
|
|
60
62
|
end
|
|
61
63
|
|
|
62
64
|
# @api private
|
|
63
65
|
# @return [String]
|
|
64
66
|
def failure_message_when_negated
|
|
65
67
|
"expected #{change_details.value_representation} not to have changed, " \
|
|
66
|
-
|
|
68
|
+
"but #{negative_failure_reason}"
|
|
67
69
|
end
|
|
68
70
|
|
|
69
71
|
# @api private
|
|
@@ -108,18 +110,16 @@ module RSpec
|
|
|
108
110
|
|
|
109
111
|
def raise_block_syntax_error
|
|
110
112
|
raise SyntaxError, "Block not received by the `change` matcher. " \
|
|
111
|
-
|
|
113
|
+
"Perhaps you want to use `{ ... }` instead of do/end?"
|
|
112
114
|
end
|
|
113
115
|
|
|
114
116
|
def positive_failure_reason
|
|
115
|
-
return "was not given a block" unless Proc === @event_proc
|
|
116
117
|
"is still #{@actual_before_description}"
|
|
117
118
|
end
|
|
118
119
|
|
|
119
120
|
def negative_failure_reason
|
|
120
|
-
return "was not given a block" unless Proc === @event_proc
|
|
121
121
|
"did change from #{@actual_before_description} " \
|
|
122
|
-
|
|
122
|
+
"to #{description_of change_details.actual_after}"
|
|
123
123
|
end
|
|
124
124
|
end
|
|
125
125
|
|
|
@@ -136,8 +136,8 @@ module RSpec
|
|
|
136
136
|
# @private
|
|
137
137
|
def failure_message
|
|
138
138
|
"expected #{@change_details.value_representation} to have changed " \
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
"#{@relativity.to_s.tr('_', ' ')} " \
|
|
140
|
+
"#{description_of @expected_delta}, but #{failure_reason}"
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
# @private
|
|
@@ -148,14 +148,14 @@ module RSpec
|
|
|
148
148
|
|
|
149
149
|
# @private
|
|
150
150
|
def does_not_match?(_event_proc)
|
|
151
|
-
raise NotImplementedError, "
|
|
152
|
-
|
|
151
|
+
raise NotImplementedError, "Using a negated form of the `change` matcher " \
|
|
152
|
+
"with `#{@relativity}()` is not supported."
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
# @private
|
|
156
156
|
def description
|
|
157
157
|
"change #{@change_details.value_representation} " \
|
|
158
|
-
|
|
158
|
+
"#{@relativity.to_s.tr('_', ' ')} #{description_of @expected_delta}"
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
# @private
|
|
@@ -171,7 +171,6 @@ module RSpec
|
|
|
171
171
|
private
|
|
172
172
|
|
|
173
173
|
def failure_reason
|
|
174
|
-
return "was not given a block" unless Proc === @event_proc
|
|
175
174
|
"was changed by #{description_of @change_details.actual_delta}"
|
|
176
175
|
end
|
|
177
176
|
end
|
|
@@ -200,7 +199,6 @@ module RSpec
|
|
|
200
199
|
|
|
201
200
|
# @private
|
|
202
201
|
def failure_message
|
|
203
|
-
return not_given_a_block_failure unless Proc === @event_proc
|
|
204
202
|
return before_value_failure unless @matches_before
|
|
205
203
|
return did_not_change_failure unless @change_details.changed?
|
|
206
204
|
after_value_failure
|
|
@@ -237,30 +235,25 @@ module RSpec
|
|
|
237
235
|
|
|
238
236
|
def before_value_failure
|
|
239
237
|
"expected #{@change_details.value_representation} " \
|
|
240
|
-
|
|
241
|
-
|
|
238
|
+
"to have initially been #{description_of @expected_before}, " \
|
|
239
|
+
"but was #{@actual_before_description}"
|
|
242
240
|
end
|
|
243
241
|
|
|
244
242
|
def after_value_failure
|
|
245
243
|
"expected #{@change_details.value_representation} " \
|
|
246
|
-
|
|
247
|
-
|
|
244
|
+
"to have changed to #{description_of @expected_after}, " \
|
|
245
|
+
"but is now #{description_of @change_details.actual_after}"
|
|
248
246
|
end
|
|
249
247
|
|
|
250
248
|
def did_not_change_failure
|
|
251
249
|
"expected #{@change_details.value_representation} " \
|
|
252
|
-
|
|
250
|
+
"to have changed #{change_description}, but did not change"
|
|
253
251
|
end
|
|
254
252
|
|
|
255
253
|
def did_change_failure
|
|
256
254
|
"expected #{@change_details.value_representation} not to have changed, but " \
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
def not_given_a_block_failure
|
|
262
|
-
"expected #{@change_details.value_representation} to have changed " \
|
|
263
|
-
"#{change_description}, but was not given a block"
|
|
255
|
+
"did change from #{@actual_before_description} " \
|
|
256
|
+
"to #{description_of @change_details.actual_after}"
|
|
264
257
|
end
|
|
265
258
|
end
|
|
266
259
|
|
|
@@ -284,8 +277,8 @@ module RSpec
|
|
|
284
277
|
# @private
|
|
285
278
|
def does_not_match?(event_proc)
|
|
286
279
|
if @description_suffix
|
|
287
|
-
raise NotImplementedError, "
|
|
288
|
-
|
|
280
|
+
raise NotImplementedError, "Using a negated form of the `change` matcher " \
|
|
281
|
+
"with `to()` is not supported."
|
|
289
282
|
end
|
|
290
283
|
|
|
291
284
|
perform_change(event_proc) && !@change_details.changed? && @matches_before
|
|
@@ -293,7 +286,6 @@ module RSpec
|
|
|
293
286
|
|
|
294
287
|
# @private
|
|
295
288
|
def failure_message_when_negated
|
|
296
|
-
return not_given_a_block_failure unless Proc === @event_proc
|
|
297
289
|
return before_value_failure unless @matches_before
|
|
298
290
|
did_change_failure
|
|
299
291
|
end
|
|
@@ -324,8 +316,8 @@ module RSpec
|
|
|
324
316
|
|
|
325
317
|
# @private
|
|
326
318
|
def does_not_match?(_event_proc)
|
|
327
|
-
raise NotImplementedError, "
|
|
328
|
-
|
|
319
|
+
raise NotImplementedError, "Using a negated form of the `change` matcher " \
|
|
320
|
+
"with `to()` is not supported."
|
|
329
321
|
end
|
|
330
322
|
|
|
331
323
|
private
|
|
@@ -352,8 +344,6 @@ module RSpec
|
|
|
352
344
|
class ChangeDetails
|
|
353
345
|
attr_reader :actual_after
|
|
354
346
|
|
|
355
|
-
UNDEFINED = Module.new.freeze
|
|
356
|
-
|
|
357
347
|
def initialize(matcher_name, receiver=nil, message=nil, &block)
|
|
358
348
|
if receiver && !message
|
|
359
349
|
raise(
|
|
@@ -368,11 +358,6 @@ module RSpec
|
|
|
368
358
|
@receiver = receiver
|
|
369
359
|
@message = message
|
|
370
360
|
@value_proc = block
|
|
371
|
-
# TODO: temporary measure to mute warning of access to an initialized
|
|
372
|
-
# instance variable when a deprecated implicit block expectation
|
|
373
|
-
# syntax is used. This may be removed once `fail` is used, and the
|
|
374
|
-
# matcher never issues this warning.
|
|
375
|
-
@actual_after = UNDEFINED
|
|
376
361
|
end
|
|
377
362
|
|
|
378
363
|
def value_representation
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -15,9 +17,9 @@ module RSpec
|
|
|
15
17
|
# @private
|
|
16
18
|
def does_not_match?(_actual)
|
|
17
19
|
raise NotImplementedError, "`expect(...).not_to matcher.#{conjunction} matcher` " \
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
"is not supported, since it creates a bit of an ambiguity. Instead, define negated versions " \
|
|
21
|
+
"of whatever matchers you wish to negate with `RSpec::Matchers.define_negated_matcher` and " \
|
|
22
|
+
"use `expect(...).to matcher.#{conjunction} matcher`."
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
# @api private
|
|
@@ -95,8 +97,8 @@ module RSpec
|
|
|
95
97
|
|
|
96
98
|
def compound_failure_message
|
|
97
99
|
"#{indent_multiline_message(matcher_1.failure_message.sub(/\n+\z/, ''))}" \
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
"\n\n...#{conjunction}:" \
|
|
101
|
+
"\n\n#{indent_multiline_message(matcher_2.failure_message.sub(/\A\n+/, ''))}"
|
|
100
102
|
end
|
|
101
103
|
|
|
102
104
|
def matcher_1_matches?
|
|
@@ -173,9 +175,9 @@ module RSpec
|
|
|
173
175
|
def matcher_matches?(matcher)
|
|
174
176
|
@match_results.fetch(matcher) do
|
|
175
177
|
raise ArgumentError, "Your #{matcher.description} has no match " \
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
"results, this can occur when an unexpected call stack or " \
|
|
179
|
+
"local jump occurs. Perhaps one of your matchers needs to " \
|
|
180
|
+
"declare `expects_call_stack_jump?` as `true`?"
|
|
179
181
|
end
|
|
180
182
|
end
|
|
181
183
|
|
|
@@ -190,8 +192,8 @@ module RSpec
|
|
|
190
192
|
Proc.new do |*inner_args|
|
|
191
193
|
unless inner_args.empty?
|
|
192
194
|
raise ArgumentError, "(#{@matcher_1.description}) and " \
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
"(#{@matcher_2.description}) cannot be combined in a compound expectation " \
|
|
196
|
+
"since both matchers pass arguments to the block."
|
|
195
197
|
end
|
|
196
198
|
|
|
197
199
|
@actual.call(*outer_args)
|
|
@@ -229,15 +231,17 @@ module RSpec
|
|
|
229
231
|
return @matcher_2, @matcher_1 unless self.class.matcher_expects_call_stack_jump?(@matcher_1)
|
|
230
232
|
|
|
231
233
|
raise ArgumentError, "(#{@matcher_1.description}) and " \
|
|
232
|
-
|
|
233
|
-
|
|
234
|
+
"(#{@matcher_2.description}) cannot be combined in a compound expectation " \
|
|
235
|
+
"because they both expect a call stack jump."
|
|
234
236
|
end
|
|
235
237
|
|
|
238
|
+
# rubocop:disable Lint/IneffectiveAccessModifier
|
|
236
239
|
def self.matcher_expects_call_stack_jump?(matcher)
|
|
237
240
|
matcher.expects_call_stack_jump?
|
|
238
241
|
rescue NoMethodError
|
|
239
242
|
false
|
|
240
243
|
end
|
|
244
|
+
# rubocop:enable Lint/IneffectiveAccessModifier
|
|
241
245
|
end
|
|
242
246
|
|
|
243
247
|
# @api public
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
4
|
-
# rubocop:disable Metrics/ClassLength
|
|
5
6
|
# @api private
|
|
6
7
|
# Provides the implementation for `contain_exactly` and `match_array`.
|
|
7
8
|
# Not intended to be instantiated directly.
|
|
9
|
+
# rubocop:disable Metrics/ClassLength
|
|
8
10
|
class ContainExactly < BaseMatcher
|
|
9
11
|
# @api private
|
|
10
12
|
# @return [String]
|
|
@@ -13,7 +15,7 @@ module RSpec
|
|
|
13
15
|
generate_failure_message
|
|
14
16
|
else
|
|
15
17
|
"expected a collection that can be converted to an array with " \
|
|
16
|
-
|
|
18
|
+
"`#to_ary` or `#to_a`, but got #{actual_formatted}"
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
@@ -107,19 +109,8 @@ module RSpec
|
|
|
107
109
|
array
|
|
108
110
|
end
|
|
109
111
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
def to_a_disallowed?(object)
|
|
113
|
-
case object
|
|
114
|
-
when NilClass, String then true
|
|
115
|
-
else Kernel == RSpec::Support.method_handle_for(object, :to_a).owner
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
# :nocov:
|
|
119
|
-
else
|
|
120
|
-
def to_a_disallowed?(object)
|
|
121
|
-
NilClass === object
|
|
122
|
-
end
|
|
112
|
+
def to_a_disallowed?(object)
|
|
113
|
+
NilClass === object
|
|
123
114
|
end
|
|
124
115
|
|
|
125
116
|
def missing_items
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -56,22 +58,10 @@ module RSpec
|
|
|
56
58
|
|
|
57
59
|
private
|
|
58
60
|
|
|
59
|
-
if RUBY_VERSION.to_f > 1.8
|
|
60
|
-
def cover?(count, number)
|
|
61
|
-
count.cover?(number)
|
|
62
|
-
end
|
|
63
|
-
else
|
|
64
|
-
# :nocov:
|
|
65
|
-
def cover?(count, number)
|
|
66
|
-
number >= count.first && number <= count.last
|
|
67
|
-
end
|
|
68
|
-
# :nocov:
|
|
69
|
-
end
|
|
70
|
-
|
|
71
61
|
def expected_count_matches?(actual_count)
|
|
72
62
|
@actual_count = actual_count
|
|
73
63
|
return @actual_count > 0 unless count_expectation_type
|
|
74
|
-
return cover?(
|
|
64
|
+
return expected_count.cover?(actual_count) if count_expectation_type == :<=>
|
|
75
65
|
|
|
76
66
|
@actual_count.__send__(count_expectation_type, expected_count)
|
|
77
67
|
end
|
|
@@ -126,8 +116,8 @@ module RSpec
|
|
|
126
116
|
when :twice then 2
|
|
127
117
|
when :thrice then 3
|
|
128
118
|
else
|
|
129
|
-
raise ArgumentError, "Expected a number, :once, :twice or :thrice," \
|
|
130
|
-
|
|
119
|
+
raise ArgumentError, "Expected a number, :once, :twice or :thrice, " \
|
|
120
|
+
"but got #{n}"
|
|
131
121
|
end
|
|
132
122
|
end
|
|
133
123
|
|
|
@@ -143,8 +133,8 @@ module RSpec
|
|
|
143
133
|
end
|
|
144
134
|
|
|
145
135
|
def count_failure_reason(action)
|
|
146
|
-
"#{count_expectation_description}" \
|
|
147
|
-
|
|
136
|
+
"#{count_expectation_description} " \
|
|
137
|
+
"but #{action}#{human_readable_count(@actual_count)}"
|
|
148
138
|
end
|
|
149
139
|
|
|
150
140
|
def human_readable_expectation_type
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -60,8 +62,8 @@ module RSpec
|
|
|
60
62
|
when 0
|
|
61
63
|
" but it does not respond to either `exist?` or `exists?`"
|
|
62
64
|
when 2
|
|
63
|
-
" but `exist?` and `exists?` returned different values:\n\n"\
|
|
64
|
-
"
|
|
65
|
+
" but `exist?` and `exists?` returned different values:\n\n " \
|
|
66
|
+
"exist?: #{existence_values.first}\n" \
|
|
65
67
|
"exists?: #{existence_values.last}"
|
|
66
68
|
end
|
|
67
69
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -69,33 +71,16 @@ module RSpec
|
|
|
69
71
|
really_responds_to?(predicate)
|
|
70
72
|
end
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
# :nocov:
|
|
75
|
-
def private_predicate?
|
|
76
|
-
@actual.private_methods.include? predicate.to_s
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def methods_include?(method)
|
|
80
|
-
@actual.methods.include?(method.to_s)
|
|
81
|
-
end
|
|
82
|
-
# :nocov:
|
|
83
|
-
else
|
|
84
|
-
def private_predicate?
|
|
85
|
-
@actual.private_methods.include? predicate
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def methods_include?(method)
|
|
89
|
-
@actual.methods.include?(method)
|
|
90
|
-
end
|
|
74
|
+
def private_predicate?
|
|
75
|
+
@actual.private_methods.include? predicate
|
|
91
76
|
end
|
|
92
77
|
|
|
93
|
-
def
|
|
94
|
-
@
|
|
78
|
+
def methods_include?(method)
|
|
79
|
+
@actual.methods.include?(method)
|
|
95
80
|
end
|
|
96
81
|
|
|
97
|
-
def
|
|
98
|
-
predicate
|
|
82
|
+
def predicate_result
|
|
83
|
+
@predicate_result = actual.__send__(predicate, *@args, &@block)
|
|
99
84
|
end
|
|
100
85
|
|
|
101
86
|
def predicate_matches?(value=true)
|
|
@@ -107,11 +92,7 @@ module RSpec
|
|
|
107
92
|
end
|
|
108
93
|
|
|
109
94
|
def root
|
|
110
|
-
|
|
111
|
-
# rather than the match data object. Changing to Regex#match appears to
|
|
112
|
-
# work around this bug. For an example of this bug, see:
|
|
113
|
-
# https://travis-ci.org/rspec/rspec-expectations/jobs/27549635
|
|
114
|
-
self.class::REGEX.match(@method_name.to_s).captures.first
|
|
95
|
+
self.class::REGEX.match(@method_name).captures.first
|
|
115
96
|
end
|
|
116
97
|
|
|
117
98
|
def method_description
|
|
@@ -169,10 +150,6 @@ module RSpec
|
|
|
169
150
|
@predicate ||= :"#{root}?"
|
|
170
151
|
end
|
|
171
152
|
|
|
172
|
-
def predicate_method_name
|
|
173
|
-
actual.respond_to?(predicate) ? predicate : present_tense_predicate
|
|
174
|
-
end
|
|
175
|
-
|
|
176
153
|
def failure_to_respond_explanation
|
|
177
154
|
super || if predicate == :true?
|
|
178
155
|
" or perhaps you meant `be true` or `be_truthy`"
|
|
@@ -180,14 +157,6 @@ module RSpec
|
|
|
180
157
|
" or perhaps you meant `be false` or `be_falsey`"
|
|
181
158
|
end
|
|
182
159
|
end
|
|
183
|
-
|
|
184
|
-
def predicate_accessible?
|
|
185
|
-
super || really_responds_to?(present_tense_predicate)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
def present_tense_predicate
|
|
189
|
-
:"#{root}s?"
|
|
190
|
-
end
|
|
191
160
|
end
|
|
192
161
|
end
|
|
193
162
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rspec/matchers/built_in/count_expectation'
|
|
2
4
|
|
|
3
5
|
module RSpec
|
|
@@ -8,6 +10,7 @@ module RSpec
|
|
|
8
10
|
# Not intended to be instantiated directly.
|
|
9
11
|
class Include < BaseMatcher # rubocop:disable Metrics/ClassLength
|
|
10
12
|
include CountExpectation
|
|
13
|
+
|
|
11
14
|
# @private
|
|
12
15
|
attr_reader :expecteds
|
|
13
16
|
|
|
@@ -95,9 +98,9 @@ module RSpec
|
|
|
95
98
|
|
|
96
99
|
def format_failure_message(preposition)
|
|
97
100
|
msg = if actual.respond_to?(:include?)
|
|
98
|
-
"expected #{description_of @actual} #{preposition}" \
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
"expected #{description_of @actual} #{preposition} " \
|
|
102
|
+
"include#{readable_list_of @divergent_items}" \
|
|
103
|
+
"#{count_failure_reason('it is included') if has_expected_count?}"
|
|
101
104
|
else
|
|
102
105
|
"#{yield}, but it does not respond to `include?`"
|
|
103
106
|
end
|
|
@@ -167,7 +170,6 @@ module RSpec
|
|
|
167
170
|
|
|
168
171
|
def actual_collection_includes?(expected_item)
|
|
169
172
|
return actual.scan(expected_item).size > 0 if Regexp === expected_item && String === actual
|
|
170
|
-
return false if String === actual && !expected_item.respond_to?(:to_str, true)
|
|
171
173
|
return true if actual.include?(expected_item)
|
|
172
174
|
|
|
173
175
|
# String lacks an `any?` method...
|
|
@@ -176,16 +178,8 @@ module RSpec
|
|
|
176
178
|
actual.any? { |value| values_match?(expected_item, value) }
|
|
177
179
|
end
|
|
178
180
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
def count_enumerable(expected_item)
|
|
182
|
-
actual.select { |value| values_match?(expected_item, value) }.size
|
|
183
|
-
end
|
|
184
|
-
# :nocov:
|
|
185
|
-
else
|
|
186
|
-
def count_enumerable(expected_item)
|
|
187
|
-
actual.count { |value| values_match?(expected_item, value) }
|
|
188
|
-
end
|
|
181
|
+
def count_enumerable(expected_item)
|
|
182
|
+
actual.count { |value| values_match?(expected_item, value) }
|
|
189
183
|
end
|
|
190
184
|
|
|
191
185
|
def count_inclusions
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
module Matchers
|
|
3
5
|
module BuiltIn
|
|
@@ -49,13 +51,13 @@ module RSpec
|
|
|
49
51
|
def match(expected, actual)
|
|
50
52
|
return match_captures(expected, actual) if @expected_captures
|
|
51
53
|
return true if values_match?(expected, actual)
|
|
52
|
-
return false if Array === expected
|
|
53
54
|
return false unless can_safely_call_match?(expected, actual)
|
|
54
55
|
actual.match(expected)
|
|
55
56
|
end
|
|
56
57
|
|
|
57
58
|
def can_safely_call_match?(expected, actual)
|
|
58
59
|
return false unless actual.respond_to?(:match)
|
|
60
|
+
return false if Array === expected
|
|
59
61
|
|
|
60
62
|
!(RSpec::Matchers.is_a_matcher?(expected) &&
|
|
61
63
|
(String === actual || Regexp === actual))
|
|
@@ -64,7 +66,6 @@ module RSpec
|
|
|
64
66
|
def match_captures(expected, actual)
|
|
65
67
|
match = actual.match(expected)
|
|
66
68
|
if match
|
|
67
|
-
match = ReliableMatchData.new(match)
|
|
68
69
|
if match.names.empty?
|
|
69
70
|
values_match?(@expected_captures, match.captures)
|
|
70
71
|
else
|
|
@@ -78,43 +79,6 @@ module RSpec
|
|
|
78
79
|
end
|
|
79
80
|
end
|
|
80
81
|
end
|
|
81
|
-
|
|
82
|
-
# @api private
|
|
83
|
-
# Used to wrap match data and make it reliable for 1.8.7
|
|
84
|
-
class ReliableMatchData
|
|
85
|
-
def initialize(match_data)
|
|
86
|
-
@match_data = match_data
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
if RUBY_VERSION == "1.8.7"
|
|
90
|
-
# @api private
|
|
91
|
-
# Returns match data names for named captures
|
|
92
|
-
# @return Array
|
|
93
|
-
# :nocov:
|
|
94
|
-
def names
|
|
95
|
-
[]
|
|
96
|
-
end
|
|
97
|
-
# :nocov:
|
|
98
|
-
else
|
|
99
|
-
# @api private
|
|
100
|
-
# Returns match data names for named captures
|
|
101
|
-
# @return Array
|
|
102
|
-
def names
|
|
103
|
-
match_data.names
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# @api private
|
|
108
|
-
# returns an array of captures from the match data
|
|
109
|
-
# @return Array
|
|
110
|
-
def captures
|
|
111
|
-
match_data.captures
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
protected
|
|
115
|
-
|
|
116
|
-
attr_reader :match_data
|
|
117
|
-
end
|
|
118
82
|
end
|
|
119
83
|
end
|
|
120
84
|
end
|