我創建了一個Rails Mountable App,並添加了'mongoid'和'rspec'gem's。如果我嘗試運行我的規格現在我得到以下錯誤:Rails Engine + Mongoid:在默認的會話中找不到配置
Mongoid::Errors::NoSessionConfig:
Problem:
No configuration could be found for a session named 'default'.
Summary:
When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect.
Resolution:
Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash.
當我加入Mongoid.load!(Rails.root.join("config", "mongoid.yml"))
行spec_helper.rb
一切工作正常。
爲什麼會這樣以及如何在普通的Rails應用程序中獲得功能,我不需要調用加載函數?
mongoid.yml
development:
sessions:
default:
database: dummy_development
hosts:
- localhost:27017
options:
options:
test:
sessions:
default:
database: dummy_test
hosts:
- localhost:27017
options:
consistency: :strong
max_retries: 1
retry_interval: 0
版本:
gem 'rails', '~> 3.2.12'
gem 'mongoid', '~> 3.1'
gem 'rspec-rails', '~> 2.13'
您可以發佈您mongoid.yml文件? – 2013-03-12 15:30:27