fluke/devops-service/spec/support/spec_support.rb

35 lines
877 B
Ruby
Raw Normal View History

2015-12-01 17:40:37 +03:00
require 'yaml'
2015-11-03 11:46:54 +03:00
module SpecSupport
2015-12-01 17:40:37 +03:00
ROOT = File.join(__dir__, '../../')
BLANK_FILE = File.join(ROOT, 'spec/support/blank_file')
def self.db_params
@db_params ||= begin
2015-12-01 17:40:37 +03:00
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
2015-11-20 18:31:54 +03:00
require 'mongo'
2015-12-01 17:40:37 +03:00
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
2015-11-20 18:31:54 +03:00
end
end
2015-11-03 11:46:54 +03:00
end