From ab41d701e5fe4b74dbec1d0c7465f3feba7b2dfe Mon Sep 17 00:00:00 2001 From: Thomas Hareau Date: Tue, 20 Oct 2020 20:44:51 +0200 Subject: [PATCH 1/3] Improve controller template when no action --- lib/generators/rspec/controller/controller_generator.rb | 1 - .../rspec/controller/templates/request_spec.rb | 9 ++++++++- .../rspec/controller/controller_generator_spec.rb | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/generators/rspec/controller/controller_generator.rb b/lib/generators/rspec/controller/controller_generator.rb index c03ae83184..8da0fe9010 100644 --- a/lib/generators/rspec/controller/controller_generator.rb +++ b/lib/generators/rspec/controller/controller_generator.rb @@ -14,7 +14,6 @@ class ControllerGenerator < Base def generate_request_spec return unless options[:request_specs] - template 'request_spec.rb', File.join('spec/requests', class_path, "#{file_name}_spec.rb") end diff --git a/lib/generators/rspec/controller/templates/request_spec.rb b/lib/generators/rspec/controller/templates/request_spec.rb index 42b4b8e01b..d957333c92 100644 --- a/lib/generators/rspec/controller/templates/request_spec.rb +++ b/lib/generators/rspec/controller/templates/request_spec.rb @@ -1,7 +1,14 @@ require 'rails_helper' RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do -<% namespaced_path = regular_class_path.join('/') %> +<% namespaced_path = regular_class_path.join('/') -%> +<% if actions.empty? -%> + describe "GET /index" do + it "returns http success" do + pending "add some scenarios (or delete) #{__FILE__}" + end + end +<% end -%> <% for action in actions -%> describe "GET /<%= action %>" do it "returns http success" do diff --git a/spec/generators/rspec/controller/controller_generator_spec.rb b/spec/generators/rspec/controller/controller_generator_spec.rb index 8516703f23..4143af50fe 100644 --- a/spec/generators/rspec/controller/controller_generator_spec.rb +++ b/spec/generators/rspec/controller/controller_generator_spec.rb @@ -17,6 +17,7 @@ it { is_expected.to exist } it { is_expected.to contain(/require 'rails_helper'/) } it { is_expected.to contain(/^RSpec.describe "Posts", #{type_metatag(:request)}/) } + it { is_expected.to contain('pending') } end end From 0769933ff20a2ab5f8183885e59ec665b6f272a7 Mon Sep 17 00:00:00 2001 From: Mustapha Date: Tue, 20 Oct 2020 23:00:26 +0200 Subject: [PATCH 2/3] fix pr according to @pirj remarks --- lib/generators/rspec/controller/templates/request_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/generators/rspec/controller/templates/request_spec.rb b/lib/generators/rspec/controller/templates/request_spec.rb index d957333c92..75c5fc129a 100644 --- a/lib/generators/rspec/controller/templates/request_spec.rb +++ b/lib/generators/rspec/controller/templates/request_spec.rb @@ -4,9 +4,7 @@ <% namespaced_path = regular_class_path.join('/') -%> <% if actions.empty? -%> describe "GET /index" do - it "returns http success" do - pending "add some scenarios (or delete) #{__FILE__}" - end + pending "add some examples (or delete) #{__FILE__}" end <% end -%> <% for action in actions -%> From 14ed3cad4137171e89622ce972d747cb8189ee9b Mon Sep 17 00:00:00 2001 From: Thomas Hareau Date: Wed, 21 Oct 2020 18:45:05 +0200 Subject: [PATCH 3/3] Fix rubocop error --- lib/generators/rspec/controller/controller_generator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/generators/rspec/controller/controller_generator.rb b/lib/generators/rspec/controller/controller_generator.rb index 8da0fe9010..c03ae83184 100644 --- a/lib/generators/rspec/controller/controller_generator.rb +++ b/lib/generators/rspec/controller/controller_generator.rb @@ -14,6 +14,7 @@ class ControllerGenerator < Base def generate_request_spec return unless options[:request_specs] + template 'request_spec.rb', File.join('spec/requests', class_path, "#{file_name}_spec.rb") end