Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/stack_master/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

module StackMaster
class Config
ConfigParseError = Class.new(StandardError)

def self.load!(config_file = 'stack_master.yml')
resolved_config_file = search_up_and_chdir(config_file)
config = YAML.load(File.read(resolved_config_file))
base_dir = File.dirname(File.expand_path(resolved_config_file))
new(config, base_dir)
rescue Psych::SyntaxError => error
raise ConfigParseError, "Unable to parse #{resolved_config_file}: #{error}"
end

attr_accessor :stacks,
Expand Down
12 changes: 12 additions & 0 deletions spec/stack_master/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@
additional_parameter_lookup_dirs: ['production']
)
}
let(:bad_yaml) { "a: b\n- c" }

describe ".load!" do
it "fails to load the config if no stack_master.yml in parent directories" do
expect { StackMaster::Config.load!('stack_master.yml') }.to raise_error Errno::ENOENT
end

it "raises exception on invalid yaml" do
begin
orig_dir = Dir.pwd
Dir.chdir './spec/fixtures/'
allow(File).to receive(:read).and_return(bad_yaml)
expect { StackMaster::Config.load!('stack_master.yml') }.to raise_error StackMaster::Config::ConfigParseError
ensure
Dir.chdir orig_dir
end
end

it "searches up the tree for stack master yaml" do
begin
orig_dir = Dir.pwd
Expand Down