spec/rake/funnel/support/environments/loader_spec.rb in rake-funnel-0.18.0 vs spec/rake/funnel/support/environments/loader_spec.rb in rake-funnel-0.19.0

- old
+ new

@@ -1,38 +1,38 @@ describe Rake::Funnel::Support::Environments::Loader do - let(:store) { - double(Configatron::Store).as_null_object - } + let(:store) do + double(Configatron::RootStore).as_null_object # rubocop:disable RSpec/VerifiedDoubles + end let(:customizer) { nil } - let(:config) { + let(:config) do { name: 'environment name', config_files: config_files.keys.map(&:to_s) } - } + end - before { + before do config_files.each do |file, content| allow(File).to receive(:read).with(file.to_s).and_return(content) end allow(Rake).to receive(:rake_output_message) - } + end describe 'loading configuration' do - let(:config_files) { + let(:config_files) do { one: 'one: 23', two: 'two: 42' } - } + end - before { + before do described_class.load_configuration(config, store, customizer) - } + end it 'should reinitialize the configatron store' do expect(store).to have_received(:unlock!) expect(store).to have_received(:reset!) end @@ -46,98 +46,98 @@ expect(File).to have_received(:read).with(file) end end it "should add each config file's values to the store" do - expect(store).to have_received(:configure_from_hash).with({ 'one' => 23 }) - expect(store).to have_received(:configure_from_hash).with({ 'two' => 42 }) + expect(store).to have_received(:configure_from_hash).with('one' => 23) + expect(store).to have_received(:configure_from_hash).with('two' => 42) end it 'should lock the store' do expect(store).to have_received(:lock!) end describe 'customization' do - let(:customizer) { double(Proc).as_null_object } + let(:customizer) { instance_double(Proc).as_null_object } it 'should run the customizer' do expect(customizer).to have_received(:call).with(store) end end context 'config file with overriding values' do - let(:config_files) { + let(:config_files) do { one: 'foo: bar', two: 'foo: baz' } - } + end - let(:store) { + let(:store) do Configatron::RootStore.new - } + end it 'should merge config values' do expect(store.foo).to eq('baz') end end context 'env also defined in config file' do - let(:config_files) { + let(:config_files) do { with_env: 'env: foo' } - } + end - let(:store) { + let(:store) do Configatron::RootStore.new - } + end it 'should override env from config' do expect(store.env).to eq('foo') end end context 'empty config file' do - let(:config_files) { + let(:config_files) do { empty: '' } - } + end it 'should configure with empty hash' do expect(store).to have_received(:configure_from_hash).with({}) end end end describe 'config file with ERb' do context 'ERb success' do - let(:config_files) { + let(:config_files) do { with_erb: 'foo: <%= 40 + 2 %>' } - } + end - before { + before do described_class.load_configuration(config, store) - } + end it 'should evaluate ERb' do - expect(store).to have_received(:configure_from_hash).with({ 'foo' => 42 }) + expect(store).to have_received(:configure_from_hash).with('foo' => 42) end end context 'ERb failure' do - let(:config_files) { + let(:config_files) do { with_erb: 'bogus: <%= 42 + "a" %>' } - } + end it 'should report file name' do expect { described_class.load_configuration(config, store) } - .to raise_error { |ex| expect(ex.backtrace.join("\n")).to match(/with_erb/) } + .to(raise_error { |ex| expect(ex.backtrace.join("\n")).to match(/with_erb/) }) end end end end