From 2fecb4bde4aec155bc614df0c2cbbfafcb23ec22 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Thu, 29 May 2014 14:31:13 +0000 Subject: [PATCH] Refactor and fix features --- features/action_echo.feature | 2 +- features/action_file_append.feature | 2 +- features/action_file_replace_content.feature | 27 ++++---- features/action_file_write.feature | 19 ++---- features/action_mkdir.feature | 21 +++--- features/action_sh.feature | 18 +----- features/cli_verbose.feature | 35 ++++------ features/recipe_macro.feature | 8 +-- features/recipe_source.feature | 4 +- features/recipe_target.feature | 4 +- features/ssh_config.feature | 4 +- features/task_condition.feature | 2 +- features/test_dir.feature | 2 +- features/test_env.feature | 58 +++++++---------- features/test_executable.feature | 26 ++++---- features/test_file.feature | 2 +- features/test_file_contains.feature | 2 +- features/test_shell_command_status.feature | 68 +++++++++----------- 18 files changed, 126 insertions(+), 178 deletions(-) diff --git a/features/action_echo.feature b/features/action_echo.feature index 5a97504..863b581 100644 --- a/features/action_echo.feature +++ b/features/action_echo.feature @@ -3,7 +3,7 @@ Feature: `echo' task action Scenario: prints text on standard output Given a recipe with: """ - task :say_hello do + task :echo_action do echo 'hello' end """ diff --git a/features/action_file_append.feature b/features/action_file_append.feature index bda1912..7cb20ec 100644 --- a/features/action_file_append.feature +++ b/features/action_file_append.feature @@ -9,7 +9,7 @@ Feature: `file_append' task action """ target 'some_host.test' - task :append_content_to_file do + task :file_append_action do file_append 'some_file', ' added' end """ diff --git a/features/action_file_replace_content.feature b/features/action_file_replace_content.feature index ab73fa9..c1b15f8 100644 --- a/features/action_file_replace_content.feature +++ b/features/action_file_replace_content.feature @@ -3,27 +3,24 @@ Feature: `file_replace_content' task action Background: Given a remote file named "some_file" with "some content" - - Scenario: replaces a string by another in the requested file - Given a recipe with: + And a remote file named "other_file" with "some content" + And a recipe with: """ 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' 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 - Given a recipe with: - """ - target 'some_host.test' - - task :replace_regexp_in_file do - file_replace_content 'some_file', /\w+\z/, 'other content' + task :file_replace_content_action_regexp do + file_replace_content 'other_file', /\w+\z/, 'other content' end """ + + Scenario: replaces a string by another in the requested file 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" diff --git a/features/action_file_write.feature b/features/action_file_write.feature index 42b575c..20f9f50 100644 --- a/features/action_file_write.feature +++ b/features/action_file_write.feature @@ -1,28 +1,23 @@ @sshd Feature: `file_write' task action - Scenario: writes given data to given file path + Background: Given a recipe with: """ target 'some_host.test' - task :write_some_data do - file_write 'some_file', 'some_content' + task :file_write_action do + file_write 'some_file', 'some_content' + file_write 'some_file_0600', 'some_content', 0600 + file_write 'some_file_0700', 'some_content', 0700 end """ + + Scenario: writes given data to given file path When I successfully execute the recipe Then the remote file "some_file" must contain "some_content" 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 Then the remote file "some_file_0600" must have 0600 mode And the remote file "some_file_0700" must have 0700 mode diff --git a/features/action_mkdir.feature b/features/action_mkdir.feature index 206bbe9..e6596ef 100644 --- a/features/action_mkdir.feature +++ b/features/action_mkdir.feature @@ -1,28 +1,23 @@ @sshd Feature: `mkdir' task action - Scenario: creates directory given as argument + Background: Given a recipe with: """ target 'some_host.test' - task :create_some_dir do + task :mkdir_action do mkdir 'some_directory' + mkdir 'some_directory_0700', 0700 + mkdir 'some_directory_0500', 0500 end """ + + Scenario: creates directory given as argument When I successfully execute the recipe Then the remote directory "some_directory" must exists 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 - Then the remote directory "0700_directory" must have 0700 mode - And the remote directory "0500_directory" must have 0500 mode + Then the remote directory "some_directory_0700" must have 0700 mode + And the remote directory "some_directory_0500" must have 0500 mode diff --git a/features/action_sh.feature b/features/action_sh.feature index c796e27..84fc067 100644 --- a/features/action_sh.feature +++ b/features/action_sh.feature @@ -1,24 +1,12 @@ @sshd 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 Given a recipe with: """ target 'some_host.test' - task :some_task do + task :sh_action do sh '\echo hello from remote' end """ @@ -30,7 +18,7 @@ Feature: `sh' task action """ target 'some_host.test' - task :some_task do + task :sh_action_aborting do sh '\false' sh '\echo after_fail' end @@ -43,7 +31,7 @@ Feature: `sh' task action """ target 'some_host.test' - task :some_task do + task :sh_action_command_error do sh '\false' end """ diff --git a/features/cli_verbose.feature b/features/cli_verbose.feature index 0287e22..89bb88b 100644 --- a/features/cli_verbose.feature +++ b/features/cli_verbose.feature @@ -1,42 +1,31 @@ Feature: CLI verbose option - Scenario: prints tasks name - 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 + Background: Given a recipe with: """ task :task_ok do condition { true } + + echo 'some mesasge' end + task :task_ko do condition { false } 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 Then the output must match /task_ok.+ condition: met.*task_ko.* condition: NOT met/ 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 - 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 - Given a recipe with: - """ - task :say_hello do - end - """ 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/ diff --git a/features/recipe_macro.feature b/features/recipe_macro.feature index 04cc34d..447be6a 100644 --- a/features/recipe_macro.feature +++ b/features/recipe_macro.feature @@ -1,6 +1,6 @@ Feature: `macro' recipe keyword - Scenario: declares new keyword accepting task code + Scenario: declares a new keyword accepting task code Given a recipe with: """ macro :hello do @@ -28,7 +28,7 @@ Feature: `macro' recipe keyword Given a recipe with: """ macro :my_echo do |message| - condition { message =~ /bar/ } + condition { message =~ /foo/ } echo message end @@ -36,5 +36,5 @@ Feature: `macro' recipe keyword %w[foo bar].each { |e| my_echo e } """ When I successfully execute the recipe - Then the output must not contain "foo" - And the output must contain "bar" + Then the output must contain "foo" + And the output must not contain "bar" diff --git a/features/recipe_source.feature b/features/recipe_source.feature index 094cfbb..d91a834 100644 --- a/features/recipe_source.feature +++ b/features/recipe_source.feature @@ -9,7 +9,9 @@ Feature: `source' recipe keyword Scenario: requires a recipe file 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 Then the output must contain "sourced recipe" diff --git a/features/recipe_target.feature b/features/recipe_target.feature index dca9e1d..07b3452 100644 --- a/features/recipe_target.feature +++ b/features/recipe_target.feature @@ -5,7 +5,9 @@ Feature: `target' recipe keyword """ target 'some_host.example' - puts env.target + task :some_task do + echo env.target + end """ When I successfully execute the recipe Then the output must contain exactly "some_host.example\n" diff --git a/features/ssh_config.feature b/features/ssh_config.feature index 717793d..55d7f08 100644 --- a/features/ssh_config.feature +++ b/features/ssh_config.feature @@ -5,7 +5,9 @@ Feature: SSH settings """ 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 diff --git a/features/task_condition.feature b/features/task_condition.feature index a86a27f..c712b7d 100644 --- a/features/task_condition.feature +++ b/features/task_condition.feature @@ -3,7 +3,7 @@ Feature: `condition' task keyword Scenario: prevents task actions application when condition is not met Given a recipe with: """ - task :hello do + task :some_task do condition { false } echo 'evaluated' diff --git a/features/test_dir.feature b/features/test_dir.feature index d16c6c4..82c188e 100644 --- a/features/test_dir.feature +++ b/features/test_dir.feature @@ -6,7 +6,7 @@ Feature: `dir?' condition keyword """ target 'some_host.test' - task :testing_directory_existence do + task :dir_test do condition { dir? 'some_directory' } echo 'evaluated' diff --git a/features/test_env.feature b/features/test_env.feature index e706931..9943dc2 100644 --- a/features/test_env.feature +++ b/features/test_env.feature @@ -1,58 +1,48 @@ @sshd Feature: `env?' condition keyword - Scenario: succeeds when remote environment variable is defined + Background: Given a recipe with: """ target 'some_host.test' - task :testing_env_var_definition do + task :env_test_definition_ok do condition { env? :shell } - echo 'evaluated' + echo 'definition_ok' end - """ - When I successfully execute the recipe - Then the output must contain "evaluated" - Scenario: fails when remote environment variable is not defined - Given a recipe with: - """ - target 'some_host.test' - - task :testing_env_var_definition do + task :env_test_definition_ko do condition { env? :non_existent_var } - echo 'evaluated' + echo 'definition_ko' end - """ - When I successfully execute the recipe - Then the output must not contain "evaluated" - Scenario: succeeds when remote environment variable value match - Given a recipe with: - """ - target 'some_host.test' - - task :testing_env_var_value do + task :env_test_value do condition { env? :shell, '/bin/sh' } - echo 'evaluated' + echo 'value_ok' end - """ - When I successfully execute the recipe - Then the output must contain "evaluated" - Scenario: fails when remote environment variable value does not match - Given a recipe with: - """ - target 'some_host.test' - - task :testing_env_var_value do + task :env_test_value do condition { env? :shell, 'non_existent_shell' } - echo 'evaluated' + echo 'value_ko' end """ + + Scenario: succeeds when remote environment variable is defined 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" diff --git a/features/test_executable.feature b/features/test_executable.feature index a32c6f2..b9363be 100644 --- a/features/test_executable.feature +++ b/features/test_executable.feature @@ -1,30 +1,28 @@ @sshd Feature: `executable?' condition keyword - Scenario: succeeds when remote executable is available + Background: Given a recipe with: """ target 'some_host.test' - task :testing_executable_availability do + task :executable_test_ok do condition { executable? 'true' } - echo 'evaluated' + echo 'test_ok' 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_executable_availability do + task :executable_test_ok do condition { executable? 'some_non_existent_executable' } - echo 'evaluated' + echo 'test_ko' end """ + + Scenario: succeeds when remote executable is available 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" diff --git a/features/test_file.feature b/features/test_file.feature index 9614be8..82fd0d5 100644 --- a/features/test_file.feature +++ b/features/test_file.feature @@ -6,7 +6,7 @@ Feature: `file?' condition keyword """ target 'some_host.test' - task :testing_file_existence do + task :file_test do condition { file? 'some_file' } echo 'evaluated' diff --git a/features/test_file_contains.feature b/features/test_file_contains.feature index e322953..d51f5af 100644 --- a/features/test_file_contains.feature +++ b/features/test_file_contains.feature @@ -6,7 +6,7 @@ Feature: `file_contains' condition keyword """ target 'some_host.test' - task :testing_content_in_file_presense do + task :file_contains_test do condition { file_contains 'some_file', 'some_content' } echo 'evaluated' diff --git a/features/test_shell_command_status.feature b/features/test_shell_command_status.feature index 890e8d3..a861cc4 100644 --- a/features/test_shell_command_status.feature +++ b/features/test_shell_command_status.feature @@ -1,58 +1,48 @@ @sshd -Feature: `` condition keyword +Feature: `sh' and `` condition keyword - Scenario: succeeds when remote command execution is a success + Background: Given a recipe with: """ 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` } - echo 'evaluated' + echo 'test_backtick_ok' 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 + task :sh_test_backtick_ko do condition { `false` } - echo 'evaluated' + echo 'test_backtick_ko' end """ + + Scenario: succeeds when remote command execution is a success 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 - Given a recipe with: - """ - target 'some_host.test' - - task :testing_remote_command do - condition { sh 'false' } - - echo 'evaluated' - end - """ + Scenario: fails when remote executable is not available 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 - Given a recipe with: - """ - target 'some_host.test' - - task :testing_remote_command do - condition { sh 'false' } - - echo 'evaluated' - end - """ + Scenario: `` alias, succeeds when remote executable is available 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"