[rspec-users] Rspec & Rails Nested Resources

Daniel C. lists at ruby-forum.com
Tue Dec 14 19:53:43 EST 2010

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

And my current spec looks like:

  it "GET new" do
    @job = stub_model(Job, :to_param => "1")
    get :new, :job_id => @job.id
    assigns[:correspondence].should_not be_nil

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/.

More information about the rspec-users mailing list