From 7d4ce37889c8b68648c0e950e8d5f1007b17c7e9 Mon Sep 17 00:00:00 2001 From: Nicolas Buduroi Date: Thu, 14 Mar 2024 11:27:11 -0400 Subject: [PATCH] Clean up generator for generator specs Don't force pluralization of the generator name in the generated spec and use the full generator name in the spec description. Also clean up an extra whitespace and empty line in the template. Note that the generator class constant cannot be directly used in the spec description as it isn't loaded by default. --- lib/generators/rspec/generator/generator_generator.rb | 4 ++-- lib/generators/rspec/generator/templates/generator_spec.rb | 3 +-- spec/generators/rspec/generator/generator_generator_spec.rb | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/generators/rspec/generator/generator_generator.rb b/lib/generators/rspec/generator/generator_generator.rb index 40118e83a2..76228ee185 100644 --- a/lib/generators/rspec/generator/generator_generator.rb +++ b/lib/generators/rspec/generator/generator_generator.rb @@ -4,7 +4,7 @@ module Rspec module Generators # @private class GeneratorGenerator < Base - class_option :generator_specs, type: :boolean, default: true, desc: "Generate generator specs" + class_option :generator_specs, type: :boolean, default: true, desc: 'Generate generator specs' def generate_generator_spec return unless options[:generator_specs] @@ -17,7 +17,7 @@ def template_name end def filename - "#{table_name}_generator_spec.rb" + "#{file_name}_generator_spec.rb" end end end diff --git a/lib/generators/rspec/generator/templates/generator_spec.rb b/lib/generators/rspec/generator/templates/generator_spec.rb index 146713908d..e755cddf7b 100644 --- a/lib/generators/rspec/generator/templates/generator_spec.rb +++ b/lib/generators/rspec/generator/templates/generator_spec.rb @@ -1,6 +1,5 @@ require 'rails_helper' -RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:generator) %> do - +RSpec.describe "<%= class_name %>Generator", <%= type_metatag(:generator) %> do pending "add some scenarios (or delete) #{__FILE__}" end diff --git a/spec/generators/rspec/generator/generator_generator_spec.rb b/spec/generators/rspec/generator/generator_generator_spec.rb index 79ea4b51b8..090fc00fdb 100644 --- a/spec/generators/rspec/generator/generator_generator_spec.rb +++ b/spec/generators/rspec/generator/generator_generator_spec.rb @@ -11,7 +11,7 @@ end it "include the standard boilerplate" do - expect(generator_spec).to contain(/require 'rails_helper'/).and(contain(/^RSpec.describe "Posts", #{type_metatag(:generator)}/)) + expect(generator_spec).to contain(/require 'rails_helper'/).and(contain(/^RSpec.describe "PostsGenerator", #{type_metatag(:generator)}/)) end end end