Controller.should_receive(:render) problem

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

On Jul 12, 2010, at 4:18 AM, Ruprict wrote:

In Rails, if I use
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.

Please post the code in the failing spec and the new action, along with
the backtrace of the error you’re getting.

Thx,
David