Closed mrteera closed 7 years ago
pinging @arthurnn
So, the problem here is that the rails runner call Minitest.run
and don't let minitest/autorun
run it. see https://github.com/rails/rails/blob/88ff3f820aa88b7235b7554668f91a73532726af/railties/lib/rails/commands/test.rb
That means that if you do:
require 'minitest/focus'
require 'minitest/autorun'
class AwesomeTest < ActiveSupport::TestCase
end
and run it with bin/rails test awesome_test.rb
That will run our runner code, as well as require minitest/autorun
, which has another exit Minitest.run
call. So that make it run twice.
And the reason focus
won't work, is that focus
mutate the ARGV
to make it work, however that's too late as our runner already called Minitest.run(ARGV)
, and at that point the ARGV was not mutated yet.
I think the solution here is to make minitest-focus work as a plugin, and change the options on the plugin_focus_options
method, instead of mutation the ARGV. Does that sound correct @zenspider , any thoughts? I can maybe try to fix that.
Dunno how it'd go... but I'm open to reviewing it. :)
Any news? :-)
@rhymes I have done the following (without minitest-focus
)
In my test_helper.rb
class ActiveSupport::TestCase
class << self
alias :old_test :test
def test_all
@__run_all = true
end
def focus
@__run_next = true
@__run_all = false
end
def test(*args, &block)
if (@__run_next || @__run_all)
old_test(*args, &block)
@__run_next = false
end
end
end
end
require 'test_helper'
class FoobarTest < ActionDispatch::IntegrationTest
# test_all # uncomment if you want to run all the tests
focus
test "bar bar" do
assert false
end
test "foobar test" do
assert true
end
focus
test "no no no" do
assert true
end
end
The only problem is that you'd have to call test_all
when you want to run all the tests.
A
@mrteera @zenspider @arthurnn @zxiest
I just tried with Rails 5.0.5 after this fix https://github.com/rails/rails/blob/v5.0.5/railties/CHANGELOG.md#rails-505rc1-july-19-2017 and it works correctly.
@rhymes sweet. I guess this can be closed then
I try to put
require 'minitest/autorun'
intotest_helper.rb
. It works butrails test
execute twice instead once. (I have 8 tests)Also, I don't see
mini-focus
was loaded in Minitest.extensions while it can see other plugins https://github.com/rails/rails/blob/b326e82dc012d81e9698cb1f402502af1788c1e9/railties/lib/rails/test_unit/minitest_plugin.rb#L97 Here I putputs Minitest.extentions
I'm not sure it's Rails issue or not, so I posted here too: https://github.com/rails/rails/issues/25048#issuecomment-246139483