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

Strange mini-test error after guard-rspec run #308

Closed
andrewhavens opened this issue Jan 14, 2015 · 6 comments
Closed

Strange mini-test error after guard-rspec run #308

andrewhavens opened this issue Jan 14, 2015 · 6 comments

Comments

@andrewhavens
Copy link

I just upgraded a bunch of testing gems in my Rails 3.2 app. I've upgraded to the latest guard (2.11.1), rspec-rails (2.99.0), guard-rspec (4.5.0), cucumber-rails (1.4.2), guard-cucumber (1.5.3), and converted from spork to using spring.

Everything seems to be working. However, when I start up guard, at the end of the rspec run, it displays this error:

/Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/test/unit.rb:55:in `process_args': invalid option: -f (OptionParser::InvalidOption)
    from /Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/minitest/unit.rb:1073:in `_run'
    from /Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/minitest/unit.rb:1066:in `run'
    from /Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/test/unit.rb:27:in `run'
    from /Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/test/unit.rb:780:in `run'
    from /Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/test/unit.rb:372:in `block (2 levels) in autorun'
    from /Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/test/unit.rb:33:in `run_once'
    from /Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/test/unit.rb:371:in `block in autorun'
    from /Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

I don't see this error when I run rspec manually (bin/rspec). I also don't see this after the cucumber run. So it seems like this bug is related to guard and guard-rspec. This issue seems related, but I don't think the solution is the same.

It doesn't appear to be causing any problems, but I'm still trying to solve this issue so that I don't continue to see this error message.

Here's a copy of my Guardfile:

guard :rspec, all_on_start: false, all_after_pass: false, failed_mode: :none, cmd: "spring rspec" do
  require "guard/rspec/dsl"
  dsl = Guard::RSpec::Dsl.new(self)

  # Feel free to open issues for suggestions and improvements

  # RSpec files
  rspec = dsl.rspec
  watch(rspec.spec_helper) { rspec.spec_dir }
  watch(rspec.spec_support) { rspec.spec_dir }
  watch(rspec.spec_files)

  # Ruby files
  ruby = dsl.ruby
  dsl.watch_spec_files_for(ruby.lib_files)

  # Rails files
  rails = dsl.rails(view_extensions: %w(erb haml slim))
  dsl.watch_spec_files_for(rails.app_files)
  dsl.watch_spec_files_for(rails.views)

  watch(rails.controllers) do |m|
    [
      rspec.spec.("routing/#{m[1]}_routing"),
      rspec.spec.("controllers/#{m[1]}_controller"),
      rspec.spec.("acceptance/#{m[1]}")
    ]
  end

  # Rails config changes
  watch(rails.spec_helper)     { rspec.spec_dir }
  watch(rails.routes)          { "#{rspec.spec_dir}/routing" }
  watch(rails.app_controller)  { "#{rspec.spec_dir}/controllers" }

  # Capybara features specs
  #watch(rails.view_dirs)     { |m| rspec.spec.("features/#{m[1]}") }
end

guard "cucumber", all_on_start: false, all_after_pass: false, focus_on: "focus", cli: "--no-profile --color --strict --format pretty" do
  watch(%r{^features/.+\.feature$})
  watch(%r{^features/support/.+$})          { "features" }

  watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m|
    Dir[File.join("**/#{m[1]}.feature")][0] || "features"
  end
end
@e2
Copy link
Contributor

e2 commented Jan 14, 2015

It seems you are including 'test/unit" somewhere - directly or indirectly. And 'test/unit' works by "autorunning" itself as soon as the process is exiting (rspec, or whatever).

So this means 'test/unit' is included somewhere.

First, stop spring to make sure any changes will take effect, e.g.

spring stop
spring status

Then, I'd check your Gemfile and add "require: false" to every gem that could be causing the problem (probably just minitest), e.g. in your Gemfile:

gem 'minitest', require: false

If that doesn't work, check your Gemfile.lock to see if any other gem is including minitest (show your Gemfile.lock if you aren't sure).

Also, I'd check for environment variables, e.g. RUBY_OPTS or similar (check .rbenv doc for possible environment setups).

If you still can't get rid of minitest/unit test, just rename the file:

/Users/andrew/.rbenv/versions/2.1.5/lib/ruby/2.1.0/test/unit.rb to something else and rerun things - it should explode.

The last option should give an error to help us find the cause.

There are too many possibilities at this point, though - even with Rails 3 requiring test case through it's test helper.

@e2
Copy link
Contributor

e2 commented Jan 14, 2015

If this is an old error (related to rails/test_help), the solution may be this:

Put something like this in one of your config files (before Rails is loaded):

gem 'minitest'
require 'minitest/unit'

module MiniTest
  class Unit
    def self.autorun
    end
  end
end

I'm not sure if this will work, but the idea is:

  1. require Minitest before it's required, so require won't work again
  2. replace the autorun method with a no-op, so when rails/test_help calls minitest which calls Minitest::Unit.autorun won't install the at_exit hook

If it doesn't work, insert a fail call in the real Minitest::Unit.autorun implementation to make sure it isn't called.

@andrewhavens
Copy link
Author

Thanks! Turns out I had a rogue require 'test/unit' somewhere in my codebase that didn't belong.

@e2
Copy link
Contributor

e2 commented Jan 14, 2015

I do recall a problem like that on Rails 3 - I'm glad you got it working!

@e2 e2 mentioned this issue Jan 21, 2015
@dchersey
Copy link

I don't have any refs to test/unit or minitest in my code or Gemfile, but my Gemfile.lock shows
activesupport (4.2.0)
i18n (> 0.7)
json (
> 1.7, >= 1.7.7)
minitest (> 5.1)
thread_safe (
> 0.3, >= 0.3.4)
tzinfo (~> 1.1)

Seems like Rails 4.2 pulls it in.

Before I try patching autorun, can anyone comment on whether there needs to be another solution in the guard codebase?

@saiqulhaq
Copy link

remove require 'rails/test_help' on your rails_helper.rb file

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

4 participants