lib/rspec/mocks/method_double.rb in rspec-mocks-3.0.4 vs lib/rspec/mocks/method_double.rb in rspec-mocks-3.1.0

- old
+ new

@@ -57,43 +57,43 @@ save_original_method! definition_target.class_exec(self, method_name, visibility) do |method_double, method_name, visibility| define_method(method_name) do |*args, &block| method_double.proxy_method_invoked(self, *args, &block) end - self.__send__ visibility, method_name + __send__(visibility, method_name) end @method_is_proxied = true end # The implementation of the proxied method. Subclasses may override this # method to perform additional operations. # # @private - def proxy_method_invoked(obj, *args, &block) + def proxy_method_invoked(_obj, *args, &block) @proxy.message_received method_name, *args, &block end # @private def restore_original_method return show_frozen_warning if object_singleton_class.frozen? return unless @method_is_proxied definition_target.__send__(:remove_method, @method_name) - if @method_stasher.method_is_stashed? - @method_stasher.restore - end + @method_stasher.restore if @method_stasher.method_is_stashed? restore_original_visibility @method_is_proxied = false end # @private def show_frozen_warning RSpec.warn_with( - "WARNING: rspec-mocks was unable to restore the original `#{@method_name}` method on #{@object.inspect} because it has been frozen. If you reuse this object, `#{@method_name}` will continue to respond with its stub implementation.", + "WARNING: rspec-mocks was unable to restore the original `#{@method_name}` " \ + "method on #{@object.inspect} because it has been frozen. If you reuse this " \ + "object, `#{@method_name}` will continue to respond with its stub implementation.", :call_site => nil, :use_spec_location_as_call_site => true ) end @@ -105,11 +105,11 @@ object_singleton_class.__send__(*@original_visibility) end # @private def verify - expectations.each {|e| e.verify_messages_received} + expectations.each { |e| e.verify_messages_received } end # @private def reset restore_original_method @@ -132,11 +132,11 @@ # @private def add_expectation(error_generator, expectation_ordering, expected_from, opts, &implementation) configure_method expectation = message_expectation_class.new(error_generator, expectation_ordering, - expected_from, self, :expectation, opts, &implementation) + expected_from, self, :expectation, opts, &implementation) expectations << expectation expectation end # @private @@ -147,11 +147,11 @@ # @private def add_stub(error_generator, expectation_ordering, expected_from, opts={}, &implementation) configure_method stub = message_expectation_class.new(error_generator, expectation_ordering, expected_from, - self, :stub, opts, &implementation) + self, :stub, opts, &implementation) stubs.unshift stub stub end # A simple stub can only return a concrete value for a message, and @@ -170,11 +170,11 @@ def add_simple_expectation(method_name, response, error_generator, backtrace_line) setup_simple_method_double method_name, response, expectations, error_generator, backtrace_line end # @private - def setup_simple_method_double(method_name, response, collection, error_generator = nil, backtrace_line = nil) + def setup_simple_method_double(method_name, response, collection, error_generator=nil, backtrace_line=nil) define_proxy_method me = SimpleMessageExpectation.new(method_name, response, error_generator, backtrace_line) collection.unshift me me @@ -200,12 +200,10 @@ # @private def raise_method_not_stubbed_error raise MockExpectationError, "The method `#{method_name}` was not stubbed or was already unstubbed" end - private - # In Ruby 2.0.0 and above prepend will alter the method lookup chain. # We use an object's singleton class to define method doubles upon, # however if the object has had it's singleton class (as opposed to # it's actual class) prepended too then the the method lookup chain # will look in the prepended module first, **before** the singleton @@ -214,10 +212,13 @@ # This code works around that by providing a mock definition target # that is either the singleton class, or if necessary, a prepended module # of our own. # if Support::RubyFeatures.module_prepends_supported? + + private + # We subclass `Module` in order to be able to easily detect our prepended module. RSpecPrependedModule = Class.new(Module) def definition_target @definition_target ||= usable_rspec_prepended_module || object_singleton_class @@ -244,9 +245,11 @@ object_singleton_class.__send__ :prepend, mod end end else + + private def definition_target object_singleton_class end