Hi,
I am having trouble setting up rspec rails with mongoid. I get the
following exception(one of the exceptions but same for all 16 cases) when
running the rspec:
16) PostsController routing routes to #destroy
Failure/Error: raise ConnectionNotEstablished, "No connection pool
with '#{spec_name}' found." unless pool
ActiveRecord::ConnectionNotEstablished:
No connection pool with 'primary' found.
#
/Users/surya/.rvm/gems/ruby-2.3.1/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:930:in
`retrieve_connection'
#
/Users/surya/.rvm/gems/ruby-2.3.1/gems/activerecord-5.1.6/lib/active_record/connection_handling.rb:116:in
`retrieve_connection'
#
/Users/surya/.rvm/gems/ruby-2.3.1/gems/activerecord-5.1.6/lib/active_record/connection_handling.rb:88:in
`connection'
#
/Users/surya/.rvm/gems/ruby-2.3.1/gems/activerecord-5.1.6/lib/active_record/fixtures.rb:516:in
`create_fixtures'
#
/Users/surya/.rvm/gems/ruby-2.3.1/gems/activerecord-5.1.6/lib/active_record/fixtures.rb:1028:in
`load_fixtures'
#
/Users/surya/.rvm/gems/ruby-2.3.1/gems/activerecord-5.1.6/lib/active_record/fixtures.rb:999:in
`setup_fixtures'
#
/Users/surya/.rvm/gems/ruby-2.3.1/gems/activerecord-5.1.6/lib/active_record/fixtures.rb:851:in
`before_setup'
Here is the sample vanilla application code -
https://github.com/suryart/rspec_mongo_test_app
Steps that I followed :
Create a new rails app -
$ rails new rspec_mongo_test_app --api --skip-active-record -T
Modify Gemfile to this:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.6'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Build JSON APIs with ease. Read more:
https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS),
making cross-origin AJAX possible
# gem 'rack-cors'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a
debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# gem 'database_cleaner', '~> 1.7'
gem 'factory_bot_rails', '~> 4.x'
gem 'forgery', '~> 0.7'
gem 'guard-rspec', '4.7.3'
gem 'mongoid-rspec', '~> 4.0'
gem 'rspec-rails', '~> 3.8'
gem 'rubocop', '~> 0.58.2', require: false
gem 'simplecov', '~> 0.16', require: false
gem 'reek', '~> 5.0', require: false
end
group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in
the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'mongoid', '~> 7.0'
gem 'devise_token_auth', '0.1.43'
Setup mongoid:
$ rails g mongoid:config
$ rails g rspec:install
Now create a controller
$ rails g scaffold post subject:string content:text
Made config change in config/application.rb to take mongoid as ORM for
generator(
https://github.com/suryart/rspec_mongo_test_app/blob/master/config/application.rb),
also modified spec_helper.rb to remove all active record related
dependencies(
https://github.com/suryart/rspec_mongo_test_app/blob/master/spec/rails_helper.rb
).
I'm not quite sure what I'm doing wrong here. The whole setup works if I
disable the `require 'rspec/rails'` line in rails_helper.rb file but then I
can't run all rails controller/requests related tests as they require
get/post etc methods. Please help.
--
Please consider the environment before printing this email.
Regards,
Surya
[image: This is my Footrr] <http://footrr.com/l/3697/>
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/CAHGOqz6BO76UTE2Ph-Sp%3DT0EO3vquvJzpVtERcaS3XQZewcxGQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.