Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 我运行rspec时收到Mongoid::Errors::NoSessionsConfig:错误_Ruby On Rails_Mongodb_Mongoid_Config_Rspec2 - Fatal编程技术网

Ruby on rails 我运行rspec时收到Mongoid::Errors::NoSessionsConfig:错误

Ruby on rails 我运行rspec时收到Mongoid::Errors::NoSessionsConfig:错误,ruby-on-rails,mongodb,mongoid,config,rspec2,Ruby On Rails,Mongodb,Mongoid,Config,Rspec2,我在Mountain Lion的rails 4.0和ruby 2.0环境中使用Mongoid 4.0和mongoDB v2.4.5。当我运行rspec测试时: require 'spec_helper' # This is a sample spec file, showing an initial effort to document a Ruby # class or module (in this case, the Array class) based on the documenta

我在Mountain Lion的rails 4.0和ruby 2.0环境中使用Mongoid 4.0和mongoDB v2.4.5。当我运行rspec测试时:

require 'spec_helper'

# This is a sample spec file, showing an initial effort to document a Ruby
# class or module (in this case, the Array class) based on the documentation
# at http://ruby-doc.org/.
describe Array do

  describe '#new' do
    it "should return the empty array" do
      let(:array) { Array.new(3) }
    end
  end

end
这就是我得到的

An error occurred in an after hook
  Mongoid::Errors::NoSessionsConfig: 
Problem:
  No sessions configuration provided.
Summary:
  Mongoid's configuration requires that you provide details about each session that can be connected to, and requires in the sessions config at least 1 default session to exist.
Resolution:
  Double check your mongoid.yml to make sure that you have a top-level sessions key with at least 1 default session configuration for it. You can regenerate a new mongoid.yml for assistance via `rails g mongoid:config`.

 Example:
   development:
     sessions:
       default:
         database: mongoid_dev
         hosts:
           - localhost:27017


  occurred at /usr/local/var/rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/bundler/gems/mongoid-06b708d37cde/lib/mongoid/sessions/factory.rb:61:in `create_session'
这是我的
mongoid.yml

    development:
  # Configure available database sessions. (required)
  sessions:
    # Defines the default session. (required)
    default:
      # Defines the name of the default database that Mongoid can connect to.
      # (required).
      database: dev_myApp
      # Provides the hosts the default session can connect to. Must be an array
      # of host:port pairs. (required)
      hosts:
        - localhost:28017
      options:
        # Change whether the session persists in safe mode by default.
        # (default: false)
        # safe: false

        # Change the default consistency model to :eventual or :strong.
        # :eventual will send reads to secondaries, :strong sends everything
        # to master. (default: :eventual)
        # consistency: :eventual

        # How many times Moped should attempt to retry an operation after
        # failure. (default: 30)
        # max_retries: 30

        # The time in seconds that Moped should wait before retrying an
        # operation on failure. (default: 1)
        # retry_interval: 1
  # Configure Mongoid specific options. (optional)
  options:
    # Enable the identity map, needed for eager loading. (default: false)
    # identity_map_enabled: false

    # Includes the root model name in json serialization. (default: false)
    # include_root_in_json: false

    # Include the _type field in serializaion. (default: false)
    # include_type_for_serialization: false

    # Preload all models in development, needed when models use
    # inheritance. (default: false)
    # preload_models: false

    # Protect id and type from mass assignment. (default: true)
    # protect_sensitive_fields: true

    # Raise an error when performing a #find and the document is not found.
    # (default: true)
    # raise_not_found_error: true

    # Raise an error when defining a scope with the same name as an
    # existing method. (default: false)
    # scope_overwrite_exception: false

    # Skip the database version check, used when connecting to a db without
    # admin access. (default: false)
    # skip_version_check: false

    # User Active Support's time zone in conversions. (default: true)
    # use_activesupport_time_zone: true

    # Ensure all times are UTC in the app side. (default: false)
    # use_utc: false

test:
  # Configure available database sessions. (required)
  sessions:
    # Defines the default session. (required)
    default:
      # Defines the name of the default database that Mongoid can connect to.
      # (required).
      database: test_myApp
      # Provides the hosts the default session can connect to. Must be an array
      # of host:port pairs. (required)
      hosts:
        - localhost:28017

Mongo的行为似乎非常正常。如何修复此问题?

看起来您的mongoid.yml配置文件中没有定义测试环境。

看起来您的mongoid.yml配置文件中没有定义测试环境。

实际上我有-请参阅更新的配置文件-我收到相同的错误-我应该更改测试端口吗?我看不到测试配置。我看了两次开发。如果您在运行测试时没有收到相同的错误,请稍后将您的
mongoid.yml
文件发送给我。事实上,我收到了-查看更新的配置文件-我收到了相同的错误-我应该更改测试端口吗?我看不到测试配置。我见过两次开发。如果在运行测试时没有遇到相同的错误,请稍后将
mongoid.yml
文件发送给我