-
-
Notifications
You must be signed in to change notification settings - Fork 48
Catch FileAlreadyExistsError and exit cleanly #319
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
Catch FileAlreadyExistsError and exit cleanly #319
Conversation
timriley
left a comment
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.
This is looking great, thanks @stephannv! :)
I've got one comment/suggestion regarding the testing. Let me know what you think and then we can merge this either now or after that change.
| it "exits with error message" do | ||
| expect do | ||
| within_application_directory { generate_action } | ||
| end.to raise_error SystemExit do |exception| | ||
| expect(exception.status).to eq 1 | ||
| expect(error_output).to eq Hanami::CLI::FileAlreadyExistsError::ERROR_MESSAGE % {file_path:} | ||
| end |
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.
All these tests for file conflict handling, spread across each generator, get pretty repetitious. With you having the experience of authoring these changes, do you have thoughts about keeping the tests more maintainable?
I think my preference would be not to worry about testing for conflicts in every generator spec, instead add e.g. a spec/unit/hanami/cli/commands/app/generate/file_conflict_handling_spec.rb that demonstrates the conflict handling for just one of the generators, which would be sufficient for us to know the code is doing what it needs.
This feels appropriate given that code is centralised into a single place, rather than something that actually requires special handling inside every generator class.
It would also make each generator spec simpler and more focused on its happy path.
Is this something you'd be happy to do, either here or in a follow-up PR?
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 agree, @timriley. I will do it in a next PR since these tests are already in the codebase currently, I just adapted them to work with the new exception. I will explore some alternatives and propose some changes.
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.
This sounds good to me, thanks!
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.
Regarding the testing approach I suggested above, we do have an existing example in this repo already: spec/unit/hanami/cli/commands/app/generate/slice_detection_spec.rb. This is a feature that applies to all generate commands, but it would have been wasteful to test the identical thing for every single one of them, so we extracted it to a dedicated file and tested it just once.
Exits with status 1 when a command tries to generate an already existing file.
Fixes #181
This is a rebased version of #279