rspec-mocks 3.0.0.beta2 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Changelog.md +104 -36
  5. data/README.md +35 -4
  6. data/lib/rspec/mocks.rb +52 -13
  7. data/lib/rspec/mocks/any_instance.rb +10 -0
  8. data/lib/rspec/mocks/any_instance/chain.rb +17 -0
  9. data/lib/rspec/mocks/any_instance/expect_chain_chain.rb +1 -1
  10. data/lib/rspec/mocks/any_instance/expectation_chain.rb +9 -6
  11. data/lib/rspec/mocks/any_instance/message_chains.rb +10 -1
  12. data/lib/rspec/mocks/any_instance/proxy.rb +112 -0
  13. data/lib/rspec/mocks/any_instance/recorder.rb +49 -18
  14. data/lib/rspec/mocks/any_instance/stub_chain.rb +5 -3
  15. data/lib/rspec/mocks/any_instance/stub_chain_chain.rb +1 -1
  16. data/lib/rspec/mocks/argument_list_matcher.rb +5 -3
  17. data/lib/rspec/mocks/argument_matchers.rb +28 -12
  18. data/lib/rspec/mocks/configuration.rb +29 -0
  19. data/lib/rspec/mocks/error_generator.rb +2 -5
  20. data/lib/rspec/mocks/example_methods.rb +122 -13
  21. data/lib/rspec/mocks/instance_method_stasher.rb +26 -2
  22. data/lib/rspec/mocks/marshal_extension.rb +41 -0
  23. data/lib/rspec/mocks/matchers/expectation_customization.rb +20 -0
  24. data/lib/rspec/mocks/matchers/receive.rb +6 -20
  25. data/lib/rspec/mocks/matchers/receive_message_chain.rb +7 -5
  26. data/lib/rspec/mocks/matchers/receive_messages.rb +1 -2
  27. data/lib/rspec/mocks/message_chain.rb +9 -9
  28. data/lib/rspec/mocks/message_expectation.rb +6 -5
  29. data/lib/rspec/mocks/method_double.rb +67 -10
  30. data/lib/rspec/mocks/method_reference.rb +1 -1
  31. data/lib/rspec/mocks/mutate_const.rb +10 -14
  32. data/lib/rspec/mocks/object_reference.rb +7 -4
  33. data/lib/rspec/mocks/proxy.rb +95 -8
  34. data/lib/rspec/mocks/space.rb +58 -9
  35. data/lib/rspec/mocks/syntax.rb +128 -210
  36. data/lib/rspec/mocks/targets.rb +6 -8
  37. data/lib/rspec/mocks/test_double.rb +16 -25
  38. data/lib/rspec/mocks/verifying_double.rb +15 -12
  39. data/lib/rspec/mocks/verifying_message_expecation.rb +3 -3
  40. data/lib/rspec/mocks/verifying_proxy.rb +23 -17
  41. data/lib/rspec/mocks/version.rb +3 -1
  42. metadata +29 -257
  43. metadata.gz.sig +0 -0
  44. data/features/README.md +0 -75
  45. data/features/Scope.md +0 -17
  46. data/features/Upgrade.md +0 -22
  47. data/features/argument_matchers/README.md +0 -27
  48. data/features/argument_matchers/explicit.feature +0 -59
  49. data/features/argument_matchers/general_matchers.feature +0 -85
  50. data/features/argument_matchers/type_matchers.feature +0 -26
  51. data/features/message_expectations/README.md +0 -75
  52. data/features/message_expectations/allow_any_instance_of.feature +0 -26
  53. data/features/message_expectations/any_instance.feature +0 -43
  54. data/features/message_expectations/block_local_expectations.feature.pending +0 -55
  55. data/features/message_expectations/call_original.feature +0 -23
  56. data/features/message_expectations/expect_message_using_expect.feature +0 -107
  57. data/features/message_expectations/expect_message_using_should_receive.feature +0 -118
  58. data/features/message_expectations/message_chains_using_expect.feature +0 -49
  59. data/features/message_expectations/receive_counts.feature +0 -209
  60. data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +0 -50
  61. data/features/method_stubs/README.md +0 -77
  62. data/features/method_stubs/allow_any_instance_of.feature +0 -136
  63. data/features/method_stubs/as_null_object.feature +0 -40
  64. data/features/method_stubs/receive_message_chain.feature +0 -51
  65. data/features/method_stubs/simple_return_value_with_allow.feature +0 -44
  66. data/features/method_stubs/simple_return_value_with_stub.feature +0 -64
  67. data/features/method_stubs/stub_implementation.feature +0 -48
  68. data/features/method_stubs/to_ary.feature +0 -51
  69. data/features/mutating_constants/README.md +0 -82
  70. data/features/mutating_constants/hiding_defined_constant.feature +0 -64
  71. data/features/mutating_constants/stub_defined_constant.feature +0 -78
  72. data/features/mutating_constants/stub_undefined_constant.feature +0 -50
  73. data/features/outside_rspec/standalone.feature +0 -33
  74. data/features/spies/spy_partial_mock_method.feature +0 -34
  75. data/features/spies/spy_pure_mock_method.feature +0 -76
  76. data/features/spies/spy_unstubbed_method.feature +0 -18
  77. data/features/step_definitions/additional_cli_steps.rb +0 -11
  78. data/features/support/env.rb +0 -22
  79. data/features/support/rubinius.rb +0 -6
  80. data/features/test_frameworks/test_unit.feature +0 -54
  81. data/features/verifying_doubles/README.md +0 -17
  82. data/features/verifying_doubles/class_doubles.feature +0 -73
  83. data/features/verifying_doubles/dynamic_classes.feature +0 -71
  84. data/features/verifying_doubles/instance_doubles.feature +0 -103
  85. data/features/verifying_doubles/object_doubles.feature +0 -65
  86. data/features/verifying_doubles/partial_doubles.feature +0 -34
  87. data/lib/rspec/mocks/extensions/marshal.rb +0 -17
  88. data/lib/rspec/mocks/framework.rb +0 -35
  89. data/lib/rspec/mocks/method_signature_verifier.rb +0 -207
  90. data/lib/rspec/mocks/ruby_features.rb +0 -24
  91. data/spec/rspec/mocks/and_call_original_spec.rb +0 -268
  92. data/spec/rspec/mocks/and_return_spec.rb +0 -23
  93. data/spec/rspec/mocks/and_yield_spec.rb +0 -126
  94. data/spec/rspec/mocks/any_instance/message_chains_spec.rb +0 -41
  95. data/spec/rspec/mocks/any_instance_spec.rb +0 -1045
  96. data/spec/rspec/mocks/array_including_matcher_spec.rb +0 -41
  97. data/spec/rspec/mocks/at_least_spec.rb +0 -123
  98. data/spec/rspec/mocks/at_most_spec.rb +0 -90
  99. data/spec/rspec/mocks/before_all_spec.rb +0 -132
  100. data/spec/rspec/mocks/block_return_value_spec.rb +0 -70
  101. data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +0 -204
  102. data/spec/rspec/mocks/configuration_spec.rb +0 -242
  103. data/spec/rspec/mocks/double_spec.rb +0 -874
  104. data/spec/rspec/mocks/example_methods_spec.rb +0 -13
  105. data/spec/rspec/mocks/extensions/marshal_spec.rb +0 -54
  106. data/spec/rspec/mocks/failing_argument_matchers_spec.rb +0 -184
  107. data/spec/rspec/mocks/hash_excluding_matcher_spec.rb +0 -67
  108. data/spec/rspec/mocks/hash_including_matcher_spec.rb +0 -94
  109. data/spec/rspec/mocks/instance_method_stasher_spec.rb +0 -74
  110. data/spec/rspec/mocks/matchers/have_received_spec.rb +0 -347
  111. data/spec/rspec/mocks/matchers/receive_message_chain_spec.rb +0 -198
  112. data/spec/rspec/mocks/matchers/receive_messages_spec.rb +0 -140
  113. data/spec/rspec/mocks/matchers/receive_spec.rb +0 -418
  114. data/spec/rspec/mocks/method_signature_verifier_spec.rb +0 -272
  115. data/spec/rspec/mocks/methods_spec.rb +0 -26
  116. data/spec/rspec/mocks/mock_expectation_error_spec.rb +0 -22
  117. data/spec/rspec/mocks/mock_ordering_spec.rb +0 -114
  118. data/spec/rspec/mocks/multiple_return_value_spec.rb +0 -132
  119. data/spec/rspec/mocks/mutate_const_spec.rb +0 -542
  120. data/spec/rspec/mocks/nil_expectation_warning_spec.rb +0 -52
  121. data/spec/rspec/mocks/null_object_mock_spec.rb +0 -133
  122. data/spec/rspec/mocks/once_counts_spec.rb +0 -52
  123. data/spec/rspec/mocks/options_hash_spec.rb +0 -35
  124. data/spec/rspec/mocks/order_group_spec.rb +0 -27
  125. data/spec/rspec/mocks/partial_double_spec.rb +0 -308
  126. data/spec/rspec/mocks/partial_double_using_mocks_directly_spec.rb +0 -95
  127. data/spec/rspec/mocks/passing_argument_matchers_spec.rb +0 -145
  128. data/spec/rspec/mocks/precise_counts_spec.rb +0 -68
  129. data/spec/rspec/mocks/record_messages_spec.rb +0 -26
  130. data/spec/rspec/mocks/serialization_spec.rb +0 -90
  131. data/spec/rspec/mocks/space_spec.rb +0 -244
  132. data/spec/rspec/mocks/stash_spec.rb +0 -46
  133. data/spec/rspec/mocks/stub_chain_spec.rb +0 -168
  134. data/spec/rspec/mocks/stub_implementation_spec.rb +0 -81
  135. data/spec/rspec/mocks/stub_spec.rb +0 -327
  136. data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +0 -58
  137. data/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb +0 -101
  138. data/spec/rspec/mocks/syntax_spec.rb +0 -19
  139. data/spec/rspec/mocks/test_double_spec.rb +0 -49
  140. data/spec/rspec/mocks/to_ary_spec.rb +0 -54
  141. data/spec/rspec/mocks/twice_counts_spec.rb +0 -66
  142. data/spec/rspec/mocks/verifying_double_spec.rb +0 -590
  143. data/spec/rspec/mocks/verifying_message_expecation_spec.rb +0 -69
  144. data/spec/rspec/mocks_spec.rb +0 -192
  145. data/spec/spec_helper.rb +0 -121
@@ -14,6 +14,18 @@ module RSpec
14
14
  @yield_receiver_to_any_instance_implementation_blocks
15
15
  end
16
16
 
17
+ # Sets whether or not RSpec will yield the receiving instance of a
18
+ # message to blocks that are used for any_instance stub implementations.
19
+ # When set, the first yielded argument will be the receiving instance.
20
+ # Defaults to `true`.
21
+ #
22
+ # @example
23
+ #
24
+ # RSpec.configure do |rspec|
25
+ # rspec.mock_with :rspc do |mocks|
26
+ # mocks.yield_receiver_to_any_instance_implementation_blocks = false
27
+ # end
28
+ # end
17
29
  def yield_receiver_to_any_instance_implementation_blocks=(arg)
18
30
  @yield_receiver_to_any_instance_implementation_blocks = arg
19
31
  end
@@ -118,6 +130,21 @@ module RSpec
118
130
  @verify_partial_doubles
119
131
  end
120
132
 
133
+ # Monkey-patch `Marshal.dump` to enable dumping of mocked or stubbed
134
+ # objects. By default this will not work since RSpec mocks works by
135
+ # adding singleton methods that cannot be serialized. This patch removes
136
+ # these singleton methods before serialization. Setting to falsey removes
137
+ # the patch.
138
+ #
139
+ # This method is idempotent.
140
+ def patch_marshal_to_support_partial_doubles=(val)
141
+ if val
142
+ RSpec::Mocks::MarshalExtension.patch!
143
+ else
144
+ RSpec::Mocks::MarshalExtension.unpatch!
145
+ end
146
+ end
147
+
121
148
  # @api private
122
149
  # Resets the configured syntax to the default.
123
150
  def reset_syntaxes_to_default
@@ -126,6 +153,8 @@ module RSpec
126
153
  end
127
154
  end
128
155
 
156
+ # Mocks specific configuration, as distinct from `RSpec.configuration`
157
+ # which is core RSpec configuration.
129
158
  def self.configuration
130
159
  @configuration ||= Configuration.new
131
160
  end
@@ -1,15 +1,12 @@
1
1
  module RSpec
2
2
  module Mocks
3
- # @public
4
3
  # Raised when a message expectation is not satisfied.
5
4
  MockExpectationError = Class.new(Exception)
6
5
 
7
- # @public
8
6
  # Raised when a test double is used after it has been torn
9
7
  # down (typically at the end of an rspec-core example).
10
8
  ExpiredTestDoubleError = Class.new(MockExpectationError)
11
9
 
12
- # @public
13
10
  # Raised when doubles or partial doubles are used outside of the per-test lifecycle.
14
11
  OutsideOfExampleError = Class.new(StandardError)
15
12
 
@@ -17,7 +14,7 @@ module RSpec
17
14
  UnsupportedMatcherError = Class.new(StandardError)
18
15
  # @private
19
16
  NegationUnsupportedError = Class.new(StandardError)
20
-
17
+ # @private
21
18
  VerifyingDoubleNotDefinedError = Class.new(StandardError)
22
19
 
23
20
  # @private
@@ -69,7 +66,7 @@ module RSpec
69
66
 
70
67
  # @private
71
68
  def raise_unimplemented_error(doubled_module, method_name)
72
- __raise "%s does not implement:\n %s" % [
69
+ __raise "%s does not implement: %s" % [
73
70
  doubled_module.description,
74
71
  method_name
75
72
  ]
@@ -1,17 +1,22 @@
1
- require 'rspec/mocks/object_reference'
1
+ RSpec::Support.require_rspec_mocks 'object_reference'
2
2
 
3
3
  module RSpec
4
4
  module Mocks
5
+ # Contains methods intended to be used from within code examples.
6
+ # Mix this in to your test context (such as a test framework base class)
7
+ # to use rspec-mocks with your test framework. If you're using rspec-core,
8
+ # it'll take care of doing this for you.
5
9
  module ExampleMethods
6
10
  include RSpec::Mocks::ArgumentMatchers
7
11
 
8
12
  # @overload double()
9
13
  # @overload double(name)
14
+ # @param name [String/Symbol] used to clarify intent
10
15
  # @overload double(stubs)
16
+ # @param stubs (Hash) hash of message/return-value pairs
11
17
  # @overload double(name, stubs)
12
- # @param name [String/Symbol] (optional) used in
13
- # clarify intent
14
- # @param stubs (Hash) (optional) hash of message/return-value pairs
18
+ # @param name [String/Symbol] used to clarify intent
19
+ # @param stubs (Hash) hash of message/return-value pairs
15
20
  # @return (Double)
16
21
  #
17
22
  # Constructs an instance of [RSpec::Mocks::Double](RSpec::Mocks::Double) configured
@@ -32,9 +37,10 @@ module RSpec
32
37
  end
33
38
 
34
39
  # @overload instance_double(doubled_class)
40
+ # @param doubled_class [String, Class]
35
41
  # @overload instance_double(doubled_class, stubs)
36
- # @param doubled_class [String, Class]
37
- # @param stubs [Hash] (optional) hash of message/return-value pairs
42
+ # @param doubled_class [String, Class]
43
+ # @param stubs [Hash] hash of message/return-value pairs
38
44
  # @return InstanceVerifyingDouble
39
45
  #
40
46
  # Constructs a test double against a specific class. If the given class
@@ -47,9 +53,10 @@ module RSpec
47
53
  end
48
54
 
49
55
  # @overload class_double(doubled_class)
56
+ # @param doubled_class [String, Module]
50
57
  # @overload class_double(doubled_class, stubs)
51
- # @param doubled_class [String, Module]
52
- # @param stubs [Hash] (optional) hash of message/return-value pairs
58
+ # @param doubled_class [String, Module]
59
+ # @param stubs [Hash] hash of message/return-value pairs
53
60
  # @return ClassVerifyingDouble
54
61
  #
55
62
  # Constructs a test double against a specific class. If the given class
@@ -62,9 +69,10 @@ module RSpec
62
69
  end
63
70
 
64
71
  # @overload object_double(object_or_name)
72
+ # @param object_or_name [String, Object]
65
73
  # @overload object_double(object_or_name, stubs)
66
- # @param object_or_name [String, Object]
67
- # @param stubs [Hash] (optional) hash of message/return-value pairs
74
+ # @param object_or_name [String, Object]
75
+ # @param stubs [Hash] hash of message/return-value pairs
68
76
  # @return ObjectVerifyingDouble
69
77
  #
70
78
  # Constructs a test double against a specific object. Only the methods
@@ -164,7 +172,108 @@ module RSpec
164
172
  Matchers::HaveReceived.new(method_name, &block)
165
173
  end
166
174
 
167
- # @api private
175
+ # @method expect
176
+ # Used to wrap an object in preparation for setting a mock expectation
177
+ # on it.
178
+ #
179
+ # @example
180
+ #
181
+ # expect(obj).to receive(:foo).with(5).and_return(:return_value)
182
+ #
183
+ # @note This method is usually provided by rspec-expectations. However,
184
+ # if you use rspec-mocks without rspec-expectations, there's a definition
185
+ # of it that is made available here. If you disable the `:expect` syntax
186
+ # this method will be undefined.
187
+
188
+ # @method allow
189
+ # Used to wrap an object in preparation for stubbing a method
190
+ # on it.
191
+ #
192
+ # @example
193
+ #
194
+ # allow(dbl).to receive(:foo).with(5).and_return(:return_value)
195
+ #
196
+ # @note If you disable the `:expect` syntax this method will be undefined.
197
+
198
+ # @method expect_any_instance_of
199
+ # Used to wrap a class in preparation for setting a mock expectation
200
+ # on instances of it.
201
+ #
202
+ # @example
203
+ #
204
+ # expect_any_instance_of(MyClass).to receive(:foo)
205
+ #
206
+ # @note If you disable the `:expect` syntax this method will be undefined.
207
+
208
+ # @method allow_any_instance_of
209
+ # Used to wrap a class in preparation for stubbing a method
210
+ # on instances of it.
211
+ #
212
+ # @example
213
+ #
214
+ # allow_any_instance_of(MyClass).to receive(:foo)
215
+ #
216
+ # @note This is only available when you have enabled the `expect` syntax.
217
+
218
+ # @method receive
219
+ # Used to specify a message that you expect or allow an object
220
+ # to receive. The object returned by `receive` supports the same
221
+ # fluent interface that `should_receive` and `stub` have always
222
+ # supported, allowing you to constrain the arguments or number of
223
+ # times, and configure how the object should respond to the message.
224
+ #
225
+ # @example
226
+ #
227
+ # expect(obj).to receive(:hello).with("world").exactly(3).times
228
+ #
229
+ # @note If you disable the `:expect` syntax this method will be undefined.
230
+
231
+ # @method receive_messages
232
+ # Shorthand syntax used to setup message(s), and their return value(s),
233
+ # that you expect or allow an object to receive. The method takes a hash
234
+ # of messages and their respective return values. Unlike with `receive`,
235
+ # you cannot apply further customizations using a block or the fluent
236
+ # interface.
237
+ #
238
+ # @example
239
+ #
240
+ # allow(obj).to receive_messages(:speak => "Hello World")
241
+ # allow(obj).to receive_messages(:speak => "Hello", :meow => "Meow")
242
+ #
243
+ # @note If you disable the `:expect` syntax this method will be undefined.
244
+
245
+ # @method receive_message_chain
246
+ # @overload receive_message_chain(method1, method2)
247
+ # @overload receive_message_chain("method1.method2")
248
+ # @overload receive_message_chain(method1, method_to_value_hash)
249
+ #
250
+ # stubs/mocks a chain of messages on an object or test double.
251
+ #
252
+ # ## Warning:
253
+ #
254
+ # Chains can be arbitrarily long, which makes it quite painless to
255
+ # violate the Law of Demeter in violent ways, so you should consider any
256
+ # use of `receive_message_chain` a code smell. Even though not all code smells
257
+ # indicate real problems (think fluent interfaces), `receive_message_chain` still
258
+ # results in brittle examples. For example, if you write
259
+ # `foo.receive_message_chain(:bar, :baz => 37)` in a spec and then the
260
+ # implementation calls `foo.baz.bar`, the stub will not work.
261
+ #
262
+ # @example
263
+ #
264
+ # allow(double).to receive_message_chain("foo.bar") { :baz }
265
+ # allow(double).to receive_message_chain(:foo, :bar => :baz)
266
+ # allow(double).to receive_message_chain(:foo, :bar) { :baz }
267
+ #
268
+ # # Given any of ^^ these three forms ^^:
269
+ # double.foo.bar # => :baz
270
+ #
271
+ # # Common use in Rails/ActiveRecord:
272
+ # allow(Article).to receive_message_chain("recent.published") { [Article.new] }
273
+ #
274
+ # @note If you disable the `:expect` syntax this method will be undefined.
275
+
276
+ # @private
168
277
  def self.included(klass)
169
278
  klass.class_exec do
170
279
  # This gets mixed in so that if `RSpec::Matchers` is included in
@@ -173,7 +282,7 @@ module RSpec
173
282
  end
174
283
  end
175
284
 
176
- # @api private
285
+ # @private
177
286
  def self.declare_verifying_double(type, ref, *args)
178
287
  if RSpec::Mocks.configuration.verify_doubled_constant_names? &&
179
288
  !ref.defined?
@@ -187,7 +296,7 @@ module RSpec
187
296
  declare_double(type, ref, *args)
188
297
  end
189
298
 
190
- # @api private
299
+ # @private
191
300
  def self.declare_double(type, *args)
192
301
  args << {} unless Hash === args.last
193
302
  type.new(*args)
@@ -65,12 +65,36 @@ module RSpec
65
65
  @klass.__send__(:undef_method, @method)
66
66
  end
67
67
 
68
- @klass.__send__(:define_method, @method, @original_method)
68
+ handle_restoration_failures do
69
+ @klass.__send__(:define_method, @method, @original_method)
70
+ end
71
+
69
72
  @original_method = nil
70
73
  end
71
74
  end
72
75
 
73
- private
76
+ if RUBY_DESCRIPTION.include?('2.0.0p247')
77
+ # ruby 2.0.0-p247 has a bug that we can't work around :(.
78
+ # https://bugs.ruby-lang.org/issues/8686
79
+ def handle_restoration_failures
80
+ yield
81
+ rescue TypeError
82
+ RSpec.warn_with(
83
+ "RSpec failed to properly restore a partial double (#{@object.inspect}) " +
84
+ "to its original state due to a known bug in MRI 2.0.0-p247 " +
85
+ "(https://bugs.ruby-lang.org/issues/8686). This object may remain " +
86
+ "screwed up for the rest of this process. Please upgrade to 2.0.0-p353 or above.",
87
+ :call_site => nil, :use_spec_location_as_call_site => true
88
+ )
89
+ end
90
+ else
91
+ def handle_restoration_failures
92
+ # No known reasons for restoration to fail on other rubies.
93
+ yield
94
+ end
95
+ end
96
+
97
+ private
74
98
 
75
99
  # @private
76
100
  def method_defined_directly_on_klass?
@@ -0,0 +1,41 @@
1
+ module RSpec
2
+ module Mocks
3
+ # Support for `patch_marshal_to_support_partial_doubles` configuration.
4
+ #
5
+ # @private
6
+ class MarshalExtension
7
+ def self.patch!
8
+ return if Marshal.respond_to?(:dump_with_rspec_mocks)
9
+
10
+ Marshal.instance_eval do
11
+ class << self
12
+ def dump_with_rspec_mocks(object, *rest)
13
+ if !::RSpec::Mocks.space.registered?(object) || NilClass === object
14
+ dump_without_rspec_mocks(object, *rest)
15
+ else
16
+ dump_without_rspec_mocks(object.dup, *rest)
17
+ end
18
+ end
19
+
20
+ alias_method :dump_without_rspec_mocks, :dump
21
+ undef_method :dump
22
+ alias_method :dump, :dump_with_rspec_mocks
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.unpatch!
28
+ return unless Marshal.respond_to?(:dump_with_rspec_mocks)
29
+
30
+ Marshal.instance_eval do
31
+ class << self
32
+ undef_method :dump_with_rspec_mocks
33
+ undef_method :dump
34
+ alias_method :dump, :dump_without_rspec_mocks
35
+ undef_method :dump_without_rspec_mocks
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ module RSpec
2
+ module Mocks
3
+ module Matchers
4
+ # @private
5
+ class ExpectationCustomization
6
+ attr_accessor :block
7
+
8
+ def initialize(method_name, args, block)
9
+ @method_name = method_name
10
+ @args = args
11
+ @block = block
12
+ end
13
+
14
+ def playback_onto(expectation)
15
+ expectation.__send__(@method_name, *@args, &@block)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,5 @@
1
+ RSpec::Support.require_rspec_mocks 'matchers/expectation_customization'
2
+
1
3
  module RSpec
2
4
  module Mocks
3
5
  module Matchers
@@ -7,7 +9,6 @@ module RSpec
7
9
  @message = message
8
10
  @block = block
9
11
  @recorded_customizations = []
10
- @backtrace_line = CallerFilter.first_non_rspec_line
11
12
  end
12
13
 
13
14
  def name
@@ -60,7 +61,7 @@ module RSpec
60
61
  private
61
62
 
62
63
  def warn_if_any_instance(expression, subject)
63
- if AnyInstance::Recorder === subject
64
+ if AnyInstance::Proxy === subject
64
65
  RSpec.warning(
65
66
  "`#{expression}(#{subject.klass}.any_instance).to` " <<
66
67
  "is probably not what you meant, it does not operate on " <<
@@ -72,12 +73,12 @@ module RSpec
72
73
 
73
74
  def setup_mock_proxy_method_substitute(subject, method, block)
74
75
  proxy = ::RSpec::Mocks.space.proxy_for(subject)
75
- setup_method_substitute(proxy, method, block, @backtrace_line)
76
+ setup_method_substitute(proxy, method, block)
76
77
  end
77
78
 
78
79
  def setup_any_instance_method_substitute(subject, method, block)
79
- any_instance_recorder = ::RSpec::Mocks.space.any_instance_recorder_for(subject)
80
- setup_method_substitute(any_instance_recorder, method, block)
80
+ proxy = ::RSpec::Mocks.space.any_instance_proxy_for(subject)
81
+ setup_method_substitute(proxy, method, block)
81
82
  end
82
83
 
83
84
  def setup_method_substitute(host, method, block, *args)
@@ -101,20 +102,5 @@ module RSpec
101
102
  end
102
103
  end
103
104
  end
104
-
105
- # @private
106
- class ExpectationCustomization
107
- attr_accessor :block
108
-
109
- def initialize(method_name, args, block)
110
- @method_name = method_name
111
- @args = args
112
- @block = block
113
- end
114
-
115
- def playback_onto(expectation)
116
- expectation.__send__(@method_name, *@args, &@block)
117
- end
118
- end
119
105
  end
120
106
  end
@@ -1,3 +1,5 @@
1
+ RSpec::Support.require_rspec_mocks 'matchers/expectation_customization'
2
+
1
3
  module RSpec
2
4
  module Mocks
3
5
  module Matchers
@@ -26,14 +28,14 @@ module RSpec
26
28
  end
27
29
 
28
30
  def setup_any_instance_allowance(subject, &block)
29
- recorder = ::RSpec::Mocks.space.any_instance_recorder_for(subject)
30
- chain = recorder.stub_chain(*@chain, &(@block || block))
31
+ proxy = ::RSpec::Mocks.space.any_instance_proxy_for(subject)
32
+ chain = proxy.stub_chain(*@chain, &(@block || block))
31
33
  replay_customizations(chain)
32
34
  end
33
35
 
34
36
  def setup_any_instance_expectation(subject, &block)
35
- recorder = ::RSpec::Mocks.space.any_instance_recorder_for(subject)
36
- chain = recorder.expect_chain(*@chain, &(@block || block))
37
+ proxy = ::RSpec::Mocks.space.any_instance_proxy_for(subject)
38
+ chain = proxy.expect_chain(*@chain, &(@block || block))
37
39
  replay_customizations(chain)
38
40
  end
39
41
 
@@ -52,7 +54,7 @@ module RSpec
52
54
  alias matches? setup_expectation
53
55
  alias does_not_match? setup_negative_expectation
54
56
 
55
- private
57
+ private
56
58
 
57
59
  def replay_customizations(chain)
58
60
  @recorded_customizations.each do |customization|