[rspec-devel] [ rspec-Bugs-9649 ] Parital mocks don't work if object loaded from fixture, and referenced via association
noreply at rubyforge.org
noreply at rubyforge.org
Sun Apr 1 11:24:12 EDT 2007
Bugs item #9649, was opened at 2007-03-28 15:44
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=9649&group_id=797
Category: mock module
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Chris Hoffman (hoffman_c)
Assigned to: Nobody (None)
Summary: Parital mocks don't work if object loaded from fixture, and referenced via association
Initial Comment:
Hello,
The following code will not function properly:
spec/fixtures/pages.yml
----------
first:
id: 1
type: LockedPage
name: the first default page
spec/fixtures/questions.yml
----------
first:
id: 1
type: LockedQuestion
name: the first default question
container_id: 1
container_type: LockedPage
spec/models/locked_question_spec.rb
----------
context "LockedQuestion#document_session, being linked to a Page that has a Document Session" do
fixtures :questions, :pages
setup do
@question = questions(:first)
@page = pages(:first)
@page.stub!(:document_session).and_return("the document session")
@question.page.should == @page #=> true
end
specify "should return the Page's Document Session" do
@question.document_session.should == "the document session" #=> fails with 'undefined method'
end
end
I would kludge something together by just assigning an unlocked page to the question, but the "Locked" that prefaces these models is a subclass that denies any modifications.
Thanks for your help.
-Chris
----------------------------------------------------------------------
>Comment By: Chris Hoffman (hoffman_c)
Date: 2007-04-01 11:24
Message:
Hello,
I have created a rails project with the models and spec that
reveal the problem. Please let me know if you need
additional information.
Also, you were indeed correct that the above example would
fail for a different reason (if not taking into account the
Question model's delegation). I apologize for the confusion.
----------------------------------------------------------------------
Comment By: David Chelimsky (dchelimsky)
Date: 2007-04-01 10:25
Message:
What's 'undefined method' getting called on? Question or Page? Can you post the backtrace?
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=9649&group_id=797
More information about the rspec-devel
mailing list