spec/lib/tomatoharvest/config_spec.rb in tomatoharvest-0.0.1 vs spec/lib/tomatoharvest/config_spec.rb in tomatoharvest-0.1.0
- old
+ new
@@ -1,21 +1,22 @@
+require 'fileutils'
require 'helper'
describe TomatoHarvest::Config do
describe '.load' do
+
let(:global_options) do
{
project: 'Project',
type: 'Ruby Development',
}
end
before do
- File.open(TomatoHarvest::Config::CONFIG_PATH, 'w') do |file|
- YAML::dump(global_options, file)
- end
+ path = TomatoHarvest::Config.config_path(TomatoHarvest::Config::GLOBAL_DIR)
+ create_yaml_file(path, global_options)
end
it 'loads from the yaml config file' do
expect(TomatoHarvest::Config.load).to eql(global_options)
end
@@ -24,18 +25,37 @@
it 'overrides global config' do
options = {
type: 'JS Development',
}
- local_config = File.join(Dir.pwd, '.tomaconfig')
- File.open(local_config, 'w') do |file|
- YAML::dump(options, file)
- end
+ path = TomatoHarvest::Config.config_path(TomatoHarvest::Config::LOCAL_DIR)
+ create_yaml_file(path, options)
- result = global_options.merge(options)
+ expected = global_options.merge(options)
- expect(TomatoHarvest::Config.load).to eql(result)
+ expect(TomatoHarvest::Config.load).to eql(expected)
+ end
+
+ end
+
+ context 'when there is an old config file' do
+
+ let(:old_config) do
+ {
+ domain: 'fake.domain.name'
+ }
+ end
+
+ it 'loads it' do
+ old_config_path = File.join(TomatoHarvest::Config::HOME_DIR, '.tomaconfig')
+ expanded_path = File.expand_path(old_config_path)
+ create_yaml_file(expanded_path, old_config)
+
+ expected = old_config.merge(global_options)
+ expect(TomatoHarvest::Config.load).to eql(expected)
+
+ File.delete(old_config_path)
end
end
end