Implement `file_write' action

This commit is contained in:
Thibault Jouan
2013-08-02 15:36:36 +00:00
parent 188ca2e08d
commit 892a9862fc
11 changed files with 111 additions and 8 deletions

View File

@@ -0,0 +1,29 @@
require 'spec_helper'
module Producer::Core
describe Actions::FileWriter do
let(:env) { Env.new }
let(:path) { 'some_path' }
let(:content) { 'some_content' }
subject(:writer) { Actions::FileWriter.new(env, path, content) }
describe '#apply' do
it 'delegates the call to env.remote.fs.file_write method' do
expect(env.remote.fs).to receive(:file_write).with(path, content)
writer.apply
end
end
describe '#path' do
it 'returns the path' do
expect(writer.path).to eq path
end
end
describe '#content' do
it 'returns the content' do
expect(writer.content).to eq content
end
end
end
end

View File

@@ -72,5 +72,30 @@ module Producer::Core
end
end
end
describe '#file_write' do
let(:sftp) { double('sftp').as_null_object }
let(:file) { double('sftp').as_null_object }
let(:path) { 'some_file_path' }
let(:content) { 'some_content' }
before do
allow(fs).to receive(:sftp) { sftp }
allow(sftp).to receive(:file) { file }
end
it 'opens the file' do
expect(file).to receive(:open).with(path, 'w')
fs.file_write path, content
end
it 'writes the content' do
expect(file).to receive(:open).with(any_args) do |&b|
expect(file).to receive(:write).with(content)
b.call file
end
fs.file_write path, content
end
end
end
end

View File

@@ -94,8 +94,7 @@ module Producer::Core
ch.sends_exec command
ch.gets_data arguments
end
remote.execute command
expect(story_completed?).to be
expect_story_completed { remote.execute command }
end
it 'returns the output' do

View File

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