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

Rails test command suggests similar test files when the given file is not found #51005

Merged
merged 1 commit into from
Mar 16, 2024

Conversation

zzak
Copy link
Member

@zzak zzak commented Feb 8, 2024

For example, if you run rails test test/models/usr_tsst.rb and the file does not exist, Rails will suggest test/models/users_test.rb as a possible file.

Could not load test file: test/models/usr_tsst.rb. Did you mean? test/models/user_test.rb

After investigating #50978, I was inspired to add this feature to Rails.

Credit to @tenderlove for the minitest implementation.

Comment on lines 63 to 64
ms = list_tests([default_test_glob])
cs = DidYouMean::SpellChecker.new(dictionary: ms).correct(path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are ms and cs short for "misspelling" and "correct spelling"? Would replacing the abbreviations with long form words lose us anything?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure the original intention, so good call.

I went with all_tests and corrections, since the former is all of the tests using the default glob and corrections is obvious.

… not found.

For example, if you run `rails test test/models/usr_tsst.rb` and the file does not exist,
Rails will suggest `test/models/users_test.rb` as a possible file.

```
Could not load test file: test/models/usr_tsst.rb. Did you mean? test/models/user_test.rb
```

Co-authored-by: Aaron Patterson <aaron@rubyonrails.org>
@zzak
Copy link
Member Author

zzak commented Mar 16, 2024

@byroot I think you were looking at minitest recently, do you think this makes sense, or we should rely on the behavior upstream?

@byroot byroot merged commit 5411787 into rails:main Mar 16, 2024
4 checks passed
@zzak zzak deleted the test-runner-did-you-mean branch March 16, 2024 10:29
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

3 participants