How to get controller output in functional test

Hi,

How do you get the rendered output (sent to the browser) in a controller functional test?

I searched for this, and tried things like

@content_for_layout
@response.template.content_for_layout
yield
yield :layout

CmdJohnson

Hi,

How do you get the rendered output (sent to the browser) in a controller
functional test?

Have a look at @response.body

Fred

@response.body is an empty string!

With the debugger, I can find @response.template.content_for_layout but that’s not accessible with a method call.

This is the controller code:

respond_to do |format|

format.html

end

@response.body is an empty string!

Are you checking this after the call to the controller has been made ?

Fred

Yes, like this:

get :reload

puts “@response.body: [#{@response.body}]”

Results in:

@response.body: []

Yes, like this:
get :reload

puts "@response.body: [#...@response.body}]"

Results in:

@response.body: []

To me that sounds like the response is actually empty.

Fred

I found the problem. Goldberg is used to generate the page title, but generated an error in test mode. A quick fix was to return an empty layout in test mode.