コントローラをテストしているときに、この問題に遭遇しました。 私はrspec-rails-3.4.2、rails-4.2.0、mongodbを使用しています。 これが私のrails_helper.rbです
`ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/core'
require 'rspec/rails/extensions'
require 'rspec/rails/view_rendering'
require 'rspec/rails/adapters'
require 'rspec/rails/matchers'
require 'rspec/rails/fixture_support'
require 'rspec/rails/example'
require 'rspec/rails/vendor/capybara'
require 'mongoid-rspec'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.orm = "mongoid"
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
require 'rspec/rails'
としてrspec-railsを要求してください。問題の原因である可能性があります。
@JonRoweすぐに返信していただきありがとうございます。 私もやってみました。 respec-railsが必要な場合、別のエラーが発生します
失敗/エラー:プールがない限り、ConnectionNotEstablished、「#{klass}の接続プールがありません」を発生させます
はい、これはあなたの側の設定ミスの問題です。ActiveRecordを使用しないように、rspec-railsの前にmongoidがロードされていることを確認する必要があります。
RSpecを試す前に、エラーなしでRAILS_ENV=test rails console
を実行できることを確認してください。
私たちがさらに支援するには、バックトレースを提供する必要があります( https://gist.github.com
経由)
最も参考になるコメント
require 'rspec/rails'
としてrspec-railsを要求してください。問題の原因である可能性があります。