rspec-mocks 2.99.4 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +14 -6
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +1 -0
  4. data/Changelog.md +89 -105
  5. data/License.txt +1 -0
  6. data/README.md +77 -57
  7. data/features/argument_matchers/explicit.feature +5 -5
  8. data/features/argument_matchers/general_matchers.feature +10 -10
  9. data/features/argument_matchers/type_matchers.feature +3 -3
  10. data/features/message_expectations/allow_any_instance_of.feature +1 -1
  11. data/features/message_expectations/any_instance.feature +27 -5
  12. data/features/message_expectations/call_original.feature +2 -2
  13. data/features/message_expectations/expect_message_using_expect.feature +2 -2
  14. data/features/message_expectations/expect_message_using_should_receive.feature +2 -2
  15. data/features/message_expectations/receive_counts.feature +7 -7
  16. data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +3 -3
  17. data/features/method_stubs/README.md +3 -0
  18. data/features/method_stubs/any_instance.feature +11 -11
  19. data/features/method_stubs/as_null_object.feature +4 -4
  20. data/features/method_stubs/simple_return_value_with_stub.feature +7 -7
  21. data/features/method_stubs/stub_chain.feature +3 -3
  22. data/features/method_stubs/stub_implementation.feature +2 -2
  23. data/features/method_stubs/to_ary.feature +2 -2
  24. data/features/mutating_constants/hiding_defined_constant.feature +2 -2
  25. data/features/mutating_constants/stub_defined_constant.feature +5 -5
  26. data/features/mutating_constants/stub_undefined_constant.feature +6 -6
  27. data/features/outside_rspec/configuration.feature +0 -2
  28. data/features/outside_rspec/standalone.feature +1 -1
  29. data/features/spies/spy_partial_mock_method.feature +2 -2
  30. data/features/spies/spy_pure_mock_method.feature +5 -5
  31. data/features/spies/spy_unstubbed_method.feature +1 -1
  32. data/features/support/env.rb +10 -1
  33. data/features/test_frameworks/test_unit.feature +1 -1
  34. data/features/verifying_doubles/class_doubles.feature +88 -0
  35. data/features/verifying_doubles/dynamic_classes.feature +72 -0
  36. data/features/verifying_doubles/introduction.feature +85 -0
  37. data/features/verifying_doubles/object_doubles.feature +65 -0
  38. data/features/verifying_doubles/partial_doubles.feature +34 -0
  39. data/lib/rspec/mocks.rb +8 -34
  40. data/lib/rspec/mocks/any_instance/chain.rb +4 -34
  41. data/lib/rspec/mocks/any_instance/expectation_chain.rb +14 -4
  42. data/lib/rspec/mocks/any_instance/message_chains.rb +27 -12
  43. data/lib/rspec/mocks/any_instance/recorder.rb +23 -31
  44. data/lib/rspec/mocks/any_instance/stub_chain.rb +9 -4
  45. data/lib/rspec/mocks/argument_list_matcher.rb +8 -1
  46. data/lib/rspec/mocks/argument_matchers.rb +26 -12
  47. data/lib/rspec/mocks/arity_calculator.rb +66 -0
  48. data/lib/rspec/mocks/configuration.rb +42 -14
  49. data/lib/rspec/mocks/error_generator.rb +34 -10
  50. data/lib/rspec/mocks/example_methods.rb +64 -19
  51. data/lib/rspec/mocks/extensions/marshal.rb +0 -15
  52. data/lib/rspec/mocks/framework.rb +4 -4
  53. data/lib/rspec/mocks/instance_method_stasher.rb +80 -62
  54. data/lib/rspec/mocks/matchers/have_received.rb +18 -14
  55. data/lib/rspec/mocks/matchers/receive.rb +29 -7
  56. data/lib/rspec/mocks/matchers/receive_messages.rb +72 -0
  57. data/lib/rspec/mocks/message_expectation.rb +95 -148
  58. data/lib/rspec/mocks/method_double.rb +77 -139
  59. data/lib/rspec/mocks/method_reference.rb +95 -0
  60. data/lib/rspec/mocks/mock.rb +1 -1
  61. data/lib/rspec/mocks/mutate_const.rb +12 -9
  62. data/lib/rspec/mocks/object_reference.rb +90 -0
  63. data/lib/rspec/mocks/order_group.rb +49 -7
  64. data/lib/rspec/mocks/proxy.rb +72 -33
  65. data/lib/rspec/mocks/proxy_for_nil.rb +2 -2
  66. data/lib/rspec/mocks/space.rb +13 -18
  67. data/lib/rspec/mocks/stub_chain.rb +2 -2
  68. data/lib/rspec/mocks/syntax.rb +61 -36
  69. data/lib/rspec/mocks/targets.rb +40 -19
  70. data/lib/rspec/mocks/test_double.rb +12 -56
  71. data/lib/rspec/mocks/verifying_double.rb +77 -0
  72. data/lib/rspec/mocks/verifying_message_expecation.rb +60 -0
  73. data/lib/rspec/mocks/verifying_proxy.rb +151 -0
  74. data/lib/rspec/mocks/version.rb +1 -1
  75. data/spec/rspec/mocks/and_call_original_spec.rb +34 -30
  76. data/spec/rspec/mocks/and_yield_spec.rb +2 -2
  77. data/spec/rspec/mocks/any_instance/message_chains_spec.rb +1 -1
  78. data/spec/rspec/mocks/any_instance_spec.rb +53 -260
  79. data/spec/rspec/mocks/argument_expectation_spec.rb +4 -4
  80. data/spec/rspec/mocks/arity_calculator_spec.rb +95 -0
  81. data/spec/rspec/mocks/array_including_matcher_spec.rb +41 -0
  82. data/spec/rspec/mocks/at_least_spec.rb +4 -32
  83. data/spec/rspec/mocks/block_return_value_spec.rb +4 -135
  84. data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +10 -11
  85. data/spec/rspec/mocks/configuration_spec.rb +79 -0
  86. data/spec/rspec/mocks/double_spec.rb +10 -78
  87. data/spec/rspec/mocks/extensions/marshal_spec.rb +0 -8
  88. data/spec/rspec/mocks/failing_argument_matchers_spec.rb +49 -4
  89. data/spec/rspec/mocks/instance_method_stasher_spec.rb +20 -3
  90. data/spec/rspec/mocks/matchers/have_received_spec.rb +74 -0
  91. data/spec/rspec/mocks/matchers/receive_messages_spec.rb +140 -0
  92. data/spec/rspec/mocks/matchers/receive_spec.rb +82 -42
  93. data/spec/rspec/mocks/methods_spec.rb +1 -1
  94. data/spec/rspec/mocks/{bug_report_830_spec.rb → mock_expectation_error_spec.rb} +4 -3
  95. data/spec/rspec/mocks/mock_ordering_spec.rb +11 -0
  96. data/spec/rspec/mocks/mock_space_spec.rb +10 -1
  97. data/spec/rspec/mocks/mock_spec.rb +26 -82
  98. data/spec/rspec/mocks/multiple_return_value_spec.rb +1 -1
  99. data/spec/rspec/mocks/mutate_const_spec.rb +18 -5
  100. data/spec/rspec/mocks/null_object_mock_spec.rb +6 -4
  101. data/spec/rspec/mocks/options_hash_spec.rb +3 -3
  102. data/spec/rspec/mocks/order_group_spec.rb +27 -0
  103. data/spec/rspec/mocks/partial_mock_spec.rb +101 -1
  104. data/spec/rspec/mocks/passing_argument_matchers_spec.rb +3 -20
  105. data/spec/rspec/mocks/record_messages_spec.rb +4 -4
  106. data/spec/rspec/mocks/serialization_spec.rb +4 -6
  107. data/spec/rspec/mocks/space_spec.rb +3 -3
  108. data/spec/rspec/mocks/stub_chain_spec.rb +0 -12
  109. data/spec/rspec/mocks/stub_spec.rb +23 -44
  110. data/spec/rspec/mocks/test_double_spec.rb +3 -22
  111. data/spec/rspec/mocks/verifying_double_spec.rb +327 -0
  112. data/spec/rspec/mocks/verifying_message_expecation_spec.rb +68 -0
  113. data/spec/rspec/mocks_spec.rb +16 -39
  114. data/spec/spec_helper.rb +29 -18
  115. metadata +131 -86
  116. metadata.gz.sig +1 -0
  117. data/features/message_expectations/expect_any_instance_of.feature +0 -27
  118. data/lib/rspec/mocks/caller_filter.rb +0 -60
  119. data/lib/rspec/mocks/deprecation.rb +0 -26
  120. data/lib/rspec/mocks/extensions/instance_exec.rb +0 -34
  121. data/lib/rspec/mocks/extensions/proc.rb +0 -63
  122. data/lib/spec/mocks.rb +0 -4
  123. data/spec/rspec/mocks/and_return_spec.rb +0 -17
  124. data/spec/rspec/mocks/any_number_of_times_spec.rb +0 -36
  125. data/spec/rspec/mocks/before_all_spec.rb +0 -74
  126. data/spec/rspec/mocks/bug_report_10260_spec.rb +0 -8
  127. data/spec/rspec/mocks/bug_report_10263_spec.rb +0 -27
  128. data/spec/rspec/mocks/bug_report_11545_spec.rb +0 -32
  129. data/spec/rspec/mocks/bug_report_496_spec.rb +0 -17
  130. data/spec/rspec/mocks/bug_report_600_spec.rb +0 -22
  131. data/spec/rspec/mocks/bug_report_7611_spec.rb +0 -16
  132. data/spec/rspec/mocks/bug_report_8165_spec.rb +0 -31
  133. data/spec/rspec/mocks/bug_report_957_spec.rb +0 -22
@@ -9,8 +9,30 @@ module RSpec
9
9
  ::RSpec::Mocks.space.verify_all
10
10
  end
11
11
 
12
- def reset_all
13
- ::RSpec::Mocks.space.reset_all
12
+ describe "expectations/allowances on any instance recorders" do
13
+ include_context "with syntax", [:expect, :should]
14
+
15
+ it "warns about allow(Klass.any_instance).to receive..." do
16
+ expect(RSpec).to receive(:warning).with(/allow.*any_instance.*is probably not what you meant.*allow_any_instance_of.*instead/)
17
+ allow(Object.any_instance).to receive(:foo)
18
+ end
19
+
20
+ it "includes the correct call site in the allow warning" do
21
+ expect_warning_with_call_site(__FILE__, __LINE__ + 1)
22
+ allow(Object.any_instance).to receive(:foo)
23
+ end
24
+
25
+ it "warns about expect(Klass.any_instance).to receive..." do
26
+ expect(RSpec).to receive(:warning).with(/expect.*any_instance.*is probably not what you meant.*expect_any_instance_of.*instead/)
27
+ expect(Object.any_instance).to receive(:foo)
28
+ Object.any_instance.foo
29
+ end
30
+
31
+ it "includes the correct call site in the expect warning" do
32
+ expect_warning_with_call_site(__FILE__, __LINE__ + 1)
33
+ expect(Object.any_instance).to receive(:foo)
34
+ Object.any_instance.foo
35
+ end
14
36
  end
15
37
 
16
38
  shared_examples_for "a receive matcher" do |*options|
@@ -28,17 +50,6 @@ module RSpec
28
50
  }.to raise_error(/received :foo with unexpected arguments/)
29
51
  end
30
52
 
31
- it 'warns about the change to === in RSpec 3 when used with a DateTime' do
32
- wrapped.to receive(:foo).with(DateTime.new(2014,1,1,1))
33
- allow_deprecation
34
- receiver.foo(DateTime.new(2014,1,1,1))
35
-
36
- expect {
37
- expect_warn_deprecation_with_call_site __FILE__, __LINE__ + 1
38
- receiver.foo(DateTime.new(2014,1,1,2))
39
- }.to raise_error(/received :foo with unexpected arguments/)
40
- end
41
-
42
53
  it 'allows a `do...end` block implementation to be provided' do
43
54
  wrapped.to receive(:foo) do
44
55
  4
@@ -85,7 +96,7 @@ module RSpec
85
96
  end
86
97
 
87
98
  shared_examples_for "an expect syntax allowance" do |*options|
88
- include_examples "a receive matcher", *options
99
+ it_behaves_like "a receive matcher", *options
89
100
 
90
101
  it 'does not expect the message to be received' do
91
102
  wrapped.to receive(:foo)
@@ -106,7 +117,7 @@ module RSpec
106
117
  end
107
118
 
108
119
  shared_examples_for "an expect syntax expectation" do |*options|
109
- include_examples "a receive matcher", *options
120
+ it_behaves_like "a receive matcher", *options
110
121
 
111
122
  it 'sets up a message expectation that passes if the message is received' do
112
123
  wrapped.to receive(:foo)
@@ -120,8 +131,6 @@ module RSpec
120
131
  expect {
121
132
  verify_all
122
133
  }.to raise_error(RSpec::Mocks::MockExpectationError)
123
-
124
- reset_all
125
134
  end
126
135
 
127
136
  it "reports the line number of expectation of unreceived message", :pending => options.include?(:does_not_report_line_num) do
@@ -181,61 +190,92 @@ module RSpec
181
190
  end
182
191
  end
183
192
 
193
+ shared_examples_for "resets partial mocks cleanly" do
194
+ let(:klass) { Struct.new(:foo) }
195
+ let(:object) { klass.new :bar }
196
+
197
+ it "removes the method double" do
198
+ target.to receive(:foo).and_return(:baz)
199
+ expect { reset object }.to change { object.foo }.from(:baz).to(:bar)
200
+ end
201
+ end
202
+
203
+ shared_examples_for "resets partial mocks of any instance cleanly" do
204
+ let(:klass) { Struct.new(:foo) }
205
+ let(:object) { klass.new :bar }
206
+
207
+ it "removes the method double" do
208
+ target.to receive(:foo).and_return(:baz)
209
+ expect {
210
+ ::RSpec::Mocks.space.verify_all
211
+ }.to change { object.foo }.from(:baz).to(:bar)
212
+ end
213
+ end
214
+
184
215
  describe "allow(...).to receive" do
185
- include_examples "an expect syntax allowance" do
216
+ it_behaves_like "an expect syntax allowance" do
186
217
  let(:receiver) { double }
187
218
  let(:wrapped) { allow(receiver) }
188
219
  end
220
+ it_behaves_like "resets partial mocks cleanly" do
221
+ let(:target) { allow(object) }
222
+ end
189
223
  end
190
224
 
191
225
  describe "allow(...).not_to receive" do
192
- include_examples "an expect syntax negative allowance" do
226
+ it_behaves_like "an expect syntax negative allowance" do
193
227
  let(:wrapped) { allow(double) }
194
228
  end
195
229
  end
196
230
 
197
231
  describe "allow_any_instance_of(...).to receive" do
198
- before { allow_unavoidable_1_8_deprecation }
199
-
200
- include_examples "an expect syntax allowance" do
232
+ it_behaves_like "an expect syntax allowance" do
201
233
  let(:klass) { Class.new }
202
234
  let(:wrapped) { allow_any_instance_of(klass) }
203
235
  let(:receiver) { klass.new }
204
236
  end
237
+
238
+ it_behaves_like "resets partial mocks of any instance cleanly" do
239
+ let(:target) { allow_any_instance_of(klass) }
240
+ end
205
241
  end
206
242
 
207
243
  describe "allow_any_instance_of(...).not_to receive" do
208
- include_examples "an expect syntax negative allowance" do
244
+ it_behaves_like "an expect syntax negative allowance" do
209
245
  let(:wrapped) { allow_any_instance_of(Class.new) }
210
246
  end
211
247
  end
212
248
 
213
249
  describe "expect(...).to receive" do
214
- include_examples "an expect syntax expectation", :allow_other_matchers do
250
+ it_behaves_like "an expect syntax expectation", :allow_other_matchers do
215
251
  let(:receiver) { double }
216
252
  let(:wrapped) { expect(receiver) }
217
253
  end
254
+ it_behaves_like "resets partial mocks cleanly" do
255
+ let(:target) { expect(object) }
256
+ end
218
257
  end
219
258
 
220
259
  describe "expect_any_instance_of(...).to receive" do
221
- before { allow_unavoidable_1_8_deprecation }
222
-
223
- include_examples "an expect syntax expectation", :does_not_report_line_num do
260
+ it_behaves_like "an expect syntax expectation", :does_not_report_line_num do
224
261
  let(:klass) { Class.new }
225
262
  let(:wrapped) { expect_any_instance_of(klass) }
226
263
  let(:receiver) { klass.new }
227
264
  end
265
+ it_behaves_like "resets partial mocks of any instance cleanly" do
266
+ let(:target) { expect_any_instance_of(klass) }
267
+ end
228
268
  end
229
269
 
230
270
  describe "expect(...).not_to receive" do
231
- include_examples "an expect syntax negative expectation" do
271
+ it_behaves_like "an expect syntax negative expectation" do
232
272
  let(:receiver) { double }
233
273
  let(:wrapped) { expect(receiver) }
234
274
  end
235
275
  end
236
276
 
237
277
  describe "expect_any_instance_of(...).not_to receive" do
238
- include_examples "an expect syntax negative expectation" do
278
+ it_behaves_like "an expect syntax negative expectation" do
239
279
  let(:klass) { Class.new }
240
280
  let(:wrapped) { expect_any_instance_of(klass) }
241
281
  let(:receiver) { klass.new }
@@ -246,7 +286,7 @@ module RSpec
246
286
  it 'can use the `expect` syntax' do
247
287
  dbl = double
248
288
 
249
- framework.new.instance_eval do
289
+ framework.new.instance_exec do
250
290
  expect(dbl).to receive(:foo).and_return(3)
251
291
  end
252
292
 
@@ -256,7 +296,7 @@ module RSpec
256
296
  it 'expects the method to be called when `expect` is used' do
257
297
  dbl = double
258
298
 
259
- framework.new.instance_eval do
299
+ framework.new.instance_exec do
260
300
  expect(dbl).to receive(:foo)
261
301
  end
262
302
 
@@ -266,7 +306,7 @@ module RSpec
266
306
  it 'supports `expect(...).not_to receive`' do
267
307
  dbl = double
268
308
 
269
- framework.new.instance_eval do
309
+ framework.new.instance_exec do
270
310
  expect(dbl).not_to receive(:foo)
271
311
  end
272
312
 
@@ -276,7 +316,7 @@ module RSpec
276
316
  it 'supports `expect(...).to_not receive`' do
277
317
  dbl = double
278
318
 
279
- framework.new.instance_eval do
319
+ framework.new.instance_exec do
280
320
  expect(dbl).to_not receive(:foo)
281
321
  end
282
322
 
@@ -295,14 +335,14 @@ module RSpec
295
335
  end
296
336
  end
297
337
 
298
- include_examples "using rspec-mocks in another test framework"
338
+ it_behaves_like "using rspec-mocks in another test framework"
299
339
 
300
340
  it 'cannot use `expect` with another matcher' do
301
341
  expect {
302
- framework.new.instance_eval do
342
+ framework.new.instance_exec do
303
343
  expect(3).to eq(3)
304
344
  end
305
- }.to raise_error(/only the `receive` matcher is supported/)
345
+ }.to raise_error(/only the `receive` or `receive_messages` matchers are supported with `expect\(...\).to`/)
306
346
  end
307
347
 
308
348
  it 'can toggle the available syntax' do
@@ -319,7 +359,7 @@ module RSpec
319
359
  context "when rspec-expectations is included in the test framework first" do
320
360
  before do
321
361
  # the examples here assume `expect` is define in RSpec::Matchers...
322
- expect(RSpec::Matchers.method_defined?(:expect)).to be true
362
+ expect(RSpec::Matchers.method_defined?(:expect)).to be_truthy
323
363
  end
324
364
 
325
365
  let(:framework) do
@@ -329,10 +369,10 @@ module RSpec
329
369
  end
330
370
  end
331
371
 
332
- include_examples "using rspec-mocks in another test framework"
372
+ it_behaves_like "using rspec-mocks in another test framework"
333
373
 
334
374
  it 'can use `expect` with any matcher' do
335
- framework.new.instance_eval do
375
+ framework.new.instance_exec do
336
376
  expect(3).to eq(3)
337
377
  end
338
378
  end
@@ -341,7 +381,7 @@ module RSpec
341
381
  context "when rspec-expectations is included in the test framework last" do
342
382
  before do
343
383
  # the examples here assume `expect` is define in RSpec::Matchers...
344
- expect(RSpec::Matchers.method_defined?(:expect)).to be true
384
+ expect(RSpec::Matchers.method_defined?(:expect)).to be_truthy
345
385
  end
346
386
 
347
387
  let(:framework) do
@@ -351,10 +391,10 @@ module RSpec
351
391
  end
352
392
  end
353
393
 
354
- include_examples "using rspec-mocks in another test framework"
394
+ it_behaves_like "using rspec-mocks in another test framework"
355
395
 
356
396
  it 'can use `expect` with any matcher' do
357
- framework.new.instance_eval do
397
+ framework.new.instance_exec do
358
398
  expect(3).to eq(3)
359
399
  end
360
400
  end
@@ -18,7 +18,7 @@ module RSpec
18
18
  expect(added_methods).to match_array([
19
19
  :as_null_object, :null_object?,
20
20
  :received_message?, :should_not_receive, :should_receive,
21
- :stub, :stub!, :stub_chain, :unstub, :unstub!
21
+ :stub, :stub_chain, :unstub
22
22
  ])
23
23
  end
24
24
  end
@@ -2,7 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  module RSpec
4
4
  module Mocks
5
- describe 'Calling a method that catches StandardError' do
5
+ describe 'MockExpectationError' do
6
+
6
7
  class Foo
7
8
  def self.foo
8
9
  bar
@@ -10,8 +11,8 @@ module RSpec
10
11
  end
11
12
  end
12
13
 
13
- it 'still reports mock failures' do
14
- Foo.should_not_receive :bar
14
+ it 'is not caught by StandardError rescue blocks' do
15
+ expect(Foo).not_to receive(:bar)
15
16
  expect {
16
17
  Foo.foo
17
18
  }.to raise_error(RSpec::Mocks::MockExpectationError)
@@ -16,6 +16,17 @@ module RSpec
16
16
  @double.three
17
17
  end
18
18
 
19
+ it "passes when messages are received in order" do
20
+ @double.stub(:something)
21
+ @double.should_receive(:one).ordered
22
+ @double.should_receive(:two).ordered
23
+ @double.should_receive(:three).at_least(:once).ordered
24
+ @double.one
25
+ @double.two
26
+ @double.three
27
+ @double.three
28
+ end
29
+
19
30
  it "passes when messages are received in order across objects" do
20
31
  a = double("a")
21
32
  b = double("b")
@@ -9,7 +9,6 @@ module RSpec
9
9
  let(:dbl_2) { Object.new }
10
10
 
11
11
  before do
12
- space.outside_example = false
13
12
  space.ensure_registered(dbl_1)
14
13
  space.ensure_registered(dbl_2)
15
14
  end
@@ -98,6 +97,16 @@ module RSpec
98
97
  expect(r1).to be(r2)
99
98
  expect(r1).not_to be(r3)
100
99
  end
100
+
101
+ it 'removes an any_instance_recorder when requested' do
102
+ klass = Class.new
103
+
104
+ space.any_instance_recorder_for(klass)
105
+
106
+ expect {
107
+ space.remove_any_instance_recorder_for(klass)
108
+ }.to change { space.any_instance_recorders.size }.by(-1)
109
+ end
101
110
  end
102
111
  end
103
112
  end
@@ -2,35 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  module RSpec
4
4
  module Mocks
5
- describe "::Mock" do
6
- before { allow_deprecation }
7
-
8
- it 'returns a reference to Double' do
9
- expect(RSpec::Mocks::Mock).to be(RSpec::Mocks::Double)
10
- end
11
-
12
- it 'prints a deprecation warning' do
13
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
14
- RSpec::Mocks::Mock
15
- end
16
-
17
- it 'does not clobber the normal const missing behavior' do
18
- expect {
19
- RSpec::Mocks::AZBYCX
20
- }.to raise_error(NameError, /RSpec::Mocks::AZBYCX/)
21
- end
22
- end
23
-
24
- describe Double do
5
+ describe Mock do
25
6
  before(:each) { @double = double("test double") }
26
7
  after(:each) { reset @double }
27
8
 
28
9
  it "has method_missing as private" do
29
- expect(RSpec::Mocks::Double.private_instance_methods).to include_method(:method_missing)
10
+ expect(RSpec::Mocks::Mock.private_instance_methods).to include_method(:method_missing)
30
11
  end
31
12
 
32
13
  it "does not respond_to? method_missing (because it's private)" do
33
- expect(RSpec::Mocks::Double.new).not_to respond_to(:method_missing)
14
+ expect(RSpec::Mocks::Mock.new).not_to respond_to(:method_missing)
34
15
  end
35
16
 
36
17
  it "reports line number of expectation of unreceived message" do
@@ -67,28 +48,18 @@ module RSpec
67
48
  }.to raise_error(/trying to negate it again/)
68
49
  end
69
50
 
70
- def expect_and_return_warning
71
- expect(RSpec).to receive(:deprecate).with(/`and_return` on a negative message expectation/)
72
- end
73
-
74
- it "warns when `should_not_receive().and_return` is used" do
75
- expect_and_return_warning
76
- @double.should_not_receive(:foo).and_return(1)
77
- end
78
-
79
- it "warns when `should_receive().never.and_return` is used" do
80
- expect_and_return_warning
81
- @double.should_receive(:foo).never.and_return(1)
82
- end
51
+ it "warns when `and_return` is called on a negative expectation" do
52
+ expect {
53
+ @double.should_not_receive(:do_something).and_return(1)
54
+ }.to raise_error(/not supported/)
83
55
 
84
- it "warns when `expect().not_to receive().and_return` is used" do
85
- expect_and_return_warning
86
- expect(@double).not_to receive(:foo).and_return(1)
87
- end
56
+ expect {
57
+ expect(@double).not_to receive(:do_something).and_return(1)
58
+ }.to raise_error(/not supported/)
88
59
 
89
- it "warns when `expect().to receive().never.and_return` is used" do
90
- expect_and_return_warning
91
- expect(@double).to receive(:foo).never.and_return(1)
60
+ expect {
61
+ expect(@double).to receive(:do_something).never.and_return(1)
62
+ }.to raise_error(/not supported/)
92
63
  end
93
64
 
94
65
  it "passes when receiving message specified as not to be received with different args" do
@@ -161,7 +132,6 @@ module RSpec
161
132
  end
162
133
 
163
134
  it "allows block to calculate return values" do
164
- allow_deprecation
165
135
  @double.should_receive(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
166
136
  expect(@double.something("a","b","c")).to eq "cba"
167
137
  verify @double
@@ -254,7 +224,7 @@ module RSpec
254
224
 
255
225
  it "fails if expectation block fails" do
256
226
  @double.should_receive(:something) do |bool|
257
- expect(bool).to be true
227
+ expect(bool).to be_truthy
258
228
  end
259
229
 
260
230
  expect {
@@ -287,28 +257,19 @@ module RSpec
287
257
  @double.foo { :bar }
288
258
  end
289
259
 
290
- context "with Ruby > 1.8.6", :unless => RUBY_VERSION.to_s == '1.8.6' do
291
- it "passes proc to expectation block without an argument" do
292
- # We eval this because Ruby 1.8.6's syntax parser barfs on { |&block| ... }
293
- # and prevents the entire spec suite from running.
294
- eval("@double.should_receive(:foo) {|&block| expect(block.call).to eq(:bar)}")
295
- @double.foo { :bar }
296
- end
297
-
298
- it "passes proc to expectation block with an argument" do
299
- eval("@double.should_receive(:foo) {|arg, &block| expect(block.call).to eq(:bar)}")
300
- @double.foo(:arg) { :bar }
301
- end
260
+ it "passes proc to expectation block with an argument" do
261
+ @double.should_receive(:foo) { |arg, &block| expect(block.call).to eq(:bar) }
262
+ @double.foo(:arg) { :bar }
263
+ end
302
264
 
303
- it "passes proc to stub block without an argurment" do
304
- eval("@double.stub(:foo) {|&block| expect(block.call).to eq(:bar)}")
305
- @double.foo { :bar }
306
- end
265
+ it "passes proc to stub block without an argurment" do
266
+ @double.stub(:foo) { |&block| expect(block.call).to eq(:bar) }
267
+ @double.foo { :bar }
268
+ end
307
269
 
308
- it "passes proc to stub block with an argument" do
309
- eval("@double.stub(:foo) {|arg, &block| expect(block.call).to eq(:bar)}")
310
- @double.foo(:arg) { :bar }
311
- end
270
+ it "passes proc to stub block with an argument" do
271
+ @double.stub(:foo) { |arg, &block| expect(block.call).to eq(:bar) }
272
+ @double.foo(:arg) { :bar }
312
273
  end
313
274
 
314
275
  it "fails right away when method defined as never is received" do
@@ -651,7 +612,7 @@ module RSpec
651
612
  end
652
613
 
653
614
  it "assigns stub return values" do
654
- double = RSpec::Mocks::Double.new('name', :message => :response)
615
+ double = RSpec::Mocks::Mock.new('name', :message => :response)
655
616
  expect(double.message).to eq :response
656
617
  end
657
618
 
@@ -709,16 +670,6 @@ module RSpec
709
670
  expect(@calls).to eq 10
710
671
  end
711
672
 
712
- it "calls the block after #any_number_of_times" do
713
- expect(RSpec).to receive(:deprecate).with("any_number_of_times", :replacement => "stub")
714
-
715
- @double.should_receive(:foo).any_number_of_times { add_call }
716
-
717
- (1..7).each { @double.foo }
718
-
719
- expect(@calls).to eq 7
720
- end
721
-
722
673
  it "calls the block after #ordered" do
723
674
  @double.should_receive(:foo).ordered { add_call }
724
675
  @double.should_receive(:bar).ordered { add_call }
@@ -776,13 +727,6 @@ module RSpec
776
727
  @double.should_receive(:foo).with('bar')
777
728
  @double.foo('bar')
778
729
  end
779
-
780
- it 'includes callsite in deprecation when called without arguments' do
781
- obj = Object.new
782
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /Using `with` without arguments/)
783
- obj.stub(:foo).with().and_return('bar')
784
- expect(obj.foo).to eq('bar')
785
- end
786
730
  end
787
731
 
788
732
  context "with non-matching args" do