forked from freerange/mocha
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidied up Mock class. Don't delegate to Object#mocha_inspect for Mock…
…#mocha_inspect so that we don't run into problems when mocking #inspect method. Remove __mock_name accessor which was only needed for testing.
- Loading branch information
1 parent
4b32739
commit 3b3136e
Showing
3 changed files
with
18 additions
and
39 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,37 +1,20 @@ | ||
require 'mocha/mock_methods' | ||
|
||
module Mocha | ||
|
||
module ExtraMethods | ||
|
||
attr_reader :__mock_name | ||
class Mock | ||
|
||
include MockMethods | ||
|
||
def initialize(stub_everything = false, name = nil) | ||
@stub_everything = stub_everything | ||
@__mock_name = name | ||
@mock_name = name | ||
end | ||
|
||
alias :mocha_inspect_before_hijacked_by_named_mocks :mocha_inspect | ||
|
||
def mocha_inspect | ||
@__mock_name ? "#<Mock:#{@__mock_name}>" : mocha_inspect_before_hijacked_by_named_mocks | ||
@mock_name ? "#<Mock:#{@mock_name}>" : "#<Mock:0x#{__id__.to_s(16)}>" | ||
end | ||
|
||
end | ||
|
||
class Mock | ||
|
||
include MockMethods | ||
include ExtraMethods | ||
|
||
end | ||
|
||
class BlankMock | ||
|
||
methods_to_keep = /^__.*__$|respond_to?|mocha_inspect|inspect|class|object_id|send|is_a\?|==|hash|nil\?|extend|eql\?/ | ||
instance_methods.each { |method_to_remove| eval("undef :#{method_to_remove}") unless method_to_remove =~ methods_to_keep } | ||
|
||
include MockMethods | ||
include ExtraMethods | ||
|
||
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