Implement `has_dir' condition keyword
This commit is contained in:
parent
9d7af04d28
commit
0b4df20f55
@ -1,3 +1,7 @@
|
|||||||
|
Given /^a remote directory named "([^"]+)"$/ do |path|
|
||||||
|
create_dir path
|
||||||
|
end
|
||||||
|
|
||||||
Given /^a remote file named "([^"]+)"$/ do |file_name|
|
Given /^a remote file named "([^"]+)"$/ do |file_name|
|
||||||
write_file file_name, ''
|
write_file file_name, ''
|
||||||
end
|
end
|
||||||
|
23
features/tests/has_dir.feature
Normal file
23
features/tests/has_dir.feature
Normal 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"
|
@ -6,6 +6,7 @@ require 'producer/core/actions/file_writer'
|
|||||||
|
|
||||||
# condition tests (need to be defined before the condition DSL)
|
# condition tests (need to be defined before the condition DSL)
|
||||||
require 'producer/core/test'
|
require 'producer/core/test'
|
||||||
|
require 'producer/core/tests/has_dir'
|
||||||
require 'producer/core/tests/has_env'
|
require 'producer/core/tests/has_env'
|
||||||
require 'producer/core/tests/has_file'
|
require 'producer/core/tests/has_file'
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ module Producer
|
|||||||
end
|
end
|
||||||
|
|
||||||
define_test :has_env, Tests::HasEnv
|
define_test :has_env, Tests::HasEnv
|
||||||
|
define_test :has_dir, Tests::HasDir
|
||||||
define_test :has_file, Tests::HasFile
|
define_test :has_file, Tests::HasFile
|
||||||
|
|
||||||
attr_reader :block, :env, :tests
|
attr_reader :block, :env, :tests
|
||||||
|
11
lib/producer/core/tests/has_dir.rb
Normal file
11
lib/producer/core/tests/has_dir.rb
Normal 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
|
@ -6,7 +6,7 @@ module Producer::Core
|
|||||||
let(:env) { double 'env' }
|
let(:env) { double 'env' }
|
||||||
subject(:dsl) { Condition::DSL.new(env, &block) }
|
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
|
it "has `#{test}' test defined" do
|
||||||
expect(dsl).to respond_to test.to_sym
|
expect(dsl).to respond_to test.to_sym
|
||||||
end
|
end
|
||||||
|
28
spec/producer/core/tests/has_dir_spec.rb
Normal file
28
spec/producer/core/tests/has_dir_spec.rb
Normal 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
|
Loading…
x
Reference in New Issue
Block a user