diff --git a/lib/mocha/inspect.rb b/lib/mocha/inspect.rb index 478651ee4..51975c5f6 100755 --- a/lib/mocha/inspect.rb +++ b/lib/mocha/inspect.rb @@ -1,55 +1,57 @@ require 'date' module Mocha - module ObjectMethods - def mocha_inspect - address = __id__ * 2 - address += 0x100000000 if address < 0 - inspect =~ /#" : inspect + module Inspect + module ObjectMethods + def mocha_inspect + address = __id__ * 2 + address += 0x100000000 if address < 0 + inspect =~ /#" : inspect + end end - end - module ArrayMethods - def mocha_inspect - "[#{collect(&:mocha_inspect).join(', ')}]" + module ArrayMethods + def mocha_inspect + "[#{collect(&:mocha_inspect).join(', ')}]" + end end - end - module HashMethods - def mocha_inspect - "{#{collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')}}" + module HashMethods + def mocha_inspect + "{#{collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')}}" + end end - end - module TimeMethods - def mocha_inspect - "#{inspect} (#{to_f} secs)" + module TimeMethods + def mocha_inspect + "#{inspect} (#{to_f} secs)" + end end - end - module DateMethods - def mocha_inspect - to_s + module DateMethods + def mocha_inspect + to_s + end end end end class Object - include Mocha::ObjectMethods + include Mocha::Inspect::ObjectMethods end class Array - include Mocha::ArrayMethods + include Mocha::Inspect::ArrayMethods end class Hash - include Mocha::HashMethods + include Mocha::Inspect::HashMethods end class Time - include Mocha::TimeMethods + include Mocha::Inspect::TimeMethods end class Date - include Mocha::DateMethods + include Mocha::Inspect::DateMethods end diff --git a/lib/mocha/parameter_matchers.rb b/lib/mocha/parameter_matchers.rb index 47a4af50f..7a64ad6dd 100644 --- a/lib/mocha/parameter_matchers.rb +++ b/lib/mocha/parameter_matchers.rb @@ -3,7 +3,7 @@ module Mocha module ParameterMatchers; end end -require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/instance_methods' require 'mocha/parameter_matchers/all_of' require 'mocha/parameter_matchers/any_of' diff --git a/lib/mocha/parameter_matchers/instance_methods.rb b/lib/mocha/parameter_matchers/instance_methods.rb new file mode 100644 index 000000000..5bb229cd4 --- /dev/null +++ b/lib/mocha/parameter_matchers/instance_methods.rb @@ -0,0 +1,18 @@ +require 'mocha/parameter_matchers/equals' + +module Mocha + module ParameterMatchers + # @private + module InstanceMethods + # @private + def to_matcher + Mocha::ParameterMatchers::Equals.new(self) + end + end + end +end + +# @private +class Object + include Mocha::ParameterMatchers::InstanceMethods +end diff --git a/lib/mocha/parameter_matchers/object.rb b/lib/mocha/parameter_matchers/object.rb deleted file mode 100644 index ceb88d8b0..000000000 --- a/lib/mocha/parameter_matchers/object.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'mocha/parameter_matchers/equals' - -module Mocha - module ObjectMethods - # @private - def to_matcher - Mocha::ParameterMatchers::Equals.new(self) - end - end -end - -# @private -class Object - include Mocha::ObjectMethods -end diff --git a/test/unit/object_methods_test.rb b/test/unit/object_methods_test.rb index be15771ba..570bbcd4e 100644 --- a/test/unit/object_methods_test.rb +++ b/test/unit/object_methods_test.rb @@ -44,7 +44,7 @@ def test_should_reset_mocha end def test_should_use_stubba_instance_method_for_object - assert_equal Mocha::InstanceMethod, Object.new.stubba_method + assert_equal Mocha::InstanceMethod, @object.stubba_method end def test_should_stub_self_for_object @@ -57,6 +57,7 @@ def test_nobody_expects_the_spanish_inquisition def test_should_alias_object_method klass = Class.new { def self.method_x; end } + klass.extend(Mocha::ObjectMethods) assert_equal klass._method(:method_x), klass.method(:method_x) end end diff --git a/test/unit/parameter_matchers/has_entries_test.rb b/test/unit/parameter_matchers/has_entries_test.rb index 18a306f0d..1f766197f 100644 --- a/test/unit/parameter_matchers/has_entries_test.rb +++ b/test/unit/parameter_matchers/has_entries_test.rb @@ -1,7 +1,7 @@ require File.expand_path('../../../test_helper', __FILE__) require 'mocha/parameter_matchers/has_entries' -require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/instance_methods' require 'mocha/inspect' class HasEntriesTest < Mocha::TestCase diff --git a/test/unit/parameter_matchers/has_entry_test.rb b/test/unit/parameter_matchers/has_entry_test.rb index 8ed116863..8526620bb 100644 --- a/test/unit/parameter_matchers/has_entry_test.rb +++ b/test/unit/parameter_matchers/has_entry_test.rb @@ -1,7 +1,7 @@ require File.expand_path('../../../test_helper', __FILE__) require 'mocha/parameter_matchers/has_entry' -require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/instance_methods' require 'mocha/parameter_matchers/equals' require 'mocha/inspect' diff --git a/test/unit/parameter_matchers/has_key_test.rb b/test/unit/parameter_matchers/has_key_test.rb index 63883dd43..9a621513d 100644 --- a/test/unit/parameter_matchers/has_key_test.rb +++ b/test/unit/parameter_matchers/has_key_test.rb @@ -1,7 +1,7 @@ require File.expand_path('../../../test_helper', __FILE__) require 'mocha/parameter_matchers/has_key' -require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/instance_methods' require 'mocha/inspect' class HasKeyTest < Mocha::TestCase diff --git a/test/unit/parameter_matchers/has_value_test.rb b/test/unit/parameter_matchers/has_value_test.rb index f9c084345..fb8aa5441 100644 --- a/test/unit/parameter_matchers/has_value_test.rb +++ b/test/unit/parameter_matchers/has_value_test.rb @@ -1,7 +1,7 @@ require File.expand_path('../../../test_helper', __FILE__) require 'mocha/parameter_matchers/has_value' -require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/instance_methods' require 'mocha/parameter_matchers/equals' require 'mocha/inspect' diff --git a/test/unit/parameter_matchers/includes_test.rb b/test/unit/parameter_matchers/includes_test.rb index 5db398fea..fb9dccbd5 100644 --- a/test/unit/parameter_matchers/includes_test.rb +++ b/test/unit/parameter_matchers/includes_test.rb @@ -1,7 +1,7 @@ require File.expand_path('../../../test_helper', __FILE__) require 'mocha/parameter_matchers/includes' -require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/instance_methods' require 'mocha/parameter_matchers/has_key' require 'mocha/parameter_matchers/regexp_matches' require 'mocha/inspect' diff --git a/test/unit/parameter_matchers/responds_with_test.rb b/test/unit/parameter_matchers/responds_with_test.rb index 6c8b89a38..493f37f19 100644 --- a/test/unit/parameter_matchers/responds_with_test.rb +++ b/test/unit/parameter_matchers/responds_with_test.rb @@ -1,7 +1,7 @@ require File.expand_path('../../../test_helper', __FILE__) require 'mocha/parameter_matchers/responds_with' -require 'mocha/parameter_matchers/object' +require 'mocha/parameter_matchers/instance_methods' require 'mocha/inspect' class RespondsWithTest < Mocha::TestCase