minitest/minitest-focus

`focus` method causes backports/tools.rb to crash

davesag opened this issue · 5 comments

In my Sinatra app I am trying to use minitest-focus 1.1.0 (thanks for the minutest v5 fix) my test, written using minitest/spec as follows (trimmed for example)

require 'minitest_helper'

describe MyController do
  include Rack::Test::Methods
  include FactoryGirl::Syntax::Methods
  include Warden::Test::Helpers

  def app
    MyApplication
  end

  let(:user) { create(:a_user) }
  let(:game) { create(:a_game) }

  before do
    DatabaseCleaner.start
  end

  after do
    DatabaseCleaner.clean
  end

  describe 'game play' do

    focus
    it "should launch a game if a user is logged in" do
      user.wont_be_nil
      login_as user
      get "/games/play/#{game.id}"
      last_response.must_be :ok?
    end

  end

end

I'm using Warden::Test::Helpers, SimpleCov, FactoryGirl, DatabaseCleaner and the Rack::Test::Methods.

Tests are run via RACK_ENV=test bundle exec rake and results in

/Users/davesag/.rvm/gems/ruby-2.0.0-p247/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require': cannot load such file -- /^(MyApplication::MyController::game play#test_0003_should launch a game if a user is logged in)$ (LoadError)
    from /Users/davesag/.rvm/gems/ruby-2.0.0-p247/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require_with_backports'
    from /Users/davesag/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/davesag/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/davesag/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
    from /Users/davesag/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/rake_test_loader.rb:15:in `block in <main>'
    from /Users/davesag/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/davesag/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib:spec" -I"/Users/davesag/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib" "/Users/davesag/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/rake_test_loader.rb" "spec/**/*_spec.rb" ]

If I comment out the focus method this test runs fine along with all the others.

I can't reproduce this error w/ all those mechanisms in play...

Could you put a p ARGV after your test and show me the output? I mainly want to know if this is a bug in my code as-is or if it is a bad interaction w/ activesupport and/or backports.

Yeah it's kinda non-trivial.

p ARGV is []

not much help I'm afraid.

When you say "after your test" I put it in the last line of the test.

I stripped down your code to the following and it works fine (unfortunately):

require "active_support/dependencies"
require "backports"
require "minitest/autorun"
require "minitest/focus"

describe "MyController" do
  describe 'game play' do

    focus
    it "should launch a game if a user is logged in" do
    end

    it "should not run" do
      flunk
    end
  end
end

Obviously your test helper is doing a lot of stuff. If you can figure out how to build up a repro, that'd help.

I'll strip something back to a more bare-bones example that still fails tomorrow. Getting late here down-under and I'm about to hit the sack.

my minitest_helper.rb looks like

require "simplecov"
SimpleCov.start

ENV['RACK_ENV'] = 'test'

require File.expand_path(File.join('config', 'application'))
require "factory_girl"
FactoryGirl.find_definitions

require 'database_cleaner'
DatabaseCleaner.strategy = :transaction

require 'minitest/focus'

config/application.rb does a whole bunch of stuff though!

Just out of interest take a look at the SAT project which I used as a rough basis for the core of my original web-app, and see if adding minitest/focus to any of his tests works or fails. (or I'll do this tomorrow if you don't mind waiting)

Thanks

dave

I'm tempted to close this...