guard-minitest: Rails 5 issues: invalid option: --guard

Upgraded to Rails 5 and guard-minitest v2.4.6 today. Got two issues:

Problem 1

bundle exec guard with guard :minitest do i get the following error:

/Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/test_unit/minitest_plugin.rb:57:in `plugin_rails_options': invalid option: --guard (OptionParser::InvalidOption)
    from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:200:in `block (2 levels) in process_args'
    from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:198:in `each'
    from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:198:in `block in process_args'
    from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:168:in `new'
    from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:168:in `process_args'
    from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:122:in `run'
    from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:62:in `block in autorun'

it might be related to the following issue: https://github.com/rails/rails/issues/25046 and #141

if i add spring to the guardfile guard :minitest, spring: true do then invalid option: --guard doesn’t appear and all tests run . Also rolling back to v2.4.5 solves the issue.

Problem 2

with spring: true i cannot get specific test to run. Having watch(%r{^test/.+_test\.rb$}) in guardfile and updating for example user_test.rb it runs all tests. Without spring it runs only user_test.rb see #130

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 7
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

For me the following setup works flawlessly:

  • guard (2.14.0)
  • guard-minitest (2.4.6)
  • minitest (5.10.1)
  • rails 5.0.1
# in Guardfile
guard :minitest, spring: "bin/rails test", all_on_start: false do
  # usual rules for Rails apps
end

For problem 1 the cause is definitely the linked Rails issue (https://github.com/rails/rails/issues/25046). Rails has its own minitest runner and that parses options ahead of time and minitest plugins could not register their own flags. This probably breaks any other plugin that uses custom command line flags.

Using a flag to signal the plugin is pretty much the recommended minitest way. I don’t know if the mentioned Rails bug should be “supported” by guard-minitest and worked around somehow.

thanks @e2, it was #130. Using spring: "bin/rails test" solved problem 2. Maybe it needs to be in the readme?

I get this error without Rails, in just a plain Ruby gem, that I created with the bundler gem command and default minitest layout. When I run it with guard -d I see that it indeed does add an additional -- --guard option to the command and that minitest does not accept it.