2012-01-12 11 views
0

RSpecとMongoidで動作するようにSporkを設定しようとしています。モデルは毎回リロードされません。 mongoidをリロードするために、次のspec_helper調整を提案する記述が見つかりましたが、現在工場の女の子は不幸です。それは戻っている:ここではマングローブ、ファクトリーガール、RSpec設定のスパークはモデルを更新しません

uninitialized constant Rails::VERSION (NameError) 
/home/dev1173/.rvm/gems/[email protected]/gems/factory_girl-2.3.2/lib/factory_girl.rb:23:in '<top (required)>' 

は、私は今、しばらくの間、この上で私の頭を叩いてきたspec/spec_helper.rb

require 'rubygems' 
require 'spork' 

Spork.prefork do 
    ENV["RAILS_ENV"] ||= 'test' 
    require "rails/mongoid" 
    Spork.trap_class_method(Rails::Mongoid, :load_models) 

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

    require 'rspec/rails' 
    require 'capybara/rspec' 
    require 'capybara/rails' 
    require "email_spec" 
    require File.expand_path(File.dirname(__FILE__) + '/../config/environment') 

    Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 

    RSpec.configure do |config| 

    config.infer_base_class_for_anonymous_controllers = false 

    # Allows email magic 
    config.include(EmailSpec::Helpers) 
    config.include(EmailSpec::Matchers) 

    require 'database_cleaner' 
    config.before(:suite) do 
     DatabaseCleaner.strategy = :truncation 
     DatabaseCleaner.orm = "mongoid" 
    end 

    config.before(:each) do 
     DatabaseCleaner.clean 
    end 

    end 
end 

Spork.each_run do 
end 

の内容です。何か案は?

答えて

3

あなたはあなたの設定/環境/ test.rbで偽cache_classesを=に設定し、次の行

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

それとも、私のガイドに従っtrueにcache_classesを維持したい場合は削除する必要があります。

Using spork and rails 3.1 with cache_classes true

+0

ありがとうございます! 'cache_classes = true'は私が逃したものです。なぜそれが適切に再ロードされなかったのか不思議でした。 –

+0

リンクされたガイドの+1。全面的なトラブルから私を得ました。ありがとう –

関連する問題