From 3610427c74a5f16aeb50d0e7c5b7183b01b67c21 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 13 Apr 2014 21:45:42 +0000 Subject: [PATCH] Improve `file_append' when file doesn't exist --- lib/producer/core/actions/file_append.rb | 5 ++++- spec/producer/core/actions/file_append_spec.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/producer/core/actions/file_append.rb b/lib/producer/core/actions/file_append.rb index ecdece1..c78362f 100644 --- a/lib/producer/core/actions/file_append.rb +++ b/lib/producer/core/actions/file_append.rb @@ -15,7 +15,10 @@ module Producer end def combined_content - fs.file_read(path) + content + original_content = fs.file_read(path) + + return content unless original_content + original_content + content end end end diff --git a/spec/producer/core/actions/file_append_spec.rb b/spec/producer/core/actions/file_append_spec.rb index 8986ab5..2185795 100644 --- a/spec/producer/core/actions/file_append_spec.rb +++ b/spec/producer/core/actions/file_append_spec.rb @@ -36,6 +36,14 @@ module Producer::Core it 'returns original content and added content combined' do expect(action.combined_content).to eq 'some content added' end + + context 'when fs.file_read returns nil' do + before { allow(remote_fs).to receive(:file_read).with(path) { nil } } + + it 'returns only the added content' do + expect(action.combined_content).to eq ' added' + end + end end end end