Refactor and fix features

This commit is contained in:
Thibault Jouan
2014-05-29 14:31:13 +00:00
parent 237e6db740
commit 2fecb4bde4
18 changed files with 126 additions and 178 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ Feature: `echo' task action
Scenario: prints text on standard output Scenario: prints text on standard output
Given a recipe with: Given a recipe with:
""" """
task :say_hello do task :echo_action do
echo 'hello' echo 'hello'
end end
""" """
+1 -1
View File
@@ -9,7 +9,7 @@ Feature: `file_append' task action
""" """
target 'some_host.test' target 'some_host.test'
task :append_content_to_file do task :file_append_action do
file_append 'some_file', ' added' file_append 'some_file', ' added'
end end
""" """
+12 -15
View File
@@ -3,27 +3,24 @@ Feature: `file_replace_content' task action
Background: Background:
Given a remote file named "some_file" with "some content" Given a remote file named "some_file" with "some content"
And a remote file named "other_file" with "some content"
Scenario: replaces a string by another in the requested file And a recipe with:
Given a recipe with:
""" """
target 'some_host.test' target 'some_host.test'
task :replace_string_in_file do task :file_replace_content_action_string do
file_replace_content 'some_file', 'content', 'other content' file_replace_content 'some_file', 'content', 'other content'
end end
"""
When I successfully execute the recipe
And the remote file "some_file" must contain exactly "some other content"
Scenario: replaces a regular expression by a string in the requested file task :file_replace_content_action_regexp do
Given a recipe with: file_replace_content 'other_file', /\w+\z/, 'other content'
"""
target 'some_host.test'
task :replace_regexp_in_file do
file_replace_content 'some_file', /\w+\z/, 'other content'
end end
""" """
Scenario: replaces a string by another in the requested file
When I successfully execute the recipe When I successfully execute the recipe
And the remote file "some_file" must contain exactly "some other content" Then the remote file "some_file" must contain exactly "some other content"
Scenario: replaces a regular expression by a string in the requested file
When I successfully execute the recipe
Then the remote file "other_file" must contain exactly "some other content"
+7 -12
View File
@@ -1,28 +1,23 @@
@sshd @sshd
Feature: `file_write' task action Feature: `file_write' task action
Scenario: writes given data to given file path Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test' target 'some_host.test'
task :write_some_data do task :file_write_action do
file_write 'some_file', 'some_content' file_write 'some_file', 'some_content'
file_write 'some_file_0600', 'some_content', 0600
file_write 'some_file_0700', 'some_content', 0700
end end
""" """
Scenario: writes given data to given file path
When I successfully execute the recipe When I successfully execute the recipe
Then the remote file "some_file" must contain "some_content" Then the remote file "some_file" must contain "some_content"
Scenario: creates file with given permissions Scenario: creates file with given permissions
Given a recipe with:
"""
target 'some_host.test'
task :write_some_data do
file_write 'some_file_0600', 'some_content', 0600
file_write 'some_file_0700', 'some_content', 0700
end
"""
When I successfully execute the recipe When I successfully execute the recipe
Then the remote file "some_file_0600" must have 0600 mode Then the remote file "some_file_0600" must have 0600 mode
And the remote file "some_file_0700" must have 0700 mode And the remote file "some_file_0700" must have 0700 mode
+8 -13
View File
@@ -1,28 +1,23 @@
@sshd @sshd
Feature: `mkdir' task action Feature: `mkdir' task action
Scenario: creates directory given as argument Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test' target 'some_host.test'
task :create_some_dir do task :mkdir_action do
mkdir 'some_directory' mkdir 'some_directory'
mkdir 'some_directory_0700', 0700
mkdir 'some_directory_0500', 0500
end end
""" """
Scenario: creates directory given as argument
When I successfully execute the recipe When I successfully execute the recipe
Then the remote directory "some_directory" must exists Then the remote directory "some_directory" must exists
Scenario: creates directory with given permissions Scenario: creates directory with given permissions
Given a recipe with:
"""
target 'some_host.test'
task :create_some_dir do
mkdir '0700_directory', 0700
mkdir '0500_directory', 0500
end
"""
When I successfully execute the recipe When I successfully execute the recipe
Then the remote directory "0700_directory" must have 0700 mode Then the remote directory "some_directory_0700" must have 0700 mode
And the remote directory "0500_directory" must have 0500 mode And the remote directory "some_directory_0500" must have 0500 mode
+3 -15
View File
@@ -1,24 +1,12 @@
@sshd @sshd
Feature: `sh' task action Feature: `sh' task action
Scenario: executes command
Given a recipe with:
"""
target 'some_host.test'
task :some_task do
sh '\true'
end
"""
When I execute the recipe
Then the exit status must be 0
Scenario: forwards standard ouput Scenario: forwards standard ouput
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test' target 'some_host.test'
task :some_task do task :sh_action do
sh '\echo hello from remote' sh '\echo hello from remote'
end end
""" """
@@ -30,7 +18,7 @@ Feature: `sh' task action
""" """
target 'some_host.test' target 'some_host.test'
task :some_task do task :sh_action_aborting do
sh '\false' sh '\false'
sh '\echo after_fail' sh '\echo after_fail'
end end
@@ -43,7 +31,7 @@ Feature: `sh' task action
""" """
target 'some_host.test' target 'some_host.test'
task :some_task do task :sh_action_command_error do
sh '\false' sh '\false'
end end
""" """
+12 -23
View File
@@ -1,42 +1,31 @@
Feature: CLI verbose option Feature: CLI verbose option
Scenario: prints tasks name Background:
Given a recipe with:
"""
task :say_hello do
end
"""
When I successfully execute the recipe with option -v
Then the output must match /Task:.+say_hello/
Scenario: prints whether condition is met
Given a recipe with: Given a recipe with:
""" """
task :task_ok do task :task_ok do
condition { true } condition { true }
echo 'some mesasge'
end end
task :task_ko do task :task_ko do
condition { false } condition { false }
end end
""" """
Scenario: prints tasks name
When I successfully execute the recipe with option -v
Then the output must match /Task:.+task_ok/
Scenario: prints whether condition is met
When I successfully execute the recipe with option -v When I successfully execute the recipe with option -v
Then the output must match /task_ok.+ condition: met.*task_ko.* condition: NOT met/ Then the output must match /task_ok.+ condition: met.*task_ko.* condition: NOT met/
Scenario: prints actions info Scenario: prints actions info
Given a recipe with:
"""
task :say_hello do
echo 'hello message'
end
"""
When I successfully execute the recipe with option -v When I successfully execute the recipe with option -v
Then the output must match /say_hello.+ action: echo/ Then the output must match /task_ok.+ action: echo/
Scenario: formats message with our simple logger Scenario: formats message with our simple logger
Given a recipe with:
"""
task :say_hello do
end
"""
When I successfully execute the recipe with option -v When I successfully execute the recipe with option -v
Then the output must match /\ATask:.+say_hello.*\n.*condition/ Then the output must match /\ATask:.+task_ok.*\n.*condition/
+4 -4
View File
@@ -1,6 +1,6 @@
Feature: `macro' recipe keyword Feature: `macro' recipe keyword
Scenario: declares new keyword accepting task code Scenario: declares a new keyword accepting task code
Given a recipe with: Given a recipe with:
""" """
macro :hello do macro :hello do
@@ -28,7 +28,7 @@ Feature: `macro' recipe keyword
Given a recipe with: Given a recipe with:
""" """
macro :my_echo do |message| macro :my_echo do |message|
condition { message =~ /bar/ } condition { message =~ /foo/ }
echo message echo message
end end
@@ -36,5 +36,5 @@ Feature: `macro' recipe keyword
%w[foo bar].each { |e| my_echo e } %w[foo bar].each { |e| my_echo e }
""" """
When I successfully execute the recipe When I successfully execute the recipe
Then the output must not contain "foo" Then the output must contain "foo"
And the output must contain "bar" And the output must not contain "bar"
+3 -1
View File
@@ -9,7 +9,9 @@ Feature: `source' recipe keyword
Scenario: requires a recipe file Scenario: requires a recipe file
Given a file named "sourced_recipe.rb" with: Given a file named "sourced_recipe.rb" with:
""" """
puts 'sourced recipe' task :some_task do
echo 'sourced recipe'
end
""" """
When I successfully execute the recipe When I successfully execute the recipe
Then the output must contain "sourced recipe" Then the output must contain "sourced recipe"
+3 -1
View File
@@ -5,7 +5,9 @@ Feature: `target' recipe keyword
""" """
target 'some_host.example' target 'some_host.example'
puts env.target task :some_task do
echo env.target
end
""" """
When I successfully execute the recipe When I successfully execute the recipe
Then the output must contain exactly "some_host.example\n" Then the output must contain exactly "some_host.example\n"
+3 -1
View File
@@ -5,7 +5,9 @@ Feature: SSH settings
""" """
target 'some_host.example' target 'some_host.example'
puts env.remote.user_name task :some_task do
echo env.remote.user_name
end
""" """
Scenario: uses current user login name as SSH user name by default Scenario: uses current user login name as SSH user name by default
+1 -1
View File
@@ -3,7 +3,7 @@ Feature: `condition' task keyword
Scenario: prevents task actions application when condition is not met Scenario: prevents task actions application when condition is not met
Given a recipe with: Given a recipe with:
""" """
task :hello do task :some_task do
condition { false } condition { false }
echo 'evaluated' echo 'evaluated'
+1 -1
View File
@@ -6,7 +6,7 @@ Feature: `dir?' condition keyword
""" """
target 'some_host.test' target 'some_host.test'
task :testing_directory_existence do task :dir_test do
condition { dir? 'some_directory' } condition { dir? 'some_directory' }
echo 'evaluated' echo 'evaluated'
+24 -34
View File
@@ -1,58 +1,48 @@
@sshd @sshd
Feature: `env?' condition keyword Feature: `env?' condition keyword
Scenario: succeeds when remote environment variable is defined Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test' target 'some_host.test'
task :testing_env_var_definition do task :env_test_definition_ok do
condition { env? :shell } condition { env? :shell }
echo 'evaluated' echo 'definition_ok'
end end
"""
When I successfully execute the recipe
Then the output must contain "evaluated"
Scenario: fails when remote environment variable is not defined task :env_test_definition_ko do
Given a recipe with:
"""
target 'some_host.test'
task :testing_env_var_definition do
condition { env? :non_existent_var } condition { env? :non_existent_var }
echo 'evaluated' echo 'definition_ko'
end end
"""
When I successfully execute the recipe
Then the output must not contain "evaluated"
Scenario: succeeds when remote environment variable value match task :env_test_value do
Given a recipe with:
"""
target 'some_host.test'
task :testing_env_var_value do
condition { env? :shell, '/bin/sh' } condition { env? :shell, '/bin/sh' }
echo 'evaluated' echo 'value_ok'
end end
"""
When I successfully execute the recipe
Then the output must contain "evaluated"
Scenario: fails when remote environment variable value does not match task :env_test_value do
Given a recipe with:
"""
target 'some_host.test'
task :testing_env_var_value do
condition { env? :shell, 'non_existent_shell' } condition { env? :shell, 'non_existent_shell' }
echo 'evaluated' echo 'value_ko'
end end
""" """
Scenario: succeeds when remote environment variable is defined
When I successfully execute the recipe When I successfully execute the recipe
Then the output must not contain "evaluated" Then the output must contain "definition_ok"
Scenario: fails when remote environment variable is not defined
When I successfully execute the recipe
Then the output must not contain "definition_ko"
Scenario: succeeds when remote environment variable value match
When I successfully execute the recipe
Then the output must contain "value_ok"
Scenario: fails when remote environment variable value does not match
When I successfully execute the recipe
Then the output must not contain "value_ko"
+12 -14
View File
@@ -1,30 +1,28 @@
@sshd @sshd
Feature: `executable?' condition keyword Feature: `executable?' condition keyword
Scenario: succeeds when remote executable is available Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test' target 'some_host.test'
task :testing_executable_availability do task :executable_test_ok do
condition { executable? 'true' } condition { executable? 'true' }
echo 'evaluated' echo 'test_ok'
end end
"""
When I successfully execute the recipe
Then the output must contain "evaluated"
Scenario: succeeds when remote executable is available task :executable_test_ok do
Given a recipe with:
"""
target 'some_host.test'
task :testing_executable_availability do
condition { executable? 'some_non_existent_executable' } condition { executable? 'some_non_existent_executable' }
echo 'evaluated' echo 'test_ko'
end end
""" """
Scenario: succeeds when remote executable is available
When I successfully execute the recipe When I successfully execute the recipe
Then the output must not contain "evaluated" Then the output must contain "test_ok"
Scenario: fails when remote executable is not available
When I successfully execute the recipe
Then the output must not contain "test_ko"
+1 -1
View File
@@ -6,7 +6,7 @@ Feature: `file?' condition keyword
""" """
target 'some_host.test' target 'some_host.test'
task :testing_file_existence do task :file_test do
condition { file? 'some_file' } condition { file? 'some_file' }
echo 'evaluated' echo 'evaluated'
+1 -1
View File
@@ -6,7 +6,7 @@ Feature: `file_contains' condition keyword
""" """
target 'some_host.test' target 'some_host.test'
task :testing_content_in_file_presense do task :file_contains_test do
condition { file_contains 'some_file', 'some_content' } condition { file_contains 'some_file', 'some_content' }
echo 'evaluated' echo 'evaluated'
+29 -39
View File
@@ -1,58 +1,48 @@
@sshd @sshd
Feature: `` condition keyword Feature: `sh' and `` condition keyword
Scenario: succeeds when remote command execution is a success Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test' target 'some_host.test'
task :testing_remote_command do task :sh_test_ok do
condition { sh 'true' }
echo 'test_ok'
end
task :sh_test_ko do
condition { sh 'false' }
echo 'test_ko'
end
task :sh_test_backtick_ok do
condition { `true` } condition { `true` }
echo 'evaluated' echo 'test_backtick_ok'
end end
"""
When I successfully execute the recipe
Then the output must contain "evaluated"
Scenario: succeeds when remote executable is available task :sh_test_backtick_ko do
Given a recipe with:
"""
target 'some_host.test'
task :testing_remote_command do
condition { `false` } condition { `false` }
echo 'evaluated' echo 'test_backtick_ko'
end end
""" """
Scenario: succeeds when remote command execution is a success
When I successfully execute the recipe When I successfully execute the recipe
Then the output must not contain "evaluated" Then the output must contain "test_ok"
Scenario: `sh' alias, succeeds when remote executable is available Scenario: fails when remote executable is not available
Given a recipe with:
"""
target 'some_host.test'
task :testing_remote_command do
condition { sh 'false' }
echo 'evaluated'
end
"""
When I successfully execute the recipe When I successfully execute the recipe
Then the output must not contain "evaluated" Then the output must not contain "test_ko"
Scenario: succeeds when remote executable is available Scenario: `` alias, succeeds when remote executable is available
Given a recipe with:
"""
target 'some_host.test'
task :testing_remote_command do
condition { sh 'false' }
echo 'evaluated'
end
"""
When I successfully execute the recipe When I successfully execute the recipe
Then the output must not contain "evaluated" Then the output must contain "test_backtick_ok"
Scenario: `` alias, fails when remote executable is not available
When I successfully execute the recipe
Then the output must not contain "test_backtick_ko"