forked from freerange/mocha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As per Jay Fields recommendations [1] and with further impetus from a…
… talk at Ruby Manor, any methods added to core classes are now added by including a module. This means that Mocha is a better citizen of the Ruby world and it's behaviour is more easily extended. [1] http://blog.jayfields.com/2008/07/ruby-underuse-of-modules.html & http://blog.jayfields.com/2008/07/ruby-redefine-method-behavior.html
- Loading branch information
1 parent
36f20a4
commit 3251107
Showing
5 changed files
with
200 additions
and
138 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,39 +1,67 @@ | |||
require 'date' | require 'date' | ||
|
|
||
class Object | module Mocha | ||
def mocha_inspect |
|
||
address = self.__id__ * 2 | module ObjectMethods | ||
address += 0x100000000 if address < 0 | def mocha_inspect | ||
inspect =~ /#</ ? "#<#{self.class}:0x#{'%x' % address}>" : inspect | address = self.__id__ * 2 | ||
address += 0x100000000 if address < 0 | |||
inspect =~ /#</ ? "#<#{self.class}:0x#{'%x' % address}>" : inspect | |||
end | |||
end | |||
|
|||
module StringMethods | |||
def mocha_inspect | |||
inspect.gsub(/\"/, "'") | |||
end | |||
end | |||
|
|||
module ArrayMethods | |||
def mocha_inspect | |||
"[#{collect { |member| member.mocha_inspect }.join(', ')}]" | |||
end | |||
end | |||
|
|||
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)" | |||
end | |||
end | |||
|
|||
module DateMethods | |||
def mocha_inspect | |||
to_s | |||
end | |||
end | |||
|
|||
end | |||
|
|||
class Object | |||
include Mocha::ObjectMethods | |||
end | end | ||
|
|
||
class String | class String | ||
def mocha_inspect | include Mocha::StringMethods | ||
inspect.gsub(/\"/, "'") | |||
end | |||
end | end | ||
|
|
||
class Array | class Array | ||
def mocha_inspect | include Mocha::ArrayMethods | ||
"[#{collect { |member| member.mocha_inspect }.join(', ')}]" | |||
end | |||
end | end | ||
|
|
||
class Hash | class Hash | ||
def mocha_inspect | include Mocha::HashMethods | ||
"{#{collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')}}" | |||
end | |||
end | end | ||
|
|
||
class Time | class Time | ||
def mocha_inspect | include Mocha::TimeMethods | ||
"#{inspect} (#{to_f} secs)" | |||
end | |||
end | end | ||
|
|
||
class Date | class Date | ||
def mocha_inspect | include Mocha::DateMethods | ||
to_s | |||
end | |||
end | 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,7 +1,13 @@ | |||
class Object | module Mocha | ||
|
|
||
def __metaclass__ | module ObjectMethods | ||
class << self; self; end | def __metaclass__ | ||
class << self; self; end | |||
end | |||
end | end | ||
|
|||
end | |||
|
|
||
class Object | |||
include Mocha::ObjectMethods | |||
end | 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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,9 +1,15 @@ | |||
require 'mocha/parameter_matchers/equals' | require 'mocha/parameter_matchers/equals' | ||
|
|
||
class Object | module Mocha | ||
|
|
||
def to_matcher # :nodoc: | module ObjectMethods | ||
Mocha::ParameterMatchers::Equals.new(self) | def to_matcher # :nodoc: | ||
Mocha::ParameterMatchers::Equals.new(self) | |||
end | |||
end | end | ||
|
|
||
end | end | ||
|
|||
class Object | |||
include Mocha::ObjectMethods | |||
end |
Oops, something went wrong.