rspec-expectations 2.99.2 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +14 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -0
  4. data/Changelog.md +63 -104
  5. data/License.txt +1 -0
  6. data/README.md +14 -8
  7. data/features/README.md +1 -2
  8. data/features/built_in_matchers/README.md +3 -0
  9. data/features/built_in_matchers/be.feature +44 -44
  10. data/features/built_in_matchers/be_within.feature +1 -1
  11. data/features/built_in_matchers/comparisons.feature +97 -0
  12. data/features/built_in_matchers/cover.feature +3 -3
  13. data/features/built_in_matchers/end_with.feature +3 -3
  14. data/features/built_in_matchers/equality.feature +20 -23
  15. data/features/built_in_matchers/exist.feature +5 -5
  16. data/features/built_in_matchers/expect_error.feature +14 -14
  17. data/features/built_in_matchers/include.feature +15 -15
  18. data/features/built_in_matchers/match.feature +4 -5
  19. data/features/built_in_matchers/match_array.feature +37 -0
  20. data/features/built_in_matchers/predicates.feature +30 -6
  21. data/features/built_in_matchers/respond_to.feature +4 -4
  22. data/features/built_in_matchers/satisfy.feature +2 -2
  23. data/features/built_in_matchers/start_with.feature +3 -3
  24. data/features/built_in_matchers/types.feature +6 -6
  25. data/features/custom_matchers/access_running_example.feature +3 -3
  26. data/features/custom_matchers/define_matcher.feature +6 -34
  27. data/features/custom_matchers/define_matcher_outside_rspec.feature +2 -2
  28. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
  29. data/features/customized_message.feature +18 -1
  30. data/features/diffing.feature +3 -3
  31. data/features/implicit_docstrings.feature +9 -9
  32. data/features/step_definitions/additional_cli_steps.rb +0 -10
  33. data/features/support/env.rb +10 -3
  34. data/features/test_frameworks/test_unit.feature +0 -40
  35. data/lib/rspec-expectations.rb +0 -5
  36. data/lib/rspec/expectations.rb +4 -18
  37. data/lib/rspec/expectations/expectation_target.rb +10 -77
  38. data/lib/rspec/expectations/extensions.rb +0 -1
  39. data/lib/rspec/expectations/handler.rb +1 -5
  40. data/lib/rspec/expectations/syntax.rb +25 -5
  41. data/lib/rspec/expectations/version.rb +1 -1
  42. data/lib/rspec/matchers.rb +7 -102
  43. data/lib/rspec/matchers/built_in/base_matcher.rb +10 -17
  44. data/lib/rspec/matchers/built_in/be.rb +5 -18
  45. data/lib/rspec/matchers/built_in/be_within.rb +2 -8
  46. data/lib/rspec/matchers/built_in/change.rb +1 -39
  47. data/lib/rspec/matchers/built_in/has.rb +7 -40
  48. data/lib/rspec/matchers/built_in/include.rb +1 -1
  49. data/lib/rspec/matchers/built_in/match_array.rb +1 -1
  50. data/lib/rspec/matchers/built_in/raise_error.rb +44 -23
  51. data/lib/rspec/matchers/built_in/respond_to.rb +1 -7
  52. data/lib/rspec/matchers/built_in/satisfy.rb +1 -7
  53. data/lib/rspec/matchers/built_in/throw_symbol.rb +2 -10
  54. data/lib/rspec/matchers/built_in/yield.rb +4 -25
  55. data/lib/rspec/matchers/compatibility.rb +2 -2
  56. data/lib/rspec/{expectations → matchers}/configuration.rb +9 -6
  57. data/lib/rspec/matchers/dsl.rb +2 -4
  58. data/lib/rspec/matchers/matcher.rb +163 -283
  59. data/lib/rspec/matchers/operator_matcher.rb +57 -71
  60. data/lib/rspec/matchers/pretty.rb +0 -4
  61. data/lib/rspec/matchers/test_unit_integration.rb +5 -22
  62. data/spec/rspec/expectations/expectation_target_spec.rb +0 -62
  63. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -4
  64. data/spec/rspec/expectations_spec.rb +2 -43
  65. data/spec/rspec/matchers/base_matcher_spec.rb +12 -27
  66. data/spec/rspec/matchers/be_spec.rb +2 -71
  67. data/spec/rspec/matchers/change_spec.rb +1 -76
  68. data/spec/rspec/{expectations → matchers}/configuration_spec.rb +41 -21
  69. data/spec/rspec/matchers/description_generation_spec.rb +2 -21
  70. data/spec/rspec/matchers/equal_spec.rb +0 -26
  71. data/spec/rspec/matchers/has_spec.rb +0 -24
  72. data/spec/rspec/matchers/match_array_spec.rb +0 -13
  73. data/spec/rspec/matchers/matcher_spec.rb +325 -279
  74. data/spec/rspec/matchers/matchers_spec.rb +36 -0
  75. data/spec/rspec/matchers/operator_matcher_spec.rb +8 -27
  76. data/spec/rspec/matchers/raise_error_spec.rb +65 -209
  77. data/spec/rspec/matchers/yield_spec.rb +32 -9
  78. data/spec/spec_helper.rb +21 -6
  79. data/spec/support/classes.rb +7 -7
  80. data/spec/support/in_sub_process.rb +7 -8
  81. data/spec/support/shared_examples.rb +0 -42
  82. metadata +113 -84
  83. metadata.gz.sig +4 -0
  84. data/features/built_in_matchers/have.feature +0 -109
  85. data/features/built_in_matchers/operators.feature +0 -227
  86. data/lib/rspec/expectations/caller_filter.rb +0 -60
  87. data/lib/rspec/expectations/deprecation.rb +0 -27
  88. data/lib/rspec/expectations/extensions/array.rb +0 -9
  89. data/lib/rspec/matchers/be_close.rb +0 -12
  90. data/lib/rspec/matchers/built_in/have.rb +0 -273
  91. data/lib/rspec/matchers/differentiate_block_method_types.rb +0 -55
  92. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  93. data/lib/rspec/matchers/match_aliases.rb +0 -22
  94. data/spec/rspec/matchers/be_close_spec.rb +0 -25
  95. data/spec/rspec/matchers/differentiate_block_method_types_spec.rb +0 -39
  96. data/spec/rspec/matchers/have_spec.rb +0 -853
  97. data/spec/rspec/matchers/pretty_spec.rb +0 -23
  98. data/spec/support/helper_methods.rb +0 -42
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec
4
+ describe Matchers do
5
+
6
+ let(:sample_matchers) do
7
+ [:be,
8
+ :be_instance_of,
9
+ :be_kind_of]
10
+ end
11
+
12
+ context "once required" do
13
+ include TestUnitIntegrationSupport
14
+
15
+ it "includes itself in Test::Unit::TestCase" do
16
+ with_test_unit_loaded do
17
+ test_unit_case = Test::Unit::TestCase.allocate
18
+ sample_matchers.each do |sample_matcher|
19
+ expect(test_unit_case).to respond_to(sample_matcher)
20
+ end
21
+ end
22
+ end
23
+
24
+ it "includes itself in MiniTest::Unit::TestCase", :if => defined?(MiniTest) do
25
+ with_test_unit_loaded do
26
+ minitest_case = MiniTest::Unit::TestCase.allocate
27
+ sample_matchers.each do |sample_matcher|
28
+ expect(minitest_case).to respond_to(sample_matcher)
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -210,41 +210,22 @@ describe "operator matchers", :uses_should do
210
210
  let(:custom_klass) { Class.new }
211
211
  let(:custom_subklass) { Class.new(custom_klass) }
212
212
 
213
- after do
214
- RSpec::Matchers::BuiltIn::OperatorMatcher.unregister(custom_klass, "=~")
215
- end
213
+ after {
214
+ RSpec::Matchers::OperatorMatcher.unregister(custom_klass, "=~")
215
+ }
216
216
 
217
217
  it "allows operator matchers to be registered for types" do
218
- RSpec::Matchers::BuiltIn::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
219
- expect(RSpec::Matchers::BuiltIn::OperatorMatcher.get(custom_klass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
218
+ RSpec::Matchers::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
219
+ expect(RSpec::Matchers::OperatorMatcher.get(custom_klass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
220
220
  end
221
221
 
222
222
  it "considers ancestors when finding an operator matcher" do
223
- RSpec::Matchers::BuiltIn::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
224
- expect(RSpec::Matchers::BuiltIn::OperatorMatcher.get(custom_subklass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
223
+ RSpec::Matchers::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
224
+ expect(RSpec::Matchers::OperatorMatcher.get(custom_subklass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
225
225
  end
226
226
 
227
227
  it "returns nil if there is no matcher registered for a type" do
228
- expect(RSpec::Matchers::BuiltIn::OperatorMatcher.get(custom_klass, "=~")).to be_nil
229
- end
230
-
231
- context "when accessing it using the old 2.x const name" do
232
- it 'returns the new constant scoped by `BuiltIn`' do
233
- allow_deprecation
234
- expect(RSpec::Matchers::OperatorMatcher).to be(RSpec::Matchers::BuiltIn::OperatorMatcher)
235
- end
236
-
237
- it 'issues a deprecation warning' do
238
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /OperatorMatcher/)
239
- RSpec::Matchers::OperatorMatcher
240
- end
241
-
242
- it 'allows other undefined constant to raise errors like normal' do
243
- expect_no_deprecation
244
- expect {
245
- RSpec::Matchers::FooBarBazz
246
- }.to raise_error(NameError, /RSpec::Matchers::FooBarBazz/)
247
- end
228
+ expect(RSpec::Matchers::OperatorMatcher.get(custom_klass, "=~")).to be_nil
248
229
  end
249
230
  end
250
231
 
@@ -1,18 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- module WrapDeprecationCallSite
4
- def expect_deprecation_with_call_site(file, line)
5
- actual_call_site = nil
6
- allow(RSpec.configuration.reporter).to receive(:deprecation) do |options|
7
- actual_call_site = options[:call_site]
8
- end
9
-
10
- yield
11
-
12
- expect(actual_call_site).to match([file, line].join(':'))
13
- end
14
- end
15
-
16
3
  describe "expect { ... }.to raise_error" do
17
4
  it_behaves_like("an RSpec matcher", :valid_value => lambda { raise "boom" },
18
5
  :invalid_value => lambda { }) do
@@ -73,23 +60,42 @@ describe "expect { ... }.to raise_error {|err| ... }" do
73
60
  end
74
61
  end
75
62
 
63
+ describe "expect { ... }.to raise_error do |err| ... end" do
64
+ it "passes the error to the block" do
65
+ error = nil
66
+ expect { non_existent_method }.to raise_error do |e|
67
+ error = e
68
+ end
69
+ expect(error).to be_kind_of(NameError)
70
+ end
71
+ end
72
+
73
+ describe "expect { ... }.to(raise_error { |err| ... }) do |err| ... end" do
74
+ it "passes the error only to the block taken directly by #raise_error" do
75
+ error_passed_to_curly = nil
76
+ error_passed_to_do_end = nil
77
+
78
+ expect { non_existent_method }.to(raise_error { |e| error_passed_to_curly = e }) do |e|
79
+ error_passed_to_do_end = e
80
+ end
81
+
82
+ expect(error_passed_to_curly).to be_kind_of(NameError)
83
+ expect(error_passed_to_do_end).to be_nil
84
+ end
85
+ end
86
+
76
87
  describe "expect { ... }.not_to raise_error" do
77
88
 
78
89
  context "with a specific error class" do
79
- it "is deprecated" do
80
- RSpec.should_receive :deprecate
81
- expect {"bees"}.not_to raise_error(RuntimeError)
90
+ it "is invalid" do
91
+ expect {
92
+ expect {"bees"}.not_to raise_error(RuntimeError)
93
+ }.to raise_error(/`expect { }\.not_to raise_error\(SpecificErrorClass\)` is not valid/)
94
+
82
95
  end
83
96
  end
84
97
 
85
98
  context "with no specific error class" do
86
- it "is not deprecated" do
87
- run = nil
88
- allow(RSpec).to receive(:deprecate) { run = true }
89
- expect {"bees"}.not_to raise_error
90
- expect(run).to be_nil
91
- end
92
-
93
99
  it "passes if nothing is raised" do
94
100
  expect {}.not_to raise_error
95
101
  end
@@ -158,47 +164,43 @@ describe "expect { ... }.to raise_error(message)" do
158
164
  end
159
165
  end
160
166
 
161
- describe "expect { ... }.not_to raise_error(message)" do
162
- include WrapDeprecationCallSite
163
-
164
- before do
165
- allow(RSpec).to receive(:deprecate)
167
+ describe "expect { ... }.to raise_error.with_message(message)" do
168
+ it "raises an argument error if raise_error itself expects a message" do
169
+ expect {
170
+ expect { }.to raise_error("bees").with_message("sup")
171
+ }.to raise_error.with_message(/`expect { }\.to raise_error\(message\)\.with_message\(message\)` is not valid/)
166
172
  end
167
173
 
168
- it "is deprecated" do
169
- expect(RSpec).to receive(:deprecate).with(
170
- /not_to raise_error\(message\)/,
171
- :replacement =>"`expect { }.not_to raise_error` (with no args)"
172
- )
173
- expect {raise 'blarg'}.not_to raise_error('blah')
174
+ it "passes if RuntimeError is raised with the right message" do
175
+ expect {raise 'blah'}.to raise_error.with_message('blah')
174
176
  end
175
177
 
176
- it 'reports the line number of the deprecated syntax' do
177
- allow(RSpec).to receive(:deprecate).and_call_original
178
-
179
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1) do
180
- expect {raise 'blarg'}.not_to raise_error('blah')
181
- end
178
+ it "passes if RuntimeError is raised with a matching message" do
179
+ expect {raise 'blah'}.to raise_error.with_message(/blah/)
182
180
  end
183
181
 
184
- it "passes if RuntimeError error is raised with the different message" do
185
- expect {raise 'blarg'}.not_to raise_error('blah')
182
+ it "passes if any other error is raised with the right message" do
183
+ expect {raise NameError.new('blah')}.to raise_error.with_message('blah')
186
184
  end
187
185
 
188
- it "passes if any other error is raised with the wrong message" do
189
- expect {raise NameError.new('blarg')}.not_to raise_error('blah')
186
+ it "fails if RuntimeError error is raised with the wrong message" do
187
+ expect do
188
+ expect {raise 'blarg'}.to raise_error.with_message('blah')
189
+ end.to fail_with(/expected Exception with \"blah\", got #<RuntimeError: blarg>/)
190
190
  end
191
191
 
192
- it "fails if RuntimeError is raised with message" do
192
+ it "fails if any other error is raised with the wrong message" do
193
193
  expect do
194
- expect {raise 'blah'}.not_to raise_error('blah')
195
- end.to fail_with(/expected no Exception with "blah", got #<RuntimeError: blah>/)
194
+ expect {raise NameError.new('blarg')}.to raise_error.with_message('blah')
195
+ end.to fail_with(/expected Exception with \"blah\", got #<NameError: blarg>/)
196
196
  end
197
+ end
197
198
 
198
- it "fails if any other error is raised with message" do
199
- expect do
200
- expect {raise NameError.new('blah')}.not_to raise_error('blah')
201
- end.to fail_with(/expected no Exception with "blah", got #<NameError: blah>/)
199
+ describe "expect { ... }.not_to raise_error(message)" do
200
+ it "is invalid" do
201
+ expect {
202
+ expect {raise 'blarg'}.not_to raise_error(/blah/)
203
+ }.to raise_error(/`expect { }\.not_to raise_error\(message\)` is not valid/)
202
204
  end
203
205
  end
204
206
 
@@ -227,39 +229,10 @@ describe "expect { ... }.to raise_error(NamedError)" do
227
229
  end
228
230
 
229
231
  describe "expect { ... }.not_to raise_error(NamedError)" do
230
- include WrapDeprecationCallSite
231
-
232
- before do
233
- allow(RSpec).to receive(:deprecate)
234
- end
235
-
236
- it "is deprecated" do
237
- expect(RSpec).to receive(:deprecate).with(
238
- /not_to raise_error\(SpecificErrorClass\)/,
239
- :replacement =>"`expect { }.not_to raise_error` (with no args)"
240
- )
241
- expect { }.not_to raise_error(NameError)
242
- end
243
-
244
- it 'reports the line number of the deprecated syntax' do
245
- allow(RSpec).to receive(:deprecate).and_call_original
246
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1) do
247
- expect { }.not_to raise_error(NameError)
248
- end
249
- end
250
-
251
- it "passes if nothing is raised" do
252
- expect { }.not_to raise_error(NameError)
253
- end
254
-
255
- it "passes if another error is raised" do
256
- expect { raise }.not_to raise_error(NameError)
257
- end
258
-
259
- it "fails if named error is raised" do
232
+ it "is invalid" do
260
233
  expect {
261
- expect { 1 + 'b' }.not_to raise_error(TypeError)
262
- }.to fail_with(/expected no TypeError, got #<TypeError: String can't be/)
234
+ expect { }.not_to raise_error(NameError)
235
+ }.to raise_error(/`expect { }\.not_to raise_error\(SpecificErrorClass\)` is not valid/)
263
236
  end
264
237
  end
265
238
 
@@ -288,43 +261,10 @@ describe "expect { ... }.to raise_error(NamedError, error_message) with String"
288
261
  end
289
262
 
290
263
  describe "expect { ... }.not_to raise_error(NamedError, error_message) with String" do
291
- include WrapDeprecationCallSite
292
-
293
- before do
294
- allow(RSpec).to receive(:deprecate)
295
- end
296
-
297
- it "is deprecated" do
298
- expect(RSpec).to receive(:deprecate).with(
299
- /not_to raise_error\(SpecificErrorClass, message\)/,
300
- :replacement =>"`expect { }.not_to raise_error` (with no args)"
301
- )
302
- expect {}.not_to raise_error(RuntimeError, "example message")
303
- end
304
-
305
- it 'reports the line number of the deprecated syntax' do
306
- allow(RSpec).to receive(:deprecate).and_call_original
307
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1) do
308
- expect {}.not_to raise_error(RuntimeError, "example message")
309
- end
310
- end
311
-
312
- it "passes if nothing is raised" do
313
- expect {}.not_to raise_error(RuntimeError, "example message")
314
- end
315
-
316
- it "passes if a different error is raised" do
317
- expect { raise }.not_to raise_error(NameError, "example message")
318
- end
319
-
320
- it "passes if same error is raised with different message" do
321
- expect { raise RuntimeError.new("not the example message") }.not_to raise_error(RuntimeError, "example message")
322
- end
323
-
324
- it "fails if named error is raised with same message" do
264
+ it "is invalid" do
325
265
  expect {
326
- expect { raise "example message" }.not_to raise_error(RuntimeError, "example message")
327
- }.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
266
+ expect {}.not_to raise_error(RuntimeError, "example message")
267
+ }.to raise_error(/`expect { }\.not_to raise_error\(SpecificErrorClass, message\)` is not valid/)
328
268
  end
329
269
  end
330
270
 
@@ -353,31 +293,10 @@ describe "expect { ... }.to raise_error(NamedError, error_message) with Regexp"
353
293
  end
354
294
 
355
295
  describe "expect { ... }.not_to raise_error(NamedError, error_message) with Regexp" do
356
- before do
357
- allow(RSpec).to receive(:deprecate)
358
- end
359
-
360
- it "is deprecated" do
361
- expect(RSpec).to receive(:deprecate)
362
- expect {}.not_to raise_error(RuntimeError, /ample mess/)
363
- end
364
-
365
- it "passes if nothing is raised" do
366
- expect {}.not_to raise_error(RuntimeError, /ample mess/)
367
- end
368
-
369
- it "passes if a different error is raised" do
370
- expect { raise }.not_to raise_error(NameError, /ample mess/)
371
- end
372
-
373
- it "passes if same error is raised with non-matching message" do
374
- expect { raise RuntimeError.new("non matching message") }.not_to raise_error(RuntimeError, /ample mess/)
375
- end
376
-
377
- it "fails if named error is raised with matching message" do
296
+ it "is invalid" do
378
297
  expect {
379
- expect { raise "example message" }.not_to raise_error(RuntimeError, /ample mess/)
380
- }.to fail_with(/expected no RuntimeError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
298
+ expect {}.not_to raise_error(RuntimeError, /ample mess/)
299
+ }.to raise_error(/`expect { }\.not_to raise_error\(SpecificErrorClass, message\)` is not valid/)
381
300
  end
382
301
  end
383
302
 
@@ -455,73 +374,10 @@ describe "expect { ... }.to raise_error(NamedError, error_message) { |err| ... }
455
374
  end
456
375
 
457
376
  describe "expect { ... }.not_to raise_error(NamedError, error_message) { |err| ... }" do
458
- before do
459
- allow(RSpec).to receive(:deprecate)
460
- end
461
-
462
- it "is deprecated" do
463
- expect(RSpec).to receive(:deprecate)
464
- expect {}.not_to raise_error(RuntimeError, "example message") { |err| }
465
- end
466
-
467
- it "passes if nothing is raised" do
468
- ran = false
469
-
470
- expect {}.not_to raise_error(RuntimeError, "example message") { |err|
471
- ran = true
472
- }
473
-
474
- expect(ran).to eq false
475
- end
476
-
477
- it "passes if a different error is raised" do
478
- ran = false
479
-
480
- expect { raise }.not_to raise_error(NameError, "example message") { |err|
481
- ran = true
482
- }
483
-
484
- expect(ran).to eq false
485
- end
486
-
487
- it "passes if same error is raised with different message" do
488
- ran = false
489
-
490
- expect {
491
- raise RuntimeError.new("not the example message")
492
- }.not_to raise_error(RuntimeError, "example message") { |err|
493
- ran = true
494
- }
495
-
496
- expect(ran).to eq false
497
- end
498
-
499
- it "fails if named error is raised with same message" do
500
- ran = false
501
-
502
- expect {
503
- expect {
504
- raise "example message"
505
- }.not_to raise_error(RuntimeError, "example message") { |err|
506
- ran = true
507
- }
508
- }.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
509
-
510
- expect(ran).to eq false
511
- end
512
-
513
- it 'skips the error verification block when using the expect {...}.to syntax' do
514
- ran = false
515
-
377
+ it "is invalid" do
516
378
  expect {
517
- expect {
518
- raise "example message"
519
- }.not_to raise_error(RuntimeError, "example message") { |err|
520
- ran = true
521
- }
522
- }.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
523
-
524
- expect(ran).to eq false
379
+ expect {}.not_to raise_error(RuntimeError, "example message") { |err| }
380
+ }.to raise_error(/`expect { }\.not_to raise_error\(SpecificErrorClass, message\)` is not valid/)
525
381
  end
526
382
  end
527
383
 
@@ -16,19 +16,18 @@ module YieldHelpers
16
16
  end
17
17
 
18
18
  class InstanceEvaler
19
- include RSpec::Matchers::Extensions::InstanceEvalWithArgs
20
19
 
21
20
  def yield_with_no_args(&block)
22
- instance_eval_with_args(&block)
21
+ instance_exec(&block)
23
22
  end
24
23
 
25
24
  def yield_with_args(*args, &block)
26
- instance_eval_with_args(*args, &block)
25
+ instance_exec(*args, &block)
27
26
  end
28
27
 
29
28
  def each_arg(*args, &block)
30
29
  args.each do |arg|
31
- instance_eval_with_args(arg, &block)
30
+ instance_exec(arg, &block)
32
31
  end
33
32
  end
34
33
  end
@@ -53,7 +52,7 @@ describe "yield_control matcher" do
53
52
  expect { |b| _yield_with_args(1, 2, &b) }.to yield_control
54
53
  end
55
54
 
56
- it 'passes if the block yields using instance_eval' do
55
+ it 'passes if the block yields using instance_exec' do
57
56
  expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_control
58
57
  end
59
58
 
@@ -63,6 +62,12 @@ describe "yield_control matcher" do
63
62
  }.to fail_with(/expected given block to yield control/)
64
63
  end
65
64
 
65
+ it 'does not return a meaningful value from the block' do
66
+ val = nil
67
+ expect { |b| val = _yield_with_args(&b) }.to yield_control
68
+ expect(val).to be_nil
69
+ end
70
+
66
71
  context "with exact count" do
67
72
  it 'fails if the block yields wrong number of times' do
68
73
  expect {
@@ -186,12 +191,18 @@ describe "yield_with_no_args matcher" do
186
191
  expect(yield_with_no_args.description).to eq("yield with no args")
187
192
  end
188
193
 
194
+ it 'does not return a meaningful value from the block' do
195
+ val = nil
196
+ expect { |b| val = _yield_with_no_args(&b) }.to yield_with_no_args
197
+ expect(val).to be_nil
198
+ end
199
+
189
200
  describe "expect {...}.to yield_with_no_args" do
190
201
  it 'passes if the block yields with no args' do
191
202
  expect { |b| _yield_with_no_args(&b) }.to yield_with_no_args
192
203
  end
193
204
 
194
- it 'passes if the block yields with no args using instance_eval' do
205
+ it 'passes if the block yields with no args using instance_exec' do
195
206
  expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_with_no_args
196
207
  end
197
208
 
@@ -265,6 +276,12 @@ describe "yield_with_args matcher" do
265
276
  expect(yield_with_args(false).description).to eq("yield with args(false)")
266
277
  end
267
278
 
279
+ it 'does not return a meaningful value from the block' do
280
+ val = nil
281
+ expect { |b| val = _yield_with_args(1, &b) }.to yield_with_args(1)
282
+ expect(val).to be_nil
283
+ end
284
+
268
285
  describe "expect {...}.to yield_with_args" do
269
286
  it 'passes if the block yields with arguments' do
270
287
  expect { |b| _yield_with_args(1, &b) }.to yield_with_args
@@ -322,7 +339,7 @@ describe "yield_with_args matcher" do
322
339
  expect { |b| _yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
323
340
  end
324
341
 
325
- it 'passes if the block yields with the given arguments using instance_eval' do
342
+ it 'passes if the block yields with the given arguments using instance_exec' do
326
343
  expect { |b| InstanceEvaler.new.yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
327
344
  end
328
345
 
@@ -362,7 +379,7 @@ describe "yield_with_args matcher" do
362
379
  expect { |b| _yield_with_args(false, &b) }.to yield_with_args(false)
363
380
  end
364
381
 
365
- it 'passes if the block yields with the given arguments using instance_eval' do
382
+ it 'passes if the block yields with the given arguments using instance_exec' do
366
383
  expect { |b| InstanceEvaler.new.yield_with_args(false, &b) }.to yield_with_args(false)
367
384
  end
368
385
 
@@ -429,6 +446,12 @@ describe "yield_successive_args matcher" do
429
446
  expect(yield_successive_args([:a, 1], [:b, 2]).description).to eq("yield successive args([:a, 1], [:b, 2])")
430
447
  end
431
448
 
449
+ it 'does not return a meaningful value from the block' do
450
+ val = nil
451
+ expect { |b| val = _yield_with_args(1, &b) }.to yield_successive_args(1)
452
+ expect(val).to be_nil
453
+ end
454
+
432
455
  describe "expect {...}.to yield_successive_args([:a, 1], [:b, 2])" do
433
456
  it 'passes when the block successively yields the given args' do
434
457
  expect { |b| [ [:a, 1], [:b, 2] ].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
@@ -452,7 +475,7 @@ describe "yield_successive_args matcher" do
452
475
  expect { |b| [1, 2, 3].each(&b) }.to yield_successive_args(1, 2, 3)
453
476
  end
454
477
 
455
- it 'passes when the block successively yields the given args using instance_eval' do
478
+ it 'passes when the block successively yields the given args using instance_exec' do
456
479
  expect { |b| InstanceEvaler.new.each_arg(1, 2, 3, &b) }.to yield_successive_args(1, 2, 3)
457
480
  end
458
481