Skip to content

Commit

Permalink
Merge pull request #404 from freerange/distinguish-object-methods-mod…
Browse files Browse the repository at this point in the history
…ules

Distinguish different ObjectMethods modules
  • Loading branch information
floehopper authored Nov 3, 2019
2 parents cc85f7c + 537a742 commit 8536868
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 49 deletions.
54 changes: 28 additions & 26 deletions lib/mocha/inspect.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
require 'date'

module Mocha
module ObjectMethods
def mocha_inspect
address = __id__ * 2
address += 0x100000000 if address < 0
inspect =~ /#</ ? "#<#{self.class}:0x#{Kernel.format('%x', address)}>" : inspect
module Inspect
module ObjectMethods
def mocha_inspect
address = __id__ * 2
address += 0x100000000 if address < 0
inspect =~ /#</ ? "#<#{self.class}:0x#{Kernel.format('%x', address)}>" : 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
2 changes: 1 addition & 1 deletion lib/mocha/parameter_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
18 changes: 18 additions & 0 deletions lib/mocha/parameter_matchers/instance_methods.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 0 additions & 15 deletions lib/mocha/parameter_matchers/object.rb

This file was deleted.

3 changes: 2 additions & 1 deletion test/unit/object_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion test/unit/parameter_matchers/has_entries_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/parameter_matchers/has_entry_test.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion test/unit/parameter_matchers/has_key_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/parameter_matchers/has_value_test.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion test/unit/parameter_matchers/includes_test.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/parameter_matchers/responds_with_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 8536868

Please sign in to comment.