-
Notifications
You must be signed in to change notification settings - Fork 22.1k
bin/rails test runner (rerun snippets, run tests by line, option documentation)
#19216
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
Conversation
|
After this is merged, a failed test would be shown like: Also things like this would work: And all the rake equivalents: cc @dhh / @tenderlove |
|
❤️ 💚 💙 💛 💜 |
|
Should we make a convention out of a test pattern, say bin/rails test models
bin/rails test models/comment which, respectively, would be the same as: bin/rails test test/models
bin/rails test test/models/comment_test.rb |
|
@kaspth That is what we had with |
|
@senny I'm having trouble following you about the discoverability part, can you elaborate? |
|
I myself find it easy to understand what the possibilities are when the first argument is called I'm not really opposed to adding it but I have the feeling that doesn't add much to the table. |
|
Also, the directories are autocompletable while the patterns are not. |
|
@senny The shipping test task does a lot of stuff that's hard to figure out. I'm 👍 on reigning it in. |
|
👍 to only using paths.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this plugin trying to do? I don't understand this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This plugin is here for two things:
- Add the
TestUnitReporter, which outputs:
Failed tests:
bin/rails test /Users/arthurnn/dev/railstest/myapp/test/models/comment_test.rb:8
- Add a filter option to minitest. So we can find the
methodthat we want to run if the runner had a line argument specified, and only run that individual test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Since we control the superclass (everything inherits from AS::TestCase) we can implement the runnables method, so maybe we don't need these globals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% if I follow.
We still need to pass to Minitest runner which method we need to run, so we need the plugin, and need someway to know if we are running with the rails_runner or not, thats why $rails_test_runner
e7108f1 to
e828ecc
Compare
|
Does this report failures as it's running, or only at the end? |
Only at the end for now. Now that we have our reporter and a rails minitest plugin we will definitely do that too. |
|
👍
|
|
Seems good to me but I don't know anything about the implementation. Maybe it is good to ask @zenspider's opinion about the implementation before merging. |
|
I've just taken a quick glance at this and I guess I don't get it. I can see that you're using the plugin system to put in a custom reporter (almost the same as the reporters provided in seattlerb/minitest-sprint btw) and that's perfect. But, I don't understand why Rails::TestRunner exists as a whole. Can you explain why it exists? It looks like it is a reinvented wheel. Also, it looks like |
|
@zenspider the
Pretty much, its main responsibility, is to encapsulate the test options, so we can use it on the minitest plugin, but also on the rails command https://github.com/rails/rails/pull/19216/files#diff-d372de5c2ec1bba7b73aa34bb2d2a798R5 https://github.com/rails/rails/pull/19216/files#diff-47b9fc20bec6924b9946969a002d33c4R9 |
|
We can do the file name and line number thing without the global. Here is a patch against master that will do it. Adding a runner file seems fine. Maybe we could get access to the option parser on minitest so we don't have to duplicate the settings. |
|
@tenderlove A few concerns of you gist:
I agree that the global is not ideal, I am sure after we merge this people will come-up with a better solution to fix this problem. But to be honest I think this is kinda a implementation detail. @senny thoughts? |
Yes, I did this as a proof of concept to show that the implementation in this PR may not be the ideal place. I'm trying to give a working demo that doesn't require so much code. |
|
While the implementation is not perfect, I'm merging this to create a foundation we can collaborate on. Feel free to send pull requests improving the runner 💛 |
|
❤️ ❤️ ❤️ ❤️ ❤️ |
3 commits were missing when we merged the PR, probably they were lost when that branch was rebased against latest master. This merge, contains those 3 commits.
|
This still seems like a metric fuckton of code for something that really only needs to hook into the plugin system that minitest already provides. Having an entire runner, adding ~400 lines but only removing ~60? Seems entirely unnecessary. This can be done in 20-30 lines using facilities that minitest already provides.
Minitest already has a system for plugins to extend option processing.
Doesn't need a wrapper. You just need to process and manipulate options
That certainly doesn't need a runner. Again, the plugin system handles this entirely. |
|
thanks @zenspider . I will give it a shot at your suggestions, and cc you in the PR. ❤️ |
|
@zenspider I agree that we can make the implementation more focus. One thing I really want to have with the new runner is to advertise it's functionality. Similar to the |
|
That's handled too. |
|
@zenspider thanks for the heads up. We'll look into a better integration with minitest to reduce the code on our end. |
|
It is worth mentioning that this integrates spring with single test runs. |
|
👍 |
|
Hi everybody, Is this in the rails 4.2.1 release? I just updated rails and it didn't show up in help. |
|
@whatasunnyday no, this is on rails 5 only. |
|
@arthurnn I just realized that it said landed on master, not 4.2.1. I'm dumb! Sorry for the useless comment. Anyways, thanks for the great work ❤️ ❤️ ❤️. |
|
@whatasunnyday I was hoping for it to be in 4.2.1 as well lol |
|
Hey guys, is this gonna be implementing fail fast, and rerun failed tests? This would be awesome. |
The `method_source` gem was added in rails#19216. It was used to determine the last line number of a given test method to support running tests by line number. But this is not something that requires an external dependency: Ripper can do this easily, and it has the added advantage of not using repeated calls to `eval` to do it. Drop `method_source` and replace it with a simple handler for Ripper's `on_def` parser event. I don't believe that there are any mainstream rubies at this point that can run Rails and don't support Ripper but correct me if I'm wrong.
The `method_source` gem was added in rails#19216. It was used to determine the last line number of a given test method to support running tests by line number. But this is not something that requires an external dependency: Ripper can do this easily, and it has the added advantage of not using `eval` calls in a loop to do it as method_source does. It gets a bit trickier when dealing with declarative `test "some test"` style methods, but ripper can still handle those in a similar way. This is a second try at a PR (rails#45904) that got rolled back because the previous effort didn't handle the declarative test style.
The `method_source` gem was added in rails#19216. It was used to determine the last line number of a given test method to support running tests by line number. But this is not something that requires an external dependency: Ripper can do this easily, and it has the added advantage of not using `eval` calls in a loop to do it as method_source does. It gets a bit trickier when dealing with declarative `test "some test"` style methods, but ripper can still handle those in a similar way. This is a second try at a PR (rails#45904) that got rolled back because the previous effort didn't handle the declarative test style.
Successor of #18596.
This is the first stab at implementing a test runner for Rails. Moving forward we want to achieve the following goals with our runner:
Rails.envsetup)Follow-up work (can happen after this PR has been merged):
rake test:prepare db:test:prepare)Next Steps
Get feedback and merge this foundation into
rails/rails. Then everyone gets the chance to help us improve the runner.Thank you @arthurnn for helping me out ❤️
This work was inspired by maxitest.