Support `file_write' status attributes

This commit is contained in:
Thibault Jouan
2014-10-08 22:30:12 +00:00
parent a84b34b7ca
commit c4006416e4
5 changed files with 34 additions and 61 deletions

View File

@@ -5,52 +5,39 @@ module Producer::Core
describe FileWriter, :env do
let(:path) { 'some_path' }
let(:content) { 'some_content' }
subject(:writer) { described_class.new(env, path, content) }
let(:options) { { } }
subject(:writer) { described_class.new(env, path, content, options) }
it_behaves_like 'action'
describe '#initialize' do
let(:options) { { mode: 0700, user: 'root' } }
it 'translates mode option as permissions' do
expect(writer.options[:permissions]).to eq 0700
end
it 'translates user option as owner' do
expect(writer.options[:owner]).to eq 'root'
end
end
describe '#apply' do
it 'writes content to file on remote filesystem' do
expect(remote_fs).to receive(:file_write).with(path, content)
expect(remote_fs)
.to receive(:file_write).with(path, content)
writer.apply
end
context 'when a mode was given' do
subject(:writer) { described_class.new(env, path, content, 0600) }
context 'when status options are given' do
let(:options) { { group: 'wheel' } }
it 'specifies the given mode' do
expect(remote_fs)
.to receive(:file_write).with(anything, anything, 0600)
it 'changes the directory status with given options' do
expect(remote_fs).to receive(:setstat).with(path, options)
writer.apply
end
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
describe '#mode' do
it 'returns nil' do
expect(writer.mode).to be nil
end
context 'when a mode was given' do
subject(:writer) { described_class.new(env, path, content, 0600) }
it 'returns the mode' do
expect(writer.mode).to eq 0600
end
end
end
end
end
end