[rspec-users] render_to_string in a controller test?

EAW ericw at xmtp.net
Mon Feb 18 20:10:48 EST 2008

Hi all,

I know that in general, view and controller tests should be isolated,  
such that controller specs don't test views etc.  However, I think  
I've run into a situation that might be an exception.

My controller uses render_to_string to produce a chunk of HTML that it  
passes to a model to be processed.

The controller then redirects the user to a different page.  The  
results of the render_to_string are not seen by the user.

Since the controller is calling render_to_string, I've been trying to  
test that it is rendered correctly in my controller spec.  Because a  
controller spec normally doesn't render views, render_to_string just  
returns the path of the view, rather than the rendered output.  This  
prevents me from testing the output of render_to_string in the  
controller spec.

I can work around the issue by using integrate_views, and I guess  
that's fine, but shouldn't render_to_string really work in controllers?

Thanks for your input,

ericw at xmtp.net

"If the answer isn't violence, neither is your silence!"
                         -- Pop Will Eat Itself, "Ich Bin Ein Auslander"

More information about the rspec-users mailing list