开发者

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

开发者 https://www.devze.com 2023-01-20 22:36 出处:网络
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 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

0

精彩评论

暂无评论...
验证码 换一张
取 消