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

Use component path for generating RSpec files #2005

Merged
merged 6 commits into from
Mar 26, 2024

Conversation

neanias
Copy link
Contributor

@neanias neanias commented Mar 21, 2024

What are you trying to accomplish?

Generally, the path to an RSpec file should match the app path, but substituting app for spec. If a user changes the generation path for their components, then the generator should use an appropriate path that matches that. In the example where the user changes the generation path from app/components to app/views/components, the RSpec component spec should be created in spec/views/components.

What approach did you choose and why?

The logic chosen here checks that the component is still being generated into the app dir, otherwise it will just fallback on the usual destination of spec/components. I've used simple string matching of start_with?("app#{File::SEPARATOR}"), but maybe using something in the File or Pathname classes would be more flexible.

Anything you want to highlight for special attention from reviewers?

Since this includes the AbstractGenerator, we can remove the file_name method as it's provided by the module.

(Hi, Simon!)

Copy link
Member

@joelhawksley joelhawksley left a comment

Choose a reason for hiding this comment

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

This generally makes sense to me! Two questions:

  1. Do you think it's worth adding a test for this change?
  2. Do you think this is a breaking change? If it isn't, I think we should at least add a more detailed changelog entry.

@neanias
Copy link
Contributor Author

neanias commented Mar 22, 2024

Tests probably aren't a bad idea — I'll get one run up. Good question re breaking change. I suppose it is since it's actively changing generator behaviour... Rails allows overrides of builtin generators, so I can write some documentation about how to set it back to the old way? I can also expand on the changelog entry. Lmk what you think!

@joelhawksley
Copy link
Member

@neanias since it's a breaking change, we'll need to either hold it for the next major release or put it behind a config flag. I would vote we do the latter, adding a config flag that defaults to false for the new behavior. We can then remove the flag in the next major release!

@neanias
Copy link
Contributor Author

neanias commented Mar 22, 2024

@joelhawksley Sounds like a plan. Should I put it under the generate collection of config options?

@neanias
Copy link
Contributor Author

neanias commented Mar 22, 2024

The config option feels like a bit of a mouthful, but I think it's clear enough?

docs/CHANGELOG.md Outdated Show resolved Hide resolved
@boardfish
Copy link
Collaborator

boardfish commented Mar 22, 2024

👋 Nice to see you around here, @neanias! And thanks for a very thorough PR 💯

@boardfish
Copy link
Collaborator

Also, worth verifying if we need the same for Minitest.

@neanias
Copy link
Contributor Author

neanias commented Mar 22, 2024

Just noticed I've used "you" in my documentation for the new config flag. Is that ok or should I change it?

@joelhawksley
Copy link
Member

Just noticed I've used "you" in my documentation for the new config flag. Is that ok or should I change it?

I'd prefer to avoid "you". Mind making the change? I'll review the language in this PR for ya ❤️

@neanias
Copy link
Contributor Author

neanias commented Mar 22, 2024

Ok, I think that's everything? Re the potential equivalent Minitest change, I think that should come under a separate PR

@neanias
Copy link
Contributor Author

neanias commented Mar 22, 2024

Left "you" in the CHANGELOG 🤦

Generally, the path to an RSpec file should match the app path, but
substituting `app` for `spec`. If a user changes the generation path for
their components, then the generator should use an appropriate path that
matches that. In the example where the user changes the generation path
from `app/components` to `app/views/components`, the RSpec component
spec should be created in `spec/views/components`.

The logic chosen here checks that the component is still being generated
into the `app` dir, otherwise it will just fallback on the usual
destination of `spec/components`.

Since this is a breaking change, it is managed by the
`use_component_path_for_rspec_tests` config option.

NB: Since this includes the `AbstractGenerator`, we can remove the
`file_name` method as it's provided by the module.
@neanias
Copy link
Contributor Author

neanias commented Mar 22, 2024

God, really burning through the GHAction minutes with this one!

Copy link
Collaborator

@Spone Spone left a comment

Choose a reason for hiding this comment

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

Good idea!

@neanias
Copy link
Contributor Author

neanias commented Mar 26, 2024

I can't merge this due to the failing compat check with Primer. Is that expected?

docs/CHANGELOG.md Outdated Show resolved Hide resolved
docs/CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: William Mathewson <neanias@users.noreply.github.com>
lib/view_component/config.rb Outdated Show resolved Hide resolved
lib/view_component/config.rb Outdated Show resolved Hide resolved
lib/view_component/config.rb Outdated Show resolved Hide resolved
lib/view_component/config.rb Outdated Show resolved Hide resolved
@joelhawksley joelhawksley merged commit c33a422 into ViewComponent:main Mar 26, 2024
38 of 39 checks passed
@joelhawksley
Copy link
Member

The PVC failure is unrelated. Merging!

@neanias neanias deleted the patch-1 branch March 26, 2024 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants