Forum: Ruby on Rails How to get controller output in functional test

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7fe5937b838b580eeaa061c85f700583?d=identicon&s=25 Commander Johnson (Guest)
on 2009-03-14 12:25
(Received via mailing list)
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-14 13:46
(Received via mailing list)
On Mar 14, 11:24 am, Commander Johnson <commanderjohn...@gmail.com>
wrote:
> Hi,
>
> How do you get the rendered output (sent to the browser) in a controller
> functional test?

Have a  look at @response.body

Fred
7fe5937b838b580eeaa061c85f700583?d=identicon&s=25 Commander Johnson (Guest)
on 2009-03-14 14:30
(Received via mailing list)
@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

On Sat, Mar 14, 2009 at 1:45 PM, Frederick Cheung <
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-14 15:36
(Received via mailing list)
On Mar 14, 1:29 pm, Commander Johnson <commanderjohn...@gmail.com>
wrote:
> @response.body is an empty string!

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

Fred
7fe5937b838b580eeaa061c85f700583?d=identicon&s=25 Commander Johnson (Guest)
on 2009-03-14 15:42
(Received via mailing list)
Yes, like this:
get :reload

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

Results in:

@response.body: []

On Sat, Mar 14, 2009 at 3:35 PM, Frederick Cheung <
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-14 18:21
(Received via mailing list)
On Mar 14, 2:41 pm, Commander Johnson <commanderjohn...@gmail.com>
wrote:
> 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
7fe5937b838b580eeaa061c85f700583?d=identicon&s=25 Commander Johnson (Guest)
on 2009-03-15 13:21
(Received via mailing list)
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.
On Sat, Mar 14, 2009 at 6:20 PM, Frederick Cheung <
This topic is locked and can not be replied to.