rspec-expectations 2.14.0 → 3.13.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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +1 -1
- data/Changelog.md +976 -25
- data/{License.txt → LICENSE.md} +5 -3
- data/README.md +162 -26
- 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 +127 -51
- data/lib/rspec/expectations/fail_with.rb +17 -57
- data/lib/rspec/expectations/failure_aggregator.rb +229 -0
- data/lib/rspec/expectations/handler.rb +146 -32
- data/lib/rspec/expectations/minitest_integration.rb +58 -0
- data/lib/rspec/expectations/syntax.rb +68 -100
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +58 -23
- 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 +191 -20
- data/lib/rspec/matchers/built_in/be.rb +114 -114
- data/lib/rspec/matchers/built_in/be_between.rb +77 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +15 -4
- data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
- data/lib/rspec/matchers/built_in/be_within.rb +35 -18
- data/lib/rspec/matchers/built_in/change.rb +389 -80
- data/lib/rspec/matchers/built_in/compound.rb +290 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +310 -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 +30 -8
- data/lib/rspec/matchers/built_in/eql.rb +23 -8
- data/lib/rspec/matchers/built_in/equal.rb +55 -22
- 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 +184 -32
- 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 +192 -44
- data/lib/rspec/matchers/built_in/respond_to.rb +154 -28
- 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 +240 -161
- data/lib/rspec/matchers/built_in.rb +47 -33
- data/lib/rspec/matchers/composable.rb +171 -0
- data/lib/rspec/matchers/dsl.rb +531 -10
- data/lib/rspec/matchers/english_phrasing.rb +58 -0
- data/lib/rspec/matchers/fail_matchers.rb +42 -0
- data/lib/rspec/matchers/generated_descriptions.rb +14 -8
- data/lib/rspec/matchers/matcher_delegator.rb +61 -0
- data/lib/rspec/matchers/matcher_protocol.rb +105 -0
- data/lib/rspec/matchers/multi_matcher_diff.rb +82 -0
- data/lib/rspec/matchers.rb +520 -173
- data.tar.gz.sig +0 -0
- metadata +141 -242
- metadata.gz.sig +2 -0
- data/features/README.md +0 -48
- 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 -161
- 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 -14
- data/features/syntax_configuration.feature +0 -71
- data/features/test_frameworks/test_unit.feature +0 -44
- data/lib/rspec/expectations/deprecation.rb +0 -17
- data/lib/rspec/expectations/differ.rb +0 -133
- 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 -29
- 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 -124
- data/lib/rspec/matchers/built_in/match_array.rb +0 -51
- 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 -108
- 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/matchers/pretty.rb +0 -70
- data/lib/rspec/matchers/test_unit_integration.rb +0 -11
- data/lib/rspec-expectations.rb +0 -1
- data/spec/rspec/expectations/differ_spec.rb +0 -192
- 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 -227
- data/spec/rspec/expectations/syntax_spec.rb +0 -139
- 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 -137
- data/spec/rspec/matchers/change_spec.rb +0 -553
- data/spec/rspec/matchers/configuration_spec.rb +0 -206
- data/spec/rspec/matchers/cover_spec.rb +0 -69
- data/spec/rspec/matchers/description_generation_spec.rb +0 -190
- 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 -455
- 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 -485
- 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 -514
- 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,514 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module YieldHelpers
|
4
|
-
# these helpers are prefixed with an underscore to prevent
|
5
|
-
# collisions with the matchers (some of which have the same names)
|
6
|
-
def _dont_yield
|
7
|
-
end
|
8
|
-
|
9
|
-
def _yield_with_no_args
|
10
|
-
yield
|
11
|
-
end
|
12
|
-
|
13
|
-
def _yield_with_args(*args)
|
14
|
-
yield(*args)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class InstanceEvaler
|
19
|
-
include RSpec::Matchers::Extensions::InstanceEvalWithArgs
|
20
|
-
|
21
|
-
def yield_with_no_args(&block)
|
22
|
-
instance_eval_with_args(&block)
|
23
|
-
end
|
24
|
-
|
25
|
-
def yield_with_args(*args, &block)
|
26
|
-
instance_eval_with_args(*args, &block)
|
27
|
-
end
|
28
|
-
|
29
|
-
def each_arg(*args, &block)
|
30
|
-
args.each do |arg|
|
31
|
-
instance_eval_with_args(arg, &block)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "yield_control matcher" do
|
37
|
-
include YieldHelpers
|
38
|
-
extend YieldHelpers
|
39
|
-
|
40
|
-
it_behaves_like "an RSpec matcher",
|
41
|
-
:valid_value => lambda { |b| _yield_with_no_args(&b) },
|
42
|
-
:invalid_value => lambda { |b| _dont_yield(&b) } do
|
43
|
-
let(:matcher) { yield_control }
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'has a description' do
|
47
|
-
expect(yield_control.description).to eq("yield control")
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "expect {...}.to yield_control" do
|
51
|
-
it 'passes if the block yields, regardless of the number of yielded arguments' do
|
52
|
-
expect { |b| _yield_with_no_args(&b) }.to yield_control
|
53
|
-
expect { |b| _yield_with_args(1, 2, &b) }.to yield_control
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'passes if the block yields using instance_eval' do
|
57
|
-
expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_control
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'fails if the block does not yield' do
|
61
|
-
expect {
|
62
|
-
expect { |b| _dont_yield(&b) }.to yield_control
|
63
|
-
}.to fail_with(/expected given block to yield control/)
|
64
|
-
end
|
65
|
-
|
66
|
-
context "with exact count" do
|
67
|
-
it 'fails if the block yields wrong number of times' do
|
68
|
-
expect {
|
69
|
-
expect { |b| [1, 2, 3].each(&b) }.to yield_control.twice
|
70
|
-
}.to fail_with(/expected given block to yield control twice/)
|
71
|
-
|
72
|
-
expect {
|
73
|
-
expect { |b| [1, 2].each(&b) }.to yield_control.exactly(3).times
|
74
|
-
}.to fail_with(/expected given block to yield control 3 times/)
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'passes if the block yields the specified number of times' do
|
78
|
-
expect { |b| [1].each(&b) }.to yield_control.once
|
79
|
-
expect { |b| [1, 2].each(&b) }.to yield_control.twice
|
80
|
-
expect { |b| [1, 2, 3].each(&b) }.to yield_control.exactly(3).times
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "with at_least count" do
|
85
|
-
it 'passes if the block yields the given number of times' do
|
86
|
-
expect { |b| [1, 2].each(&b) }.to yield_control.at_least(2).times
|
87
|
-
expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_least(3).times
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'passes if the block yields more times' do
|
91
|
-
expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_least(2).times
|
92
|
-
expect { |b| [1, 2, 3, 4].each(&b) }.to yield_control.at_least(3).times
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'allows :once and :twice to be passed as counts' do
|
96
|
-
expect { |b| [1].each(&b) }.to yield_control.at_least(:once)
|
97
|
-
expect { |b| [1, 2].each(&b) }.to yield_control.at_least(:once)
|
98
|
-
|
99
|
-
expect {
|
100
|
-
expect { |b| [].each(&b) }.to yield_control.at_least(:once)
|
101
|
-
}.to fail_with(/at least once/)
|
102
|
-
|
103
|
-
expect { |b| [1, 2].each(&b) }.to yield_control.at_least(:twice)
|
104
|
-
expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_least(:twice)
|
105
|
-
|
106
|
-
expect {
|
107
|
-
expect { |b| [1].each(&b) }.to yield_control.at_least(:twice)
|
108
|
-
}.to fail_with(/at least twice/)
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'fails if the block yields too few times' do
|
112
|
-
expect {
|
113
|
-
expect { |b| _yield_with_no_args(&b) }.to yield_control.at_least(2).times
|
114
|
-
}.to fail_with(/expected given block to yield control at least twice/)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "with at_most count" do
|
119
|
-
it 'passes if the block yields the given number of times' do
|
120
|
-
expect { |b| [1, 2].each(&b) }.to yield_control.at_most(2).times
|
121
|
-
expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_most(3).times
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'passes if the block yields fewer times' do
|
125
|
-
expect { |b| [1, 2].each(&b) }.to yield_control.at_most(3).times
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'allows :once and :twice to be passed as counts' do
|
129
|
-
expect { |b| [1].each(&b) }.to yield_control.at_most(:once)
|
130
|
-
|
131
|
-
expect {
|
132
|
-
expect { |b| [1, 2].each(&b) }.to yield_control.at_most(:once)
|
133
|
-
}.to fail_with(/expected given block to yield control at most once/)
|
134
|
-
|
135
|
-
expect { |b| [1, 2].each(&b) }.to yield_control.at_most(:twice)
|
136
|
-
|
137
|
-
expect {
|
138
|
-
expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_most(:twice)
|
139
|
-
}.to fail_with(/expected given block to yield control at most twice/)
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'fails if the block yields too many times' do
|
143
|
-
expect {
|
144
|
-
expect { |b| [1, 2, 3].each(&b) }.to yield_control.at_most(2).times
|
145
|
-
}.to fail_with(/expected given block to yield control at most twice/)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "expect {...}.not_to yield_control" do
|
151
|
-
it 'passes if the block does not yield' do
|
152
|
-
expect { |b| _dont_yield(&b) }.not_to yield_control
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'fails if the block does yield' do
|
156
|
-
expect {
|
157
|
-
expect { |b| _yield_with_no_args(&b) }.not_to yield_control
|
158
|
-
}.to fail_with(/expected given block not to yield control/)
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'fails if the expect block does not accept an argument' do
|
162
|
-
expect {
|
163
|
-
expect { }.not_to yield_control
|
164
|
-
}.to raise_error(/expect block must accept an argument/)
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'raises an error if the expect block arg is not passed to a method as a block' do
|
168
|
-
expect {
|
169
|
-
expect { |b| }.not_to yield_control
|
170
|
-
}.to raise_error(/must pass the argument.*as a block/)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe "yield_with_no_args matcher" do
|
176
|
-
include YieldHelpers
|
177
|
-
extend YieldHelpers
|
178
|
-
|
179
|
-
it_behaves_like "an RSpec matcher",
|
180
|
-
:valid_value => lambda { |b| _yield_with_no_args(&b) },
|
181
|
-
:invalid_value => lambda { |b| _dont_yield(&b) } do
|
182
|
-
let(:matcher) { yield_with_no_args }
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'has a description' do
|
186
|
-
expect(yield_with_no_args.description).to eq("yield with no args")
|
187
|
-
end
|
188
|
-
|
189
|
-
describe "expect {...}.to yield_with_no_args" do
|
190
|
-
it 'passes if the block yields with no args' do
|
191
|
-
expect { |b| _yield_with_no_args(&b) }.to yield_with_no_args
|
192
|
-
end
|
193
|
-
|
194
|
-
it 'passes if the block yields with no args using instance_eval' do
|
195
|
-
expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_with_no_args
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'fails if the block does not yield' do
|
199
|
-
expect {
|
200
|
-
expect { |b| _dont_yield(&b) }.to yield_with_no_args
|
201
|
-
}.to fail_with(/expected given block to yield with no arguments, but did not yield/)
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'fails if the block yields with args' do
|
205
|
-
expect {
|
206
|
-
expect { |b| _yield_with_args(1, &b) }.to yield_with_no_args
|
207
|
-
}.to fail_with(/expected given block to yield with no arguments, but yielded with arguments/)
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'fails if the block yields with arg false' do
|
211
|
-
expect {
|
212
|
-
expect { |b| _yield_with_args(false, &b) }.to yield_with_no_args
|
213
|
-
}.to fail_with(/expected given block to yield with no arguments, but yielded with arguments/)
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'raises an error if it yields multiple times' do
|
217
|
-
expect {
|
218
|
-
expect { |b| [1, 2].each(&b) }.to yield_with_no_args
|
219
|
-
}.to raise_error(/not designed.*yields multiple times/)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "expect {...}.not_to yield_with_no_args" do
|
224
|
-
it "passes if the block does not yield" do
|
225
|
-
expect { |b| _dont_yield(&b) }.not_to yield_with_no_args
|
226
|
-
end
|
227
|
-
|
228
|
-
it "passes if the block yields with args" do
|
229
|
-
expect { |b| _yield_with_args(1, &b) }.not_to yield_with_no_args
|
230
|
-
end
|
231
|
-
|
232
|
-
it "fails if the block yields with no args" do
|
233
|
-
expect {
|
234
|
-
expect { |b| _yield_with_no_args(&b) }.not_to yield_with_no_args
|
235
|
-
}.to fail_with(/expected given block not to yield with no arguments, but did/)
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'fails if the expect block does not accept an argument' do
|
239
|
-
expect {
|
240
|
-
expect { }.not_to yield_with_no_args
|
241
|
-
}.to raise_error(/expect block must accept an argument/)
|
242
|
-
end
|
243
|
-
|
244
|
-
it 'raises an error if the expect block arg is not passed to a method as a block' do
|
245
|
-
expect {
|
246
|
-
expect { |b| }.not_to yield_with_no_args
|
247
|
-
}.to raise_error(/must pass the argument.*as a block/)
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
describe "yield_with_args matcher" do
|
253
|
-
include YieldHelpers
|
254
|
-
extend YieldHelpers
|
255
|
-
|
256
|
-
it_behaves_like "an RSpec matcher",
|
257
|
-
:valid_value => lambda { |b| _yield_with_args(1, &b) },
|
258
|
-
:invalid_value => lambda { |b| _dont_yield(&b) } do
|
259
|
-
let(:matcher) { yield_with_args }
|
260
|
-
end
|
261
|
-
|
262
|
-
it 'has a description' do
|
263
|
-
expect(yield_with_args.description).to eq("yield with args")
|
264
|
-
expect(yield_with_args(1, 3).description).to eq("yield with args(1, 3)")
|
265
|
-
expect(yield_with_args(false).description).to eq("yield with args(false)")
|
266
|
-
end
|
267
|
-
|
268
|
-
describe "expect {...}.to yield_with_args" do
|
269
|
-
it 'passes if the block yields with arguments' do
|
270
|
-
expect { |b| _yield_with_args(1, &b) }.to yield_with_args
|
271
|
-
end
|
272
|
-
|
273
|
-
it 'fails if the block does not yield' do
|
274
|
-
expect {
|
275
|
-
expect { |b| _dont_yield(&b) }.to yield_with_args
|
276
|
-
}.to fail_with(/expected given block to yield with arguments, but did not yield/)
|
277
|
-
end
|
278
|
-
|
279
|
-
it 'fails if the block yields with no arguments' do
|
280
|
-
expect {
|
281
|
-
expect { |b| _yield_with_no_args(&b) }.to yield_with_args
|
282
|
-
}.to fail_with(/expected given block to yield with arguments, but yielded with no arguments/)
|
283
|
-
end
|
284
|
-
|
285
|
-
it 'raises an error if it yields multiple times' do
|
286
|
-
expect {
|
287
|
-
expect { |b| [1, 2].each(&b) }.to yield_with_args
|
288
|
-
}.to raise_error(/not designed.*yields multiple times/)
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
describe "expect {...}.not_to yield_with_args" do
|
293
|
-
it 'fails if the block yields with arguments' do
|
294
|
-
expect {
|
295
|
-
expect { |b| _yield_with_args(1, &b) }.not_to yield_with_args
|
296
|
-
}.to fail_with(/expected given block not to yield with arguments, but did/)
|
297
|
-
end
|
298
|
-
|
299
|
-
it 'passes if the block does not yield' do
|
300
|
-
expect { |b| _dont_yield(&b) }.not_to yield_with_args
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'passes if the block yields with no arguments' do
|
304
|
-
expect { |b| _yield_with_no_args(&b) }.not_to yield_with_args
|
305
|
-
end
|
306
|
-
|
307
|
-
it 'fails if the expect block does not accept an argument' do
|
308
|
-
expect {
|
309
|
-
expect { }.not_to yield_with_args
|
310
|
-
}.to raise_error(/expect block must accept an argument/)
|
311
|
-
end
|
312
|
-
|
313
|
-
it 'raises an error if the expect block arg is not passed to a method as a block' do
|
314
|
-
expect {
|
315
|
-
expect { |b| }.not_to yield_with_args
|
316
|
-
}.to raise_error(/must pass the argument.*as a block/)
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
describe "expect {...}.to yield_with_args(3, 17)" do
|
321
|
-
it 'passes if the block yields with the given arguments' do
|
322
|
-
expect { |b| _yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
|
323
|
-
end
|
324
|
-
|
325
|
-
it 'passes if the block yields with the given arguments using instance_eval' do
|
326
|
-
expect { |b| InstanceEvaler.new.yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
|
327
|
-
end
|
328
|
-
|
329
|
-
it 'fails if the block does not yield' do
|
330
|
-
expect {
|
331
|
-
expect { |b| _dont_yield(&b) }.to yield_with_args(3, 17)
|
332
|
-
}.to fail_with(/expected given block to yield with arguments, but did not yield/)
|
333
|
-
end
|
334
|
-
|
335
|
-
it 'fails if the block yields with no arguments' do
|
336
|
-
expect {
|
337
|
-
expect { |b| _yield_with_no_args(&b) }.to yield_with_args(3, 17)
|
338
|
-
}.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
|
339
|
-
end
|
340
|
-
|
341
|
-
it 'fails if the block yields with different arguments' do
|
342
|
-
expect {
|
343
|
-
expect { |b| _yield_with_args("a", "b", &b) }.to yield_with_args("a", "c")
|
344
|
-
}.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
describe "expect {...}.not_to yield_with_args(3, 17)" do
|
349
|
-
it 'passes if the block yields with different arguments' do
|
350
|
-
expect { |b| _yield_with_args("a", "b", &b) }.not_to yield_with_args("a", "c")
|
351
|
-
end
|
352
|
-
|
353
|
-
it 'fails if the block yields with the given arguments' do
|
354
|
-
expect {
|
355
|
-
expect { |b| _yield_with_args("a", "b", &b) }.not_to yield_with_args("a", "b")
|
356
|
-
}.to fail_with(/expected given block not to yield with arguments, but yielded with expected arguments/)
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
describe "expect {...}.to yield_with_args( false )" do
|
361
|
-
it 'passes if the block yields with the given arguments' do
|
362
|
-
expect { |b| _yield_with_args(false, &b) }.to yield_with_args(false)
|
363
|
-
end
|
364
|
-
|
365
|
-
it 'passes if the block yields with the given arguments using instance_eval' do
|
366
|
-
expect { |b| InstanceEvaler.new.yield_with_args(false, &b) }.to yield_with_args(false)
|
367
|
-
end
|
368
|
-
|
369
|
-
it 'fails if the block does not yield' do
|
370
|
-
expect {
|
371
|
-
expect { |b| _dont_yield(&b) }.to yield_with_args(false)
|
372
|
-
}.to fail_with(/expected given block to yield with arguments, but did not yield/)
|
373
|
-
end
|
374
|
-
|
375
|
-
it 'fails if the block yields with no arguments' do
|
376
|
-
expect {
|
377
|
-
expect { |b| _yield_with_no_args(&b) }.to yield_with_args(false)
|
378
|
-
}.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
|
379
|
-
end
|
380
|
-
|
381
|
-
it 'fails if the block yields with different arguments' do
|
382
|
-
expect {
|
383
|
-
expect { |b| _yield_with_args(false, &b) }.to yield_with_args(true)
|
384
|
-
}.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
describe "expect {...}.to yield_with_args(/reg/, /ex/)" do
|
389
|
-
it "passes if the block yields strings matching the regexes" do
|
390
|
-
expect { |b| _yield_with_args("regular", "expression", &b) }.to yield_with_args(/reg/, /ex/)
|
391
|
-
end
|
392
|
-
|
393
|
-
it "fails if the block yields strings that do not match the regexes" do
|
394
|
-
expect {
|
395
|
-
expect { |b| _yield_with_args("no", "match", &b) }.to yield_with_args(/reg/, /ex/)
|
396
|
-
}.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
|
397
|
-
end
|
398
|
-
end
|
399
|
-
|
400
|
-
describe "expect {...}.to yield_with_args(String, Fixnum)" do
|
401
|
-
it "passes if the block yields objects of the given types" do
|
402
|
-
expect { |b| _yield_with_args("string", 15, &b) }.to yield_with_args(String, Fixnum)
|
403
|
-
end
|
404
|
-
|
405
|
-
it "passes if the block yields the given types" do
|
406
|
-
expect { |b| _yield_with_args(String, Fixnum, &b) }.to yield_with_args(String, Fixnum)
|
407
|
-
end
|
408
|
-
|
409
|
-
it "fails if the block yields objects of different types" do
|
410
|
-
expect {
|
411
|
-
expect { |b| _yield_with_args(15, "string", &b) }.to yield_with_args(String, Fixnum)
|
412
|
-
}.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
|
413
|
-
end
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
describe "yield_successive_args matcher" do
|
418
|
-
include YieldHelpers
|
419
|
-
extend YieldHelpers
|
420
|
-
|
421
|
-
it_behaves_like "an RSpec matcher",
|
422
|
-
:valid_value => lambda { |b| [1, 2].each(&b) },
|
423
|
-
:invalid_value => lambda { |b| _dont_yield(&b) } do
|
424
|
-
let(:matcher) { yield_successive_args(1, 2) }
|
425
|
-
end
|
426
|
-
|
427
|
-
it 'has a description' do
|
428
|
-
expect(yield_successive_args(1, 3).description).to eq("yield successive args(1, 3)")
|
429
|
-
expect(yield_successive_args([:a, 1], [:b, 2]).description).to eq("yield successive args([:a, 1], [:b, 2])")
|
430
|
-
end
|
431
|
-
|
432
|
-
describe "expect {...}.to yield_successive_args([:a, 1], [:b, 2])" do
|
433
|
-
it 'passes when the block successively yields the given args' do
|
434
|
-
expect { |b| [ [:a, 1], [:b, 2] ].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
|
435
|
-
end
|
436
|
-
|
437
|
-
it 'fails when the block does not yield that many times' do
|
438
|
-
expect {
|
439
|
-
expect { |b| [[:a, 1]].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
|
440
|
-
}.to fail_with(/but yielded with unexpected arguments/)
|
441
|
-
end
|
442
|
-
|
443
|
-
it 'fails when the block yields the right number of times but with different arguments' do
|
444
|
-
expect {
|
445
|
-
expect { |b| [ [:a, 1], [:b, 3] ].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
|
446
|
-
}.to fail_with(/but yielded with unexpected arguments/)
|
447
|
-
end
|
448
|
-
end
|
449
|
-
|
450
|
-
describe "expect {...}.to yield_successive_args(1, 2, 3)" do
|
451
|
-
it 'passes when the block successively yields the given args' do
|
452
|
-
expect { |b| [1, 2, 3].each(&b) }.to yield_successive_args(1, 2, 3)
|
453
|
-
end
|
454
|
-
|
455
|
-
it 'passes when the block successively yields the given args using instance_eval' do
|
456
|
-
expect { |b| InstanceEvaler.new.each_arg(1, 2, 3, &b) }.to yield_successive_args(1, 2, 3)
|
457
|
-
end
|
458
|
-
|
459
|
-
it 'fails when the block does not yield the expected args' do
|
460
|
-
expect {
|
461
|
-
expect { |b| [1, 2, 4].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
|
462
|
-
}.to fail_with(/but yielded with unexpected arguments/)
|
463
|
-
end
|
464
|
-
end
|
465
|
-
|
466
|
-
describe "expect {...}.not_to yield_successive_args(1, 2, 3)" do
|
467
|
-
it 'passes when the block does not yield' do
|
468
|
-
expect { |b| _dont_yield(&b) }.not_to yield_successive_args(1, 2, 3)
|
469
|
-
end
|
470
|
-
|
471
|
-
it 'passes when the block yields the wrong number of times' do
|
472
|
-
expect { |b| [1, 2].each(&b) }.not_to yield_successive_args(1, 2, 3)
|
473
|
-
end
|
474
|
-
|
475
|
-
it 'passes when the block yields the wrong arguments' do
|
476
|
-
expect { |b| [1, 2, 4].each(&b) }.not_to yield_successive_args(1, 2, 3)
|
477
|
-
end
|
478
|
-
|
479
|
-
it 'fails when the block yields the given arguments' do
|
480
|
-
expect {
|
481
|
-
expect { |b| [1, 2, 3].each(&b) }.not_to yield_successive_args(1, 2, 3)
|
482
|
-
}.to fail_with(/expected given block not to yield successively/)
|
483
|
-
end
|
484
|
-
|
485
|
-
it 'fails if the expect block does not accept an argument' do
|
486
|
-
expect {
|
487
|
-
expect { }.not_to yield_successive_args(1, 2, 3)
|
488
|
-
}.to raise_error(/expect block must accept an argument/)
|
489
|
-
end
|
490
|
-
|
491
|
-
it 'raises an error if the expect block arg is not passed to a method as a block' do
|
492
|
-
expect {
|
493
|
-
expect { |b| }.not_to yield_successive_args(1, 2, 3)
|
494
|
-
}.to raise_error(/must pass the argument.*as a block/)
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
describe "expect {...}.to yield_successive_args(String, Fixnum)" do
|
499
|
-
it "passes if the block successively yields objects of the given types" do
|
500
|
-
expect { |b| ["string", 15].each(&b) }.to yield_successive_args(String, Fixnum)
|
501
|
-
end
|
502
|
-
|
503
|
-
it "passes if the block yields the given types" do
|
504
|
-
expect { |b| [String, Fixnum].each(&b) }.to yield_successive_args(String, Fixnum)
|
505
|
-
end
|
506
|
-
|
507
|
-
it "fails if the block yields objects of different types" do
|
508
|
-
expect {
|
509
|
-
expect { |b| [15, "string"].each(&b) }.to yield_successive_args(String, Fixnum)
|
510
|
-
}.to fail_with(/expected given block to yield successively with arguments/)
|
511
|
-
end
|
512
|
-
end
|
513
|
-
end
|
514
|
-
|
data/spec/spec_helper.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
Dir['./spec/support/**/*'].each {|f| require f}
|
2
|
-
|
3
|
-
RSpec::configure do |config|
|
4
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
5
|
-
config.color_enabled = true
|
6
|
-
config.filter_run :focused
|
7
|
-
config.run_all_when_everything_filtered = true
|
8
|
-
config.order = :random
|
9
|
-
|
10
|
-
config.expect_with :rspec do |expectations|
|
11
|
-
$default_expectation_syntax = expectations.syntax
|
12
|
-
expectations.syntax = :expect
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
shared_context "with #should enabled", :uses_should do
|
17
|
-
orig_syntax = nil
|
18
|
-
|
19
|
-
before(:all) do
|
20
|
-
orig_syntax = RSpec::Matchers.configuration.syntax
|
21
|
-
RSpec::Matchers.configuration.syntax = [:expect, :should]
|
22
|
-
end
|
23
|
-
|
24
|
-
after(:all) do
|
25
|
-
RSpec::Matchers.configuration.syntax = orig_syntax
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
shared_context "with #should exclusively enabled", :uses_only_should do
|
31
|
-
orig_syntax = nil
|
32
|
-
|
33
|
-
before(:all) do
|
34
|
-
orig_syntax = RSpec::Matchers.configuration.syntax
|
35
|
-
RSpec::Matchers.configuration.syntax = :should
|
36
|
-
end
|
37
|
-
|
38
|
-
after(:all) do
|
39
|
-
RSpec::Matchers.configuration.syntax = orig_syntax
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
module TestUnitIntegrationSupport
|
44
|
-
include InSubProcess
|
45
|
-
|
46
|
-
def with_test_unit_loaded
|
47
|
-
in_sub_process do
|
48
|
-
require 'test/unit'
|
49
|
-
load 'rspec/matchers/test_unit_integration.rb'
|
50
|
-
yield
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
data/spec/support/classes.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# various classes used by the specs
|
2
|
-
module RSpec
|
3
|
-
module Expectations
|
4
|
-
module Helper
|
5
|
-
class CollectionWithSizeMethod
|
6
|
-
def initialize; @list = []; end
|
7
|
-
def size; @list.size; end
|
8
|
-
def push(item); @list.push(item); end
|
9
|
-
end
|
10
|
-
|
11
|
-
class CollectionWithLengthMethod
|
12
|
-
def initialize; @list = []; end
|
13
|
-
def length; @list.size; end
|
14
|
-
def push(item); @list.push(item); end
|
15
|
-
end
|
16
|
-
|
17
|
-
class CollectionWithCountMethod
|
18
|
-
def initialize; @list = []; end
|
19
|
-
def count; @list.count; end
|
20
|
-
def push(item); @list.push(item); end
|
21
|
-
end
|
22
|
-
|
23
|
-
class CollectionOwner
|
24
|
-
attr_reader :items_in_collection_with_size_method, :items_in_collection_with_length_method, :items_in_collection_with_count_method
|
25
|
-
|
26
|
-
def initialize
|
27
|
-
@items_in_collection_with_size_method = CollectionWithSizeMethod.new
|
28
|
-
@items_in_collection_with_length_method = CollectionWithLengthMethod.new
|
29
|
-
@items_in_collection_with_count_method = CollectionWithCountMethod.new
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_to_collection_with_size_method(item)
|
33
|
-
@items_in_collection_with_size_method.push(item)
|
34
|
-
end
|
35
|
-
|
36
|
-
def add_to_collection_with_length_method(item)
|
37
|
-
@items_in_collection_with_length_method.push(item)
|
38
|
-
end
|
39
|
-
|
40
|
-
def add_to_collection_with_count_method(item)
|
41
|
-
@items_in_collection_with_count_method.push(item)
|
42
|
-
end
|
43
|
-
|
44
|
-
def items_for(arg)
|
45
|
-
return [1, 2, 3] if arg == 'a'
|
46
|
-
[1]
|
47
|
-
end
|
48
|
-
|
49
|
-
def items
|
50
|
-
@items_in_collection_with_size_method
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module InSubProcess
|
2
|
-
if RUBY_PLATFORM == 'java'
|
3
|
-
def in_sub_process
|
4
|
-
pending "This spec requires forking to work properly, " +
|
5
|
-
"and JRuby does not support forking"
|
6
|
-
end
|
7
|
-
else
|
8
|
-
# Useful as a way to isolate a global change to a subprocess.
|
9
|
-
def in_sub_process
|
10
|
-
readme, writeme = IO.pipe
|
11
|
-
|
12
|
-
pid = Process.fork do
|
13
|
-
value = nil
|
14
|
-
begin
|
15
|
-
yield
|
16
|
-
rescue => e
|
17
|
-
value = e
|
18
|
-
end
|
19
|
-
|
20
|
-
writeme.write Marshal.dump(value)
|
21
|
-
|
22
|
-
readme.close
|
23
|
-
writeme.close
|
24
|
-
exit! # prevent at_exit hooks from running (e.g. minitest)
|
25
|
-
end
|
26
|
-
|
27
|
-
writeme.close
|
28
|
-
Process.waitpid(pid)
|
29
|
-
|
30
|
-
if exception = Marshal.load(readme.read)
|
31
|
-
raise exception
|
32
|
-
end
|
33
|
-
|
34
|
-
readme.close
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
data/spec/support/matchers.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :include_method do |expected|
|
2
|
-
match do |actual|
|
3
|
-
actual.map { |m| m.to_s }.include?(expected.to_s)
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
module RSpec
|
8
|
-
module Matchers
|
9
|
-
def fail
|
10
|
-
raise_error(RSpec::Expectations::ExpectationNotMetError)
|
11
|
-
end
|
12
|
-
|
13
|
-
def fail_with(message)
|
14
|
-
raise_error(RSpec::Expectations::ExpectationNotMetError, message)
|
15
|
-
end
|
16
|
-
|
17
|
-
def fail_matching(message)
|
18
|
-
raise_error(RSpec::Expectations::ExpectationNotMetError, /#{Regexp.escape(message)}/)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|