rspec-expectations 3.0.0.beta2 → 3.0.0.rc1
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.tar.gz.sig +2 -2
- data/.yardopts +0 -1
- data/Changelog.md +115 -35
- data/README.md +2 -2
- data/lib/rspec/expectations.rb +13 -8
- data/lib/rspec/{matchers → expectations}/configuration.rb +38 -13
- data/lib/rspec/expectations/expectation_target.rb +72 -8
- data/lib/rspec/expectations/fail_with.rb +10 -52
- data/lib/rspec/expectations/handler.rb +9 -11
- data/lib/rspec/expectations/syntax.rb +37 -35
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +60 -9
- data/lib/rspec/matchers/aliased_matcher.rb +6 -0
- data/lib/rspec/matchers/built_in.rb +9 -1
- data/lib/rspec/matchers/built_in/all.rb +78 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +39 -1
- data/lib/rspec/matchers/built_in/be.rb +117 -42
- data/lib/rspec/matchers/built_in/be_between.rb +22 -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 +26 -6
- data/lib/rspec/matchers/built_in/change.rb +89 -13
- data/lib/rspec/matchers/built_in/compound.rb +19 -3
- data/lib/rspec/matchers/built_in/contain_exactly.rb +17 -6
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +20 -5
- data/lib/rspec/matchers/built_in/eql.rb +15 -3
- data/lib/rspec/matchers/built_in/equal.rb +23 -6
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +58 -3
- data/lib/rspec/matchers/built_in/include.rb +16 -1
- data/lib/rspec/matchers/built_in/match.rb +14 -4
- data/lib/rspec/matchers/built_in/operators.rb +16 -0
- data/lib/rspec/matchers/built_in/output.rb +47 -5
- data/lib/rspec/matchers/built_in/raise_error.rb +40 -23
- data/lib/rspec/matchers/built_in/respond_to.rb +37 -16
- data/lib/rspec/matchers/built_in/satisfy.rb +15 -0
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +29 -14
- data/lib/rspec/matchers/built_in/throw_symbol.rb +32 -3
- data/lib/rspec/matchers/built_in/yield.rb +148 -44
- data/lib/rspec/matchers/composable.rb +48 -7
- data/lib/rspec/matchers/dsl.rb +45 -17
- data/lib/rspec/matchers/generated_descriptions.rb +7 -0
- data/lib/rspec/matchers/matcher_delegator.rb +6 -2
- data/lib/rspec/matchers/pretty.rb +15 -19
- metadata +33 -236
- metadata.gz.sig +0 -0
- data/features/README.md +0 -48
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -96
- data/features/built_in_matchers/be.feature +0 -175
- data/features/built_in_matchers/be_within.feature +0 -48
- data/features/built_in_matchers/comparisons.feature +0 -97
- data/features/built_in_matchers/contain_exactly.feature +0 -46
- 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 -136
- 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/include.feature +0 -126
- data/features/built_in_matchers/match.feature +0 -51
- data/features/built_in_matchers/output.feature +0 -70
- data/features/built_in_matchers/predicates.feature +0 -161
- 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 -161
- data/features/composing_matchers.feature +0 -250
- data/features/compound_expectations.feature +0 -45
- 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 -34
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -39
- 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 -21
- data/features/support/rubinius.rb +0 -6
- data/features/syntax_configuration.feature +0 -71
- data/features/test_frameworks/minitest.feature +0 -44
- data/lib/rspec-expectations.rb +0 -1
- data/lib/rspec/expectations/diff_presenter.rb +0 -141
- data/lib/rspec/expectations/differ.rb +0 -44
- data/lib/rspec/expectations/encoded_string.rb +0 -56
- data/spec/rspec/expectations/diff_presenter_spec.rb +0 -249
- data/spec/rspec/expectations/encoded_string_spec.rb +0 -74
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -114
- data/spec/rspec/expectations/handler_spec.rb +0 -205
- data/spec/rspec/expectations/minitest_integration_spec.rb +0 -27
- data/spec/rspec/expectations/syntax_spec.rb +0 -89
- data/spec/rspec/expectations_spec.rb +0 -12
- data/spec/rspec/matchers/aliased_matcher_spec.rb +0 -48
- data/spec/rspec/matchers/aliases_spec.rb +0 -449
- data/spec/rspec/matchers/built_in/base_matcher_spec.rb +0 -83
- data/spec/rspec/matchers/built_in/be_between_spec.rb +0 -159
- data/spec/rspec/matchers/built_in/be_instance_of_spec.rb +0 -63
- data/spec/rspec/matchers/built_in/be_kind_of_spec.rb +0 -41
- data/spec/rspec/matchers/built_in/be_spec.rb +0 -592
- data/spec/rspec/matchers/built_in/be_within_spec.rb +0 -141
- data/spec/rspec/matchers/built_in/change_spec.rb +0 -808
- data/spec/rspec/matchers/built_in/compound_spec.rb +0 -292
- data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +0 -441
- data/spec/rspec/matchers/built_in/cover_spec.rb +0 -69
- data/spec/rspec/matchers/built_in/eq_spec.rb +0 -156
- data/spec/rspec/matchers/built_in/eql_spec.rb +0 -41
- data/spec/rspec/matchers/built_in/equal_spec.rb +0 -106
- data/spec/rspec/matchers/built_in/exist_spec.rb +0 -124
- data/spec/rspec/matchers/built_in/has_spec.rb +0 -161
- data/spec/rspec/matchers/built_in/include_spec.rb +0 -540
- data/spec/rspec/matchers/built_in/match_spec.rb +0 -102
- data/spec/rspec/matchers/built_in/operators_spec.rb +0 -252
- data/spec/rspec/matchers/built_in/output_spec.rb +0 -165
- data/spec/rspec/matchers/built_in/raise_error_spec.rb +0 -461
- data/spec/rspec/matchers/built_in/respond_to_spec.rb +0 -292
- data/spec/rspec/matchers/built_in/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/built_in/start_and_end_with_spec.rb +0 -253
- data/spec/rspec/matchers/built_in/throw_symbol_spec.rb +0 -135
- data/spec/rspec/matchers/built_in/yield_spec.rb +0 -627
- data/spec/rspec/matchers/configuration_spec.rb +0 -213
- data/spec/rspec/matchers/description_generation_spec.rb +0 -191
- data/spec/rspec/matchers/dsl_spec.rb +0 -895
- data/spec/rspec/matchers/legacy_spec.rb +0 -101
- data/spec/rspec/matchers_spec.rb +0 -74
- data/spec/spec_helper.rb +0 -85
- data/spec/support/matchers.rb +0 -22
- data/spec/support/shared_examples.rb +0 -35
@@ -1,24 +1,17 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Matchers
|
3
3
|
module BuiltIn
|
4
|
+
# @api private
|
5
|
+
# Base class for the `end_with` and `start_with` matchers.
|
6
|
+
# Not intended to be instantiated directly.
|
4
7
|
class StartAndEndWith < BaseMatcher
|
5
8
|
def initialize(*expected)
|
6
9
|
@actual_does_not_have_ordered_elements = false
|
7
10
|
@expected = expected.length == 1 ? expected.first : expected
|
8
11
|
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
begin
|
14
|
-
return subset_matches? if expected.respond_to?(:length)
|
15
|
-
element_matches?
|
16
|
-
rescue ArgumentError
|
17
|
-
@actual_does_not_have_ordered_elements = true
|
18
|
-
return false
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
13
|
+
# @api private
|
14
|
+
# @return [String]
|
22
15
|
def failure_message
|
23
16
|
super.tap do |msg|
|
24
17
|
if @actual_does_not_have_ordered_elements
|
@@ -29,6 +22,8 @@ module RSpec
|
|
29
22
|
end
|
30
23
|
end
|
31
24
|
|
25
|
+
# @api private
|
26
|
+
# @return [String]
|
32
27
|
def description
|
33
28
|
return super unless Hash === expected
|
34
29
|
"#{name_to_sentence} #{surface_descriptions_in(expected).inspect}"
|
@@ -36,13 +31,29 @@ module RSpec
|
|
36
31
|
|
37
32
|
private
|
38
33
|
|
34
|
+
def match(expected, actual)
|
35
|
+
return false unless actual.respond_to?(:[])
|
36
|
+
|
37
|
+
begin
|
38
|
+
return subset_matches? if expected.respond_to?(:length)
|
39
|
+
element_matches?
|
40
|
+
rescue ArgumentError
|
41
|
+
@actual_does_not_have_ordered_elements = true
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
39
46
|
def actual_is_unordered
|
40
47
|
ArgumentError.new("#{actual.inspect} does not have ordered elements")
|
41
48
|
end
|
42
49
|
end
|
43
50
|
|
51
|
+
# @api private
|
52
|
+
# Provides the implementation for `start_with`.
|
53
|
+
# Not intended to be instantiated directly.
|
44
54
|
class StartWith < StartAndEndWith
|
45
|
-
|
55
|
+
|
56
|
+
private
|
46
57
|
|
47
58
|
def subset_matches?
|
48
59
|
values_match?(expected, actual[0, expected.length])
|
@@ -53,8 +64,12 @@ module RSpec
|
|
53
64
|
end
|
54
65
|
end
|
55
66
|
|
67
|
+
# @api private
|
68
|
+
# Provides the implementation for `end_with`.
|
69
|
+
# Not intended to be instantiated directly.
|
56
70
|
class EndWith < StartAndEndWith
|
57
|
-
|
71
|
+
|
72
|
+
private
|
58
73
|
|
59
74
|
def subset_matches?
|
60
75
|
values_match?(expected, actual[-expected.length, expected.length])
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Matchers
|
3
3
|
module BuiltIn
|
4
|
+
# @api private
|
5
|
+
# Provides the implementation for `throw_symbol`.
|
6
|
+
# Not intended to be instantiated directly.
|
4
7
|
class ThrowSymbol
|
5
8
|
include Composable
|
6
9
|
|
@@ -10,7 +13,11 @@ module RSpec
|
|
10
13
|
@caught_symbol = @caught_arg = nil
|
11
14
|
end
|
12
15
|
|
16
|
+
# @private
|
13
17
|
def matches?(given_proc)
|
18
|
+
@block = given_proc
|
19
|
+
return false unless Proc === given_proc
|
20
|
+
|
14
21
|
begin
|
15
22
|
if @expected_symbol.nil?
|
16
23
|
given_proc.call
|
@@ -54,19 +61,41 @@ module RSpec
|
|
54
61
|
end
|
55
62
|
end
|
56
63
|
|
64
|
+
def does_not_match?(given_proc)
|
65
|
+
!matches?(given_proc) && Proc === given_proc
|
66
|
+
end
|
67
|
+
|
68
|
+
# @api private
|
69
|
+
# @return [String]
|
57
70
|
def failure_message
|
58
|
-
"expected #{expected} to be thrown,
|
71
|
+
"expected #{expected} to be thrown, #{actual_result}"
|
59
72
|
end
|
60
73
|
|
74
|
+
# @api private
|
75
|
+
# @return [String]
|
61
76
|
def failure_message_when_negated
|
62
|
-
"expected #{expected('no Symbol')}#{' not' if @expected_symbol} to be thrown,
|
77
|
+
"expected #{expected('no Symbol')}#{' not' if @expected_symbol} to be thrown, #{actual_result}"
|
63
78
|
end
|
64
79
|
|
80
|
+
# @api private
|
81
|
+
# @return [String]
|
65
82
|
def description
|
66
83
|
"throw #{expected}"
|
67
84
|
end
|
68
85
|
|
69
|
-
private
|
86
|
+
# @api private
|
87
|
+
# Indicates this matcher matches against a block.
|
88
|
+
# @return [True]
|
89
|
+
def supports_block_expectations?
|
90
|
+
true
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def actual_result
|
96
|
+
return "but was not a block" unless Proc === @block
|
97
|
+
"got #{caught}"
|
98
|
+
end
|
70
99
|
|
71
100
|
def expected(symbol_desc = 'a Symbol')
|
72
101
|
throw_description(@expected_symbol || symbol_desc, @expected_arg)
|
@@ -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
|
|
@@ -58,71 +68,98 @@ module RSpec
|
|
58
68
|
"are."
|
59
69
|
end
|
60
70
|
|
61
|
-
def
|
62
|
-
return if block.arity == 1
|
71
|
+
def assert_valid_expect_block!
|
72
|
+
return if @block.arity == 1
|
63
73
|
raise "Your expect block must accept an argument to be used with this " +
|
64
74
|
"matcher. Pass the argument as a block on to the method you are testing."
|
65
75
|
end
|
66
76
|
end
|
67
77
|
|
78
|
+
# @api private
|
79
|
+
# Provides the implementation for `yield_control`.
|
80
|
+
# Not intended to be instantiated directly.
|
68
81
|
class YieldControl < BaseMatcher
|
69
82
|
def initialize
|
70
83
|
@expectation_type = nil
|
71
84
|
@expected_yields_count = nil
|
72
85
|
end
|
73
86
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
if @expectation_type
|
78
|
-
probe.num_yields.send(@expectation_type, @expected_yields_count)
|
79
|
-
else
|
80
|
-
probe.yielded_once?(:yield_control)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
87
|
+
# @api public
|
88
|
+
# Specifies that the method is expected to yield once.
|
84
89
|
def once
|
85
90
|
exactly(1)
|
86
91
|
self
|
87
92
|
end
|
88
93
|
|
94
|
+
# @api public
|
95
|
+
# Specifies that the method is expected to yield once.
|
89
96
|
def twice
|
90
97
|
exactly(2)
|
91
98
|
self
|
92
99
|
end
|
93
100
|
|
101
|
+
# @api public
|
102
|
+
# Specifies that the method is expected to yield the given number of times.
|
94
103
|
def exactly(number)
|
95
104
|
set_expected_yields_count(:==, number)
|
96
105
|
self
|
97
106
|
end
|
98
107
|
|
108
|
+
# @api public
|
109
|
+
# Specifies the maximum number of times the method is expected to yield
|
99
110
|
def at_most(number)
|
100
111
|
set_expected_yields_count(:<=, number)
|
101
112
|
self
|
102
113
|
end
|
103
114
|
|
115
|
+
# @api public
|
116
|
+
# Specifies the minimum number of times the method is expected to yield
|
104
117
|
def at_least(number)
|
105
118
|
set_expected_yields_count(:>=, number)
|
106
119
|
self
|
107
120
|
end
|
108
121
|
|
122
|
+
# @api public
|
123
|
+
# No-op. Provides syntactic sugar.
|
109
124
|
def times
|
110
125
|
self
|
111
126
|
end
|
112
127
|
|
113
|
-
|
114
|
-
|
115
|
-
|
128
|
+
# @private
|
129
|
+
def matches?(block)
|
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)
|
116
137
|
end
|
117
138
|
end
|
118
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]
|
119
153
|
def failure_message_when_negated
|
120
|
-
'expected given block not to yield control'
|
121
|
-
failure_message << relativity_failure_message
|
122
|
-
end
|
154
|
+
'expected given block not to yield control' + failure_reason
|
123
155
|
end
|
124
156
|
|
125
|
-
private
|
157
|
+
# @private
|
158
|
+
def supports_block_expectations?
|
159
|
+
true
|
160
|
+
end
|
161
|
+
|
162
|
+
private
|
126
163
|
|
127
164
|
def set_expected_yields_count(relativity, n)
|
128
165
|
@expectation_type = relativity
|
@@ -133,7 +170,8 @@ module RSpec
|
|
133
170
|
end
|
134
171
|
end
|
135
172
|
|
136
|
-
def
|
173
|
+
def failure_reason
|
174
|
+
return " but was not a block" unless @probe.has_block?
|
137
175
|
return '' unless @expected_yields_count
|
138
176
|
" #{human_readable_expecation_type}#{human_readable_count}"
|
139
177
|
end
|
@@ -155,32 +193,54 @@ module RSpec
|
|
155
193
|
end
|
156
194
|
end
|
157
195
|
|
196
|
+
# @api private
|
197
|
+
# Provides the implementation for `yield_with_no_args`.
|
198
|
+
# Not intended to be instantiated directly.
|
158
199
|
class YieldWithNoArgs < BaseMatcher
|
159
|
-
|
200
|
+
# @private
|
160
201
|
def matches?(block)
|
161
202
|
@probe = YieldProbe.probe(block)
|
203
|
+
return false unless @probe.has_block?
|
162
204
|
@probe.yielded_once?(:yield_with_no_args) && @probe.single_yield_args.empty?
|
163
205
|
end
|
164
206
|
|
207
|
+
# @private
|
208
|
+
def does_not_match?(block)
|
209
|
+
!matches?(block) && @probe.has_block?
|
210
|
+
end
|
211
|
+
|
212
|
+
# @private
|
165
213
|
def failure_message
|
166
|
-
"expected given block to yield with no arguments, but #{
|
214
|
+
"expected given block to yield with no arguments, but #{positive_failure_reason}"
|
167
215
|
end
|
168
216
|
|
217
|
+
# @private
|
169
218
|
def failure_message_when_negated
|
170
|
-
"expected given block not to yield with no arguments, but
|
219
|
+
"expected given block not to yield with no arguments, but #{negative_failure_reason}"
|
220
|
+
end
|
221
|
+
|
222
|
+
# @private
|
223
|
+
def supports_block_expectations?
|
224
|
+
true
|
171
225
|
end
|
172
226
|
|
173
227
|
private
|
174
228
|
|
175
|
-
def
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
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"
|
181
238
|
end
|
182
239
|
end
|
183
240
|
|
241
|
+
# @api private
|
242
|
+
# Provides the implementation for `yield_with_args`.
|
243
|
+
# Not intended to be instantiated directly.
|
184
244
|
class YieldWithArgs
|
185
245
|
include Composable
|
186
246
|
|
@@ -188,34 +248,47 @@ module RSpec
|
|
188
248
|
@expected = args
|
189
249
|
end
|
190
250
|
|
251
|
+
# @private
|
191
252
|
def matches?(block)
|
192
253
|
@probe = YieldProbe.probe(block)
|
254
|
+
return false unless @probe.has_block?
|
193
255
|
@actual = @probe.single_yield_args
|
194
256
|
@probe.yielded_once?(:yield_with_args) && args_match?
|
195
257
|
end
|
196
258
|
|
259
|
+
# @private
|
260
|
+
def does_not_match?(block)
|
261
|
+
!matches?(block) && @probe.has_block?
|
262
|
+
end
|
263
|
+
|
264
|
+
# @private
|
197
265
|
def failure_message
|
198
266
|
"expected given block to yield with arguments, but #{positive_failure_reason}"
|
199
267
|
end
|
200
268
|
|
269
|
+
# @private
|
201
270
|
def failure_message_when_negated
|
202
271
|
"expected given block not to yield with arguments, but #{negative_failure_reason}"
|
203
272
|
end
|
204
273
|
|
274
|
+
# @private
|
205
275
|
def description
|
206
276
|
desc = "yield with args"
|
207
277
|
desc << "(#{expected_arg_description})" unless @expected.empty?
|
208
278
|
desc
|
209
279
|
end
|
210
280
|
|
281
|
+
# @private
|
282
|
+
def supports_block_expectations?
|
283
|
+
true
|
284
|
+
end
|
285
|
+
|
211
286
|
private
|
212
287
|
|
213
288
|
def positive_failure_reason
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
@positive_args_failure
|
218
|
-
end
|
289
|
+
return "was not a block" unless @probe.has_block?
|
290
|
+
return "did not yield" if @probe.num_yields.zero?
|
291
|
+
@positive_args_failure
|
219
292
|
end
|
220
293
|
|
221
294
|
def expected_arg_description
|
@@ -223,7 +296,9 @@ module RSpec
|
|
223
296
|
end
|
224
297
|
|
225
298
|
def negative_failure_reason
|
226
|
-
if
|
299
|
+
if !@probe.has_block?
|
300
|
+
"was not a block"
|
301
|
+
elsif all_args_match?
|
227
302
|
"yielded with expected arguments" +
|
228
303
|
"\nexpected not: #{surface_descriptions_in(@expected).inspect}" +
|
229
304
|
"\n got: #{@actual.inspect}"
|
@@ -252,6 +327,9 @@ module RSpec
|
|
252
327
|
end
|
253
328
|
end
|
254
329
|
|
330
|
+
# @api private
|
331
|
+
# Provides the implementation for `yield_successive_args`.
|
332
|
+
# Not intended to be instantiated directly.
|
255
333
|
class YieldSuccessiveArgs
|
256
334
|
include Composable
|
257
335
|
|
@@ -259,30 +337,40 @@ module RSpec
|
|
259
337
|
@expected = args
|
260
338
|
end
|
261
339
|
|
340
|
+
# @private
|
262
341
|
def matches?(block)
|
263
342
|
@probe = YieldProbe.probe(block)
|
343
|
+
return false unless @probe.has_block?
|
264
344
|
@actual = @probe.successive_yield_args
|
265
345
|
args_match?
|
266
346
|
end
|
267
347
|
|
348
|
+
def does_not_match?(block)
|
349
|
+
!matches?(block) && @probe.has_block?
|
350
|
+
end
|
351
|
+
|
352
|
+
# @private
|
268
353
|
def failure_message
|
269
|
-
"expected given block to yield successively with arguments, but
|
270
|
-
"\nexpected: #{surface_descriptions_in(@expected).inspect}" +
|
271
|
-
"\n got: #{@actual.inspect}"
|
354
|
+
"expected given block to yield successively with arguments, but #{positive_failure_reason}"
|
272
355
|
end
|
273
356
|
|
357
|
+
# @private
|
274
358
|
def failure_message_when_negated
|
275
|
-
"expected given block not to yield successively with arguments, but
|
276
|
-
"\nexpected not: #{surface_descriptions_in(@expected).inspect}" +
|
277
|
-
"\n got: #{@actual.inspect}"
|
359
|
+
"expected given block not to yield successively with arguments, but #{negative_failure_reason}"
|
278
360
|
end
|
279
361
|
|
362
|
+
# @private
|
280
363
|
def description
|
281
364
|
desc = "yield successive args"
|
282
365
|
desc << "(#{expected_arg_description})"
|
283
366
|
desc
|
284
367
|
end
|
285
368
|
|
369
|
+
# @private
|
370
|
+
def supports_block_expectations?
|
371
|
+
true
|
372
|
+
end
|
373
|
+
|
286
374
|
private
|
287
375
|
|
288
376
|
def args_match?
|
@@ -292,6 +380,22 @@ module RSpec
|
|
292
380
|
def expected_arg_description
|
293
381
|
@expected.map { |e| description_of e }.join(", ")
|
294
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}"
|
398
|
+
end
|
295
399
|
end
|
296
400
|
end
|
297
401
|
end
|