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

Support custom test paths #46264

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

TastyPi
Copy link
Contributor

@TastyPi TastyPi commented Oct 18, 2022

Motivation / Background

This Pull Request has been created because we're using Packwerk for our Rails app. We'd like to have tests for code in a package be defined in the directory for that package, e.g. packages/a/test. However, there is not a trivial way to make Rails's standard test/test:all etc. commands also run these tests. Our current solution is a custom rake file that redefines the tasks to include the packages' tests, but ideally this would be supported by Rails itself.

Detail

This Pull Request changes Rails::TestUnit::Runner to support specifying default test paths using Rails::Paths::Path. This mirrors how Rails::Engine and Rails::Application can be configured to use different paths from the standard. It also loads config/tests.rb if present, otherwise there is not a good place to configure the paths.

For the example above, the config/tests.rb would contain something like:

Dir.glob("packages/*/test").each do |path|
  Rails::TestUnit::Runner.paths["test"] << path
end

Additional information

This is my first time contributing to Rails, so I suspect this pattern does not fully follow Rails conventions, however I have at least checked that it works. I have not tested it with a project that uses rspec as I am unfamiliar with it.

I would say the most questionable parts are:

  1. Is Rails::TestUnit::Runner the right class for this configuration?
  2. Is Rails::Paths::Path the best solution for specifying these paths?
  3. Should config/tests.rb be introduced or is there a better way to run code before tests that I am unaware of?

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • There are no typos in commit messages and comments.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Feature branch is up-to-date with main (if not - rebase it).
  • Pull request only contains one commit for bug fixes and small features. If it's a larger feature, multiple commits are permitted but must be descriptive.
  • Tests are added if you fix a bug or add a feature.
    (I have not investigated how to test this and do not wish to spend too much time on it before I know the final implementation and whether this feature is wanted)
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.
  • PR is not in a draft state.
  • CI is passing.

@rails-bot rails-bot bot added the railties label Oct 18, 2022
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

1 participant