Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generator spec generator #2217

Merged
merged 8 commits into from Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions features/generator_specs/generator_specs.feature
@@ -0,0 +1,16 @@
Feature: Generator spec

RSpec spec(s) can be generated when generating application components. For instance, `rails generate model` will also generate an RSpec spec file for the model but you can also write your own generator. See [customizing your workflow](https://guides.rubyonrails.org/generators.html#customizing-your-workflow)

Scenario: Use custom generator
When I run `bundle exec rails generate generator my_generator`
Then the features should pass
Then the output should contain:
"""
create lib/generators/my_generator
create lib/generators/my_generator/my_generator_generator.rb
create lib/generators/my_generator/USAGE
create lib/generators/my_generator/templates
invoke rspec
create spec/generator/my_generators_generator_spec.rb
"""
Expand Up @@ -3,8 +3,8 @@
module Rspec
module Generators
# @private
class GeneratorsGenerator < Base
class_option :generator_specs, type: :boolean, default: false, desc: "Generate generator specs"
class GeneratorGenerator < Base
class_option :generator_specs, type: :boolean, default: true, desc: "Generate generator specs"

def generate_generator_spec
return unless options[:generator_specs]
Expand Down
22 changes: 22 additions & 0 deletions spec/generators/rspec/generator/generator_generator_spec.rb
@@ -0,0 +1,22 @@
require 'generators/rspec/generator/generator_generator'
require 'support/generators'

RSpec.describe Rspec::Generators::GeneratorGenerator, :type => :generator do
setup_default_destination

describe "generator specs" do
subject(:generator_spec) { file("spec/generator/posts_generator_spec.rb") }
before do
run_generator %w(posts)
end
it "creates the spec file by default" do
expect(generator_spec).to exist
end
it "contains 'rails_helper in the spec file'" do
expect(generator_spec).to contain(/require 'rails_helper'/)
end
it "includes the generator type in the metadata" do
expect(generator_spec).to contain(/^RSpec.describe \"Posts\", #{type_metatag(:generator)}/)
end
end
end
35 changes: 0 additions & 35 deletions spec/generators/rspec/generators/generator_generator_spec.rb

This file was deleted.