oskarae
oskarae

Reputation: 520

How to test if correct layout was used in controller using RSpec and Rails 3

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 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?

Upvotes: 2

Views: 1231

Answers (1)

zetetic
zetetic

Reputation: 47548

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

Upvotes: 2

Related Questions