Implement `has_dir' condition keyword

This commit is contained in:
Thibault Jouan 2014-01-21 15:02:07 +00:00
parent 9d7af04d28
commit 0b4df20f55
7 changed files with 69 additions and 1 deletions

View File

@ -1,3 +1,7 @@
Given /^a remote directory named "([^"]+)"$/ do |path|
create_dir path
end
Given /^a remote file named "([^"]+)"$/ do |file_name|
write_file file_name, ''
end

View File

@ -0,0 +1,23 @@
@sshd
Feature: `has_dir' condition keyword
Background:
Given a recipe with:
"""
target 'some_host.test'
task :testing_directory_existence do
condition { has_dir 'some_directory' }
echo 'evaluated'
end
"""
Scenario: succeeds when directory exists
Given a remote directory named "some_directory"
When I successfully execute the recipe
Then the output must contain "evaluated"
Scenario: fails when directory does not exist
When I successfully execute the recipe
Then the output must not contain "evaluated"

View File

@ -6,6 +6,7 @@ require 'producer/core/actions/file_writer'
# condition tests (need to be defined before the condition DSL)
require 'producer/core/test'
require 'producer/core/tests/has_dir'
require 'producer/core/tests/has_env'
require 'producer/core/tests/has_file'

View File

@ -14,6 +14,7 @@ module Producer
end
define_test :has_env, Tests::HasEnv
define_test :has_dir, Tests::HasDir
define_test :has_file, Tests::HasFile
attr_reader :block, :env, :tests

View File

@ -0,0 +1,11 @@
module Producer
module Core
module Tests
class HasDir < Test
def verify
fs.dir? arguments.first
end
end
end
end
end

View File

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

View File

@ -0,0 +1,28 @@
require 'spec_helper'
module Producer::Core
describe Tests::HasDir do
let(:env) { Env.new }
let(:path) { 'some_directory' }
subject(:has_dir) { Tests::HasDir.new(env, path) }
it 'is a kind of test' do
expect(has_dir).to be_a Test
end
describe '#verify', :ssh do
before { sftp_story }
it 'delegates the call on remote FS' do
expect(env.remote.fs).to receive(:dir?).with(path)
has_dir.verify
end
it 'returns the dir existence' do
existence = double 'existence'
allow(env.remote.fs).to receive(:dir?) { existence }
expect(has_dir.verify).to be existence
end
end
end
end