Skip to content

Commit

Permalink
Clean up generator for generator specs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
budu committed Mar 14, 2024
1 parent 260b3bf commit 7d4ce37
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/generators/rspec/generator/generator_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -17,7 +17,7 @@ def template_name
end

def filename
"#{table_name}_generator_spec.rb"
"#{file_name}_generator_spec.rb"
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/generators/rspec/generator/templates/generator_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7d4ce37

Please sign in to comment.