Implement `file_append' task action

This commit is contained in:
Thibault Jouan
2014-03-05 02:38:00 +00:00
parent b1c7ff27b4
commit 387f37f3f5
6 changed files with 95 additions and 3 deletions

View File

@@ -0,0 +1,42 @@
require 'spec_helper'
module Producer::Core
module Actions
describe FileAppend, :env do
let(:path) { 'some_path' }
let(:content) { 'some content' }
let(:added_content) { ' added' }
subject(:action) { FileAppend.new(env, path, added_content) }
it_behaves_like 'action'
before { allow(remote_fs).to receive(:file_read).with(path) { content } }
describe '#apply' do
it 'appends given content to requested file on remote filesystem' do
expect(remote_fs)
.to receive(:file_write).with(path, action.combined_content)
action.apply
end
end
describe '#path' do
it 'returns the file path' do
expect(action.path).to eq path
end
end
describe '#content' do
it 'returns the content to append' do
expect(action.content).to eq added_content
end
end
describe '#combined_content' do
it 'returns original content and added content combined' do
expect(action.combined_content).to eq 'some content added'
end
end
end
end
end

View File

@@ -7,7 +7,14 @@ module Producer::Core
let(:env) { Env.new }
subject(:dsl) { DSL.new(env, &block) }
%w[echo sh mkdir file_write file_replace_content].each do |action|
%w[
echo
sh
mkdir
file_append
file_replace_content
file_write
].each do |action|
it "has `#{action}' action defined" do
expect(dsl).to respond_to action.to_sym
end