Try assigns(:correspondence) instead. If that doesn't work, I would inspect the 
value of @job.correspondences.build (when run in the test). It's possible that 
stub_model is causing #build to return nil -- I don't remember the behavior off 
the top of my head and don't have a Ruby available to check. Anyway if it is 
nil then you'll need to do some more stubbing setup. stub_chain may be useful.

Pat



On Dec 14, 2010, at 4:53 PM, "Daniel C." <li...@ruby-forum.com> wrote:

> Hey all,
> 
> I'm new to Rspec and I was just wondering what the standard way of
> testing nested resources is?
> 
> I currently have a Job model which has many Correspondences.
> 
> The new action of my CorrespondencesController looks like:
> 
>  def new
>    @job = Job.find params[:job_id]
>    @correspondence = @job.correspondences.build
>  end
> 
> And my current spec looks like:
> 
>  it "GET new" do
>    @job = stub_model(Job, :to_param => "1")
>    Job.should_receive(:find).and_return(@job)
>    get :new, :job_id => @job.id
>    assigns[:correspondence].should_not be_nil
>  end
> 
> The test is currently failing with correspondence is nil, but it works
> fine in the browser.
> 
> Any help here would be great, thanks.
> 
> -- 
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to