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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a cucumber scenario demonstrating their use, thats one reason why this was merged broken in the first place :)
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we want to flip the default state here, generally speaking generators are a rarely used feature so I think its fine to have to request them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not strongly against it, however, this may be quite confusing if we rely on the rails documentation [1]
The following command will silently ignore the spec
bin/rails generate generator my_awesome_generator
We need to explicitly ask for
bin/rails generate generator my_awesome_generator --generator-specs
Which it sounds a bit unnatural to me, but your call here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I freely admit I might be misunderstanding the hierarchy here. I agree that:
bin/rails generate generator my_generator
should work, but in no other circumstance should you end up with them without adding --generator-specs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bin/rails generate generator my_generator
works.
It just a matter of default behavior here.
No Spec generated:
bin/rails generate generator foo
exist lib/generators/foo
create lib/generators/foo/foo_generator.rb
create lib/generators/foo/USAGE
exist lib/generators/foo/templates
invoke rspec
Spec generated:
bin/rails generate generator bar --generator-specs
exist lib/generators/bar
create lib/generators/bar/bar_generator.rb
create lib/generators/bar/USAGE
exist lib/generators/bar/templates
invoke rspec
create spec/generator/bars_generator_spec.rb
Your call.
@JonRowe I have no clue how to write that, are there scenarios already for any generators I can use as inspirations? |
There's only a markdown file, but the cucumber scenarios pretty much have the affect of running a command line er command, and then introspecting the output, any of them should be enough to get going, you essentially want a when step that runs the command and some then steps that check the generated output. The benefit is they are isolated from rspec so can use the rails commands and thus check the loading etc |
Can you rebase this? |
03f4516
to
12e94d8
Compare
Is that okay? |
Absolutely. |
@joel does this now work for you? How are you going with a cucumber scenario? |
@joel Are you up to wrap this up? Does this work as expected now? |
12e94d8
to
32a6b7e
Compare
32a6b7e
to
2ae4d21
Compare
I can help if needed for Cucumber @joel. 🙇🏻♂️ |
@benoittgt it would be awesome! Can you open a PR on top of mine? |
@JonRowe Where do you see the feature test? I wrote something like: --- /dev/null
+++ b/features/generator_specs/generator_specs.feature
@@ -0,0 +1,21 @@
+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)
+
+ Scenario: Use custom generator
+ When I run `rails generate generator my_generator`
+ Then the features should pass
+ And 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_generator_generator_spec.rb
+ """ But this feature spec needs to verify the output from an existing Rails app. We have the |
There is an app generated in the cukes, is that not enough? |
I added a proposal in d7ff45d I think we should add specs by default. See this question #2217 (comment) When I was writing test I didn't understand why we had @joel, feel free to edit my commit. This is a draft but it should work. Especially the feature description. If you have better idea for the before hook feel free to share your tips. |
The before hook help us to redo the test and clean the files
d7ff45d
to
3553463
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @benoittgt, just a bit of feedback
db35f41
to
9dc2924
Compare
@JonRowe what do you think about:
I think we should always generated specs. |
@benoittgt I would say I agree and it was what I did in the first place, even if is not a big deal for generators though. |
Anyway thanks @benoittgt 👍 |
I just read this answer from Jon:
Sorry I missed it. The PR is ready for review and even merge if it's ok for you. |
No you can flip it, I mis understood (I rarely use generators). I'm ok with the default being to generate generator specs. |
I guess really few people use them 😅 |
I switch to default generated spec. I think we are good. :) I can squash if needed. |
EDIT: updating to I am facing this issue yet again with
I don't have the
in the helptext, plus the same |
For Rails 6.0 support you need rspec-rails > 4.0.0. (Repeated despite edit to make it clear to future travellers). |
Context
Rails offer the possibility to create our own set of generators [1]. While executing the following command
the test framework is called
See hook_for :test_framework
RSpec must give the expected generator
Problem
The given command get this error
History
@yhirano55 provided an implementation #1847 Jul 19, 2017, which I don't know why it wasn't integrated in the first place, @penelopezone?
@tragiclifestories opened an issue about it #2084 on Feb 26, 2019.
@ConSou implemented a version #2085 the same day and it was merged a couple of days after by @JonRowe on Mar 1, 2019.
However, as @kdiogenes commented a couple of days ago here #2085 (comment) this doesn't work.
Environment
This PR fix the issue.