gma / tconsole

Testing console for Rails. Helps out with test performance and also makes it easier to run specific tests
177 stars 18 forks source link

Doesn't load database.yml #48

Closed gma closed 12 years ago

gma commented 12 years ago

Any thoughts on what could be causing this?

tconsole> all
Running tests...

/Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:23:in `spec'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/config.rb:161:in `block in configure'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/config.rb:86:in `call'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/config.rb:86:in `before_test_run!'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/server.rb:136:in `block (2 levels) in run_tests'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/server.rb:97:in `call'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/server.rb:97:in `block in run_in_fork'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/server.rb:94:in `fork'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/server.rb:94:in `run_in_fork'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/server.rb:121:in `block in run_tests'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/server.rb:120:in `run_tests'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/server.rb:195:in `run_file_set'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole/server.rb:15:in `handle'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole.rb:62:in `block in run'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole.rb:53:in `fork'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/lib/tconsole.rb:53:in `run'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tconsole-1.1.1/bin/tconsole:5:in `<top (required)>'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/bin/tconsole:19:in `load'
        from /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/bin/tconsole:19:in `<main>'

Test time (including load): 1.300522s

The "non production" part of my Gemfile look like this:

group :development do
  gem 'guard-coffeescript'
  gem 'guard-ctags-bundler'
  gem 'guard-livereload'
  gem 'guard-spin'
  gem 'rb-readline'
  gem 'ruby-debug19', :require => 'ruby-debug'
end

group :development, :test do
  gem 'database_cleaner'
  gem 'factory_girl_rails'
  gem 'guard-minitest', :git => 'git://github.com/gma/guard-minitest.git'
  gem 'minitest-rails',
    :git => 'git://github.com/rawongithub/minitest-rails.git',
    :branch => 'gemspec'
  gem 'mocha'
  gem 'tconsole'
  gem 'turn'
end
gma commented 12 years ago

Interestingly, when I removed turn from Gemfile I got a different error, indicating that ::MiniTest hadn't been loaded (from line 55 of minitest_handler.rb.

gma commented 12 years ago

A bit more info on my setup:

I've been digging for about an hour. No clue…

nalanj commented 12 years ago

@gma Can you send me a sample test file that you're using with mintiest rails. Ideally it'll be one that if you call it's class in TConsole by just passing the class name you see the same error you're seeing above. That'll help out with identifying what's going on.

Thanks!

nalanj commented 12 years ago

@gma I think I may have actually reproduced the issue you were experiencing.

What file names do your tests have? Do they follow the normal pattern of _test.rb or are they using _spec.rb?

gma commented 12 years ago

They're all named *_test.rb, but I'm using the spec dsl to create describe and it blocks (but using standard assertions within those blocks).

% tree test/
test/
├── controllers
│   ├── cards_controller_test.rb
│   ├── iterations_controller_test.rb
│   └── projects_controller_test.rb
├── domain
│   └── iteration_logic_test.rb
├── factories.rb
├── helpers
│   ├── cards_helper_test.rb
│   ├── iterations_helper_test.rb
│   └── projects_helper_test.rb
├── minitest_helper.rb
├── minitest_no_rails_helper.rb
├── models
│   ├── account_test.rb
│   ├── card_test.rb
│   ├── iteration_test.rb
│   └── project_test.rb
└── presenters
    ├── card_presenter_test.rb
    └── iteration_presenter_test.rb

5 directories, 16 files

Here's card_test.rb (that fails with the db env problem when I just enter CardTest):

require_relative '../minitest_helper'

describe Card do
  it 'should return nil for number when unsaved' do
    assert_nil FactoryGirl.build(:card).number
  end

  describe 'that exists' do
    before do
      @card = FactoryGirl.create(:card)
    end

    it 'should return id for number' do
      assert_equal @card.id, @card.number
    end
  end
end

If file names could cause it, could it be something to do with the paths? I suspect minitest-rails is responsible for my tests being in test/models rather than test/units, but haven't checked that.

gma commented 12 years ago

That was it; I changed test/unit and test/functionals in lib/tconsole/config.rb to test/models and test/functionals and then all would run some tests.

Adding this .tconsole file fixed it:

TConsole::Config.run do |config|
  config.file_sets = {
    "all" => ["#{config.test_dir}/**/*_test.rb"],
    "models" => ["#{config.test_dir}/models/**/*_test.rb"],
    "controllers" => ["#{config.test_dir}/controllers/**/*_test.rb"],
    "helpers" => ["#{config.test_dir}/helpers/**/*_test.rb"],
    "integration" => ["#{config.test_dir}/integration/**/*_test.rb"]
  }
end

I wonder whether or not the if is_rails? block ought to be replacing the file sets, or whether it should keep the existing one for all (which would work better when people add tests outside of unit, functional or integration directories).

nalanj commented 12 years ago

I rolled out an update in the latest prerelease to make sure that an error message shows up if no files match the file set being executed against. I'll try to get your code merged in once I can write up some tests for it.

gma commented 12 years ago

I had a quick look at config_test.rb and didn't notice anything about changing file_sets in Rails, so I just patched it and tested it off my own branch.

Apologies for lack of tests; if you'd like to suggest an approach I'll take a look at it for you, but if you've got something in mind and would rather just crack on with it, that's fine by me...

nalanj commented 12 years ago

@gma I'm thinking for these particular situations I'm almost going to have to do integration testing - it's definitely not your fault that tests aren't there - just something that's pretty hard to figure out on a crazy forking, super environment dependent tool like TConsole is.