spec/lib/config_spec.rb in hieracles-0.2.0 vs spec/lib/config_spec.rb in hieracles-0.2.1

- old
+ new

@@ -1,16 +1,11 @@ require 'spec_helper' describe Hieracles::Config do describe '.load' do context 'with an existing file' do - let(:options) do - { - config: 'spec/files/config.yml', - basepath: 'spec/files' - } - end + let(:options) { { config: 'spec/files/config.yml' } } let(:expected) do { classpath: File.expand_path('spec/files/farm_modules/%s.pp'), modulepath: File.expand_path('spec/files/modules'), hierafile: File.expand_path('spec/files/hiera.yaml') @@ -29,11 +24,10 @@ context 'with additional parameters' do let(:hierapath) { 'hiera.yaml' } let(:options) do { config: 'spec/files/config.yml', - basepath: 'spec/files', hierafile: hierapath } end let(:expected) do { @@ -50,15 +44,51 @@ expect(Hieracles::Config.hierafile).to eq expected[:hierafile] expect(Hieracles::Config.format).to eq 'Console' end end + context 'with db set' do + context 'when no param is provided' do + let(:options) do + { + config: 'spec/files/config_withdb.yml' + } + end + before { Hieracles::Config.load options } + it { expect(Hieracles::Config.usedb).to be_truthy } + end + context 'with nodb passed as param' do + let(:options) do + { + config: 'spec/files/config_withdb.yml', + nodb: true + } + end + before { Hieracles::Config.load options } + it { expect(Hieracles::Config.usedb).to be_falsey } + end + end + + context 'with no-db set' do + context 'and db passed as param' do + let(:options) do + { + config: 'spec/files/config.yml', + db: true + } + end + before { Hieracles::Config.load options } + it { expect(Hieracles::Config.usedb).to be_truthy } + end + end + + context 'without an existing config file' do let(:options) do { - basepath: 'spec/files', - config: 'spec/files/config_no.yml' + config: 'spec/files/config_no.yml', + basepath: 'spec/files' } end before do FileUtils.rm(options[:config]) if File.exist? options[:config] Hieracles::Config.load options @@ -88,11 +118,10 @@ describe '.scope' do context 'with a yaml file' do let(:options) do { config: 'spec/files/config.yml', - basepath: 'spec/files', yaml_facts: 'spec/files/facts.yaml' } end let(:expected) { 'Debian' } before { Hieracles::Config.load options } @@ -101,17 +130,28 @@ end context 'with a json file' do let(:options) do { config: 'spec/files/config.yml', - basepath: 'spec/files', json_facts: 'spec/files/facts.json' } end let(:expected) { 'Debian' } before { Hieracles::Config.load options } it { expect(Hieracles::Config.scope[:osfamily]).to eq expected } + end + end + + describe '.resolve_path' do + context "when path is found" do + let(:path) { 'README.md' } + let(:expected) { File.expand_path('README.md') } + it { expect(Hieracles::Config.resolve_path(path)).to eq expected } + end + context "when path is not found anywhere" do + let(:path) { 'README-NOT.md' } + it { expect { Hieracles::Config.resolve_path(path) }.to raise_error(IOError) } end end end