ruby – Spork.prefork正在加载app / models / *

前端之家收集整理的这篇文章主要介绍了ruby – Spork.prefork正在加载app / models / *前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我不知道如何让spork不加载我所有的应用程序模型.测试我的模型的变化是非常慢的,因为我无法使用spork来帮助.这是我调试什么spork正在加载时我得到的:
    - Spork Diagnosis -
    -- Summary --
    app/models/account.rb
    app/models/admin.rb
    app/models/affiliate.rb
    app/models/app.rb
    app/models/application_server.rb
    app/models/domain_record.rb
    app/models/domain_zone.rb
    app/models/event.rb
    app/models/oid.rb
    app/models/user.rb
    config/application.rb
    config/boot.rb
    config/environment.rb
    config/environments/test.rb
    config/initializers/api_conversions.rb
    config/initializers/backtrace_silencers.rb
    config/initializers/compass.rb
    config/initializers/devise.rb
    config/initializers/hoptoad.rb
    config/initializers/inflections.rb
    config/initializers/mime_types.rb
    config/initializers/rspec_generator.rb
    config/initializers/secret_token.rb
    config/initializers/session_store.rb
    config/routes.rb
    lib/application_server_api.rb
    lib/oid_helper.rb
    lib/soa_record.rb
    spec/spec_helper.rb



    -- Detail --



    --- app/models/account.rb ---
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `block in require'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:227:in `load_dependency'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:346:in `require_or_load'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:300:in `depend_on'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:216:in `require_dependency'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/mongoid-2.0.0.rc.7/lib/rails/mongoid.rb:54:in `load_model'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/mongoid-2.0.0.rc.7/lib/rails/mongoid.rb:17:in `block (2 levels) in load_models'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/mongoid-2.0.0.rc.7/lib/rails/mongoid.rb:16:in `each'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/mongoid-2.0.0.rc.7/lib/rails/mongoid.rb:16:in `block in load_models'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/paths.rb:102:in `block in each'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/paths.rb:102:in `each'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/paths.rb:102:in `each'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/mongoid-2.0.0.rc.7/lib/rails/mongoid.rb:15:in `load_models'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/mongoid-2.0.0.rc.7/lib/mongoid/railtie.rb:88:in `block (2 levels) in '
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:419:in `_run_prepare_callbacks'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.3/lib/action_dispatch/middleware/callbacks.rb:40:in `initialize'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.3/lib/action_dispatch/middleware/stack.rb:33:in `new'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.3/lib/action_dispatch/middleware/stack.rb:33:in `build'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.3/lib/action_dispatch/middleware/stack.rb:79:in `block in build'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.3/lib/action_dispatch/middleware/stack.rb:79:in `each'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.3/lib/action_dispatch/middleware/stack.rb:79:in `inject'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.3/lib/action_dispatch/middleware/stack.rb:79:in `build'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/application.rb:162:in `app'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/application/finisher.rb:35:in `block in '
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `block in run_initializers'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
    config/environment.rb:8:in `'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `block in require'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
    spec/spec_helper.rb:9:in `block in '
    /Users/sean/.rvm/gems/ruby-1.9.2-p136/gems/spork-0.9.0.rc3/lib/spork.rb:23:in `prefork'
    spec/spec_helper.rb:4:in `'

更新:我的spec_helper.rb

require 'rubygems'
require 'spork'

ENV["RAILS_ENV"] = "test"

Spork.prefork do
  require File.expand_path(File.dirname(__FILE__) + '/../config/environment')
  require 'rspec/rails'
end

Spork.each_run do
  # Hub::Application.reload_routes!
end

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

如果我移动需要File.expand_path(File.dirname(__ FILE__)’/../config/environment’)的prefork,我的模型不预加载,但是您可能期望运行我的测试需要更长的时间.

任何关于如何获得spork的Rails 3应用程序没有加载模型的想法?我试过使用spork 0.8.4,master分支,目前是0.9.0.rc3.有没有人有任何想法如何避免模型预加载

解决方法

经过很多时间旋转我的车轮,我终于有了可以接受的东西:
Spork.prefork do
  require "rails/mongoid"
  Spork.trap_class_method(Rails::Mongoid,:load_models)

  # The following does not work correctly with Devise's routes that load the User model. 
  # Results in NameError unintitialized *
  # :reload_routes! triggers :devise_for which loads and caches the User class.
  # https://github.com/timcharper/spork/wiki/Spork.trap_method-Jujutsu
  # require "rails/application"
  # Spork.trap_method(Rails::Application,:reload_routes!) 

  require 'factory_girl_rails'
  Spork.trap_class_method(Factory,:find_definitions)

  require File.expand_path(File.dirname(__FILE__) + '/../config/environment')

end

问题主要是由于Rails :: Mongoid#load_models.在检查spork的调试输出和如何加载事情的回溯之后,提供了关于加载模型的一些线索.这个页面有更详细的https://github.com/timcharper/spork/wiki/Spork.trap_method-Jujutsu,但是我没有找到:reload_routes!帮助Devise强制将用户类预先加载.

我的规格现在运行得更快如果只有我可以让我的用户模式不被缓存,我才会幸福,但直到那时,我将会很满意.

原文链接:https://www.f2er.com/ruby/272627.html

猜你在找的Ruby相关文章