[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
Mon Apr 2 10:23:54 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: Closed
>Resolution: Rejected
Priority: 3
Submitted By: Chris Hoffman (hoffman_c)
>Assigned to: Aslak Hellesøy (aslak_hellesoy)
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: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-04-02 10:23

Message:
Your Rails version is one year old, and the oldest Rails version RSpec is tested against is 1.1.6 (8 months old).

It's too much work for us to ensure things work against old Railses, so I'm closing this bug.

Feel free to reopen this bug if it still applies to Rails 1.1.6 or 1.2.x. (In the near future we will probably drop support for 1.1.6 though).


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

Comment By: Chris Hoffman (hoffman_c)
Date: 2007-04-02 07:44

Message:
I am not sure how to do partial mocks with Test::Unit.  As
far as versions, I have the following:

rspec 0.8.2
rails 1.1.2

Is the attached rails application not giving you an error
when you run rake spec:models?

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

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-04-02 07:19

Message:
Can you confirm that you're not getting the same problem when you use Test::Unit?

What are your versions of everything?

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

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