rspec-expectations 2.9.1 → 2.10.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.
@@ -0,0 +1,374 @@
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
+
39
+ it 'has a description' do
40
+ yield_control.description.should eq("yield control")
41
+ end
42
+
43
+ describe "expect {...}.to yield_control" do
44
+ it 'passes if the block yields, regardless of the number of yielded arguments' do
45
+ expect { |b| _yield_with_no_args(&b) }.to yield_control
46
+ expect { |b| _yield_with_args(1, 2, &b) }.to yield_control
47
+ end
48
+
49
+ it 'passes if the block yields using instance_eval' do
50
+ expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_control
51
+ end
52
+
53
+ it 'fails if the block does not yield' do
54
+ expect {
55
+ expect { |b| _dont_yield(&b) }.to yield_control
56
+ }.to fail_with(/expected given block to yield control/)
57
+ end
58
+
59
+ it 'raises an error if it yields multiple times' do
60
+ expect {
61
+ expect { |b| [1, 2].each(&b) }.to yield_control
62
+ }.to raise_error(/not designed.*yields multiple times/)
63
+ end
64
+ end
65
+
66
+ describe "expect {...}.not_to yield_control" do
67
+ it 'passes if the block does not yield' do
68
+ expect { |b| _dont_yield(&b) }.not_to yield_control
69
+ end
70
+
71
+ it 'fails if the block does yield' do
72
+ expect {
73
+ expect { |b| _yield_with_no_args(&b) }.not_to yield_control
74
+ }.to fail_with(/expected given block not to yield control/)
75
+ end
76
+
77
+ it 'fails if the expect block does not accept an argument' do
78
+ expect {
79
+ expect { }.not_to yield_control
80
+ }.to raise_error(/expect block must accept an argument/)
81
+ end
82
+
83
+ it 'raises an error if the expect block arg is not passed to a method as a block' do
84
+ expect {
85
+ expect { |b| }.not_to yield_control
86
+ }.to raise_error(/must pass the argument.*as a block/)
87
+ end
88
+ end
89
+ end
90
+
91
+ describe "yield_with_no_args matcher" do
92
+ include YieldHelpers
93
+
94
+ it 'has a description' do
95
+ yield_with_no_args.description.should eq("yield with no args")
96
+ end
97
+
98
+ describe "expect {...}.to yield_with_no_args" do
99
+ it 'passes if the block yields with no args' do
100
+ expect { |b| _yield_with_no_args(&b) }.to yield_with_no_args
101
+ end
102
+
103
+ it 'passes if the block yields with no args using instance_eval' do
104
+ expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_with_no_args
105
+ end
106
+
107
+ it 'fails if the block does not yield' do
108
+ expect {
109
+ expect { |b| _dont_yield(&b) }.to yield_with_no_args
110
+ }.to fail_with(/expected given block to yield with no arguments, but did not yield/)
111
+ end
112
+
113
+ it 'fails if the block yields with args' do
114
+ expect {
115
+ expect { |b| _yield_with_args(1, &b) }.to yield_with_no_args
116
+ }.to fail_with(/expected given block to yield with no arguments, but yielded with arguments/)
117
+ end
118
+
119
+ it 'raises an error if it yields multiple times' do
120
+ expect {
121
+ expect { |b| [1, 2].each(&b) }.to yield_with_no_args
122
+ }.to raise_error(/not designed.*yields multiple times/)
123
+ end
124
+ end
125
+
126
+ describe "expect {...}.not_to yield_with_no_args" do
127
+ it "passes if the block does not yield" do
128
+ expect { |b| _dont_yield(&b) }.not_to yield_with_no_args
129
+ end
130
+
131
+ it "passes if the block yields with args" do
132
+ expect { |b| _yield_with_args(1, &b) }.not_to yield_with_no_args
133
+ end
134
+
135
+ it "fails if the block yields with no args" do
136
+ expect {
137
+ expect { |b| _yield_with_no_args(&b) }.not_to yield_with_no_args
138
+ }.to fail_with(/expected given block not to yield with no arguments, but did/)
139
+ end
140
+
141
+ it 'fails if the expect block does not accept an argument' do
142
+ expect {
143
+ expect { }.not_to yield_with_no_args
144
+ }.to raise_error(/expect block must accept an argument/)
145
+ end
146
+
147
+ it 'raises an error if the expect block arg is not passed to a method as a block' do
148
+ expect {
149
+ expect { |b| }.not_to yield_with_no_args
150
+ }.to raise_error(/must pass the argument.*as a block/)
151
+ end
152
+ end
153
+ end
154
+
155
+ describe "yield_with_args matcher" do
156
+ include YieldHelpers
157
+
158
+ it 'has a description' do
159
+ yield_with_args.description.should eq("yield with args")
160
+ yield_with_args(1, 3).description.should eq("yield with args(1, 3)")
161
+ end
162
+
163
+ describe "expect {...}.to yield_with_args" do
164
+ it 'passes if the block yields with arguments' do
165
+ expect { |b| _yield_with_args(1, &b) }.to yield_with_args
166
+ end
167
+
168
+ it 'fails if the block does not yield' do
169
+ expect {
170
+ expect { |b| _dont_yield(&b) }.to yield_with_args
171
+ }.to fail_with(/expected given block to yield with arguments, but did not yield/)
172
+ end
173
+
174
+ it 'fails if the block yields with no arguments' do
175
+ expect {
176
+ expect { |b| _yield_with_no_args(&b) }.to yield_with_args
177
+ }.to fail_with(/expected given block to yield with arguments, but yielded with no arguments/)
178
+ end
179
+
180
+ it 'raises an error if it yields multiple times' do
181
+ expect {
182
+ expect { |b| [1, 2].each(&b) }.to yield_with_args
183
+ }.to raise_error(/not designed.*yields multiple times/)
184
+ end
185
+ end
186
+
187
+ describe "expect {...}.not_to yield_with_args" do
188
+ it 'fails if the block yields with arguments' do
189
+ expect {
190
+ expect { |b| _yield_with_args(1, &b) }.not_to yield_with_args
191
+ }.to fail_with(/expected given block not to yield with arguments, but did/)
192
+ end
193
+
194
+ it 'passes if the block does not yield' do
195
+ expect { |b| _dont_yield(&b) }.not_to yield_with_args
196
+ end
197
+
198
+ it 'passes if the block yields with no arguments' do
199
+ expect { |b| _yield_with_no_args(&b) }.not_to yield_with_args
200
+ end
201
+
202
+ it 'fails if the expect block does not accept an argument' do
203
+ expect {
204
+ expect { }.not_to yield_with_args
205
+ }.to raise_error(/expect block must accept an argument/)
206
+ end
207
+
208
+ it 'raises an error if the expect block arg is not passed to a method as a block' do
209
+ expect {
210
+ expect { |b| }.not_to yield_with_args
211
+ }.to raise_error(/must pass the argument.*as a block/)
212
+ end
213
+ end
214
+
215
+ describe "expect {...}.to yield_with_args(3, 17)" do
216
+ it 'passes if the block yields with the given arguments' do
217
+ expect { |b| _yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
218
+ end
219
+
220
+ it 'passes if the block yields with the given arguments using instance_eval' do
221
+ expect { |b| InstanceEvaler.new.yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
222
+ end
223
+
224
+ it 'fails if the block does not yield' do
225
+ expect {
226
+ expect { |b| _dont_yield(&b) }.to yield_with_args(3, 17)
227
+ }.to fail_with(/expected given block to yield with arguments, but did not yield/)
228
+ end
229
+
230
+ it 'fails if the block yields with no arguments' do
231
+ expect {
232
+ expect { |b| _yield_with_no_args(&b) }.to yield_with_args(3, 17)
233
+ }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
234
+ end
235
+
236
+ it 'fails if the block yields with different arguments' do
237
+ expect {
238
+ expect { |b| _yield_with_args("a", "b", &b) }.to yield_with_args("a", "c")
239
+ }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
240
+ end
241
+ end
242
+
243
+ describe "expect {...}.not_to yield_with_args(3, 17)" do
244
+ it 'passes if the block yields with different arguments' do
245
+ expect { |b| _yield_with_args("a", "b", &b) }.not_to yield_with_args("a", "c")
246
+ end
247
+
248
+ it 'fails if the block yields with the given arguments' do
249
+ expect {
250
+ expect { |b| _yield_with_args("a", "b", &b) }.not_to yield_with_args("a", "b")
251
+ }.to fail_with(/expected given block not to yield with arguments, but yielded with expected arguments/)
252
+ end
253
+ end
254
+
255
+ describe "expect {...}.to yield_with_args(/reg/, /ex/)" do
256
+ it "passes if the block yields strings matching the regexes" do
257
+ expect { |b| _yield_with_args("regular", "expression", &b) }.to yield_with_args(/reg/, /ex/)
258
+ end
259
+
260
+ it "fails if the block yields strings that do not match the regexes" do
261
+ expect {
262
+ expect { |b| _yield_with_args("no", "match", &b) }.to yield_with_args(/reg/, /ex/)
263
+ }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
264
+ end
265
+ end
266
+
267
+ describe "expect {...}.to yield_with_args(String, Fixnum)" do
268
+ it "passes if the block yields objects of the given types" do
269
+ expect { |b| _yield_with_args("string", 15, &b) }.to yield_with_args(String, Fixnum)
270
+ end
271
+
272
+ it "passes if the block yields the given types" do
273
+ expect { |b| _yield_with_args(String, Fixnum, &b) }.to yield_with_args(String, Fixnum)
274
+ end
275
+
276
+ it "fails if the block yields objects of different types" do
277
+ expect {
278
+ expect { |b| _yield_with_args(15, "string", &b) }.to yield_with_args(String, Fixnum)
279
+ }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
280
+ end
281
+ end
282
+ end
283
+
284
+ describe "yield_successive_args matcher" do
285
+ include YieldHelpers
286
+
287
+ it 'has a description' do
288
+ yield_successive_args(1, 3).description.should eq("yield successive args(1, 3)")
289
+ yield_successive_args([:a, 1], [:b, 2]).description.should eq("yield successive args([:a, 1], [:b, 2])")
290
+ end
291
+
292
+ describe "expect {...}.to yield_successive_args([:a, 1], [:b, 2])" do
293
+ it 'passes when the block successively yields the given args' do
294
+ expect { |b| { :a => 1, :b => 2 }.each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
295
+ end
296
+
297
+ it 'fails when the block does not yield that many times' do
298
+ expect {
299
+ expect { |b| { :a => 1 }.each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
300
+ }.to fail_with(/but yielded with unexpected arguments/)
301
+ end
302
+
303
+ it 'fails when the block yields the right number of times but with different arguments' do
304
+ expect {
305
+ expect { |b| { :a => 1, :b => 3 }.each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
306
+ }.to fail_with(/but yielded with unexpected arguments/)
307
+ end
308
+ end
309
+
310
+ describe "expect {...}.to yield_successive_args(1, 2, 3)" do
311
+ it 'passes when the block successively yields the given args' do
312
+ expect { |b| [1, 2, 3].each(&b) }.to yield_successive_args(1, 2, 3)
313
+ end
314
+
315
+ it 'passes when the block successively yields the given args using instance_eval' do
316
+ expect { |b| InstanceEvaler.new.each_arg(1, 2, 3, &b) }.to yield_successive_args(1, 2, 3)
317
+ end
318
+
319
+ it 'fails when the block does not yield the expected args' do
320
+ expect {
321
+ expect { |b| [1, 2, 4].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
322
+ }.to fail_with(/but yielded with unexpected arguments/)
323
+ end
324
+ end
325
+
326
+ describe "expect {...}.not_to yield_successive_args(1, 2, 3)" do
327
+ it 'passes when the block does not yield' do
328
+ expect { |b| _dont_yield(&b) }.not_to yield_successive_args(1, 2, 3)
329
+ end
330
+
331
+ it 'passes when the block yields the wrong number of times' do
332
+ expect { |b| [1, 2].each(&b) }.not_to yield_successive_args(1, 2, 3)
333
+ end
334
+
335
+ it 'passes when the block yields the wrong arguments' do
336
+ expect { |b| [1, 2, 4].each(&b) }.not_to yield_successive_args(1, 2, 3)
337
+ end
338
+
339
+ it 'fails when the block yields the given arguments' do
340
+ expect {
341
+ expect { |b| [1, 2, 3].each(&b) }.not_to yield_successive_args(1, 2, 3)
342
+ }.to fail_with(/expected given block not to yield successively/)
343
+ end
344
+
345
+ it 'fails if the expect block does not accept an argument' do
346
+ expect {
347
+ expect { }.not_to yield_successive_args(1, 2, 3)
348
+ }.to raise_error(/expect block must accept an argument/)
349
+ end
350
+
351
+ it 'raises an error if the expect block arg is not passed to a method as a block' do
352
+ expect {
353
+ expect { |b| }.not_to yield_successive_args(1, 2, 3)
354
+ }.to raise_error(/must pass the argument.*as a block/)
355
+ end
356
+ end
357
+
358
+ describe "expect {...}.to yield_successive_args(String, Fixnum)" do
359
+ it "passes if the block successively yields objects of the given types" do
360
+ expect { |b| ["string", 15].each(&b) }.to yield_successive_args(String, Fixnum)
361
+ end
362
+
363
+ it "passes if the block yields the given types" do
364
+ expect { |b| [String, Fixnum].each(&b) }.to yield_successive_args(String, Fixnum)
365
+ end
366
+
367
+ it "fails if the block yields objects of different types" do
368
+ expect {
369
+ expect { |b| [15, "string"].each(&b) }.to yield_successive_args(String, Fixnum)
370
+ }.to fail_with(/expected given block to yield successively with arguments/)
371
+ end
372
+ end
373
+ end
374
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.1
4
+ version: 2.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-03 00:00:00.000000000 Z
13
+ date: 2012-05-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: diff-lcs
@@ -117,7 +117,9 @@ files:
117
117
  - lib/rspec/matchers/built_in/raise_error.rb
118
118
  - lib/rspec/matchers/built_in/respond_to.rb
119
119
  - lib/rspec/matchers/built_in/satisfy.rb
120
+ - lib/rspec/matchers/built_in/start_and_end_with.rb
120
121
  - lib/rspec/matchers/built_in/throw_symbol.rb
122
+ - lib/rspec/matchers/built_in/yield.rb
121
123
  - lib/rspec/matchers/compatibility.rb
122
124
  - lib/rspec/matchers/dsl.rb
123
125
  - lib/rspec/matchers/extensions/instance_eval_with_args.rb
@@ -131,12 +133,13 @@ files:
131
133
  - Changelog.md
132
134
  - .yardopts
133
135
  - .document
134
- - features/README.markdown
136
+ - features/README.md
135
137
  - features/Upgrade.md
136
138
  - features/built_in_matchers/README.md
137
139
  - features/built_in_matchers/be.feature
138
140
  - features/built_in_matchers/be_within.feature
139
141
  - features/built_in_matchers/cover.feature
142
+ - features/built_in_matchers/end_with.feature
140
143
  - features/built_in_matchers/equality.feature
141
144
  - features/built_in_matchers/exist.feature
142
145
  - features/built_in_matchers/expect_change.feature
@@ -148,8 +151,10 @@ files:
148
151
  - features/built_in_matchers/predicates.feature
149
152
  - features/built_in_matchers/respond_to.feature
150
153
  - features/built_in_matchers/satisfy.feature
154
+ - features/built_in_matchers/start_with.feature
151
155
  - features/built_in_matchers/throw_symbol.feature
152
156
  - features/built_in_matchers/types.feature
157
+ - features/built_in_matchers/yield.feature
153
158
  - features/custom_matchers/access_running_example.feature
154
159
  - features/custom_matchers/define_diffable_matcher.feature
155
160
  - features/custom_matchers/define_matcher.feature
@@ -192,7 +197,9 @@ files:
192
197
  - spec/rspec/matchers/raise_error_spec.rb
193
198
  - spec/rspec/matchers/respond_to_spec.rb
194
199
  - spec/rspec/matchers/satisfy_spec.rb
200
+ - spec/rspec/matchers/start_with_end_with_spec.rb
195
201
  - spec/rspec/matchers/throw_symbol_spec.rb
202
+ - spec/rspec/matchers/yield_spec.rb
196
203
  - spec/spec_helper.rb
197
204
  - spec/support/classes.rb
198
205
  - spec/support/matchers.rb
@@ -213,7 +220,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
220
  version: '0'
214
221
  segments:
215
222
  - 0
216
- hash: -382523939105044110
223
+ hash: -3405734179281869157
217
224
  required_rubygems_version: !ruby/object:Gem::Requirement
218
225
  none: false
219
226
  requirements:
@@ -222,20 +229,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
229
  version: '0'
223
230
  segments:
224
231
  - 0
225
- hash: -382523939105044110
232
+ hash: -3405734179281869157
226
233
  requirements: []
227
234
  rubyforge_project: rspec
228
- rubygems_version: 1.8.21
235
+ rubygems_version: 1.8.24
229
236
  signing_key:
230
237
  specification_version: 3
231
- summary: rspec-expectations-2.9.1
238
+ summary: rspec-expectations-2.10.0
232
239
  test_files:
233
- - features/README.markdown
240
+ - features/README.md
234
241
  - features/Upgrade.md
235
242
  - features/built_in_matchers/README.md
236
243
  - features/built_in_matchers/be.feature
237
244
  - features/built_in_matchers/be_within.feature
238
245
  - features/built_in_matchers/cover.feature
246
+ - features/built_in_matchers/end_with.feature
239
247
  - features/built_in_matchers/equality.feature
240
248
  - features/built_in_matchers/exist.feature
241
249
  - features/built_in_matchers/expect_change.feature
@@ -247,8 +255,10 @@ test_files:
247
255
  - features/built_in_matchers/predicates.feature
248
256
  - features/built_in_matchers/respond_to.feature
249
257
  - features/built_in_matchers/satisfy.feature
258
+ - features/built_in_matchers/start_with.feature
250
259
  - features/built_in_matchers/throw_symbol.feature
251
260
  - features/built_in_matchers/types.feature
261
+ - features/built_in_matchers/yield.feature
252
262
  - features/custom_matchers/access_running_example.feature
253
263
  - features/custom_matchers/define_diffable_matcher.feature
254
264
  - features/custom_matchers/define_matcher.feature
@@ -291,8 +301,11 @@ test_files:
291
301
  - spec/rspec/matchers/raise_error_spec.rb
292
302
  - spec/rspec/matchers/respond_to_spec.rb
293
303
  - spec/rspec/matchers/satisfy_spec.rb
304
+ - spec/rspec/matchers/start_with_end_with_spec.rb
294
305
  - spec/rspec/matchers/throw_symbol_spec.rb
306
+ - spec/rspec/matchers/yield_spec.rb
295
307
  - spec/spec_helper.rb
296
308
  - spec/support/classes.rb
297
309
  - spec/support/matchers.rb
298
310
  - spec/support/ruby_version.rb
311
+ has_rdoc: