Implement `` condition keyword (shell cmd status)

This commit is contained in:
Thibault Jouan 2014-03-08 19:43:41 +00:00
parent a2ca62e7f8
commit 7c6ac4c9d8
6 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,30 @@
@sshd
Feature: `` condition keyword
Scenario: succeeds when remote command execution is a success
Given a recipe with:
"""
target 'some_host.test'
task :testing_remote_command do
condition { `true` }
echo 'evaluated'
end
"""
When I successfully execute the recipe
Then the output must contain "evaluated"
Scenario: succeeds when remote executable is available
Given a recipe with:
"""
target 'some_host.test'
task :testing_remote_command do
condition { `false` }
echo 'evaluated'
end
"""
When I successfully execute the recipe
Then the output must not contain "evaluated"

View File

@ -21,6 +21,7 @@ require 'producer/core/tests/has_dir'
require 'producer/core/tests/has_env'
require 'producer/core/tests/has_executable'
require 'producer/core/tests/has_file'
require 'producer/core/tests/shell_command_status'
require 'producer/core/cli'
require 'producer/core/condition'

View File

@ -13,6 +13,7 @@ module Producer
end
end
define_test :`, Tests::ShellCommandStatus
define_test :file_contains, Tests::FileContains
define_test :has_env, Tests::HasEnv
define_test :has_executable, Tests::HasExecutable

View File

@ -0,0 +1,18 @@
module Producer
module Core
module Tests
class ShellCommandStatus < Test
def verify
remote.execute(command)
true
rescue RemoteCommandExecutionError
false
end
def command
arguments.first
end
end
end
end
end

View File

@ -8,6 +8,7 @@ module Producer::Core
subject(:dsl) { DSL.new(env, &block) }
%w[
`
file_contains
has_dir
has_env

View File

@ -0,0 +1,34 @@
require 'spec_helper'
module Producer::Core
module Tests
describe ShellCommandStatus, :env do
let(:command) { 'true' }
subject(:test) { described_class.new(env, command) }
it_behaves_like 'test'
describe '#verify' do
context 'command return status is 0' do
it 'returns true' do
expect(test.verify).to be true
end
end
context 'command return status is not 0' do
let(:command) { 'false' }
it 'returns false' do
expect(test.verify).to be false
end
end
end
describe '#command' do
it 'returns the first argument' do
expect(test.command).to eq command
end
end
end
end
end