[rspec-users] controller.should_receive(:render) problem

Ruprict glenn.goodrich at gmail.com
Mon Jul 12 05:18:17 EDT 2010


Hi.

My issue is similar to the one in this post:
http://groups.google.com/group/rspec/browse_thread/thread/973d770e45bdd6cd/8ba067476003f08f?lnk=gst&q=render+controller+should_receive#8ba067476003f08f

(which, btw, I could not reply to...only option was "Reply to Author")
where I have a RESTful controller.  I want create to redirect/render
the new action if the model fails to save with the supplied form
values.  Pretty basic and typical stuff.

In Rails, if I use

redirect_to(new_my_model_path)

then the entered values along with the error_messages on the object
are lost and I can't re-fill the form or list the errors.  If I use

render :action => "new"

then I keep all the request data and can use it to fill in form, etc.

In my spec, if I use

controller.should_receive(:render).with({:action=>"new"})

I get an expectation error that render is never called.  This is true
if I remove the .with() as well.

If y'all could let me know either 1) Why my redirect_to vs render
argument is flawed and/or 2) What I am doing wrong in the spec, I'd
appreciate it.

Thanks,
Ruprict


More information about the rspec-users mailing list