Skip to content

Commit 3b297ed

Browse files
author
Sam Phippen
authored
Specify layout with render template (#2063)
* Add to render_template docs: specify that a request renders a given layout * Fix example spec
1 parent e75c725 commit 3b297ed

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

features/matchers/render_template_matcher.feature

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: render_template matcher
22

33
The `render_template` matcher is used to specify that a request renders a
4-
given template. It delegates to
4+
given template or layout. It delegates to
55
[`assert_template`](http://api.rubyonrails.org/classes/ActionController/TemplateAssertions.html#method-i-assert_template)
66

77
It is available in controller specs (spec/controllers) and request
@@ -33,6 +33,28 @@ Feature: render_template matcher
3333
When I run `rspec spec/controllers/gadgets_spec.rb`
3434
Then the examples should all pass
3535

36+
Scenario: specify that a request renders a given layout
37+
Given a file named "spec/controllers/gadgets_spec.rb" with:
38+
"""ruby
39+
require "rails_helper"
40+
41+
RSpec.describe GadgetsController do
42+
describe "GET #index" do
43+
subject { get :index }
44+
45+
it "renders the application layout" do
46+
expect(subject).to render_template("layouts/application")
47+
end
48+
49+
it "does not render a different layout" do
50+
expect(subject).to_not render_template("layouts/admin")
51+
end
52+
end
53+
end
54+
"""
55+
When I run `rspec spec/controllers/gadgets_spec.rb`
56+
Then the examples should all pass
57+
3658
Scenario: render_template in a view spec
3759
Given a file named "spec/views/gadgets/index.html.erb_spec.rb" with:
3860
"""ruby

0 commit comments

Comments
 (0)