Permalink
Browse files

Only try to pass messages to the superclass if the superclass respond…

…s to the method

Fixes LH Bug #1049 and GH Bug #15 and #17
  • Loading branch information...
Andrew Selder authored and dchelimsky committed Mar 4, 2011
1 parent fd553b8 commit c723627e245e80b552e4c9e1e47d32bc7751ee13
Showing with 31 additions and 1 deletion.
  1. +1 −1 lib/spec/mocks/proxy.rb
  2. +30 −0 spec/spec/mocks/bug_report_1049_spec.rb
View
@@ -116,7 +116,7 @@ def message_received(sym, *args, &block)
elsif stub = find_almost_matching_stub(sym, *args)
stub.advise(*args)
raise_unexpected_message_args_error(stub, *args)
- elsif @target.is_a?(Class)
+ elsif @target.is_a?(Class) && @target.superclass.respond_to?(sym, true)
@target.superclass.send(sym, *args, &block)
else
@target.__send__ :method_missing, sym, *args, &block
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+class Bug1049Class
+
+ def self.singleton
+ @singleton ||= new
+ end
+
+ # Redirect all missing class methods to the singleton instance for backwards compatible API
+ def self.method_missing(name,*args,&block)
+ self.singleton.send(name,*args,&block)
+ end
+
+ def bar
+ "abc"
+ end
+end
+
+describe Bug1049Class do
+
+ it "should mock correctly" do
+ Bug1049Class.should_receive(:bar).and_return(123)
+ Bug1049Class.bar.should == 123
+ end
+
+ it "should call successfully after a mock" do
+ Bug1049Class.bar.should == "abc"
+ end
+
+end

1 comment on commit c723627

@nel

This comment has been minimized.

Show comment Hide comment
@nel

nel Apr 10, 2011

This bug is really nasty I just spend a lot of time to track it down. It is currently working in 1.3.0 and failing in 1.3.1 but and working in this commit.

This definitely deserve a 1.3.2 bug fix release because there is a "severe" regression between 1.3.0 and 1.3.1

nel commented on c723627 Apr 10, 2011

This bug is really nasty I just spend a lot of time to track it down. It is currently working in 1.3.0 and failing in 1.3.1 but and working in this commit.

This definitely deserve a 1.3.2 bug fix release because there is a "severe" regression between 1.3.0 and 1.3.1

Please sign in to comment.