mock expectations fail when a subclass is instantiated
Reported by David Chelimsky | August 17th, 2008 @ 12:45 AM | in No-Milestone-Assigned
From: Chuck Remes cremes.devlist@mac.com
Date: Sat, Aug 16, 2008 at 4:25 PM
Subject: [rspec-users] [bug] mock expectations fail when a subclass is instantiated
To: rspec-users rspec-users@rubyforge.org
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
Comments and changes to this ticket
-
David Chelimsky August 17th, 2008 @ 01:08 AM
- → Tag changed from to bug mocks
- → Assigned user changed from to David Chelimsky
I simplified the code example and committed it as pending:
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Behaviour Driven Development for Ruby.
