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.
Files changed (142) hide show
  1. checksums.yaml +15 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +413 -23
  4. data/License.txt +1 -0
  5. data/README.md +109 -80
  6. data/lib/rspec/{matchers → expectations}/configuration.rb +44 -14
  7. data/lib/rspec/expectations/expectation_target.rb +71 -38
  8. data/lib/rspec/expectations/fail_with.rb +12 -44
  9. data/lib/rspec/expectations/handler.rb +135 -35
  10. data/lib/rspec/expectations/minitest_integration.rb +16 -0
  11. data/lib/rspec/expectations/syntax.rb +60 -94
  12. data/lib/rspec/expectations/version.rb +1 -1
  13. data/lib/rspec/expectations.rb +46 -24
  14. data/lib/rspec/matchers/aliased_matcher.rb +41 -0
  15. data/lib/rspec/matchers/built_in/all.rb +78 -0
  16. data/lib/rspec/matchers/built_in/base_matcher.rb +63 -15
  17. data/lib/rspec/matchers/built_in/be.rb +170 -79
  18. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  19. data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
  20. data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
  21. data/lib/rspec/matchers/built_in/be_within.rb +40 -16
  22. data/lib/rspec/matchers/built_in/change.rb +275 -74
  23. data/lib/rspec/matchers/built_in/compound.rb +122 -0
  24. data/lib/rspec/matchers/built_in/contain_exactly.rb +256 -0
  25. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  26. data/lib/rspec/matchers/built_in/eq.rb +60 -6
  27. data/lib/rspec/matchers/built_in/eql.rb +17 -5
  28. data/lib/rspec/matchers/built_in/equal.rb +55 -21
  29. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  30. data/lib/rspec/matchers/built_in/has.rb +71 -15
  31. data/lib/rspec/matchers/built_in/include.rb +58 -29
  32. data/lib/rspec/matchers/built_in/match.rb +19 -1
  33. data/lib/rspec/matchers/built_in/operators.rb +119 -0
  34. data/lib/rspec/matchers/built_in/output.rb +150 -0
  35. data/lib/rspec/matchers/built_in/raise_error.rb +91 -33
  36. data/lib/rspec/matchers/built_in/respond_to.rb +42 -20
  37. data/lib/rspec/matchers/built_in/satisfy.rb +19 -3
  38. data/lib/rspec/matchers/built_in/start_and_end_with.rb +54 -18
  39. data/lib/rspec/matchers/built_in/throw_symbol.rb +38 -8
  40. data/lib/rspec/matchers/built_in/yield.rb +237 -55
  41. data/lib/rspec/matchers/built_in.rb +45 -33
  42. data/lib/rspec/matchers/composable.rb +179 -0
  43. data/lib/rspec/matchers/dsl.rb +362 -5
  44. data/lib/rspec/matchers/generated_descriptions.rb +13 -6
  45. data/lib/rspec/matchers/matcher_delegator.rb +37 -0
  46. data/lib/rspec/matchers/pretty.rb +33 -20
  47. data/lib/rspec/matchers.rb +450 -227
  48. data.tar.gz.sig +1 -0
  49. metadata +100 -215
  50. metadata.gz.sig +0 -0
  51. data/features/README.md +0 -49
  52. data/features/Upgrade.md +0 -53
  53. data/features/built_in_matchers/README.md +0 -90
  54. data/features/built_in_matchers/be.feature +0 -175
  55. data/features/built_in_matchers/be_within.feature +0 -48
  56. data/features/built_in_matchers/cover.feature +0 -47
  57. data/features/built_in_matchers/end_with.feature +0 -48
  58. data/features/built_in_matchers/equality.feature +0 -139
  59. data/features/built_in_matchers/exist.feature +0 -45
  60. data/features/built_in_matchers/expect_change.feature +0 -59
  61. data/features/built_in_matchers/expect_error.feature +0 -144
  62. data/features/built_in_matchers/have.feature +0 -109
  63. data/features/built_in_matchers/include.feature +0 -174
  64. data/features/built_in_matchers/match.feature +0 -52
  65. data/features/built_in_matchers/operators.feature +0 -227
  66. data/features/built_in_matchers/predicates.feature +0 -137
  67. data/features/built_in_matchers/respond_to.feature +0 -84
  68. data/features/built_in_matchers/satisfy.feature +0 -33
  69. data/features/built_in_matchers/start_with.feature +0 -48
  70. data/features/built_in_matchers/throw_symbol.feature +0 -91
  71. data/features/built_in_matchers/types.feature +0 -116
  72. data/features/built_in_matchers/yield.feature +0 -146
  73. data/features/custom_matchers/access_running_example.feature +0 -53
  74. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  75. data/features/custom_matchers/define_matcher.feature +0 -368
  76. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  77. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  78. data/features/customized_message.feature +0 -22
  79. data/features/diffing.feature +0 -85
  80. data/features/implicit_docstrings.feature +0 -52
  81. data/features/step_definitions/additional_cli_steps.rb +0 -22
  82. data/features/support/env.rb +0 -5
  83. data/features/syntax_configuration.feature +0 -68
  84. data/features/test_frameworks/test_unit.feature +0 -46
  85. data/lib/rspec/expectations/deprecation.rb +0 -38
  86. data/lib/rspec/expectations/differ.rb +0 -115
  87. data/lib/rspec/expectations/errors.rb +0 -9
  88. data/lib/rspec/expectations/extensions/array.rb +0 -9
  89. data/lib/rspec/expectations/extensions/object.rb +0 -39
  90. data/lib/rspec/expectations/extensions.rb +0 -2
  91. data/lib/rspec/matchers/be_close.rb +0 -9
  92. data/lib/rspec/matchers/built_in/have.rb +0 -108
  93. data/lib/rspec/matchers/built_in/match_array.rb +0 -51
  94. data/lib/rspec/matchers/compatibility.rb +0 -14
  95. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  96. data/lib/rspec/matchers/matcher.rb +0 -300
  97. data/lib/rspec/matchers/method_missing.rb +0 -12
  98. data/lib/rspec/matchers/operator_matcher.rb +0 -109
  99. data/lib/rspec-expectations.rb +0 -1
  100. data/spec/rspec/expectations/differ_spec.rb +0 -170
  101. data/spec/rspec/expectations/expectation_target_spec.rb +0 -75
  102. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  103. data/spec/rspec/expectations/fail_with_spec.rb +0 -95
  104. data/spec/rspec/expectations/handler_spec.rb +0 -206
  105. data/spec/rspec/expectations/syntax_spec.rb +0 -97
  106. data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
  107. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  108. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
  109. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
  110. data/spec/rspec/matchers/be_spec.rb +0 -516
  111. data/spec/rspec/matchers/be_within_spec.rb +0 -129
  112. data/spec/rspec/matchers/change_spec.rb +0 -542
  113. data/spec/rspec/matchers/configuration_spec.rb +0 -238
  114. data/spec/rspec/matchers/cover_spec.rb +0 -69
  115. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  116. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  117. data/spec/rspec/matchers/eq_spec.rb +0 -60
  118. data/spec/rspec/matchers/eql_spec.rb +0 -41
  119. data/spec/rspec/matchers/equal_spec.rb +0 -78
  120. data/spec/rspec/matchers/exist_spec.rb +0 -124
  121. data/spec/rspec/matchers/has_spec.rb +0 -122
  122. data/spec/rspec/matchers/have_spec.rb +0 -445
  123. data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
  124. data/spec/rspec/matchers/include_spec.rb +0 -531
  125. data/spec/rspec/matchers/match_array_spec.rb +0 -194
  126. data/spec/rspec/matchers/match_spec.rb +0 -61
  127. data/spec/rspec/matchers/matcher_spec.rb +0 -471
  128. data/spec/rspec/matchers/matchers_spec.rb +0 -37
  129. data/spec/rspec/matchers/method_missing_spec.rb +0 -28
  130. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
  131. data/spec/rspec/matchers/raise_error_spec.rb +0 -395
  132. data/spec/rspec/matchers/respond_to_spec.rb +0 -292
  133. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  134. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
  135. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  136. data/spec/rspec/matchers/yield_spec.rb +0 -437
  137. data/spec/spec_helper.rb +0 -54
  138. data/spec/support/classes.rb +0 -56
  139. data/spec/support/in_sub_process.rb +0 -38
  140. data/spec/support/matchers.rb +0 -22
  141. data/spec/support/ruby_version.rb +0 -10
  142. data/spec/support/shared_examples.rb +0 -13
@@ -1,437 +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
- it 'raises an error if it yields multiple times' do
67
- expect {
68
- expect { |b| [1, 2].each(&b) }.to yield_control
69
- }.to raise_error(/not designed.*yields multiple times/)
70
- end
71
- end
72
-
73
- describe "expect {...}.not_to yield_control" do
74
- it 'passes if the block does not yield' do
75
- expect { |b| _dont_yield(&b) }.not_to yield_control
76
- end
77
-
78
- it 'fails if the block does yield' do
79
- expect {
80
- expect { |b| _yield_with_no_args(&b) }.not_to yield_control
81
- }.to fail_with(/expected given block not to yield control/)
82
- end
83
-
84
- it 'fails if the expect block does not accept an argument' do
85
- expect {
86
- expect { }.not_to yield_control
87
- }.to raise_error(/expect block must accept an argument/)
88
- end
89
-
90
- it 'raises an error if the expect block arg is not passed to a method as a block' do
91
- expect {
92
- expect { |b| }.not_to yield_control
93
- }.to raise_error(/must pass the argument.*as a block/)
94
- end
95
- end
96
- end
97
-
98
- describe "yield_with_no_args matcher" do
99
- include YieldHelpers
100
- extend YieldHelpers
101
-
102
- it_behaves_like "an RSpec matcher",
103
- :valid_value => lambda { |b| _yield_with_no_args(&b) },
104
- :invalid_value => lambda { |b| _dont_yield(&b) } do
105
- let(:matcher) { yield_with_no_args }
106
- end
107
-
108
- it 'has a description' do
109
- expect(yield_with_no_args.description).to eq("yield with no args")
110
- end
111
-
112
- describe "expect {...}.to yield_with_no_args" do
113
- it 'passes if the block yields with no args' do
114
- expect { |b| _yield_with_no_args(&b) }.to yield_with_no_args
115
- end
116
-
117
- it 'passes if the block yields with no args using instance_eval' do
118
- expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_with_no_args
119
- end
120
-
121
- it 'fails if the block does not yield' do
122
- expect {
123
- expect { |b| _dont_yield(&b) }.to yield_with_no_args
124
- }.to fail_with(/expected given block to yield with no arguments, but did not yield/)
125
- end
126
-
127
- it 'fails if the block yields with args' do
128
- expect {
129
- expect { |b| _yield_with_args(1, &b) }.to yield_with_no_args
130
- }.to fail_with(/expected given block to yield with no arguments, but yielded with arguments/)
131
- end
132
-
133
- it 'fails if the block yields with arg false' do
134
- expect {
135
- expect { |b| _yield_with_args(false, &b) }.to yield_with_no_args
136
- }.to fail_with(/expected given block to yield with no arguments, but yielded with arguments/)
137
- end
138
-
139
- it 'raises an error if it yields multiple times' do
140
- expect {
141
- expect { |b| [1, 2].each(&b) }.to yield_with_no_args
142
- }.to raise_error(/not designed.*yields multiple times/)
143
- end
144
- end
145
-
146
- describe "expect {...}.not_to yield_with_no_args" do
147
- it "passes if the block does not yield" do
148
- expect { |b| _dont_yield(&b) }.not_to yield_with_no_args
149
- end
150
-
151
- it "passes if the block yields with args" do
152
- expect { |b| _yield_with_args(1, &b) }.not_to yield_with_no_args
153
- end
154
-
155
- it "fails if the block yields with no args" do
156
- expect {
157
- expect { |b| _yield_with_no_args(&b) }.not_to yield_with_no_args
158
- }.to fail_with(/expected given block not to yield with no arguments, but did/)
159
- end
160
-
161
- it 'fails if the expect block does not accept an argument' do
162
- expect {
163
- expect { }.not_to yield_with_no_args
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_with_no_args
170
- }.to raise_error(/must pass the argument.*as a block/)
171
- end
172
- end
173
- end
174
-
175
- describe "yield_with_args matcher" do
176
- include YieldHelpers
177
- extend YieldHelpers
178
-
179
- it_behaves_like "an RSpec matcher",
180
- :valid_value => lambda { |b| _yield_with_args(1, &b) },
181
- :invalid_value => lambda { |b| _dont_yield(&b) } do
182
- let(:matcher) { yield_with_args }
183
- end
184
-
185
- it 'has a description' do
186
- expect(yield_with_args.description).to eq("yield with args")
187
- expect(yield_with_args(1, 3).description).to eq("yield with args(1, 3)")
188
- expect(yield_with_args(false).description).to eq("yield with args(false)")
189
- end
190
-
191
- describe "expect {...}.to yield_with_args" do
192
- it 'passes if the block yields with arguments' do
193
- expect { |b| _yield_with_args(1, &b) }.to yield_with_args
194
- end
195
-
196
- it 'fails if the block does not yield' do
197
- expect {
198
- expect { |b| _dont_yield(&b) }.to yield_with_args
199
- }.to fail_with(/expected given block to yield with arguments, but did not yield/)
200
- end
201
-
202
- it 'fails if the block yields with no arguments' do
203
- expect {
204
- expect { |b| _yield_with_no_args(&b) }.to yield_with_args
205
- }.to fail_with(/expected given block to yield with arguments, but yielded with no arguments/)
206
- end
207
-
208
- it 'raises an error if it yields multiple times' do
209
- expect {
210
- expect { |b| [1, 2].each(&b) }.to yield_with_args
211
- }.to raise_error(/not designed.*yields multiple times/)
212
- end
213
- end
214
-
215
- describe "expect {...}.not_to yield_with_args" do
216
- it 'fails if the block yields with arguments' do
217
- expect {
218
- expect { |b| _yield_with_args(1, &b) }.not_to yield_with_args
219
- }.to fail_with(/expected given block not to yield with arguments, but did/)
220
- end
221
-
222
- it 'passes if the block does not yield' do
223
- expect { |b| _dont_yield(&b) }.not_to yield_with_args
224
- end
225
-
226
- it 'passes if the block yields with no arguments' do
227
- expect { |b| _yield_with_no_args(&b) }.not_to yield_with_args
228
- end
229
-
230
- it 'fails if the expect block does not accept an argument' do
231
- expect {
232
- expect { }.not_to yield_with_args
233
- }.to raise_error(/expect block must accept an argument/)
234
- end
235
-
236
- it 'raises an error if the expect block arg is not passed to a method as a block' do
237
- expect {
238
- expect { |b| }.not_to yield_with_args
239
- }.to raise_error(/must pass the argument.*as a block/)
240
- end
241
- end
242
-
243
- describe "expect {...}.to yield_with_args(3, 17)" do
244
- it 'passes if the block yields with the given arguments' do
245
- expect { |b| _yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
246
- end
247
-
248
- it 'passes if the block yields with the given arguments using instance_eval' do
249
- expect { |b| InstanceEvaler.new.yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
250
- end
251
-
252
- it 'fails if the block does not yield' do
253
- expect {
254
- expect { |b| _dont_yield(&b) }.to yield_with_args(3, 17)
255
- }.to fail_with(/expected given block to yield with arguments, but did not yield/)
256
- end
257
-
258
- it 'fails if the block yields with no arguments' do
259
- expect {
260
- expect { |b| _yield_with_no_args(&b) }.to yield_with_args(3, 17)
261
- }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
262
- end
263
-
264
- it 'fails if the block yields with different arguments' do
265
- expect {
266
- expect { |b| _yield_with_args("a", "b", &b) }.to yield_with_args("a", "c")
267
- }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
268
- end
269
- end
270
-
271
- describe "expect {...}.not_to yield_with_args(3, 17)" do
272
- it 'passes if the block yields with different arguments' do
273
- expect { |b| _yield_with_args("a", "b", &b) }.not_to yield_with_args("a", "c")
274
- end
275
-
276
- it 'fails if the block yields with the given arguments' do
277
- expect {
278
- expect { |b| _yield_with_args("a", "b", &b) }.not_to yield_with_args("a", "b")
279
- }.to fail_with(/expected given block not to yield with arguments, but yielded with expected arguments/)
280
- end
281
- end
282
-
283
- describe "expect {...}.to yield_with_args( false )" do
284
- it 'passes if the block yields with the given arguments' do
285
- expect { |b| _yield_with_args(false, &b) }.to yield_with_args(false)
286
- end
287
-
288
- it 'passes if the block yields with the given arguments using instance_eval' do
289
- expect { |b| InstanceEvaler.new.yield_with_args(false, &b) }.to yield_with_args(false)
290
- end
291
-
292
- it 'fails if the block does not yield' do
293
- expect {
294
- expect { |b| _dont_yield(&b) }.to yield_with_args(false)
295
- }.to fail_with(/expected given block to yield with arguments, but did not yield/)
296
- end
297
-
298
- it 'fails if the block yields with no arguments' do
299
- expect {
300
- expect { |b| _yield_with_no_args(&b) }.to yield_with_args(false)
301
- }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
302
- end
303
-
304
- it 'fails if the block yields with different arguments' do
305
- expect {
306
- expect { |b| _yield_with_args(false, &b) }.to yield_with_args(true)
307
- }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
308
- end
309
- end
310
-
311
- describe "expect {...}.to yield_with_args(/reg/, /ex/)" do
312
- it "passes if the block yields strings matching the regexes" do
313
- expect { |b| _yield_with_args("regular", "expression", &b) }.to yield_with_args(/reg/, /ex/)
314
- end
315
-
316
- it "fails if the block yields strings that do not match the regexes" do
317
- expect {
318
- expect { |b| _yield_with_args("no", "match", &b) }.to yield_with_args(/reg/, /ex/)
319
- }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
320
- end
321
- end
322
-
323
- describe "expect {...}.to yield_with_args(String, Fixnum)" do
324
- it "passes if the block yields objects of the given types" do
325
- expect { |b| _yield_with_args("string", 15, &b) }.to yield_with_args(String, Fixnum)
326
- end
327
-
328
- it "passes if the block yields the given types" do
329
- expect { |b| _yield_with_args(String, Fixnum, &b) }.to yield_with_args(String, Fixnum)
330
- end
331
-
332
- it "fails if the block yields objects of different types" do
333
- expect {
334
- expect { |b| _yield_with_args(15, "string", &b) }.to yield_with_args(String, Fixnum)
335
- }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
336
- end
337
- end
338
- end
339
-
340
- describe "yield_successive_args matcher" do
341
- include YieldHelpers
342
- extend YieldHelpers
343
-
344
- it_behaves_like "an RSpec matcher",
345
- :valid_value => lambda { |b| [1, 2].each(&b) },
346
- :invalid_value => lambda { |b| _dont_yield(&b) } do
347
- let(:matcher) { yield_successive_args(1, 2) }
348
- end
349
-
350
- it 'has a description' do
351
- expect(yield_successive_args(1, 3).description).to eq("yield successive args(1, 3)")
352
- expect(yield_successive_args([:a, 1], [:b, 2]).description).to eq("yield successive args([:a, 1], [:b, 2])")
353
- end
354
-
355
- describe "expect {...}.to yield_successive_args([:a, 1], [:b, 2])" do
356
- it 'passes when the block successively yields the given args' do
357
- expect { |b| [ [:a, 1], [:b, 2] ].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
358
- end
359
-
360
- it 'fails when the block does not yield that many times' do
361
- expect {
362
- expect { |b| [[:a, 1]].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
363
- }.to fail_with(/but yielded with unexpected arguments/)
364
- end
365
-
366
- it 'fails when the block yields the right number of times but with different arguments' do
367
- expect {
368
- expect { |b| [ [:a, 1], [:b, 3] ].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
369
- }.to fail_with(/but yielded with unexpected arguments/)
370
- end
371
- end
372
-
373
- describe "expect {...}.to yield_successive_args(1, 2, 3)" do
374
- it 'passes when the block successively yields the given args' do
375
- expect { |b| [1, 2, 3].each(&b) }.to yield_successive_args(1, 2, 3)
376
- end
377
-
378
- it 'passes when the block successively yields the given args using instance_eval' do
379
- expect { |b| InstanceEvaler.new.each_arg(1, 2, 3, &b) }.to yield_successive_args(1, 2, 3)
380
- end
381
-
382
- it 'fails when the block does not yield the expected args' do
383
- expect {
384
- expect { |b| [1, 2, 4].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
385
- }.to fail_with(/but yielded with unexpected arguments/)
386
- end
387
- end
388
-
389
- describe "expect {...}.not_to yield_successive_args(1, 2, 3)" do
390
- it 'passes when the block does not yield' do
391
- expect { |b| _dont_yield(&b) }.not_to yield_successive_args(1, 2, 3)
392
- end
393
-
394
- it 'passes when the block yields the wrong number of times' do
395
- expect { |b| [1, 2].each(&b) }.not_to yield_successive_args(1, 2, 3)
396
- end
397
-
398
- it 'passes when the block yields the wrong arguments' do
399
- expect { |b| [1, 2, 4].each(&b) }.not_to yield_successive_args(1, 2, 3)
400
- end
401
-
402
- it 'fails when the block yields the given arguments' do
403
- expect {
404
- expect { |b| [1, 2, 3].each(&b) }.not_to yield_successive_args(1, 2, 3)
405
- }.to fail_with(/expected given block not to yield successively/)
406
- end
407
-
408
- it 'fails if the expect block does not accept an argument' do
409
- expect {
410
- expect { }.not_to yield_successive_args(1, 2, 3)
411
- }.to raise_error(/expect block must accept an argument/)
412
- end
413
-
414
- it 'raises an error if the expect block arg is not passed to a method as a block' do
415
- expect {
416
- expect { |b| }.not_to yield_successive_args(1, 2, 3)
417
- }.to raise_error(/must pass the argument.*as a block/)
418
- end
419
- end
420
-
421
- describe "expect {...}.to yield_successive_args(String, Fixnum)" do
422
- it "passes if the block successively yields objects of the given types" do
423
- expect { |b| ["string", 15].each(&b) }.to yield_successive_args(String, Fixnum)
424
- end
425
-
426
- it "passes if the block yields the given types" do
427
- expect { |b| [String, Fixnum].each(&b) }.to yield_successive_args(String, Fixnum)
428
- end
429
-
430
- it "fails if the block yields objects of different types" do
431
- expect {
432
- expect { |b| [15, "string"].each(&b) }.to yield_successive_args(String, Fixnum)
433
- }.to fail_with(/expected given block to yield successively with arguments/)
434
- end
435
- end
436
- end
437
-
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.rb'
50
- yield
51
- end
52
- end
53
- end
54
-
@@ -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
-
@@ -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
-
@@ -1,10 +0,0 @@
1
- module RSpec
2
- module Ruby
3
- class << self
4
- def version
5
- RUBY_VERSION
6
- end
7
- end
8
- end
9
- end
10
-
@@ -1,13 +0,0 @@
1
- shared_examples_for "an RSpec matcher" do |options|
2
- let(:valid_value) { options.fetch(:valid_value) }
3
- let(:invalid_value) { options.fetch(:invalid_value) }
4
-
5
- it 'matches a valid value when using #== so it can be composed' do
6
- expect(matcher).to eq(valid_value)
7
- end
8
-
9
- it 'does not match an invalid value when using #== so it can be composed' do
10
- expect(matcher).not_to eq(invalid_value)
11
- end
12
- end
13
-