Repository navigation
Add Files#create_or_skip for optional files - #481
Merged
Merged
Conversation
Add `Files#create_or_skip` for generating optional files: if the file already exists, this method does not change it and reports it with a new `skip` verb. With `force: true`, it overwrites the file, just like `#create`. This method is intended for generators creating files that are helpful but not essential, like the test files generated by Hanami RSpec and Hanami Minitest. Their generators run _after_ the main generator has written its files, and they have been using `#write`, which replaces a user’s existing test files without a warning. See hanami/hanami-rspec#53.
timriley
force-pushed
the
skip-existing-files
branch
from
November 26, 2026 12:39
acbe3ed to
6465055
Compare
katafrakt
approved these changes
Nov 26, 2026
| fs.create_or_skip("spec/thing_spec.rb", "new content", force: true) | ||
|
|
||
| expect(fs.read("spec/thing_spec.rb")).to eq "new content" | ||
| expect(stdout.string).to eq " update spec/thing_spec.rb\n" |
Contributor
There was a problem hiding this comment.
I guess technically it "replace" or "overwrite" ("updated" is when we add routes to routes.rb). But I guess this is a different change, outside of the scope of this PR.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
Files#create_or_skipfor generating optional files: if the file already exists, this method does not change it and reports it with a newskipverb. Withforce: true, it overwrites the file, just like#create.This method is intended for generators creating files that are helpful but not essential, like the test files generated by Hanami RSpec and Hanami Minitest. Their generators run after the main generator has written its files, and they have been using
#write, which replaces a user’s existing test files without a warning.See hanami/hanami-rspec#53.