RuntimeError when running rails test: "Application has been already initialized." -


i new rails. have develop new app , have not made many changes default configurations.

when running "rails test", following runtimeerror:

    running via spring preloader in process 1447     /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/application.rb:351:in `initialize!': application has been initialized. (runtimeerror)         /users/holth/documents/code/rails/ocmp/config/environment.rb:9:in `<top (required)>'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'         /users/holth/documents/code/rails/ocmp/test/test_helper.rb:2:in `<top (required)>'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'         /users/holth/documents/code/rails/ocmp/test/controllers/buy_controller_test.rb:1:in `<top (required)>'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/test_unit/test_requirer.rb:11:in `block in require_files'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/test_unit/test_requirer.rb:10:in `each'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/test_unit/test_requirer.rb:10:in `require_files'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/test_unit/minitest_plugin.rb:76:in `plugin_rails_init'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:80:in `block in init_plugins'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:78:in `each'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:78:in `init_plugins'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.9.0/lib/minitest.rb:129:in `run'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/test.rb:9:in `<top (required)>'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:138:in `require_command!'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:95:in `test'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in `run_command!'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands.rb:18:in `<top (required)>'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'         /users/holth/documents/code/rails/ocmp/bin/rails:9:in `<top (required)>'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `load'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `block in load'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `load'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'         /users/holth/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'         -e:1:in `<main>' 

i have tried modifying "config/environment.rb" have:

    rails.application.initialize! unless rails.env.test? 

rails test begin error on test.

    activerecord::connectionnotestablished: no connection pool id primary found. 

here's "database.yml":

default: &default   adapter: postgresql   encoding: unicode   pool: <%= env.fetch("rails_max_threads") { 5 } %>   timeout: 5000  development:   <<: *default   database: ocmp_development   host: localhost  test:   <<: *default   database: ocmp_test 

here's "test_helper.rb":

env['rails_env'] ||= 'test' require file.expand_path('../../config/environment', __file__) require 'rails/test_help'  class activesupport::testcase   # setup fixtures in test/fixtures/*.yml tests in alphabetical order.   fixtures :all    # add more helper methods used tests here... end 

please help, many thanks.


Comments