rspec-expectations 2.11.3 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/Changelog.md +25 -2
  2. data/README.md +5 -1
  3. data/features/built_in_matchers/be.feature +4 -4
  4. data/features/built_in_matchers/be_within.feature +1 -1
  5. data/features/built_in_matchers/cover.feature +1 -1
  6. data/features/built_in_matchers/end_with.feature +2 -2
  7. data/features/built_in_matchers/equality.feature +5 -5
  8. data/features/built_in_matchers/exist.feature +1 -1
  9. data/features/built_in_matchers/expect_change.feature +3 -3
  10. data/features/built_in_matchers/expect_error.feature +4 -4
  11. data/features/built_in_matchers/have.feature +2 -2
  12. data/features/built_in_matchers/include.feature +3 -3
  13. data/features/built_in_matchers/match.feature +2 -2
  14. data/features/built_in_matchers/operators.feature +3 -3
  15. data/features/built_in_matchers/predicates.feature +9 -8
  16. data/features/built_in_matchers/respond_to.feature +2 -2
  17. data/features/built_in_matchers/satisfy.feature +1 -1
  18. data/features/built_in_matchers/start_with.feature +2 -2
  19. data/features/built_in_matchers/throw_symbol.feature +3 -3
  20. data/features/built_in_matchers/types.feature +2 -2
  21. data/features/built_in_matchers/yield.feature +5 -5
  22. data/features/custom_matchers/access_running_example.feature +3 -3
  23. data/features/custom_matchers/define_diffable_matcher.feature +1 -1
  24. data/features/custom_matchers/define_matcher.feature +12 -12
  25. data/features/custom_matchers/define_matcher_outside_rspec.feature +1 -1
  26. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
  27. data/features/customized_message.feature +1 -1
  28. data/features/diffing.feature +4 -4
  29. data/features/implicit_docstrings.feature +2 -2
  30. data/features/test_frameworks/test_unit.feature +1 -1
  31. data/lib/rspec/expectations/differ.rb +35 -1
  32. data/lib/rspec/expectations/handler.rb +21 -6
  33. data/lib/rspec/expectations/version.rb +1 -1
  34. data/lib/rspec/matchers/built_in/be_instance_of.rb +4 -0
  35. data/lib/rspec/matchers/built_in/include.rb +3 -1
  36. data/lib/rspec/matchers/built_in/match_array.rb +12 -6
  37. data/lib/rspec/matchers/built_in/raise_error.rb +17 -7
  38. data/lib/rspec/matchers/built_in/yield.rb +5 -5
  39. data/lib/rspec/matchers/configuration.rb +42 -0
  40. data/lib/rspec/matchers/generated_descriptions.rb +2 -3
  41. data/spec/rspec/expectations/differ_spec.rb +24 -0
  42. data/spec/rspec/expectations/handler_spec.rb +40 -40
  43. data/spec/rspec/expectations/syntax_spec.rb +35 -0
  44. data/spec/rspec/matchers/be_instance_of_spec.rb +19 -2
  45. data/spec/rspec/matchers/be_spec.rb +10 -10
  46. data/spec/rspec/matchers/configuration_spec.rb +155 -123
  47. data/spec/rspec/matchers/dsl_spec.rb +8 -8
  48. data/spec/rspec/matchers/have_spec.rb +8 -38
  49. data/spec/rspec/matchers/include_spec.rb +6 -0
  50. data/spec/rspec/matchers/match_array_spec.rb +14 -0
  51. data/spec/rspec/matchers/raise_error_spec.rb +89 -38
  52. data/spec/rspec/matchers/start_with_end_with_spec.rb +1 -1
  53. data/spec/rspec/matchers/yield_spec.rb +35 -0
  54. metadata +70 -78
@@ -22,13 +22,13 @@ describe "a matcher defined using the matcher DSL" do
22
22
  end
23
23
 
24
24
  it "has access to methods available in the scope of the example" do
25
- RSpec::Matchers::define(:ignore) {}
26
- ignore.question?.should eq(:answer)
25
+ RSpec::Matchers::define(:matcher_a) {}
26
+ matcher_a.question?.should eq(:answer)
27
27
  end
28
28
 
29
29
  it "raises when method is missing from local scope as well as matcher" do
30
- RSpec::Matchers::define(:ignore) {}
31
- expect { ignore.i_dont_exist }.to raise_error(NameError)
30
+ RSpec::Matchers::define(:matcher_b) {}
31
+ expect { matcher_b.i_dont_exist }.to raise_error(NameError)
32
32
  end
33
33
 
34
34
  it "clears user instance variables between invocations" do
@@ -45,13 +45,13 @@ describe "a matcher defined using the matcher DSL" do
45
45
 
46
46
  describe "#respond_to?" do
47
47
  it "returns true for methods in example scope" do
48
- RSpec::Matchers::define(:ignore) {}
49
- ignore.should respond_to(:question?)
48
+ RSpec::Matchers::define(:matcher_c) {}
49
+ matcher_c.should respond_to(:question?)
50
50
  end
51
51
 
52
52
  it "returns false for methods not defined in matcher or example scope" do
53
- RSpec::Matchers::define(:ignore) {}
54
- ignore.should_not respond_to(:i_dont_exist)
53
+ RSpec::Matchers::define(:matcher_d) {}
54
+ matcher_d.should_not respond_to(:i_dont_exist)
55
55
  end
56
56
  end
57
57
  end
@@ -2,22 +2,16 @@ require 'spec_helper'
2
2
  require 'stringio'
3
3
 
4
4
  describe "have matcher" do
5
-
6
- before(:each) do
7
- if defined?(::ActiveSupport::Inflector) && ::ActiveSupport::Inflector.respond_to?(:pluralize)
8
- @active_support_was_defined = true
9
- else
10
- @active_support_was_defined = false
11
- module ::ActiveSupport
12
- class Inflector
13
- def self.pluralize(string)
14
- string.to_s + 's'
15
- end
16
- end
5
+ let(:inflector) do
6
+ Class.new do
7
+ def self.pluralize(string)
8
+ string.to_s + 's'
17
9
  end
18
10
  end
19
11
  end
20
12
 
13
+ before(:each) { stub_const("ActiveSupport::Inflector", inflector) }
14
+
21
15
  def create_collection_owner_with(n)
22
16
  owner = RSpec::Expectations::Helper::CollectionOwner.new
23
17
  (1..n).each do |number|
@@ -91,45 +85,21 @@ describe "have matcher" do
91
85
  context "when ActiveSupport::Inflector is partially loaded without its inflectors" do
92
86
 
93
87
  it "does not pluralize the collection name" do
94
- (class << ::ActiveSupport::Inflector; self; end).send :undef_method, :pluralize
88
+ stub_const("ActiveSupport::Inflector", Module.new)
95
89
  owner = create_collection_owner_with(1)
96
90
  expect { owner.should have(1).item }.to raise_error(NoMethodError)
97
91
  end
98
92
 
99
93
  end
100
-
101
- after(:each) do
102
- unless @active_support_was_defined
103
- Object.__send__ :remove_const, :ActiveSupport
104
- end
105
- end
106
94
  end
107
95
 
108
96
  describe 'should have(1).item when Inflector is defined' do
109
-
110
- before(:each) do
111
- if defined?(Inflector)
112
- @inflector_was_defined = true
113
- else
114
- @inflector_was_defined = false
115
- class ::Inflector
116
- def self.pluralize(string)
117
- string.to_s + 's'
118
- end
119
- end
120
- end
121
- end
97
+ before { stub_const("Inflector", inflector) }
122
98
 
123
99
  it 'pluralizes the collection name' do
124
100
  owner = create_collection_owner_with(1)
125
101
  owner.should have(1).item
126
102
  end
127
-
128
- after(:each) do
129
- unless @inflector_was_defined
130
- Object.__send__ :remove_const, :Inflector
131
- end
132
- end
133
103
  end
134
104
 
135
105
  describe "should have(n).items where result responds to items but returns something other than a collection" do
@@ -56,6 +56,12 @@ describe "#include matcher" do
56
56
  {:key => 'value'}.should include(:other)
57
57
  }.should fail_matching(%Q|expected {:key=>"value"} to include :other|)
58
58
  end
59
+
60
+ it "fails if target doesn't have a key and we expect nil" do
61
+ lambda {
62
+ {}.should include(:something => nil)
63
+ }.should fail_matching(%Q|expected {} to include {:something=>nil}|)
64
+ end
59
65
  end
60
66
  end
61
67
 
@@ -122,3 +122,17 @@ describe "should_not =~ [:with, :multiple, :args]" do
122
122
  }.should fail_with(/Matcher does not support should_not/)
123
123
  end
124
124
  end
125
+
126
+ describe "matching against things that aren't arrays" do
127
+ it "fails with nil and the expected error message is given" do
128
+ expect { nil.should match_array([1,2,3]) }.to fail_with(/expected an array/)
129
+ end
130
+
131
+ it "fails with a float and the expected error message is given" do
132
+ expect { (3.7).should match_array([1,2,3]) }.to fail_with(/expected an array/)
133
+ end
134
+
135
+ it "fails with a string and the expected error message is given" do
136
+ expect { "I like turtles".should match_array([1,2,3]) }.to fail_with(/expected an array/)
137
+ end
138
+ end
@@ -9,7 +9,7 @@ describe "should raise_error" do
9
9
  it "passes if anything is raised" do
10
10
  lambda {raise}.should raise_error
11
11
  end
12
-
12
+
13
13
  it "fails if nothing is raised" do
14
14
  lambda {
15
15
  lambda {}.should raise_error
@@ -45,11 +45,32 @@ describe "should_not raise_error" do
45
45
  it "passes if nothing is raised" do
46
46
  lambda {}.should_not raise_error
47
47
  end
48
-
48
+
49
49
  it "fails if anything is raised" do
50
50
  lambda {
51
51
  lambda { raise RuntimeError, "example message" }.should_not raise_error
52
- }.should fail_with("expected no Exception, got #<RuntimeError: example message>")
52
+ }.should fail_with(/expected no Exception, got #<RuntimeError: example message>/)
53
+ end
54
+
55
+ it 'includes the backtrace of the error that was raised in the error message' do
56
+ expect {
57
+ expect { raise "boom" }.not_to raise_error
58
+ }.to raise_error { |e|
59
+ backtrace_line = "#{File.basename(__FILE__)}:#{__LINE__ - 2}"
60
+ e.message.should include("with backtrace", backtrace_line)
61
+ }
62
+ end
63
+
64
+ it 'formats the backtrace using the configured backtrace formatter' do
65
+ RSpec::Matchers.configuration.backtrace_formatter.
66
+ stub(:format_backtrace).
67
+ and_return("formatted-backtrace")
68
+
69
+ expect {
70
+ expect { raise "boom" }.not_to raise_error
71
+ }.to raise_error { |e|
72
+ e.message.should include("with backtrace", "formatted-backtrace")
73
+ }
53
74
  end
54
75
  end
55
76
 
@@ -57,21 +78,34 @@ describe "should raise_error(message)" do
57
78
  it "passes if RuntimeError is raised with the right message" do
58
79
  lambda {raise 'blah'}.should raise_error('blah')
59
80
  end
81
+
60
82
  it "passes if RuntimeError is raised with a matching message" do
61
83
  lambda {raise 'blah'}.should raise_error(/blah/)
62
84
  end
85
+
63
86
  it "passes if any other error is raised with the right message" do
64
87
  lambda {raise NameError.new('blah')}.should raise_error('blah')
65
88
  end
89
+
66
90
  it "fails if RuntimeError error is raised with the wrong message" do
67
91
  lambda do
68
92
  lambda {raise 'blarg'}.should raise_error('blah')
69
- end.should fail_with("expected Exception with \"blah\", got #<RuntimeError: blarg>")
93
+ end.should fail_with(/expected Exception with \"blah\", got #<RuntimeError: blarg>/)
70
94
  end
95
+
71
96
  it "fails if any other error is raised with the wrong message" do
72
97
  lambda do
73
98
  lambda {raise NameError.new('blarg')}.should raise_error('blah')
74
- end.should fail_with("expected Exception with \"blah\", got #<NameError: blarg>")
99
+ end.should fail_with(/expected Exception with \"blah\", got #<NameError: blarg>/)
100
+ end
101
+
102
+ it 'includes the backtrace of any other error in the failure message' do
103
+ expect {
104
+ expect { raise "boom" }.to raise_error(ArgumentError)
105
+ }.to raise_error { |e|
106
+ backtrace_line = "#{File.basename(__FILE__)}:#{__LINE__ - 2}"
107
+ e.message.should include("with backtrace", backtrace_line)
108
+ }
75
109
  end
76
110
  end
77
111
 
@@ -79,18 +113,21 @@ describe "should_not raise_error(message)" do
79
113
  it "passes if RuntimeError error is raised with the different message" do
80
114
  lambda {raise 'blarg'}.should_not raise_error('blah')
81
115
  end
116
+
82
117
  it "passes if any other error is raised with the wrong message" do
83
118
  lambda {raise NameError.new('blarg')}.should_not raise_error('blah')
84
119
  end
120
+
85
121
  it "fails if RuntimeError is raised with message" do
86
122
  lambda do
87
123
  lambda {raise 'blah'}.should_not raise_error('blah')
88
- end.should fail_with(%Q|expected no Exception with "blah", got #<RuntimeError: blah>|)
124
+ end.should fail_with(/expected no Exception with "blah", got #<RuntimeError: blah>/)
89
125
  end
126
+
90
127
  it "fails if any other error is raised with message" do
91
128
  lambda do
92
129
  lambda {raise NameError.new('blah')}.should_not raise_error('blah')
93
- end.should fail_with(%Q|expected no Exception with "blah", got #<NameError: blah>|)
130
+ end.should fail_with(/expected no Exception with "blah", got #<NameError: blah>/)
94
131
  end
95
132
  end
96
133
 
@@ -98,19 +135,19 @@ describe "should raise_error(NamedError)" do
98
135
  it "passes if named error is raised" do
99
136
  lambda { non_existent_method }.should raise_error(NameError)
100
137
  end
101
-
138
+
102
139
  it "fails if nothing is raised" do
103
140
  lambda {
104
141
  lambda { }.should raise_error(NameError)
105
- }.should fail_with("expected NameError but nothing was raised")
142
+ }.should fail_with(/expected NameError but nothing was raised/)
106
143
  end
107
-
144
+
108
145
  it "fails if another error is raised (NameError)" do
109
146
  lambda {
110
147
  lambda { raise RuntimeError, "example message" }.should raise_error(NameError)
111
- }.should fail_with("expected NameError, got #<RuntimeError: example message>")
148
+ }.should fail_with(/expected NameError, got #<RuntimeError: example message>/)
112
149
  end
113
-
150
+
114
151
  it "fails if another error is raised (NameError)" do
115
152
  lambda {
116
153
  lambda { load "non/existent/file" }.should raise_error(NameError)
@@ -122,35 +159,35 @@ describe "should_not raise_error(NamedError)" do
122
159
  it "passes if nothing is raised" do
123
160
  lambda { }.should_not raise_error(NameError)
124
161
  end
125
-
162
+
126
163
  it "passes if another error is raised" do
127
164
  lambda { raise }.should_not raise_error(NameError)
128
165
  end
129
-
166
+
130
167
  it "fails if named error is raised" do
131
168
  lambda {
132
169
  lambda { 1 + 'b' }.should_not raise_error(TypeError)
133
170
  }.should fail_with(/expected no TypeError, got #<TypeError: String can't be/)
134
- end
171
+ end
135
172
  end
136
173
 
137
174
  describe "should raise_error(NamedError, error_message) with String" do
138
175
  it "passes if named error is raised with same message" do
139
176
  lambda { raise "example message" }.should raise_error(RuntimeError, "example message")
140
177
  end
141
-
178
+
142
179
  it "fails if nothing is raised" do
143
180
  lambda {
144
181
  lambda {}.should raise_error(RuntimeError, "example message")
145
- }.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
182
+ }.should fail_with(/expected RuntimeError with \"example message\" but nothing was raised/)
146
183
  end
147
-
184
+
148
185
  it "fails if incorrect error is raised" do
149
186
  lambda {
150
187
  lambda { raise RuntimeError, "example message" }.should raise_error(NameError, "example message")
151
- }.should fail_with("expected NameError with \"example message\", got #<RuntimeError: example message>")
188
+ }.should fail_with(/expected NameError with \"example message\", got #<RuntimeError: example message>/)
152
189
  end
153
-
190
+
154
191
  it "fails if correct error is raised with incorrect message" do
155
192
  lambda {
156
193
  lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, "example message")
@@ -197,7 +234,7 @@ describe "should raise_error(NamedError, error_message) { |err| ... }" do
197
234
  lambda {}.should raise_error(RuntimeError, "example message") { |err|
198
235
  ran = true
199
236
  }
200
- }.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
237
+ }.should fail_with(/expected RuntimeError with \"example message\" but nothing was raised/)
201
238
 
202
239
  ran.should == false
203
240
  end
@@ -211,7 +248,7 @@ describe "should raise_error(NamedError, error_message) { |err| ... }" do
211
248
  }.should raise_error(SyntaxError, "example message") { |err|
212
249
  ran = true
213
250
  }
214
- }.should fail_with("expected SyntaxError with \"example message\", got #<RuntimeError: example message>")
251
+ }.should fail_with(/expected SyntaxError with \"example message\", got #<RuntimeError: example message>/)
215
252
 
216
253
  ran.should == false
217
254
  end
@@ -225,7 +262,7 @@ describe "should raise_error(NamedError, error_message) { |err| ... }" do
225
262
  }.should raise_error(RuntimeError, "different message") { |err|
226
263
  ran = true
227
264
  }
228
- }.should fail_with("expected RuntimeError with \"different message\", got #<RuntimeError: example message>")
265
+ }.should fail_with(/expected RuntimeError with \"different message\", got #<RuntimeError: example message>/)
229
266
 
230
267
  ran.should == false
231
268
  end
@@ -273,7 +310,21 @@ describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
273
310
  }.should_not raise_error(RuntimeError, "example message") { |err|
274
311
  ran = true
275
312
  }
276
- }.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
313
+ }.should fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
314
+
315
+ ran.should == false
316
+ end
317
+
318
+ it 'skips the error verification block when using the expect {...}.to syntax' do
319
+ ran = false
320
+
321
+ expect {
322
+ expect {
323
+ raise "example message"
324
+ }.not_to raise_error(RuntimeError, "example message") { |err|
325
+ ran = true
326
+ }
327
+ }.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
277
328
 
278
329
  ran.should == false
279
330
  end
@@ -283,19 +334,19 @@ describe "should_not raise_error(NamedError, error_message) with String" do
283
334
  it "passes if nothing is raised" do
284
335
  lambda {}.should_not raise_error(RuntimeError, "example message")
285
336
  end
286
-
337
+
287
338
  it "passes if a different error is raised" do
288
339
  lambda { raise }.should_not raise_error(NameError, "example message")
289
340
  end
290
-
341
+
291
342
  it "passes if same error is raised with different message" do
292
343
  lambda { raise RuntimeError.new("not the example message") }.should_not raise_error(RuntimeError, "example message")
293
344
  end
294
-
345
+
295
346
  it "fails if named error is raised with same message" do
296
347
  lambda {
297
348
  lambda { raise "example message" }.should_not raise_error(RuntimeError, "example message")
298
- }.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
349
+ }.should fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
299
350
  end
300
351
  end
301
352
 
@@ -303,23 +354,23 @@ describe "should raise_error(NamedError, error_message) with Regexp" do
303
354
  it "passes if named error is raised with matching message" do
304
355
  lambda { raise "example message" }.should raise_error(RuntimeError, /ample mess/)
305
356
  end
306
-
357
+
307
358
  it "fails if nothing is raised" do
308
359
  lambda {
309
360
  lambda {}.should raise_error(RuntimeError, /ample mess/)
310
- }.should fail_with("expected RuntimeError with message matching /ample mess/ but nothing was raised")
361
+ }.should fail_with(/expected RuntimeError with message matching \/ample mess\/ but nothing was raised/)
311
362
  end
312
-
363
+
313
364
  it "fails if incorrect error is raised" do
314
365
  lambda {
315
366
  lambda { raise RuntimeError, "example message" }.should raise_error(NameError, /ample mess/)
316
- }.should fail_with("expected NameError with message matching /ample mess/, got #<RuntimeError: example message>")
367
+ }.should fail_with(/expected NameError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
317
368
  end
318
-
369
+
319
370
  it "fails if correct error is raised with incorrect message" do
320
371
  lambda {
321
372
  lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, /less than ample mess/)
322
- }.should fail_with("expected RuntimeError with message matching /less than ample mess/, got #<RuntimeError: not the example message>")
373
+ }.should fail_with(/expected RuntimeError with message matching \/less than ample mess\/, got #<RuntimeError: not the example message>/)
323
374
  end
324
375
  end
325
376
 
@@ -327,18 +378,18 @@ describe "should_not raise_error(NamedError, error_message) with Regexp" do
327
378
  it "passes if nothing is raised" do
328
379
  lambda {}.should_not raise_error(RuntimeError, /ample mess/)
329
380
  end
330
-
381
+
331
382
  it "passes if a different error is raised" do
332
383
  lambda { raise }.should_not raise_error(NameError, /ample mess/)
333
384
  end
334
-
385
+
335
386
  it "passes if same error is raised with non-matching message" do
336
387
  lambda { raise RuntimeError.new("non matching message") }.should_not raise_error(RuntimeError, /ample mess/)
337
388
  end
338
-
389
+
339
390
  it "fails if named error is raised with matching message" do
340
391
  lambda {
341
392
  lambda { raise "example message" }.should_not raise_error(RuntimeError, /ample mess/)
342
- }.should fail_with("expected no RuntimeError with message matching /ample mess/, got #<RuntimeError: example message>")
393
+ }.should fail_with(/expected no RuntimeError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
343
394
  end
344
395
  end
@@ -130,7 +130,7 @@ describe "should end_with" do
130
130
  end
131
131
 
132
132
  context "with an object that does not respond to :[]" do
133
- it "should raise an error if expected value can't be indexed'" do
133
+ it "raises an error if expected value can't be indexed'" do
134
134
  expect { Object.new.should end_with 0 }.to raise_error(ArgumentError, /does not respond to :\[\]/)
135
135
  end
136
136
  end
@@ -130,6 +130,12 @@ describe "yield_with_no_args matcher" do
130
130
  }.to fail_with(/expected given block to yield with no arguments, but yielded with arguments/)
131
131
  end
132
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
+
133
139
  it 'raises an error if it yields multiple times' do
134
140
  expect {
135
141
  expect { |b| [1, 2].each(&b) }.to yield_with_no_args
@@ -179,6 +185,7 @@ describe "yield_with_args matcher" do
179
185
  it 'has a description' do
180
186
  yield_with_args.description.should eq("yield with args")
181
187
  yield_with_args(1, 3).description.should eq("yield with args(1, 3)")
188
+ yield_with_args(false).description.should eq("yield with args(false)")
182
189
  end
183
190
 
184
191
  describe "expect {...}.to yield_with_args" do
@@ -273,6 +280,34 @@ describe "yield_with_args matcher" do
273
280
  end
274
281
  end
275
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
+
276
311
  describe "expect {...}.to yield_with_args(/reg/, /ex/)" do
277
312
  it "passes if the block yields strings matching the regexes" do
278
313
  expect { |b| _yield_with_args("regular", "expression", &b) }.to yield_with_args(/reg/, /ex/)