add specs config

This commit is contained in:
Anton Chuchkalov 2015-12-01 17:40:37 +03:00
parent b65dca60a9
commit 82ad9cac0d
2 changed files with 35 additions and 5 deletions

View File

@ -0,0 +1,7 @@
# only :db key is required
mongo:
:db: devops_test
:host:
:port:
:user:
:password:

View File

@ -1,8 +1,9 @@
require 'core/devops-application'
require 'yaml'
module SpecSupport
BLANK_FILE = File.join(Devops::Application.root, 'spec/support/blank_file')
TEST_DB = 'devops_test'
ROOT = File.join(__dir__, '../../')
BLANK_FILE = File.join(ROOT, 'spec/support/blank_file')
def stub_loggers
allow(DevopsLogger).to receive_message_chain('logger.debug')
@ -10,10 +11,32 @@ module SpecSupport
allow(DevopsLogger).to receive_message_chain('logger.error')
end
def self.db
def self.db_params
@db ||= begin
conf = config['mongo']
db_name = conf.fetch(:db)
[db_name, conf[:host], conf[:port], conf[:user], conf[:password]]
end
end
def self.db
unless @db
require 'mongo'
Mongo::MongoClient.new.db(TEST_DB)
db_name, host, port, user, password = db_params
@db = MongoClient.new(host, port).db(db_name)
@db.authenticate(user, password) unless user.nil? or password.nil?
end
@db
end
def self.config
@config ||= begin
config_file = ENV['RSPEC_CONFIG_PATH'] || File.join(ROOT, 'spec/support/config.yml')
if File.exists?(config_file)
YAML.load_file(config_file)
else
raise "There is no config file: '#{config_file}'"
end
end
end
end