[rspec-users] [bug] mock expectations fail when a subclass is instantiated

David Chelimsky dchelimsky at gmail.com
Sat Aug 16 18:51:44 EDT 2008


On Sat, Aug 16, 2008 at 4:25 PM, Chuck Remes <cremes.devlist at mac.com> 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

>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
>
> 1)
> 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:in `foo'
> ./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! :)
>
> cr
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list