I am using Rails 4.2 with Ruby 2.2 and rspec for test files. I have installed
Rails.env = 'test'
in both spec_helper and rails_helper. Here is my database.yml file:
development: adapter: postgresql encoding: unicode database: app_dev pool: 5 username: postgres password: root test: adapter: postgresql encoding: unicode database: app_test pool: 5 username: postgres password: root production: adapter: postgresql encoding: unicode database: app_prod pool: 5 username: postgres password: root
Here is my rails_helper:
Rails.env = 'test' require 'spec_helper' require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } ActiveRecord::Migration.maintain_test_schema! RSpec.configure do |config| config.include JsonHelper config.include PathHelper config.include S3Helper config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = true config.infer_spec_type_from_file_location! end
application.rb:
require File.expand_path('../boot', __FILE__) require 'rails/all' require 'yaml' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module AppName class Application < Rails::Application config.generators do |g| g.assets = false g.helper = false g.views = false end # Load all locale files config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')] config.i18n.load_path += Dir[Rails.root.join( 'config', 'locales', '**', '**', '*.{rb,yml}')] config.autoload_paths += %W(#{config.root}/lib) config.autoload_paths += Dir["#{config.root}/lib/**/"] config.autoload_paths += Dir["#{config.root}/app/workers/"] config.action_controller.include_all_helpers = false config.active_record.schema_format = :sql config.i18n.available_locales = [:en, :hi, :mr] config.i18n.default_locale = :hi config.i18n.fallbacks = [:en] config.active_record.raise_in_transactional_callbacks = true end end
Gemfile:
source 'https://rubygems.org'
When I run my test cases, Rails.env "validates" as expected (used for validation). However, my test cases always fall into the development database.
Rails.env #=> "test" ActiveRecord::Base.connection_config #=> {:adapter=>"postgresql", :encoding=>"unicode", :database=>"app_dev", :pool=>5, :username=>"postgres", :password=>"root"}
spec_helper:
require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' require 'simplecov' require 'simplecov-rcov' require 'database_cleaner' require 'factory_girl_rails' ENV['RAILS_ENV'] ||= 'test' SimpleCov.start RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods
I have been scratching my head since the last few hours, but it seems that nothing is hiding secrets. Any help would be helpful!