我一直在使用Michael Hartl的Rails Tutorial来学习Ruby on Rails,并且最近正在阅读本教程的新Rails 4.0版本。我遇到了Spork的问题;我知道我们使用的是Spork的自定义fork,以实现Rails 4.0兼容性,并且这可能是一种不同的不兼容性,但是我想发布我的问题,看看我是在做错什么还是有人有什么想法。每当我在Spork运行时调用RSpec时,都会收到ActiveRecord异常,而如果我单独调用RSpec则我的测试将成功运行-下面的示例终端转储:
oren@VM:~/ruby_projects/test_app$ rspec
Exception encountered: #<ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished>
backtrace:
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/activerecord-4.0.0/lib/active_record/migration.rb:792:in `current_version'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/activerecord-4.0.0/lib/active_record/migration.rb:800:in `needs_migration?'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/activerecord-4.0.0/lib/active_record/migration.rb:379:in `check_pending!'
/home/oren/ruby_projects/test_app/spec/spec_helper.rb:105:in `<top (required)>'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `block in load'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/spork-1.0.0rc3/lib/spork/run_strategy/forking.rb:11:in `block in run'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/spork-1.0.0rc3/lib/spork/forker.rb:21:in `block in initialize'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/spork-1.0.0rc3/lib/spork/forker.rb:18:in `fork'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/spork-1.0.0rc3/lib/spork/forker.rb:18:in `initialize'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/spork-1.0.0rc3/lib/spork/run_strategy/forking.rb:9:in `new'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/spork-1.0.0rc3/lib/spork/run_strategy/forking.rb:9:in `run'
/home/oren/.rvm/gems/ruby-2.0.0-p195@rails_4_0/gems/spork-1.0.0rc3/lib/spork/server.rb:48:in `run'
/home/oren/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/drb/drb.rb:1588:in `perform_without_block'
/home/oren/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/drb/drb.rb:1548:in `perform'
/home/oren/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/drb/drb.rb:1626:in `block (2 levels) in main_loop'
/home/oren/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/drb/drb.rb:1622:in `loop'
/home/oren/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/drb/drb.rb:1622:in `block in main_loop'
我可以根据要求提供应用程序中的任何文件,只是不确定什么最有用。我基本上遵循了本教程第3章的前几个步骤(设置新应用,添加StaticPages Controller ,设置RSpec和添加第一个规范)以及有关设置Guard和Spork的说明(第3.6.2和3.6节) .3)。
谢谢你的帮助!
最佳答案
您的spec/spec_helper.rb
可能有问题。用https://github.com/railstutorial/sample_app_rails_4/blob/master/spec/spec_helper.rb替换您拥有的东西,看看是否可以解决该问题。
关于ruby-on-rails - Rails 4.0 Spork/ActiveRecord异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17311480/