add specs config
This commit is contained in:
parent
b65dca60a9
commit
82ad9cac0d
7
devops-service/spec/support/config.yml
Normal file
7
devops-service/spec/support/config.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# only :db key is required
|
||||||
|
mongo:
|
||||||
|
:db: devops_test
|
||||||
|
:host:
|
||||||
|
:port:
|
||||||
|
:user:
|
||||||
|
:password:
|
||||||
@ -1,8 +1,9 @@
|
|||||||
require 'core/devops-application'
|
require 'yaml'
|
||||||
|
|
||||||
module SpecSupport
|
module SpecSupport
|
||||||
BLANK_FILE = File.join(Devops::Application.root, 'spec/support/blank_file')
|
ROOT = File.join(__dir__, '../../')
|
||||||
TEST_DB = 'devops_test'
|
BLANK_FILE = File.join(ROOT, 'spec/support/blank_file')
|
||||||
|
|
||||||
|
|
||||||
def stub_loggers
|
def stub_loggers
|
||||||
allow(DevopsLogger).to receive_message_chain('logger.debug')
|
allow(DevopsLogger).to receive_message_chain('logger.debug')
|
||||||
@ -10,10 +11,32 @@ module SpecSupport
|
|||||||
allow(DevopsLogger).to receive_message_chain('logger.error')
|
allow(DevopsLogger).to receive_message_chain('logger.error')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.db
|
def self.db_params
|
||||||
@db ||= begin
|
@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'
|
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
|
end
|
||||||
end
|
end
|
||||||
Loading…
Reference in New Issue
Block a user