Skip to content
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

Remove unneeded subdirectories in generator tests #45653

Merged
merged 1 commit into from Jul 26, 2022

Conversation

skipkayhil
Copy link
Member

Summary

This pattern is useful in some cases, like moving the project folder
from myapp to myapp_moved, or testing generated behavior based on the
app name being hyphenated-app.

However, for the majority of cases this is not needed and adds
additional complexity to some assertion helpers. For example,
assert_file always expands paths relative to destination_root
instead of whatever the working directory is.

Other Information

Ref #45652

@rails-bot rails-bot bot added the railties label Jul 25, 2022

FileUtils.cd(app_root) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test and the others like it are passing because the generator chdirs to its destination_root, rather than because setup does1. It would probably be better not to rely on that though.

If we want to clean up the cd blocks a bit, we could introduce an in_root helper method, like generators themselves have.

Alternatively, if we want to eliminate the cd blocks, we could introduce run_app_update and read_file helper methods (and maybe write_file for test_app_update_does_not_change_config_target_version). run_app_update would chdir as necessary, and read_file would simply File.expand_path with destination_root. That could be a follow-up PR, though.

Footnotes

  1. setup actually calls ensure_current_path, which chdirs to File.expand_path(Dir.pwd).

This pattern is useful in some cases, like moving the project folder
from myapp to myapp_moved, or testing generated behavior based on the
app name being hyphenated-app.

However, for the majority of cases this is not needed and adds
additional complexity to some assertion helpers. For example,
`assert_file` always expands paths relative to `destination_root`
instead of whatever the working directory is.
@jonathanhefner jonathanhefner merged commit 894686b into rails:main Jul 26, 2022
@jonathanhefner
Copy link
Member

Thank you, @skipkayhil! 😄

@skipkayhil skipkayhil deleted the rm-myapp-generator-tests branch July 26, 2022 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants