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
@@ -3,17 +3,15 @@ require 'spec_helper'
3
3
  module RSpec
4
4
  module Mocks
5
5
  describe TestDouble do
6
- before { allow_deprecation }
7
-
8
6
  before(:all) do
9
- Module.class_eval do
7
+ Module.class_exec do
10
8
  private
11
9
  def use; end
12
10
  end
13
11
  end
14
12
 
15
13
  after(:all) do
16
- Module.class_eval do
14
+ Module.class_exec do
17
15
  undef use
18
16
  end
19
17
  end
@@ -30,12 +28,7 @@ module RSpec
30
28
 
31
29
  it 'sets the test double name when a name is passed' do
32
30
  double = Module.new { TestDouble.extend_onto(self, "MyDouble") }
33
- expect { double.foo }.to raise_error(/Mock "MyDouble" received/)
34
- end
35
-
36
- it 'warns when `extend_onto` is used' do
37
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /RSpec::Mocks::TestDouble.extend_onto/)
38
- Module.new { TestDouble.extend_onto(self) }
31
+ expect { double.foo }.to raise_error(/Double "MyDouble" received/)
39
32
  end
40
33
 
41
34
  [[:should, :expect], [:expect], [:should]].each do |syntax|
@@ -51,18 +44,6 @@ module RSpec
51
44
  end
52
45
  end
53
46
  end
54
-
55
- it 'indicates what type of test double it is in error messages' do
56
- double = Module.new do
57
- TestDouble.extend_onto(self, "A", :__declared_as => "ModuleMock")
58
- end
59
- expect { double.foo }.to raise_error(/ModuleMock "A"/)
60
- end
61
-
62
- it 'is declared as a mock by default' do
63
- double = Module.new { TestDouble.extend_onto(self) }
64
- expect { double.foo }.to raise_error(/Mock received/)
65
- end
66
47
  end
67
48
  end
68
49
  end
@@ -0,0 +1,327 @@
1
+ require 'spec_helper'
2
+
3
+ class LoadedClass
4
+ M = :m
5
+ N = :n
6
+ INSTANCE = LoadedClass.new
7
+
8
+ def defined_instance_method; end
9
+ def self.defined_class_method; end
10
+
11
+ def respond_to?(method_name)
12
+ return true if method_name == :dynamic_instance_method
13
+ super
14
+ end
15
+
16
+ def self.respond_to?(method_name)
17
+ return true if method_name == :dynamic_class_method
18
+ super
19
+ end
20
+
21
+ def self.send
22
+ # fake out!
23
+ end
24
+
25
+ class Nested; end
26
+ end
27
+
28
+ module RSpec
29
+ module Mocks
30
+ describe 'verifying doubles' do
31
+ describe 'instance doubles' do
32
+ describe 'when doubled class is not loaded' do
33
+ include_context "with isolated configuration"
34
+
35
+ before do
36
+ RSpec::Mocks.configuration.verify_doubled_constant_names = false
37
+ end
38
+
39
+ it 'allows any instance method to be stubbed' do
40
+ o = instance_double('NonloadedClass')
41
+ o.stub(:undefined_instance_method).with(:arg).and_return(true)
42
+ expect(o.undefined_instance_method(:arg)).to eq(true)
43
+ end
44
+
45
+ it 'allows any instance method to be expected' do
46
+ o = instance_double("NonloadedClass")
47
+
48
+ expect(o).to receive(:undefined_instance_method).
49
+ with(:arg).
50
+ and_return(true)
51
+
52
+ expect(o.undefined_instance_method(:arg)).to eq(true)
53
+ end
54
+ end
55
+
56
+ describe 'when doubled class is loaded' do
57
+ include_context "with isolated configuration"
58
+
59
+ before do
60
+ RSpec::Mocks.configuration.verify_doubled_constant_names = true
61
+ end
62
+
63
+ it 'only allows instance methods that exist to be stubbed' do
64
+ o = instance_double('LoadedClass', :defined_instance_method => 1)
65
+ expect(o.defined_instance_method).to eq(1)
66
+
67
+ prevents { o.stub(:undefined_instance_method) }
68
+ prevents { o.stub(:defined_class_method) }
69
+ end
70
+
71
+ it 'only allows instance methods that exist to be expected' do
72
+ o = instance_double('LoadedClass')
73
+ expect(o).to receive(:defined_instance_method)
74
+ o.defined_instance_method
75
+
76
+ prevents { expect(o).to receive(:undefined_instance_method) }
77
+ prevents { expect(o).to receive(:defined_class_method) }
78
+ prevents { o.should_receive(:undefined_instance_method) }
79
+ prevents { o.should_receive(:defined_class_method) }
80
+ end
81
+
82
+ it 'does not allow dynamic methods to be expected' do
83
+ # This isn't possible at the moment since an instance of the class
84
+ # would be required for the verification, and we only have the
85
+ # class itself.
86
+ #
87
+ # This spec exists as "negative" documentation of the absence of a
88
+ # feature, to highlight the asymmetry from class doubles (that do
89
+ # support this behaviour).
90
+ prevents {
91
+ instance_double('LoadedClass', :dynamic_instance_method => 1)
92
+ }
93
+ end
94
+
95
+ it 'checks the arity of stubbed methods' do
96
+ o = instance_double('LoadedClass')
97
+ prevents {
98
+ expect(o).to receive(:defined_instance_method).with(:a)
99
+ }
100
+ end
101
+
102
+ it 'checks that stubbed methods are invoked with the correct arity' do
103
+ o = instance_double('LoadedClass', :defined_instance_method => 25)
104
+ expect {
105
+ o.defined_instance_method(:a)
106
+ }.to raise_error(ArgumentError)
107
+ end
108
+
109
+ it 'allows class to be specified by constant' do
110
+ o = instance_double(LoadedClass, :defined_instance_method => 1)
111
+ expect(o.defined_instance_method).to eq(1)
112
+ end
113
+
114
+ it 'only allows defined methods for null objects' do
115
+ o = instance_double('LoadedClass').as_null_object
116
+
117
+ expect(o.defined_instance_method).to eq(o)
118
+ prevents { o.undefined_method }
119
+ end
120
+ end
121
+
122
+ it 'cannot be constructed with a non-module object' do
123
+ expect {
124
+ instance_double(Object.new)
125
+ }.to raise_error(/Module or String expected/)
126
+ end
127
+
128
+ it 'can be constructed with a struct' do
129
+ o = instance_double(Struct.new(:defined_method), :defined_method => 1)
130
+
131
+ expect(o.defined_method).to eq(1)
132
+ end
133
+ end
134
+
135
+ describe 'class doubles' do
136
+ describe 'when doubled class is not loaded' do
137
+ include_context "with isolated configuration"
138
+
139
+ before do
140
+ RSpec::Mocks.configuration.verify_doubled_constant_names = false
141
+ end
142
+
143
+ it 'allows any method to be stubbed' do
144
+ o = class_double('NonloadedClass')
145
+ allow(o).to receive(:undefined_instance_method).with(:arg).and_return(1)
146
+ expect(o.undefined_instance_method(:arg)).to eq(1)
147
+ end
148
+ end
149
+
150
+ describe 'when doubled class is loaded' do
151
+ include_context "with isolated configuration"
152
+
153
+ before do
154
+ RSpec::Mocks.configuration.verify_doubled_constant_names = true
155
+ end
156
+
157
+ it 'only allows class methods that exist to be stubbed' do
158
+ o = class_double('LoadedClass', :defined_class_method => 1)
159
+ expect(o.defined_class_method).to eq(1)
160
+
161
+ prevents { o.stub(:undefined_instance_method) }
162
+ prevents { o.stub(:defined_instance_method) }
163
+ end
164
+
165
+ it 'only allows class methods that exist to be expected' do
166
+ o = class_double('LoadedClass')
167
+ expect(o).to receive(:defined_class_method)
168
+ o.defined_class_method
169
+
170
+ prevents { expect(o).to receive(:undefined_instance_method) }
171
+ prevents { expect(o).to receive(:defined_instance_method) }
172
+ prevents { o.should_receive(:undefined_instance_method) }
173
+ prevents { o.should_receive(:defined_instance_method) }
174
+ end
175
+
176
+ it 'checks that stubbed methods are invoked with the correct arity' do
177
+ o = class_double('LoadedClass', :defined_class_method => 1)
178
+ expect {
179
+ o.defined_class_method(:a)
180
+ }.to raise_error(ArgumentError)
181
+ end
182
+
183
+ it 'allows dynamically defined class method stubs with arguments' do
184
+ o = class_double('LoadedClass')
185
+ allow(o).to receive(:dynamic_class_method).with(:a) { 1 }
186
+
187
+ expect(o.dynamic_class_method(:a)).to eq(1)
188
+ end
189
+
190
+ it 'allows dynamically defined class method mocks with arguments' do
191
+ o = class_double('LoadedClass')
192
+ expect(o).to receive(:dynamic_class_method).with(:a)
193
+
194
+ o.dynamic_class_method(:a)
195
+ end
196
+
197
+ it 'allows dynamically defined class methods to be expected' do
198
+ o = class_double('LoadedClass', :dynamic_class_method => 1)
199
+ expect(o.dynamic_class_method).to eq(1)
200
+ end
201
+
202
+ it 'allows class to be specified by constant' do
203
+ o = class_double(LoadedClass, :defined_class_method => 1)
204
+ expect(o.defined_class_method).to eq(1)
205
+ end
206
+
207
+ it 'can replace existing constants for the duration of the test' do
208
+ original = LoadedClass
209
+ object = class_double('LoadedClass').as_stubbed_const
210
+ expect(object).to receive(:defined_class_method)
211
+
212
+ expect(LoadedClass).to eq(object)
213
+ ::RSpec::Mocks.space.reset_all
214
+ expect(LoadedClass).to eq(original)
215
+ end
216
+
217
+ it 'can transfer nested constants to the double' do
218
+ class_double("LoadedClass").
219
+ as_stubbed_const(:transfer_nested_constants => true)
220
+ expect(LoadedClass::M).to eq(:m)
221
+ expect(LoadedClass::N).to eq(:n)
222
+ end
223
+
224
+ it 'correctly verifies expectations when constant is removed' do
225
+ dbl1 = class_double(LoadedClass::Nested).as_stubbed_const
226
+ class_double(LoadedClass).as_stubbed_const
227
+
228
+ prevents {
229
+ expect(dbl1).to receive(:undefined_class_method)
230
+ }
231
+ end
232
+
233
+ it 'only allows defined methods for null objects' do
234
+ o = class_double('LoadedClass').as_null_object
235
+
236
+ expect(o.defined_class_method).to eq(o)
237
+ prevents { o.undefined_method }
238
+ end
239
+ end
240
+
241
+ it 'cannot be constructed with a non-module object' do
242
+ expect {
243
+ class_double(Object.new)
244
+ }.to raise_error(/Module or String expected/)
245
+ end
246
+ end
247
+
248
+ describe 'object doubles' do
249
+ it 'replaces an unloaded constant' do
250
+ o = object_double("LoadedClass::NOINSTANCE").as_stubbed_const
251
+
252
+ expect(LoadedClass::NOINSTANCE).to eq(o)
253
+
254
+ expect(o).to receive(:undefined_instance_method)
255
+ o.undefined_instance_method
256
+ end
257
+
258
+ it 'replaces a constant by name and verifies instances methods' do
259
+ o = object_double("LoadedClass::INSTANCE").as_stubbed_const
260
+
261
+ expect(LoadedClass::INSTANCE).to eq(o)
262
+
263
+ prevents { expect(o).to receive(:undefined_instance_method) }
264
+ prevents { expect(o).to receive(:defined_class_method) }
265
+ prevents { o.defined_instance_method }
266
+
267
+ expect(o).to receive(:defined_instance_method)
268
+ o.defined_instance_method
269
+ end
270
+
271
+ it 'can create a double that matches the interface of any arbitrary object' do
272
+ o = object_double(LoadedClass.new)
273
+
274
+ prevents { expect(o).to receive(:undefined_instance_method) }
275
+ prevents { expect(o).to receive(:defined_class_method) }
276
+ prevents { o.defined_instance_method }
277
+
278
+ expect(o).to receive(:defined_instance_method)
279
+ o.defined_instance_method
280
+ end
281
+
282
+ it 'does not allow transferring constants to an object' do
283
+ expect {
284
+ object_double("LoadedClass::INSTANCE").
285
+ as_stubbed_const(:transfer_nested_constants => true)
286
+ }.to raise_error(/Cannot transfer nested constants/)
287
+ end
288
+
289
+ it 'does not allow as_stubbed_constant for real objects' do
290
+ expect {
291
+ object_double(LoadedClass.new).as_stubbed_const
292
+ }.to raise_error(/Can not perform constant replacement with an object/)
293
+ end
294
+
295
+ it 'is not a module' do
296
+ expect(object_double("LoadedClass::INSTANCE")).to_not be_a(Module)
297
+ end
298
+ end
299
+
300
+
301
+ describe 'when verify_doubled_constant_names config option is set' do
302
+ include_context "with isolated configuration"
303
+
304
+ before do
305
+ RSpec::Mocks.configuration.verify_doubled_constant_names = true
306
+ end
307
+
308
+ it 'prevents creation of instance doubles for unloaded constants' do
309
+ expect {
310
+ instance_double('LoadedClas')
311
+ }.to raise_error(NameError)
312
+ end
313
+
314
+ it 'prevents creation of class doubles for unloaded constants' do
315
+ expect {
316
+ class_double('LoadedClas')
317
+ }.to raise_error(NameError)
318
+ end
319
+ end
320
+
321
+ it 'can only be named with a string or a module' do
322
+ expect { instance_double(1) }.to raise_error(ArgumentError)
323
+ expect { instance_double(nil) }.to raise_error(ArgumentError)
324
+ end
325
+ end
326
+ end
327
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec
4
+ module Mocks
5
+ describe VerifyingMessageExpectation do
6
+ describe '#with' do
7
+ let(:error_generator) { double.as_null_object }
8
+ let(:string_module_reference) { DirectModuleReference.new(String) }
9
+
10
+ subject {
11
+ null = double.as_null_object
12
+
13
+ described_class.new(error_generator, null, null, null)
14
+ }
15
+
16
+ describe 'when expected method is not loaded' do
17
+ it 'allows any arguments to be expected' do
18
+ subject.with(:foo, :bar)
19
+ end
20
+ end
21
+
22
+ describe 'when arity match fails' do
23
+ it 'raises error' do
24
+ subject.method_reference = InstanceMethodReference.new(string_module_reference, :replace)
25
+ expect(error_generator).to receive(:raise_arity_error).
26
+ with(instance_of(ArityCalculator), 2)
27
+
28
+ subject.with("abc123", "xyz987")
29
+ end
30
+ end
31
+
32
+ describe 'when called with arguments' do
33
+ it 'matches arity against the number of arguments' do
34
+ subject.method_reference = InstanceMethodReference.new(string_module_reference, :replace)
35
+ expect(error_generator).not_to receive(:raise_arity_error)
36
+
37
+ subject.with("abc123")
38
+ end
39
+ end
40
+
41
+ describe 'when called with any arguments matcher' do
42
+ it 'does not try to match arity' do
43
+ subject.method_reference = InstanceMethodReference.new(string_module_reference, :replace)
44
+ subject.with(any_args)
45
+ end
46
+ end
47
+
48
+ describe 'when called with no arguments matcher' do
49
+ it 'matches arity to 0' do
50
+ subject.method_reference = InstanceMethodReference.new(string_module_reference, :replace)
51
+ expect(error_generator).to receive(:raise_arity_error).
52
+ with(instance_of(ArityCalculator), 0)
53
+
54
+ subject.with(no_args)
55
+ end
56
+ end
57
+
58
+ describe 'when called with no arguments and no block' do
59
+ it 'raises' do
60
+ expect {
61
+ subject.with
62
+ }.to raise_error(ArgumentError)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -2,25 +2,6 @@ require "spec_helper"
2
2
 
3
3
  describe RSpec::Mocks do
4
4
  describe "::setup" do
5
- it "prints a deprecation warning when given a non-rspec host" do
6
- o = Object.new
7
- expect(RSpec).to receive(:deprecate).with(
8
- "The host argument to `RSpec::Mocks.setup`",
9
- :replacement=>"`include RSpec::Mocks::ExampleMethods` in #{o}"
10
- )
11
- RSpec::Mocks::setup(o)
12
- end
13
-
14
- it "prints the deprecation warning with the correct line" do
15
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
16
- RSpec::Mocks::setup(Object.new)
17
- end
18
-
19
- it "does not print a deprecation warning when self (the example group) is passed." do
20
- expect(RSpec).not_to receive(:deprecate)
21
- RSpec::Mocks::setup(self)
22
- end
23
-
24
5
  context "with an existing Mock::Space" do
25
6
  before do
26
7
  @orig_space = RSpec::Mocks::space
@@ -31,12 +12,20 @@ describe RSpec::Mocks do
31
12
  end
32
13
 
33
14
  it "memoizes the space" do
34
- RSpec::Mocks::setup
15
+ RSpec::Mocks::setup(Object.new)
35
16
  space = RSpec::Mocks::space
36
- RSpec::Mocks::setup
17
+ RSpec::Mocks::setup(Object.new)
37
18
  expect(RSpec::Mocks::space).to equal(space)
38
19
  end
39
20
  end
21
+
22
+ context "with no pre-existing Mock::Space" do
23
+ it "initializes a Mock::Space" do
24
+ RSpec::Mocks::space = nil
25
+ RSpec::Mocks::setup(Object.new)
26
+ expect(RSpec::Mocks::space).not_to be_nil
27
+ end
28
+ end
40
29
  end
41
30
 
42
31
  describe "::verify" do
@@ -51,11 +40,12 @@ describe RSpec::Mocks do
51
40
 
52
41
  describe "::teardown" do
53
42
  it "delegates to the space" do
54
- foo = "foo"
55
- foo.stub(:reverse) { "reversed" }
56
- RSpec::Mocks.teardown
57
- RSpec::Mocks.setup
58
- expect(foo.reverse).to eq("oof")
43
+ foo = double
44
+ foo.should_receive(:bar)
45
+ RSpec::Mocks::teardown
46
+ expect do
47
+ foo.bar
48
+ end.to raise_error(/received unexpected message/)
59
49
  end
60
50
  end
61
51
 
@@ -66,13 +56,6 @@ describe RSpec::Mocks do
66
56
  end
67
57
  end
68
58
 
69
- context 'when requiring spec/mocks (as was valid for rspec 1)' do
70
- it 'prints a deprecation warning' do
71
- expect(::RSpec).to receive(:deprecate).with("require 'spec/mocks'", :replacement => "require 'rspec/mocks'")
72
- load "spec/mocks.rb"
73
- end
74
- end
75
-
76
59
  def file_contents_for(lib, filename)
77
60
  # http://rubular.com/r/HYpUMftlG2
78
61
  path = $LOAD_PATH.find { |p| p.match(/\/rspec-#{lib}(-[a-f0-9]+)?\/lib/) }
@@ -80,10 +63,4 @@ describe RSpec::Mocks do
80
63
  File.read(file)
81
64
  end
82
65
 
83
- it 'has an up-to-date caller_filter file' do
84
- mocks = file_contents_for("mocks", "rspec/mocks/caller_filter.rb")
85
- core = file_contents_for("core", "rspec/core/caller_filter.rb")
86
-
87
- expect(mocks).to eq(core)
88
- end
89
66
  end