Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec testing layout

How do I test that a specific layout is used in RSpec? I've tried template.layout, response.layout, and response.should render_template("layout") with no luck.

like image 551
Eric M. Avatar asked Dec 12 '10 23:12

Eric M.


People also ask

How do I run a specific test in RSpec?

Running tests by their file or directory names is the most familiar way to run tests with RSpec. RSpec can take a file name or directory name and run the file or the contents of the directory. So you can do: rspec spec/jobs to run the tests found in the jobs directory.

What is RSpec testing?

RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.

Is RSpec used for unit testing?

RSpec is a unit test framework for the Ruby programming language. RSpec is different than traditional xUnit frameworks like JUnit because RSpec is a Behavior driven development tool.


1 Answers

In rspec 2, in a controller spec, you use render_template as you guessed, but you need to include a path relative to the views directory. So if your layout is app/views/layouts/mylayout.html.erb, your spec looks like this:

response.should render_template "layouts/mylayout"
like image 144
Rob Davis Avatar answered Dec 07 '22 15:12

Rob Davis