You might want to follow this answer from StackOverflow 
<https://stackoverflow.com/a/29442541/2832282>. In my previous mongoid 
project I did not need such patching but apparently we either missed 
something, or some strong dependencies were added in Rails/RSpec which 
makes it harder to separate it from ActiveRecord

On Tuesday, September 11, 2018 at 10:07:15 PM UTC+2, Surya wrote:
>
> Here is the complete trace:
>
>
>   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'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-rails-3.8.0/lib/rspec/rails/adapters.rb:126:in
>  
> `block (2 levels) in <module:MinitestLifecycleAdapter>'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in
>  
> `instance_exec'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in
>  
> `instance_exec'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:373:in
>  
> `execute_with'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:606:in
>  
> `block (2 levels) in run_around_example_hooks_for'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:342:in
>  
> `call'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:607:in
>  
> `run_around_example_hooks_for'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:464:in
>  
> `run'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:457:in
>  
> `with_around_example_hooks'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:500:in
>  
> `with_around_and_singleton_context_hooks'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:251:in
>  
> `run'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:629:in
>  
> `block in run_examples'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:625:in
>  
> `map'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:625:in
>  
> `run_examples'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:591:in
>  
> `run'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in
>  
> `block in run'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in
>  
> `map'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in
>  
> `run'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in
>  
> `block (3 levels) in run_specs'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in
>  
> `map'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in
>  
> `block (2 levels) in run_specs'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1989:in
>  
> `with_suite_hooks'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:111:in
>  
> `block in run_specs'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:74:in
>  
> `report'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:110:in
>  
> `run_specs'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:87:in
>  
> `run'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:71:in
>  
> `run'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:45:in
>  
> `invoke'
>       # 
> /Users/surya/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.8.0/exe/rspec:4:in 
> `<top (required)>'
>       # /Users/surya/.rvm/gems/ruby-2.3.1/bin/rspec:23:in `load'
>       # /Users/surya/.rvm/gems/ruby-2.3.1/bin/rspec:23:in `<main>'
>       # /Users/surya/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in 
> `eval'
>       # /Users/surya/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in 
> `<main>'
>       #
>       #   Showing full backtrace because every line was filtered out.
>       #   See docs for RSpec::Configuration#backtrace_exclusion_patterns 
> and
>       #   RSpec::Configuration#backtrace_inclusion_patterns for more 
> information.
>
> On Wed, 12 Sep 2018 at 01:35, Surya <[email protected] <javascript:>> 
> wrote:
>
>> 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/>
>>
>
>
> -- 
>
> 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/ac26adaf-2659-4cd8-9a5e-2442f798058e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to