views:

32

answers:

1

I want to write a rspec test that tests if correct layout is used for controller. (Actually I want to test that no layout is used :) ).

I did some googling and also Looked here http://stackoverflow.com/questions/109284/testing-rendering-of-a-given-layout-with-rspec-rails

But all of this does not work for Rails3.

I have used:

controller.layout

and

controller.class.read_inheritable_attribute(:layout)

but none of these give me actual layout used.

Do you have any ideas how to get which layout was used for controller?

A: 

Try response.layout

EDIT

Sure enough, response.layout no longer works in Rspec2. However you can verify the correct layout was rendered using render_template as described on this Rails Forum thread:

response.should render_template("layouts/mylayout")

As to the second part of your question, I don't see a way of checking for the absence of a layout. response.should_not render_template("layouts/mylayout") does not appear to work. See this discussion

zetetic
No there is no such method as `layout` for response object in RoR3 :NoMethodError (undefined method `layout' for #<ActionDispatch::Response:0x9322ea0>):
oskarae
You're right. See my edited answer.
zetetic