Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Allow stubs on parent and child classes simultaneously [#600 state:re…
Browse files Browse the repository at this point in the history
…solved]
  • Loading branch information
Jim Lindley authored and dchelimsky committed Nov 17, 2008
1 parent 00180b8 commit a37751b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 12 additions & 8 deletions lib/spec/mocks/proxy.rb
Expand Up @@ -125,14 +125,18 @@ def warn_if_nil_class(sym)

def define_expected_method(sym)
visibility_string = "#{visibility(sym)} :#{sym}"
if target_responds_to?(sym) && !target_metaclass.method_defined?(munge(sym))
munged_sym = munge(sym)
target_metaclass.instance_eval do
alias_method munged_sym, sym if method_defined?(sym.to_s)
if !@proxied_methods.include?(sym)
if target_responds_to?(sym) && !target_metaclass.method_defined?(munge(sym))
munged_sym = munge(sym)
target_metaclass.instance_eval do
alias_method munged_sym, sym if method_defined?(sym.to_s)
end
@proxied_methods << sym
elsif target_metaclass.method_defined?(munge(sym))
@proxied_methods << sym
end
@proxied_methods << sym
end

target_metaclass.class_eval(<<-EOF, __FILE__, __LINE__)
def #{sym}(*args, &block)
__mock_proxy.message_received :#{sym}, *args, &block
Expand All @@ -144,7 +148,7 @@ def #{sym}(*args, &block)
def target_responds_to?(sym)
return @target.send(munge(:respond_to?),sym) if @already_proxied_respond_to
return @already_proxied_respond_to = true if sym == :respond_to?
return @target.respond_to?(sym)
return @target.respond_to?(sym, true)
end

def visibility(sym)
Expand Down Expand Up @@ -193,7 +197,7 @@ def reset_proxied_methods
alias_method sym, munged_sym
undef_method munged_sym
else
undef_method sym
remove_method sym
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions spec/spec/mocks/bug_report_11545_spec.rb
Expand Up @@ -3,11 +3,11 @@
class LiarLiarPantsOnFire
include Spec::MetaClass
extend Spec::MetaClass
def respond_to?(sym)
def respond_to?(sym, incl_private=false)
true
end

def self.respond_to?(sym)
def self.respond_to?(sym, incl_private=false)
true
end
end
Expand All @@ -31,3 +31,4 @@ def self.respond_to?(sym)
LiarLiarPantsOnFire.metaclass.instance_methods.should_not include("something")
end
end

0 comments on commit a37751b

Please sign in to comment.