Refactor and fix features
This commit is contained in:
		| @@ -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 | ||||
|       """ | ||||
|   | ||||
| @@ -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 | ||||
|       """ | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|       """ | ||||
|   | ||||
| @@ -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/ | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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' | ||||
|   | ||||
| @@ -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' | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
| @@ -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' | ||||
|   | ||||
| @@ -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' | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user