From 8a654c5ebd94d8cdb1f19e51ff3af69365ac3bf5 Mon Sep 17 00:00:00 2001 From: Ivan Yurchanka Date: Mon, 9 Sep 2024 11:44:12 +0200 Subject: [PATCH] Improve consistency with official controller spec style --- features/matchers/redirect_to_matcher.feature | 19 +++++++++------ .../matchers/render_template_matcher.feature | 24 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/features/matchers/redirect_to_matcher.feature b/features/matchers/redirect_to_matcher.feature index 5abfe3eef..ee3c277fe 100644 --- a/features/matchers/redirect_to_matcher.feature +++ b/features/matchers/redirect_to_matcher.feature @@ -13,25 +13,30 @@ Feature: `redirect_to` matcher require "rails_helper" RSpec.describe WidgetsController do - describe "#create" do - subject { post :create, :params => { :widget => { :name => "Foo" } } } - it "redirects to widget_url(@widget)" do - expect(subject).to redirect_to(widget_url(assigns(:widget))) + post :create, :params => { :widget => { :name => "Foo" } } + + expect(response).to redirect_to(widget_url(assigns(:widget))) end it "redirects_to :action => :show" do - expect(subject).to redirect_to :action => :show, + post :create, :params => { :widget => { :name => "Foo" } } + + expect(response).to redirect_to :action => :show, :id => assigns(:widget).id end it "redirects_to(@widget)" do - expect(subject).to redirect_to(assigns(:widget)) + post :create, :params => { :widget => { :name => "Foo" } } + + expect(response).to redirect_to(assigns(:widget)) end it "redirects_to /widgets/:id" do - expect(subject).to redirect_to("/widgets/#{assigns(:widget).id}") + post :create, :params => { :widget => { :name => "Foo" } } + + expect(response).to redirect_to("/widgets/#{assigns(:widget).id}") end end end diff --git a/features/matchers/render_template_matcher.feature b/features/matchers/render_template_matcher.feature index e8f7f3f91..0f4e159bb 100644 --- a/features/matchers/render_template_matcher.feature +++ b/features/matchers/render_template_matcher.feature @@ -16,16 +16,18 @@ Feature: `render_template` matcher RSpec.describe GadgetsController do describe "GET #index" do - subject { get :index } - it "renders the index template" do - expect(subject).to render_template(:index) - expect(subject).to render_template("index") - expect(subject).to render_template("gadgets/index") + get :index + + expect(response).to render_template(:index) + expect(response).to render_template("index") + expect(response).to render_template("gadgets/index") end it "does not render a different template" do - expect(subject).to_not render_template("gadgets/show") + get :index + + expect(response).to_not render_template("gadgets/show") end end end @@ -40,14 +42,16 @@ Feature: `render_template` matcher RSpec.describe GadgetsController do describe "GET #index" do - subject { get :index } - it "renders the application layout" do - expect(subject).to render_template("layouts/application") + get :index + + expect(response).to render_template("layouts/application") end it "does not render a different layout" do - expect(subject).to_not render_template("layouts/admin") + get :index + + expect(response).to_not render_template("layouts/admin") end end end