@@ -23,8 +23,8 @@ def self.warn_unless_should_configured(method_name , replacement="the new `:expe
23
23
24
24
# @api private
25
25
# Enables the should syntax (`dbl.stub`, `dbl.should_receive`, etc).
26
- def self . enable_should ( syntax_host = default_should_syntax_host )
27
- @warn_about_should = false if syntax_host == default_should_syntax_host
26
+ def self . enable_should ( syntax_host = :: BasicObject )
27
+ @warn_about_should = false if syntax_host == :: BasicObject
28
28
return if should_enabled? ( syntax_host )
29
29
30
30
syntax_host . class_exec do
@@ -86,7 +86,7 @@ def any_instance
86
86
87
87
# @api private
88
88
# Disables the should syntax (`dbl.stub`, `dbl.should_receive`, etc).
89
- def self . disable_should ( syntax_host = default_should_syntax_host )
89
+ def self . disable_should ( syntax_host = :: BasicObject )
90
90
return unless should_enabled? ( syntax_host )
91
91
92
92
syntax_host . class_exec do
@@ -166,7 +166,7 @@ def self.disable_expect(syntax_host=::RSpec::Mocks::ExampleMethods)
166
166
167
167
# @api private
168
168
# Indicates whether or not the should syntax is enabled.
169
- def self . should_enabled? ( syntax_host = default_should_syntax_host )
169
+ def self . should_enabled? ( syntax_host = :: BasicObject )
170
170
syntax_host . method_defined? ( :should_receive )
171
171
end
172
172
@@ -175,109 +175,98 @@ def self.should_enabled?(syntax_host=default_should_syntax_host)
175
175
def self . expect_enabled? ( syntax_host = ::RSpec ::Mocks ::ExampleMethods )
176
176
syntax_host . method_defined? ( :allow )
177
177
end
178
-
179
- # @api private
180
- # Determines where the methods like `should_receive`, and `stub` are added.
181
- def self . default_should_syntax_host
182
- # MacRuby has BasicObject but it's not the root class.
183
- return Object unless Object . ancestors . last == ::BasicObject
184
-
185
- ::BasicObject
186
- end
187
178
end
188
179
end
189
180
end
190
181
191
- if defined? ( BasicObject )
192
- # The legacy `:should` syntax adds the following methods directly to
193
- # `BasicObject` so that they are available off of any object. Note, however,
194
- # that this syntax does not always play nice with delegate/proxy objects.
195
- # We recommend you use the non-monkeypatching `:expect` syntax instead.
196
- # @see Class
197
- class BasicObject
198
- # @method should_receive
199
- # Sets an expectation that this object should receive a message before
200
- # the end of the example.
201
- #
202
- # @example
203
- # logger = double('logger')
204
- # thing_that_logs = ThingThatLogs.new(logger)
205
- # logger.should_receive(:log)
206
- # thing_that_logs.do_something_that_logs_a_message
207
- #
208
- # @note This is only available when you have enabled the `should` syntax.
209
- # @see RSpec::Mocks::ExampleMethods#expect
210
-
211
- # @method should_not_receive
212
- # Sets and expectation that this object should _not_ receive a message
213
- # during this example.
214
- # @see RSpec::Mocks::ExampleMethods#expect
215
-
216
- # @method stub
217
- # Tells the object to respond to the message with the specified value.
218
- #
219
- # @example
220
- # counter.stub(:count).and_return(37)
221
- # counter.stub(:count => 37)
222
- # counter.stub(:count) { 37 }
223
- #
224
- # @note This is only available when you have enabled the `should` syntax.
225
- # @see RSpec::Mocks::ExampleMethods#allow
226
-
227
- # @method unstub
228
- # Removes a stub. On a double, the object will no longer respond to
229
- # `message`. On a real object, the original method (if it exists) is
230
- # restored.
231
- #
232
- # This is rarely used, but can be useful when a stub is set up during a
233
- # shared `before` hook for the common case, but you want to replace it
234
- # for a special case.
235
- #
236
- # @note This is only available when you have enabled the `should` syntax.
237
-
238
- # @method stub_chain
239
- # @overload stub_chain(method1, method2)
240
- # @overload stub_chain("method1.method2")
241
- # @overload stub_chain(method1, method_to_value_hash)
242
- #
243
- # Stubs a chain of methods.
244
- #
245
- # ## Warning:
246
- #
247
- # Chains can be arbitrarily long, which makes it quite painless to
248
- # violate the Law of Demeter in violent ways, so you should consider any
249
- # use of `stub_chain` a code smell. Even though not all code smells
250
- # indicate real problems (think fluent interfaces), `stub_chain` still
251
- # results in brittle examples. For example, if you write
252
- # `foo.stub_chain(:bar, :baz => 37)` in a spec and then the
253
- # implementation calls `foo.baz.bar`, the stub will not work.
254
- #
255
- # @example
256
- # double.stub_chain("foo.bar") { :baz }
257
- # double.stub_chain(:foo, :bar => :baz)
258
- # double.stub_chain(:foo, :bar) { :baz }
259
- #
260
- # # Given any of ^^ these three forms ^^:
261
- # double.foo.bar # => :baz
262
- #
263
- # # Common use in Rails/ActiveRecord:
264
- # Article.stub_chain("recent.published") { [Article.new] }
265
- #
266
- # @note This is only available when you have enabled the `should` syntax.
267
- # @see RSpec::Mocks::ExampleMethods#receive_message_chain
268
-
269
- # @method as_null_object
270
- # Tells the object to respond to all messages. If specific stub values
271
- # are declared, they'll work as expected. If not, the receiver is
272
- # returned.
273
- #
274
- # @note This is only available when you have enabled the `should` syntax.
275
-
276
- # @method null_object?
277
- # Returns true if this object has received `as_null_object`
278
- #
279
- # @note This is only available when you have enabled the `should` syntax.
280
- end
182
+ # The legacy `:should` syntax adds the following methods directly to
183
+ # `BasicObject` so that they are available off of any object. Note, however,
184
+ # that this syntax does not always play nice with delegate/proxy objects.
185
+ # We recommend you use the non-monkeypatching `:expect` syntax instead.
186
+ # @see Class
187
+ class BasicObject
188
+ # @method should_receive
189
+ # Sets an expectation that this object should receive a message before
190
+ # the end of the example.
191
+ #
192
+ # @example
193
+ # logger = double('logger')
194
+ # thing_that_logs = ThingThatLogs.new(logger)
195
+ # logger.should_receive(:log)
196
+ # thing_that_logs.do_something_that_logs_a_message
197
+ #
198
+ # @note This is only available when you have enabled the `should` syntax.
199
+ # @see RSpec::Mocks::ExampleMethods#expect
200
+
201
+ # @method should_not_receive
202
+ # Sets and expectation that this object should _not_ receive a message
203
+ # during this example.
204
+ # @see RSpec::Mocks::ExampleMethods#expect
205
+
206
+ # @method stub
207
+ # Tells the object to respond to the message with the specified value.
208
+ #
209
+ # @example
210
+ # counter.stub(:count).and_return(37)
211
+ # counter.stub(:count => 37)
212
+ # counter.stub(:count) { 37 }
213
+ #
214
+ # @note This is only available when you have enabled the `should` syntax.
215
+ # @see RSpec::Mocks::ExampleMethods#allow
216
+
217
+ # @method unstub
218
+ # Removes a stub. On a double, the object will no longer respond to
219
+ # `message`. On a real object, the original method (if it exists) is
220
+ # restored.
221
+ #
222
+ # This is rarely used, but can be useful when a stub is set up during a
223
+ # shared `before` hook for the common case, but you want to replace it
224
+ # for a special case.
225
+ #
226
+ # @note This is only available when you have enabled the `should` syntax.
227
+
228
+ # @method stub_chain
229
+ # @overload stub_chain(method1, method2)
230
+ # @overload stub_chain("method1.method2")
231
+ # @overload stub_chain(method1, method_to_value_hash)
232
+ #
233
+ # Stubs a chain of methods.
234
+ #
235
+ # ## Warning:
236
+ #
237
+ # Chains can be arbitrarily long, which makes it quite painless to
238
+ # violate the Law of Demeter in violent ways, so you should consider any
239
+ # use of `stub_chain` a code smell. Even though not all code smells
240
+ # indicate real problems (think fluent interfaces), `stub_chain` still
241
+ # results in brittle examples. For example, if you write
242
+ # `foo.stub_chain(:bar, :baz => 37)` in a spec and then the
243
+ # implementation calls `foo.baz.bar`, the stub will not work.
244
+ #
245
+ # @example
246
+ # double.stub_chain("foo.bar") { :baz }
247
+ # double.stub_chain(:foo, :bar => :baz)
248
+ # double.stub_chain(:foo, :bar) { :baz }
249
+ #
250
+ # # Given any of ^^ these three forms ^^:
251
+ # double.foo.bar # => :baz
252
+ #
253
+ # # Common use in Rails/ActiveRecord:
254
+ # Article.stub_chain("recent.published") { [Article.new] }
255
+ #
256
+ # @note This is only available when you have enabled the `should` syntax.
257
+ # @see RSpec::Mocks::ExampleMethods#receive_message_chain
258
+
259
+ # @method as_null_object
260
+ # Tells the object to respond to all messages. If specific stub values
261
+ # are declared, they'll work as expected. If not, the receiver is
262
+ # returned.
263
+ #
264
+ # @note This is only available when you have enabled the `should` syntax.
265
+
266
+ # @method null_object?
267
+ # Returns true if this object has received `as_null_object`
268
+ #
269
+ # @note This is only available when you have enabled the `should` syntax.
281
270
end
282
271
283
272
# The legacy `:should` syntax adds the `any_instance` to `Class`.
0 commit comments