While testing my controllers I came across this issue. I am using rspec-rails-3.4.2, rails-4.2.0 and mongodb. Here is my 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
Please just require rspec-rails as require 'rspec/rails'
it's likely thats the cause of your issues
@JonRowe Thanks for the immediate reply. I tried that too. when I require respec-rails it causes another error
Failure/Error: raise ConnectionNotEstablished, "No connection pool for #{klass}" unless pool
Yep, this is a misconfiguration issue on your end, you need to ensure mongoid is loaded before rspec-rails so it doesn't try to use ActiveRecord.
Make sure you can do RAILS_ENV=test rails console
without error before trying RSpec.
For us to help any further you'll have to provide backtraces (via https://gist.github.com
)
Most helpful comment
Please just require rspec-rails as
require 'rspec/rails'
it's likely thats the cause of your issues