-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Distinguish module defining mocha_inspect methods
Previously this Mocha::ObjectMethods module was re-opening the module defined in `lib/mocha/object_methods.rb`. I think this was potentially confusing and so I've moved the modules containing the mocha_inspect method definitions to into a new Mocha::Inspect namespace to make things clearer. Note that I've had to amend a couple of tests in ObjectMethodsTest, because they had previously been relying on the Mocha::ObjectMethods being included elsewhere.
- Loading branch information
1 parent
ab619c8
commit 537a742
Showing
2 changed files
with
30 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters