Skip to content

Commit

Permalink
fixup! Add rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
barraq committed Jun 6, 2016
1 parent a1a43d5 commit ad17ed7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
36 changes: 33 additions & 3 deletions spec/nanoc/base/entities/configuration_spec.rb
@@ -1,10 +1,9 @@
describe Nanoc::Int::Configuration do
let(:configuration) { described_class.new(hash) }

let(:hash) { { foo: 'bar' } }
let(:config) { described_class.new(hash) }

describe '#key?' do
subject { configuration.key?(key) }
subject { config.key?(key) }

context 'non-existent key' do
let(:key) { :donkey }
Expand All @@ -16,4 +15,35 @@
it { is_expected.to be }
end
end

context 'with environments defined' do
let(:hash) { { foo: 'bar', environments: { test: { foo: 'test-bar' }, default: { foo: 'default-bar' } } } }
let(:config) { described_class.new(hash).with_environment(env) }

subject { config }

context 'with existing environment' do
let(:env) { :test }

it 'inherits options from given environment' do
expect(subject[:foo]).to eq('test-bar')
end
end

context 'with unknown environment' do
let(:env) { :wtf }

it 'does not inherits options from any environment' do
expect(subject[:foo]).to eq('bar')
end
end

context 'without given environment' do
let(:env) { nil }

it 'inherits options from default environment' do
expect(subject[:foo]).to eq('default-bar')
end
end
end
end
19 changes: 19 additions & 0 deletions spec/nanoc/base/repos/config_loader_spec.rb
Expand Up @@ -52,6 +52,25 @@
expect(subject[:parent_config_file]).to be_nil
end
end

context 'config file present and environment defined' do
before do
File.write('nanoc.yaml', YAML.dump({ foo: 'bar', environments: { test: { foo: 'test-bar' }, default: { foo: 'default-bar' } } }))
end

it 'returns the configuration' do
expect(subject).to be_a(Nanoc::Int::Configuration)
end

it 'has the test environment custom option' do
allow(ENV).to receive(:fetch).with('NANOC_ENVIRONMENT', :default).and_return('test')
expect(subject[:foo]).to eq('test-bar')
end

it 'has the default environment custom option' do
expect(subject[:foo]).to eq('default-bar')
end
end
end

describe '.cwd_is_nanoc_site? + .config_filename_for_cwd' do
Expand Down

0 comments on commit ad17ed7

Please sign in to comment.