Skip to content

Commit

Permalink
Merge pull request #22 from farisj/jf-endline-bug
Browse files Browse the repository at this point in the history
[Bug] Add newline at end of final replaced value
  • Loading branch information
farisj committed Oct 22, 2017
2 parents 83e3993 + ffd81cc commit 6aeae76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/dotenvious/value_replacer.rb
Expand Up @@ -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
Expand Down
25 changes: 14 additions & 11 deletions spec/dotenvious/value_replacer_spec.rb
Expand Up @@ -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

0 comments on commit 6aeae76

Please sign in to comment.