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

How to rerun single failing test by name #133

Closed
jmarceli opened this issue Oct 31, 2015 · 7 comments
Closed

How to rerun single failing test by name #133

jmarceli opened this issue Oct 31, 2015 · 7 comments

Comments

@jmarceli
Copy link

Is it possible to re-run single test directly from Guard console?

I know I can do this from command line with:

ruby -Ilib:test test/path/to/my_controller.rb -n test_name

but it would be really handy if I could just type something into Guard console e.g.

guard-minitest -n test_name

or something like that.

@e2
Copy link
Contributor

e2 commented Oct 31, 2015

I think you can pass it through Minitest's environment variable TESTOPTS, but you'd have to probably restart guard.

Maybe it's enough if you type in in the console:

ENV['TESTOPTS'] = '--name test_name'

And then just save the file with the test name?

@jmarceli
Copy link
Author

I've tried your approach but with no luck. I'm not sure if I do this the right way.
After failing test I write in Guard console:

[1] guard(main)> ENV['TESTOPTS'] = '--name test_my_test_function'

But then I just get:

=> "--name test_my_test_function"

as an output and nothing else.

@e2
Copy link
Contributor

e2 commented Nov 1, 2015

But then I just get:

Yes - nothing will happen, because that line just sets the environment variable guard's process.

You need to MODIFY the file, so guard picks up the change and runs minitest - minitest should then check the environment variable - and run only the test matching the name.

It's as if on an ordinary commandline you ran:

TESTOPTS="-n test_name" ruby -Ilib:test test/path/to/my_controller.rb

The problem with the above workaround is (if it works): you have to clear the ENV every time to run all the tests.

In RSpec, you can just tell rspec which tests to run/skip by using the "focus" feature. Since there's no such thing in Minitest (as far as I know), probably the best option is to set and clear the environment variable.

Simply put, Minitest doesn't have a runner like RSpec does - so it's hard to tell guard to tell guard-minitest to use a special option when you want it to.

Instead, you may use the --cli option, e.g.:

guard :minitest, cli: '--name test_name' do
  # ...
end

and Guard should restart when you change the file anyway.

Hope that helps.

@e2
Copy link
Contributor

e2 commented Nov 1, 2015

You can also probably just add the Pry command yourself, by adding Ruby code to your ~/.guard.rb file.

Here's what a Pry plugin looks like for the change command:

https://github.com/guard/guard/blob/master/lib/guard/commands/change.rb

Here's more about the currently supported commands: https://github.com/guard/guard/wiki/Interacting-with-Guard

@e2
Copy link
Contributor

e2 commented Nov 1, 2015

Also, the easiest way is to just probably copy the just test you want being run to a new file.

@jmarceli
Copy link
Author

jmarceli commented Nov 2, 2015

Thanks for your assistance. I see that (probably) easiest way to do what I want is to switch from minitest to RSpec (where it is built in functionality). That's a pity because I really like minitest syntax :(

@jmarceli jmarceli closed this as completed Nov 2, 2015
@e2
Copy link
Contributor

e2 commented Nov 3, 2015

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

No branches or pull requests

2 participants