[bug] mock expectations fail when a subclass is instantiated

I took a look at the web site but did not see any issue/bug tracker,
so I’m reporting this here.

The mock framework fails to differentiate between messages sent to a
parent class versus a subclass, so some of my expectations fail when I
assert some expectation on a parent. Here’s code to show it:

cremes$ cat c.rb
class A
end

class B < A
end

class C
def foo
a = A.new
b = B.new
end
end

cremes$ cat c_spec.rb
require ‘rubygems’
require ‘spec’
require ‘c’

describe C, “mock” do
it “should incorrectly pick up message sent to parent class as a
subclass err” do
A.should_receive(:new).once
c = C.new
c.foo
end
end

cremes$ spec c_spec.rb
F

NoMethodError in ‘C mock should incorrectly pick up message sent to
parent class as a subclass err’
undefined method new' for B:Class ./c.rb:10:infoo’
./c_spec.rb:9:

Finished in 0.006664 seconds

1 example, 1 failure

If I capture the exception thrown here, it is at lib/spec/mocks/
proxy.rb line 75. I’d provide a patch if I knew how to fix it! :slight_smile:

cr

On Sat, Aug 16, 2008 at 4:25 PM, Chuck R. [email protected]
wrote:

I took a look at the web site but did not see any issue/bug tracker

http://rspec.lighthouseapp.com

I forwarded this there:
http://rspec.lighthouseapp.com/projects/5645/tickets/496

Will respond in that ticket.

Cheers,
David