Skip to content

Commit 46726b8

Browse files
authored
Merge pull request #2799 from i7an/main
Improve consistency with official controller spec style
2 parents c7d4200 + 8a654c5 commit 46726b8

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

features/matchers/redirect_to_matcher.feature

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,30 @@ Feature: `redirect_to` matcher
1313
require "rails_helper"
1414
1515
RSpec.describe WidgetsController do
16-
1716
describe "#create" do
18-
subject { post :create, :params => { :widget => { :name => "Foo" } } }
19-
2017
it "redirects to widget_url(@widget)" do
21-
expect(subject).to redirect_to(widget_url(assigns(:widget)))
18+
post :create, :params => { :widget => { :name => "Foo" } }
19+
20+
expect(response).to redirect_to(widget_url(assigns(:widget)))
2221
end
2322
2423
it "redirects_to :action => :show" do
25-
expect(subject).to redirect_to :action => :show,
24+
post :create, :params => { :widget => { :name => "Foo" } }
25+
26+
expect(response).to redirect_to :action => :show,
2627
:id => assigns(:widget).id
2728
end
2829
2930
it "redirects_to(@widget)" do
30-
expect(subject).to redirect_to(assigns(:widget))
31+
post :create, :params => { :widget => { :name => "Foo" } }
32+
33+
expect(response).to redirect_to(assigns(:widget))
3134
end
3235
3336
it "redirects_to /widgets/:id" do
34-
expect(subject).to redirect_to("/widgets/#{assigns(:widget).id}")
37+
post :create, :params => { :widget => { :name => "Foo" } }
38+
39+
expect(response).to redirect_to("/widgets/#{assigns(:widget).id}")
3540
end
3641
end
3742
end

features/matchers/render_template_matcher.feature

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ Feature: `render_template` matcher
1616
1717
RSpec.describe GadgetsController do
1818
describe "GET #index" do
19-
subject { get :index }
20-
2119
it "renders the index template" do
22-
expect(subject).to render_template(:index)
23-
expect(subject).to render_template("index")
24-
expect(subject).to render_template("gadgets/index")
20+
get :index
21+
22+
expect(response).to render_template(:index)
23+
expect(response).to render_template("index")
24+
expect(response).to render_template("gadgets/index")
2525
end
2626
2727
it "does not render a different template" do
28-
expect(subject).to_not render_template("gadgets/show")
28+
get :index
29+
30+
expect(response).to_not render_template("gadgets/show")
2931
end
3032
end
3133
end
@@ -40,14 +42,16 @@ Feature: `render_template` matcher
4042
4143
RSpec.describe GadgetsController do
4244
describe "GET #index" do
43-
subject { get :index }
44-
4545
it "renders the application layout" do
46-
expect(subject).to render_template("layouts/application")
46+
get :index
47+
48+
expect(response).to render_template("layouts/application")
4749
end
4850
4951
it "does not render a different layout" do
50-
expect(subject).to_not render_template("layouts/admin")
52+
get :index
53+
54+
expect(response).to_not render_template("layouts/admin")
5155
end
5256
end
5357
end

0 commit comments

Comments
 (0)