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.
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.
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.
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With