[rspec-devel] [ rspec-Bugs-8165 ] Partial Mock Errors when respond_to? is true but the method is not in the object

noreply at rubyforge.org noreply at rubyforge.org
Thu Jan 25 21:59:43 EST 2007


Bugs item #8165, was opened at 2007-01-25 18:59
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=8165&group_id=797

Category: None
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Brian Takita (btakita)
Assigned to: Nobody (None)
Summary: Partial Mock Errors when respond_to? is true but the method is not in the object

Initial Comment:
Unfortunately, this happens with ActiveRecord until #define_read_methods is called.

dir = File.dirname(__FILE__)
require "#{dir}/spec_helper"

context "An object where respond_to? is true and does not have method" do
  specify "should not raise an exception" do
    obj = Object.new
    obj.should_receive(:respond_to?).with(:foobar).and_return(true)
    obj.should_receive(:foobar).and_return(:baz)
    obj.foobar.should == :baz
  end
end


Here is an ActiveRecord case:

context "An object where respond_to? is true and does not have method" do
  specify "should not raise an exception" do
    obj = Person.new
    obj.should_receive(:respond_to?).with(:foobar).and_return(true)
    obj.should_receive(:foobar).and_return(:baz)
    obj.foobar.should == :baz
  end
end

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=8165&group_id=797


More information about the rspec-devel mailing list