我创建了一个 Rails Mountable 应用程序并添加了“mongoid”和“rspec”gem。如果我现在尝试运行我的规范,我会收到以下错误:
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'