Skip to content

Commit

Permalink
Add feature spec when generating generator
Browse files Browse the repository at this point in the history
The before hook help us to redo the test and clean the files
  • Loading branch information
benoittgt committed Jan 20, 2020
1 parent 2ae4d21 commit 3553463
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
33 changes: 33 additions & 0 deletions features/generator_specs/generator_specs.feature
@@ -0,0 +1,33 @@
Feature: Generator spec

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

@remove-generator-files
Scenario: Use custom generator without '--generator-specs' arg
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
"""

@remove-generator-files
Scenario: Use custom generator with '--generator-specs' arg
When I run `bundle exec rails generate generator my_generator --generator-specs`
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
"""
11 changes: 11 additions & 0 deletions features/support/hooks.rb
@@ -0,0 +1,11 @@
Before('@remove-generator-files') do
command = <<-COMMAND
rm -f \
tmp/example_app/lib/generators/my_generator \
tmp/example_app/lib/generators/my_generator/my_generator_generator.rb \
tmp/example_app/lib/generators/my_generator/USAGE \
tmp/example_app/lib/generators/my_generator/templates \
tmp/example_app/spec/generator/my_generator_spec.rb
COMMAND
system(command)
end

0 comments on commit 3553463

Please sign in to comment.