【rails】spork测试中出现ActiveRecord::ConnectionNotEstablished的解决方案

错误提示如下:

18:17:13 - INFO - Guard is now watching at '/home/guochy/sample_app'
18:17:20 - INFO - Running: spec/requests/static_pages_spec.rb
Running tests with args ["--drb", "-f", "progress", "-r", "/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/guard-rspec-2.5.0/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec/requests/static_pages_spec.rb"]...
Exception encountered: #<ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished>
backtrace:
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:792:in `current_version'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:800:in `needs_migration?'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:379:in `check_pending!'
/home/guochy/sample_app/spec/spec_helper.rb:73:in `<top (required)>'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `block in load'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/spork-1.0.0rc4/lib/spork/run_strategy/forking.rb:11:in `block in run'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/spork-1.0.0rc4/lib/spork/forker.rb:21:in `block in initialize'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/spork-1.0.0rc4/lib/spork/forker.rb:18:in `fork'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/spork-1.0.0rc4/lib/spork/forker.rb:18:in `initialize'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/spork-1.0.0rc4/lib/spork/run_strategy/forking.rb:9:in `new'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/spork-1.0.0rc4/lib/spork/run_strategy/forking.rb:9:in `run'
/home/guochy/.rvm/gems/ruby-2.0.0-p247/gems/spork-1.0.0rc4/lib/spork/server.rb:49:in `run'
/home/guochy/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1588:in `perform_without_block'
/home/guochy/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1548:in `perform'
/home/guochy/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1626:in `block (2 levels) in main_loop'
/home/guochy/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1622:in `loop'
/home/guochy/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1622:in `block in main_loop'
Done.


解决方法很简单:

rake db:create

rake db:migrate

轻松解决。

你可能感兴趣的:(on,Ruby,ActiveRecord,Rails,guard)