Question

I am using Ruby 2.1.1 and rails-4.1.0 with Spring.

I cannot launch rake with RAILS_ENV=test attribute. For some reasons rake command

RAILS_ENV=test rake db:migrate

lead to the following error:

/home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load': cannot load such file -- /home/user/rbpr/getLead/db:migrate (LoadError)
    from /home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `each'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load_spec_files'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22:in `run'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'

My Rakfefile was not changed, it is default:

require File.expand_path('../config/application', __FILE__)
GetLead::Application.load_tasks

With RAILS_ENV=development and RAILS_ENV=production I have no LoadErrors. How can I catch this bug?

UPDATE

I have installed test DB and I have no pending migrations (all migrations are in status up for RAILS_ENV=test).

test:
  adapter: postgresql
  encoding: unicode
  database: pgdb_getlead_test
  pool: 15
  username: ***
  password: ***

I have update RSpec, but still have the same error:

/home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load': cannot load such file -- /home/user/rbpr/getLead/db:reset (LoadError)
    from /home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/configuration.rb:886:in `block in load_spec_files'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/configuration.rb:886:in `each'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/configuration.rb:886:in `load_spec_files'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/command_line.rb:22:in `run'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/runner.rb:90:in `run'
    from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/runner.rb:17:in `block in autorun'

The same with rake db:test:prepare:

WARNING: db:test:prepare is deprecated. The Rails test helper now maintains your test schema automatically, see the release notes for details.
/home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load': cannot load such file -- /home/user/rbpr/getLead/db:test:prepare (LoadError)
  from /home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
  from /home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
  from /home/user/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
  from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/configuration.rb:886:in `block in load_spec_files'
  from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/configuration.rb:886:in `each'
  from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/configuration.rb:886:in `load_spec_files'
  from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/command_line.rb:22:in `run'
  from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/runner.rb:90:in `run'
  from /home/user/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta1/lib/rspec/core/runner.rb:17:in `block in autorun'

Here is source code where this error occurred

FINAL UPDATE

The problem was with the Gemfile and gems for testing in development group, many thanks for your attention.

Was it helpful?

Solution

The issue is with the Gemfile and the grouping of certain gems to also load in development environment. If they're testing gems, keep them in group :test unless absolutely necessary to move them to development, like factory_gril_rails in example. So having,

group :test do
  gem 'rspec'
  gem 'rspec-rails', '~> 3.0.0.beta'
  ...

instead of:

group :development, :test do 
  gem 'rspec'
  ...

worked for me on my machine cloning your project. Hope this helps, give it a try.

p.s: there is also an old issue reported earlier here.

Also, I think you'll not have to require factory_girl_rails in you Gemfile like:

gem 'factory_girl_rails', require: false 

And then require it in your spec_helper:

require 'factory_girl_rails'

This way you're using this gem but you don't need to require it in other places than spec_helper.rb

OTHER TIPS

Look at the error message, it says

WARNING: db:test:prepare is deprecated. The Rails test helper now maintains your test schema automatically, see the release notes for details.

In Rails 4.1+, they deprecated db:test:prepare with that message

Check this answer

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top