I want to write a rspec test that tests if correct layout is used for controller. (Actually I want to test that no l开发者_JS百科ayout 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?
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
精彩评论