作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 spork 运行测试没有问题,但是,偶尔我必须重新启动 spork 服务器才能让它识别新添加的路由。在这种情况下,我重新启动了 spork 服务器,现在每当我运行任何测试时都会收到以下错误消息:
Exception encountered: #<NoMethodError: undefined method `instantiate_observers' for ActiveRecord::Base:Class>
backtrace:
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/Users/mydocs/Documents/rails_projects/sample_app_rails_4/spec/spec_helper.rb:56:in `block in <top (required)>'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork.rb:69:in `call'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork.rb:69:in `block in exec_each_run'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork.rb:69:in `each'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork.rb:69:in `exec_each_run'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/run_strategy/forking.rb:12:in `block in run'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/forker.rb:21:in `block in initialize'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/forker.rb:18:in `fork'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/forker.rb:18:in `initialize'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/run_strategy/forking.rb:9:in `new'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/run_strategy/forking.rb:9:in `run'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/server.rb:48:in `run'
/Users/mydocs/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1588:in `perform_without_block'
/Users/mydocs/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1548:in `perform'
/Users/mydocs/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1626:in `block (2 levels) in main_loop'
/Users/mydocs/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1622:in `loop'
/Users/mydocs/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1622:in `block in main_loop'
Spork.each_run do
ActiveSupport::Dependencies.clear
ActiveRecord::Base.instantiate_observers <--- This is line 56
load "#{Rails.root}/config/routes.rb"
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
end if Spork.using_spork?
最佳答案
观察者已从 Rails 4 中删除。尝试实例化它们是行不通的。您拥有的代码示例可能来自 Rails 3。
删除该行。不会有什么不好的事情发生。
关于ruby-on-rails - Undefined method 'instantiate_observers' 重启spork server后报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18095864/
我使用 spork 运行测试没有问题,但是,偶尔我必须重新启动 spork 服务器才能让它识别新添加的路由。在这种情况下,我重新启动了 spork 服务器,现在每当我运行任何测试时都会收到以下错误消息
我是一名优秀的程序员,十分优秀!