2

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?

Community
  • 1
  • 1
oskarae
  • 520
  • 2
  • 5
  • 16

1 Answers1

2

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
  • 47,184
  • 10
  • 111
  • 119
  • 1
    No there is no such method as `layout` for response object in RoR3 : NoMethodError (undefined method `layout' for #): – oskarae Oct 21 '10 at 12:21