Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec test to render no layout

I can test my controller to render a certain layout with

expect { get :index }.to render_template(layout: 'my_layout')

But how can I test the controller to render NO layout?

The following first expectation passes, but be careful: the second expectation also passes! (testing the same code)

expect { get :index }.to render_template(layout: false)
expect { get :index }.to render_template(layout: true)

In Nov 2008, @david-chelimsky said:

One way I've handled this successfully is to integrate_views for this one example (in its own group) and specify that html elements from the layout are not present in the form. It's a brittle example, but it's only one.

I dont want to check the rendered view, but I did not find any better solution so far.

Does someone has a good approach?

like image 823
Robin Avatar asked May 16 '13 16:05

Robin


1 Answers

In my tests when there is no layout I just check if it is not loading "application" layout

expect { get :index }.to_not render_template(layout: "application")
like image 61
Anezio Campos Avatar answered Oct 03 '22 08:10

Anezio Campos