Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature spec when generating generator
The before hook help us to redo the test and clean the files
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |