Refactor actions specs with shared examples
This commit is contained in:
parent
23d5d8a1df
commit
4624a81100
@ -2,46 +2,6 @@ require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Action do
|
||||
let(:input) { StringIO.new }
|
||||
let(:output) { StringIO.new }
|
||||
let(:env) { Env.new(input: input, output: output) }
|
||||
let(:arguments) { [:some, :arguments] }
|
||||
subject(:action) { Action.new(env, *arguments) }
|
||||
|
||||
describe '#env' do
|
||||
it 'returns the assigned env' do
|
||||
expect(action.env).to be env
|
||||
end
|
||||
end
|
||||
|
||||
describe '#arguments' do
|
||||
it 'returns the assigned arguments' do
|
||||
expect(action.arguments).to eq arguments
|
||||
end
|
||||
end
|
||||
|
||||
describe '#input' do
|
||||
it 'returns env input' do
|
||||
expect(action.input).to be input
|
||||
end
|
||||
end
|
||||
|
||||
describe '#output' do
|
||||
it 'returns env output' do
|
||||
expect(action.output).to be output
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remote' do
|
||||
it 'returns env remote' do
|
||||
expect(action.remote).to be action.env.remote
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fs' do
|
||||
it 'returns env remote fs' do
|
||||
expect(action.fs).to be action.env.remote.fs
|
||||
end
|
||||
end
|
||||
it_behaves_like 'action'
|
||||
end
|
||||
end
|
||||
|
@ -7,6 +7,8 @@ module Producer::Core
|
||||
let(:text) { 'hello' }
|
||||
subject(:echo) { Echo.new(env, text) }
|
||||
|
||||
it_behaves_like 'action'
|
||||
|
||||
describe '#apply' do
|
||||
it 'writes the given string to env output with a record separator' do
|
||||
echo.apply
|
||||
|
@ -8,6 +8,8 @@ module Producer::Core
|
||||
let(:content) { 'some_content' }
|
||||
subject(:writer) { FileWriter.new(env, path, content) }
|
||||
|
||||
it_behaves_like 'action'
|
||||
|
||||
describe '#apply' do
|
||||
it 'writes content to file on remote filesystem' do
|
||||
expect(writer.fs).to receive(:file_write).with(path, content)
|
||||
|
@ -7,6 +7,8 @@ module Producer::Core
|
||||
let(:path) { 'some_path' }
|
||||
subject(:mkdir) { Mkdir.new(env, path) }
|
||||
|
||||
it_behaves_like 'action'
|
||||
|
||||
describe '#apply' do
|
||||
it 'creates directory on remote filesystem' do
|
||||
expect(mkdir.fs).to receive(:mkdir).with(path)
|
||||
|
@ -8,6 +8,8 @@ module Producer::Core
|
||||
let(:command) { "echo #{command_args}" }
|
||||
subject(:sh) { ShellCommand.new(env, command) }
|
||||
|
||||
it_behaves_like 'action'
|
||||
|
||||
describe '#apply' do
|
||||
it 'executes the remote command' do
|
||||
expect(sh.remote).to receive(:execute).with(command)
|
||||
|
45
spec/support/shared_action.rb
Normal file
45
spec/support/shared_action.rb
Normal file
@ -0,0 +1,45 @@
|
||||
module Producer::Core
|
||||
shared_examples 'action' do
|
||||
let(:input) { StringIO.new }
|
||||
let(:output) { StringIO.new }
|
||||
let(:env) { Env.new(input: input, output: output) }
|
||||
let(:arguments) { [:some, :arguments] }
|
||||
subject(:action) { described_class.new(env, *arguments) }
|
||||
|
||||
describe '#env' do
|
||||
it 'returns the assigned env' do
|
||||
expect(action.env).to be env
|
||||
end
|
||||
end
|
||||
|
||||
describe '#arguments' do
|
||||
it 'returns the assigned arguments' do
|
||||
expect(action.arguments).to eq arguments
|
||||
end
|
||||
end
|
||||
|
||||
describe '#input' do
|
||||
it 'returns env input' do
|
||||
expect(action.input).to be input
|
||||
end
|
||||
end
|
||||
|
||||
describe '#output' do
|
||||
it 'returns env output' do
|
||||
expect(action.output).to be output
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remote' do
|
||||
it 'returns env remote' do
|
||||
expect(action.remote).to be action.env.remote
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fs' do
|
||||
it 'returns env remote fs' do
|
||||
expect(action.fs).to be action.env.remote.fs
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user