Refactor features

This commit is contained in:
Thibault Jouan 2014-07-18 12:23:17 +00:00
parent 959ffca4e9
commit a033e19583
15 changed files with 40 additions and 63 deletions

View File

@ -7,11 +7,9 @@ Feature: `file_append' task action
Scenario: appends given content to requested file Scenario: appends given content to requested file
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :file_append_action do task :file_append_action do
file_append 'some_file', ' added' file_append 'some_file', ' added'
end end
""" """
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the remote file "some_file" must contain exactly "some content added" Then the remote file "some_file" must contain exactly "some content added"

View File

@ -6,8 +6,6 @@ Feature: `file_replace_content' task action
And a remote file named "other_file" with "some content" And a remote file named "other_file" with "some content"
And a recipe with: And a recipe with:
""" """
target 'some_host.test'
task :file_replace_content_action_string 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
@ -18,9 +16,9 @@ Feature: `file_replace_content' task action
""" """
Scenario: replaces a string by another in the requested file Scenario: replaces a string by another in the requested file
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then 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 Scenario: replaces a regular expression by a string in the requested file
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the remote file "other_file" must contain exactly "some other content" Then the remote file "other_file" must contain exactly "some other content"

View File

@ -4,8 +4,6 @@ Feature: `file_write' task action
Background: Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :file_write_action 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_0600', 'some_content', 0600
@ -14,10 +12,10 @@ Feature: `file_write' task action
""" """
Scenario: writes given data to given file path Scenario: writes given data to given file path
When I successfully execute the recipe When I successfully execute the recipe on remote target
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
When I successfully execute the recipe When I successfully execute the recipe on remote target
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

View File

@ -4,8 +4,6 @@ Feature: `mkdir' task action
Background: Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :mkdir_action do task :mkdir_action do
mkdir 'some_directory' mkdir 'some_directory'
mkdir 'some_directory_0700', 0700 mkdir 'some_directory_0700', 0700
@ -14,10 +12,10 @@ Feature: `mkdir' task action
""" """
Scenario: creates directory given as argument Scenario: creates directory given as argument
When I successfully execute the recipe When I successfully execute the recipe on remote target
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
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the remote directory "some_directory_0700" must have 0700 mode Then the remote directory "some_directory_0700" must have 0700 mode
And the remote directory "some_directory_0500" must have 0500 mode And the remote directory "some_directory_0500" must have 0500 mode

View File

@ -4,36 +4,30 @@ Feature: `sh' task action
Scenario: forwards standard ouput Scenario: forwards standard ouput
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :sh_action do task :sh_action do
sh '\echo hello from remote' sh '\echo hello from remote'
end end
""" """
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain exactly "hello from remote\n" Then the output must contain exactly "hello from remote\n"
Scenario: aborts on failed command execution Scenario: aborts on failed command execution
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :sh_action_aborting do task :sh_action_aborting do
sh '\false' sh '\false'
sh '\echo after_fail' sh '\echo after_fail'
end end
""" """
When I execute the recipe When I execute the recipe on remote target
Then the output must not contain "after_fail" Then the output must not contain "after_fail"
Scenario: prints command when execution fail Scenario: prints command when execution fail
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :sh_action_command_error do task :sh_action_command_error do
sh '\false' sh '\false'
end end
""" """
When I execute the recipe When I execute the recipe on remote target
Then the output must match /\A\w+Error:\s+\\false/ Then the output must match /\A\w+Error:\s+\\false/

View File

@ -10,6 +10,6 @@ Feature: CLI target option
end end
""" """
Scenario: prints tasks name Scenario: override the recipe target
When I successfully execute the recipe with option -t other_host.example When I successfully execute the recipe with option -t other_host.example
Then the output must contain exactly "other_host.example\n" Then the output must contain exactly "other_host.example\n"

View File

@ -22,8 +22,6 @@ Feature: `test_macro' recipe keyword
Scenario: has access to core tests Scenario: has access to core tests
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
test_macro(:other_env?) { |k| env? k } test_macro(:other_env?) { |k| env? k }
[:shell, :non_existent_var].each do |k| [:shell, :non_existent_var].each do |k|
@ -33,7 +31,7 @@ Feature: `test_macro' recipe keyword
end end
end end
""" """
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain "shell_ok" Then the output must contain "shell_ok"
Then the output must not contain "non_existent_var_ok" Then the output must not contain "non_existent_var_ok"

View File

@ -6,11 +6,20 @@ When /^I execute the recipe$/ do
run_simple 'producer recipe.rb', false run_simple 'producer recipe.rb', false
end end
When /^I execute the recipe on remote target$/ do
run_simple 'producer recipe.rb -t some_host.test', false
end
When /^I successfully execute the recipe$/ do When /^I successfully execute the recipe$/ do
step 'I execute the recipe' step 'I execute the recipe'
assert_exit_status 0 assert_exit_status 0
end end
When /^I successfully execute the recipe on remote target$/ do
step 'I execute the recipe on remote target'
assert_exit_status 0
end
When /^I successfully execute the recipe with option (-.+)$/ do |option| When /^I successfully execute the recipe with option (-.+)$/ do |option|
run_simple "producer #{option} recipe.rb", false run_simple "producer #{option} recipe.rb", false
assert_exit_status 0 assert_exit_status 0

View File

@ -4,8 +4,6 @@ Feature: `dir?' condition keyword
Background: Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :dir_test do task :dir_test do
condition { dir? 'some_directory' } condition { dir? 'some_directory' }
@ -15,9 +13,9 @@ Feature: `dir?' condition keyword
Scenario: succeeds when directory exists Scenario: succeeds when directory exists
Given a remote directory named "some_directory" Given a remote directory named "some_directory"
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain "evaluated" Then the output must contain "evaluated"
Scenario: fails when directory does not exist Scenario: fails when directory does not exist
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must not contain "evaluated" Then the output must not contain "evaluated"

View File

@ -4,8 +4,6 @@ Feature: `env?' condition keyword
Background: Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :env_test_definition_ok do task :env_test_definition_ok do
condition { env? :shell } condition { env? :shell }
@ -32,17 +30,17 @@ Feature: `env?' condition keyword
""" """
Scenario: succeeds when remote environment variable is defined Scenario: succeeds when remote environment variable is defined
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain "definition_ok" Then the output must contain "definition_ok"
Scenario: fails when remote environment variable is not defined Scenario: fails when remote environment variable is not defined
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must not contain "definition_ko" Then the output must not contain "definition_ko"
Scenario: succeeds when remote environment variable value match Scenario: succeeds when remote environment variable value match
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain "value_ok" Then the output must contain "value_ok"
Scenario: fails when remote environment variable value does not match Scenario: fails when remote environment variable value does not match
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must not contain "value_ko" Then the output must not contain "value_ko"

View File

@ -4,8 +4,6 @@ Feature: `executable?' condition keyword
Background: Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :executable_test_ok do task :executable_test_ok do
condition { executable? 'true' } condition { executable? 'true' }
@ -20,9 +18,9 @@ Feature: `executable?' condition keyword
""" """
Scenario: succeeds when remote executable is available Scenario: succeeds when remote executable is available
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain "test_ok" Then the output must contain "test_ok"
Scenario: fails when remote executable is not available Scenario: fails when remote executable is not available
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must not contain "test_ko" Then the output must not contain "test_ko"

View File

@ -4,8 +4,6 @@ Feature: `file?' condition keyword
Background: Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :file_test do task :file_test do
condition { file? 'some_file' } condition { file? 'some_file' }
@ -15,9 +13,9 @@ Feature: `file?' condition keyword
Scenario: succeeds when file exists Scenario: succeeds when file exists
Given a remote file named "some_file" Given a remote file named "some_file"
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain "evaluated" Then the output must contain "evaluated"
Scenario: fails when file does not exist Scenario: fails when file does not exist
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must not contain "evaluated" Then the output must not contain "evaluated"

View File

@ -4,8 +4,6 @@ Feature: `file_contains' condition keyword
Background: Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :file_contains_test do task :file_contains_test do
condition { file_contains 'some_file', 'some_content' } condition { file_contains 'some_file', 'some_content' }
@ -15,14 +13,14 @@ Feature: `file_contains' condition keyword
Scenario: succeeds when file contains expected content Scenario: succeeds when file contains expected content
Given a remote file named "some_file" with "some_content" Given a remote file named "some_file" with "some_content"
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain "evaluated" Then the output must contain "evaluated"
Scenario: fails when file does not contain expected content Scenario: fails when file does not contain expected content
Given a remote file named "some_file" with "some_other_content" Given a remote file named "some_file" with "some_other_content"
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must not contain "evaluated" Then the output must not contain "evaluated"
Scenario: fails when file does not exist Scenario: fails when file does not exist
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must not contain "evaluated" Then the output must not contain "evaluated"

View File

@ -4,8 +4,6 @@ Feature: negated test prefix (no_)
Scenario: prefixed test fails when non-prefixed test is successful Scenario: prefixed test fails when non-prefixed test is successful
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :successful_test do task :successful_test do
condition { env? :shell } condition { env? :shell }
@ -18,15 +16,13 @@ Feature: negated test prefix (no_)
echo 'negated_test' echo 'negated_test'
end end
""" """
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain "successful_test" Then the output must contain "successful_test"
And the output must not contain "negated_test" And the output must not contain "negated_test"
Scenario: prefixed test fails when non-prefixed test is failing Scenario: prefixed test fails when non-prefixed test is failing
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :failing_test do task :failing_test do
condition { env? :inexistent_var } condition { env? :inexistent_var }
@ -39,6 +35,6 @@ Feature: negated test prefix (no_)
echo 'negated_test' echo 'negated_test'
end end
""" """
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must not contain "failing_test" Then the output must not contain "failing_test"
And the output must contain "negated_test" And the output must contain "negated_test"

View File

@ -4,8 +4,6 @@ Feature: `sh' and `` condition keyword
Background: Background:
Given a recipe with: Given a recipe with:
""" """
target 'some_host.test'
task :sh_test_ok do task :sh_test_ok do
condition { sh 'true' } condition { sh 'true' }
@ -32,17 +30,17 @@ Feature: `sh' and `` condition keyword
""" """
Scenario: succeeds when remote command execution is a success Scenario: succeeds when remote command execution is a success
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain "test_ok" Then the output must contain "test_ok"
Scenario: fails when remote executable is not available Scenario: fails when remote executable is not available
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must not contain "test_ko" Then the output must not contain "test_ko"
Scenario: `` alias, succeeds when remote executable is available Scenario: `` alias, succeeds when remote executable is available
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must contain "test_backtick_ok" Then the output must contain "test_backtick_ok"
Scenario: `` alias, fails when remote executable is not available Scenario: `` alias, fails when remote executable is not available
When I successfully execute the recipe When I successfully execute the recipe on remote target
Then the output must not contain "test_backtick_ko" Then the output must not contain "test_backtick_ko"