From ffd81cc9a757552484b3dbfc990087042d271694 Mon Sep 17 00:00:00 2001 From: farisj Date: Sun, 22 Oct 2017 11:50:01 -0400 Subject: [PATCH] [Bug] Add newline at end of final replaced value --- lib/dotenvious/value_replacer.rb | 2 +- spec/dotenvious/value_replacer_spec.rb | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/dotenvious/value_replacer.rb b/lib/dotenvious/value_replacer.rb index 28ac9bf..95022ce 100644 --- a/lib/dotenvious/value_replacer.rb +++ b/lib/dotenvious/value_replacer.rb @@ -10,7 +10,7 @@ def replace(key) end updated_env = base_env.dup updated_env[line_number] = "#{key}=#{ENV_EXAMPLE[key]}" - env_writer.write(updated_env.join("\n")) + env_writer.write(updated_env.join("\n") + "\n") end private diff --git a/spec/dotenvious/value_replacer_spec.rb b/spec/dotenvious/value_replacer_spec.rb index 0ed800f..8b47f96 100644 --- a/spec/dotenvious/value_replacer_spec.rb +++ b/spec/dotenvious/value_replacer_spec.rb @@ -3,21 +3,24 @@ describe Dotenvious::ValueReplacer do describe '#replace' do before do - stub_const('Dotenvious::ENV_EXAMPLE', {'fake' => 'correct'} ) + stub_const('Dotenvious::ENV_EXAMPLE', example_const ) end - it "replaces the key's value in .env if user presses yes" do - expect(File).to receive(:read). - with('.big-ol-env'). - and_return("test=1234\nfake=missing") + context 'given a key with a different value' do + let(:example_const) { {'fake' => 'correct'} } + it "replaces the key's value in .env if user presses yes" do + expect(File).to receive(:read). + with('.big-ol-env'). + and_return("test=1234\nfake=missing") - env_double = double('File', write: nil) - expect(env_double).to receive(:write).with("test=1234\nfake=correct") + env_double = double('File', write: nil) + expect(env_double).to receive(:write).with("test=1234\nfake=correct\n") - expect(File).to receive(:open). - with('.big-ol-env', 'w'). - and_return(env_double) + expect(File).to receive(:open). + with('.big-ol-env', 'w'). + and_return(env_double) - described_class.new('.big-ol-env').replace('fake') + described_class.new('.big-ol-env').replace('fake') + end end end end