Implement `file_replace_content' task action
This commit is contained in:
49
spec/producer/core/actions/file_replace_content_spec.rb
Normal file
49
spec/producer/core/actions/file_replace_content_spec.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
module Actions
|
||||
describe FileReplaceContent, :env do
|
||||
let(:path) { 'some_path' }
|
||||
let(:pattern) { 'content' }
|
||||
let(:replacement) { 'other content' }
|
||||
let(:content) { 'some content' }
|
||||
subject(:action) { FileReplaceContent.new(env, path, pattern, replacement) }
|
||||
|
||||
it_behaves_like 'action'
|
||||
|
||||
before { allow(remote_fs).to receive(:file_read).with(path) { content } }
|
||||
|
||||
describe '#apply' do
|
||||
it 'writes replaced content to file on remote filesystem' do
|
||||
expect(remote_fs)
|
||||
.to receive(:file_write).with(path, action.replaced_content)
|
||||
action.apply
|
||||
end
|
||||
end
|
||||
|
||||
describe '#path' do
|
||||
it 'returns the file path' do
|
||||
expect(action.path).to eq path
|
||||
end
|
||||
end
|
||||
|
||||
describe '#pattern' do
|
||||
it 'returns the pattern' do
|
||||
expect(action.pattern).to eq pattern
|
||||
end
|
||||
end
|
||||
|
||||
describe '#replacement' do
|
||||
it 'returns the replacement' do
|
||||
expect(action.replacement).to eq replacement
|
||||
end
|
||||
end
|
||||
|
||||
describe '#replaced_content' do
|
||||
it 'returns content with pattern occurrences pattern replaced' do
|
||||
expect(action.replaced_content).to eq 'some other content'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -7,7 +7,7 @@ module Producer::Core
|
||||
let(:env) { Env.new }
|
||||
subject(:dsl) { DSL.new(env, &block) }
|
||||
|
||||
%w[echo sh mkdir file_write].each do |action|
|
||||
%w[echo sh mkdir file_write file_replace_content].each do |action|
|
||||
it "has `#{action}' action defined" do
|
||||
expect(dsl).to respond_to action.to_sym
|
||||
end
|
||||
|
Reference in New Issue
Block a user