From 4a5773678090efdaafbb8ead3ccbc9724a719bae Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Wed, 12 Aug 2015 21:47:35 +0200 Subject: [PATCH 001/118] Allo exit code as well --- lib/aruba/cucumber.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index 421b7bd33..67dda50c2 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -249,11 +249,11 @@ assert_not_matching_output(expected, all_output) end -Then /^the exit status should be (\d+)$/ do |exit_status| +Then /^the exit (?:status|code) should be (\d+)$/ do |exit_status| assert_exit_status(exit_status.to_i) end -Then /^the exit status should not be (\d+)$/ do |exit_status| +Then /^the exit (?:status|code) not be (\d+)$/ do |exit_status| assert_not_exit_status(exit_status.to_i) end From 51507215c0c503ef1da41174bc5ef6b0f41e842e Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 17:57:04 +0200 Subject: [PATCH 002/118] Improve documentation --- features/announce.feature | 213 +++++++++ features/commands/debug_command.feature | 85 ++++ .../commands/environment_variables.feature | 64 +++ features/commands/flushing.feature | 74 +++ features/commands/interactive.feature | 90 ++++ features/commands/output/all_output.feature | 448 ++++++++++++++++++ features/commands/output/stdout.feature | 66 +++ features/core/cleanup_aruba_directory.feature | 52 ++ features/debug.feature | 15 - features/development/build.feature | 16 + features/development/test.feature | 23 + .../lib/cli/app/suppress_simple_cov_output.rb | 15 + features/flushing.feature | 26 - features/interactive.feature | 66 --- features/no_clobber.feature | 25 - features/output.feature | 221 ++------- features/step_definitions/aruba_dev_steps.rb | 11 +- features/usage/install.feature | 9 + 18 files changed, 1205 insertions(+), 314 deletions(-) create mode 100644 features/announce.feature create mode 100644 features/commands/debug_command.feature create mode 100644 features/commands/environment_variables.feature create mode 100644 features/commands/flushing.feature create mode 100644 features/commands/interactive.feature create mode 100644 features/commands/output/all_output.feature create mode 100644 features/commands/output/stdout.feature create mode 100644 features/core/cleanup_aruba_directory.feature delete mode 100644 features/debug.feature create mode 100644 features/development/build.feature create mode 100644 features/development/test.feature create mode 100644 features/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb delete mode 100644 features/flushing.feature delete mode 100644 features/interactive.feature delete mode 100644 features/no_clobber.feature create mode 100644 features/usage/install.feature diff --git a/features/announce.feature b/features/announce.feature new file mode 100644 index 000000000..df8fc8ad0 --- /dev/null +++ b/features/announce.feature @@ -0,0 +1,213 @@ +Feature: Announce output during test run + + In order to specify expected output + As a developer using Cucumber + I want to use the "the output should contain" step + + Background: + Given I use a fixture named "cli-app" + + Scenario: Announce change of directory (deprecated) + Given a file named "features/exit_status.feature" with: + """ + Feature: Announce + @announce-dir + Scenario: Run command + Given a directory named "dir.d" + When I cd to "dir.d" + """ + When I run `cucumber` + Then the features should all pass + And the output should contain: + """ + $ cd / + """ + And the output should contain: + """ + tmp/aruba/dir.d + """ + + Scenario: Announce change of directory + Given a file named "features/exit_status.feature" with: + """ + Feature: Announce + @announce-directory + Scenario: Run command + Given a directory named "dir.d" + When I cd to "dir.d" + """ + When I run `cucumber` + Then the features should all pass + And the output should contain: + """ + $ cd / + """ + And the output should contain: + """ + tmp/aruba/dir.d + """ + + Scenario: Announce stdout + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + puts 'Hello World' + """ + And a file named "features/exit_status.feature" with: + """ + Feature: Announce + @announce-stdout + Scenario: Run command + When I run `cli` + Then the exit status should be 0 + """ + When I run `cucumber` + Then the features should all pass + And the output should contain: + """ + <<-STDOUT + Hello World + + STDOUT + """ + + Scenario: Announce stderr + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + $stderr.puts 'Hello World' + """ + And a file named "features/exit_status.feature" with: + """ + Feature: Announce + @announce-stderr + Scenario: Run command + When I run `cli` + Then the exit status should be 0 + """ + When I run `cucumber` + Then the features should all pass + And the output should contain: + """ + <<-STDERR + Hello World + + STDERR + """ + + Scenario: Announce both stderr and stdout + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + $stderr.puts 'Hello' + puts 'World' + """ + And a file named "features/exit_status.feature" with: + """ + Feature: Announce + @announce-output + Scenario: Run command + When I run `cli` + Then the exit status should be 0 + """ + When I run `cucumber` + Then the features should all pass + And the output should contain: + """ + <<-STDERR + Hello + + STDERR + """ + And the output should contain: + """ + <<-STDOUT + World + + STDOUT + """ + + Scenario: Announce command + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $stderr.puts 'Hello' + puts 'World' + """ + And a file named "features/exit_status.feature" with: + """ + Feature: Announce + @announce-cmd + Scenario: Run command + When I run `cli` + Then the exit status should be 0 + """ + When I run `cucumber` + Then the features should all pass + And the output should contain: + """ + $ cli + """ + + Scenario: Announce change of environment variable + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts 'World' + """ + And a file named "features/exit_status.feature" with: + """ + Feature: Announce + @announce-env + Scenario: Run command + When I set the environment variables to: + | variable | value | + | MY_VAR | my_value | + And I run `cli` + Then the exit status should be 0 + """ + When I run `cucumber` + Then the features should all pass + And the output should contain: + """ + $ export MY_VAR=my_value + """ + + Scenario: Announce change of environment variable which contains special characters + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts 'World' + """ + And a file named "features/exit_status.feature" with: + """ + Feature: Announce + @announce-env + Scenario: Run command + When I set the environment variables to: + | variable | value | + | MY_VAR | my value ! | + And I run `cli` + Then the exit status should be 0 + """ + When I run `cucumber` + Then the features should all pass + And the output should contain: + """ + $ export MY_VAR=my\ value\ \ + """ diff --git a/features/commands/debug_command.feature b/features/commands/debug_command.feature new file mode 100644 index 000000000..312681321 --- /dev/null +++ b/features/commands/debug_command.feature @@ -0,0 +1,85 @@ +Feature: Debug your command in cucumber-test-run + + As a developer + I want to use some debugger in my code and therefor need system() to execute my program + In order to find a bug + + Background: + Given I use a fixture named "cli-app" + + Scenario: Can handle exit status 0 + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + exit 0 + """ + And a file named "features/debug.feature" with: + """ + Feature: Exit status in debug environment + + @debug + Scenario: Run program with debug code + When I run `cli` + Then the exit status should be 0 + """ + When I successfully run `cucumber` + Then the features should all pass + + Scenario: Can handle exit status 1 + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + exit 1 + """ + And a file named "features/debug.feature" with: + """ + Feature: Exit status in debug environment + + @debug + Scenario: Run program with debug code + When I run `cli` + Then the exit status should be 1 + """ + When I successfully run `cucumber` + Then the features should all pass + + Scenario: You can use a debug repl in your cli program + + If you want to debug a strange error, which only occures in one of your + `cucumber`-tests, the `@debug`-tag becomes handy. You can add `@debug` in + front of your feature/scenario to make `binding.pry` or `byebug` work in + your program. + + Please make sure, that there's a statement after the `binding.pry`-call. + Otherwise you might not get an interactive shell, because your program will + just exit. + + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + require 'pry' + binding.pry + + exit 0 + """ + And a file named "features/debug.feature" with: + """ + Feature: Exit status in debug environment + + @debug + Scenario: Run program with debug code + When I run `cli` + Then the exit status should be 0 + """ + When I run `cucumber` interactively + And I stop the command if output contains: + """ + pry + """ + Then the output should contain: + """ + pry(main)> + """ diff --git a/features/commands/environment_variables.feature b/features/commands/environment_variables.feature new file mode 100644 index 000000000..25f764760 --- /dev/null +++ b/features/commands/environment_variables.feature @@ -0,0 +1,64 @@ +Feature: Modify environment variables + + In order to test command line applications which make use of environment variables + As a developer using Cucumber + I want to use the command environment variable step + + Background: + Given I use a fixture named "cli-app" + + Scenario: Change/Set value of arbitrary environment variable + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts ENV['LONG_LONG_VARIABLE'] + """ + And a file named "features/environment_variable.feature" with: + """ + Feature: Flushing output + Scenario: Run command + Given I set the environment variables to: + | variable | value | + | LONG_LONG_VARIABLE | long_value | + When I run `cli` + Then the output should contain "long_value" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Change the HOME-variable of current user during test using custom step + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts File.expand_path('~/') + """ + And a file named "features/home_directory.feature" with: + """ + Feature: Run command with different home directory + Scenario: Run command + Given a mocked home directory + When I run `cli` + Then the output should contain "tmp/aruba" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Change the HOME-variable of current user during test using tag + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts File.expand_path('~/') + """ + And a file named "features/home_directory.feature" with: + """ + Feature: Run command + @mocked_home_directory + Scenario: Run command + When I run `cli` + Then the output should contain "tmp/aruba" + """ + When I run `cucumber` + Then the features should all pass diff --git a/features/commands/flushing.feature b/features/commands/flushing.feature new file mode 100644 index 000000000..a8851fe93 --- /dev/null +++ b/features/commands/flushing.feature @@ -0,0 +1,74 @@ +Feature: Flushing the output of your application + + In order to test processes that output a lot of data + As a developer using Aruba + I want to make sure that large amounts of output aren't buffered + + Background: + Given I use a fixture named "cli-app" + + Scenario: A little output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env bash + + for ((c=0; c<256; c = c+1)); do + echo -n "a" + done + """ + And a file named "features/flushing.feature" with: + """ + Feature: Flushing output + Scenario: Run command + When I run `cli` + Then the output should contain "a" + And the output should be 256 bytes long + And the exit status should be 0 + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Tons of output + Given the default aruba timeout is 10 seconds + And a file named "bin/cli" with: + """ + #!/usr/bin/env bash + + for ((c=0; c<65536; c = c+1)); do + echo -n "a" + done + """ + And a file named "features/flushing.feature" with: + """ + Feature: Flushing output + Scenario: Run command + When I run `cli` + Then the output should contain "a" + And the output should be 65536 bytes long + And the exit status should be 0 + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Tons of interactive output + Given the default aruba timeout is 10 seconds + And a file named "bin/cli" with: + """ + #!/usr/bin/env bash + + read size; for ((c=0; c<$size; c = c+1)); do + echo -n "a" + done + """ + And a file named "features/flushing.feature" with: + """ + Feature: Flushing output + Scenario: Run command + When I run `cli` interactively + And I type "65536" + Then the output should contain "a" + And the output should be 65536 bytes long + And the exit status should be 0 + """ + When I run `cucumber` + Then the features should all pass diff --git a/features/commands/interactive.feature b/features/commands/interactive.feature new file mode 100644 index 000000000..9512ff50d --- /dev/null +++ b/features/commands/interactive.feature @@ -0,0 +1,90 @@ +Feature: Interactive process control + + In order to test interactive command line applications + As a developer using Cucumber + I want to use the interactive session steps + + Background: + Given I use a fixture named "cli-app" + + @wip-jruby-java-1.6 + Scenario: Running ruby interactively + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + while res = gets.chomp + break if res == "quit" + puts res.reverse + end + """ + And a file named "features/interactive.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` interactively + And I type "hello, world" + And I type "quit" + Then it should pass with "dlrow ,olleh" + """ + When I run `cucumber` + Then the features should all pass + + @posix + Scenario: Running a native binary interactively + Given a file named "features/interactive.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cat` interactively + And I type "Hello, world" + And I type "" + Then the output should contain "Hello, world" + """ + When I run `cucumber` + Then the features should all pass + + @posix + Scenario: Pipe in a file + Given a file named "features/interactive.feature" with: + """ + Feature: Run command + Scenario: Run command + Given a file named "test.txt" with "line1\nline2" + When I run `cat` interactively + And I pipe in the file "test.txt" + Then the output should contain "line1\nline2" + """ + When I run `cucumber` + Then the features should all pass + + @posix + Scenario: Close stdin stream + Given a file named "features/interactive.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cat` interactively + And I type "Hello, world" + And I close the stdin stream + Then the output should contain "Hello, world" + """ + When I run `cucumber` + Then the features should all pass + + @posix + Scenario: All processes are stopped before checking for filesystem changes + + See: http://github.com/aslakhellesoy/aruba/issues#issue/17 for context + + Given a file named "features/interactive.feature" with: + """ + Feature: Run command + Scenario: Run command + Given a directory named "rename_me" + When I run `mv rename_me renamed` interactively + Then the directory "renamed" should exist + And the directory "rename_me" should not exist + """ + When I run `cucumber` + Then the features should all pass diff --git a/features/commands/output/all_output.feature b/features/commands/output/all_output.feature new file mode 100644 index 000000000..37bde8fa8 --- /dev/null +++ b/features/commands/output/all_output.feature @@ -0,0 +1,448 @@ +Feature: All output of commands which were executed + + In order to specify expected output + As a developer using Cucumber + I want to use the "the output should contain" step + + Background: + Given I use a fixture named "cli-app" + + Scenario: Detect subset of one-line output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts 'hello world' + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should contain "hello world" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Detect absence of one-line output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts 'hello world' + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should not contain "good-bye" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Detect subset of multiline output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts "hello\nworld" + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should contain: + \"\"\" + hello + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + @debug + Scenario: Detect absence of subset of multiline output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts "hello\nworld" + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should not contain: + \"\"\" + good-bye + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + @posix + Scenario: Detect exact one-line output for posix commands + Given a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `printf 'hello world'` + Then the output should contain exactly: + \"\"\" + hello world + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Detect exact one-line output for ruby commands + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + print "hello world" + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should contain exactly: + \"\"\" + hello world + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + When I run `printf "\e[36mhello world\e[0m"` + Then the output should contain exactly: + """ + """ + + @ansi + Scenario: Detect exact one-line output with ANSI output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + print "\e[36mhello world\e[0m" + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should contain exactly: + \"\"\" + \e[36mhello world\e[0m + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Detect exact one-line output with ANSI output stripped by default + Given the default aruba timeout is 12 seconds + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + print "\e[36mhello world\e[0m" + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should contain exactly: + \"\"\" + hello world + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Detect exact multiline output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + print "hello\nworld" + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should contain exactly: + \"\"\" + hello + world + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Detect subset of one-line output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts 'hello world' + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should contain "hello world" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Detect subset of one-line output with regex + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts 'hello, ruby' + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should match /^hello(, world)?/ + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Detect subset of multiline output with regex + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts "hello\nworld\nextra line1\nextra line2\nimportant line" + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should match: + \"\"\" + he..o + wor.d + .* + important line + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Negative matching of one-line output with regex + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts "hello, ruby" + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should not match /ruby is a better perl$/ + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Negative matching of multiline output with regex + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts "hello\nworld\nextra line1\nextra line2\nimportant line" + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the output should not match: + \"\"\" + ruby + is + a + .* + perl + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Match passing exit status and partial output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts "hello world" + exit 0 + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then it should pass with: + \"\"\" + hello + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Match passing exit status and exact output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + print "hello\nworld" + exit 0 + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then it should pass with exactly: + \"\"\" + hello + world + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Match failing exit status and partial output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts "hello\nworld" + exit 1 + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then it should fail with: + \"\"\" + hello + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + + Scenario: Match failing exit status and exact output + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + puts "hello\nworld" + exit 1 + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then it should fail with: + \"\"\" + hello + world + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Match failing exit status and output with regex + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + puts "hello\nworld" + exit 1 + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then it should fail with regex: + \"\"\" + hello\s*world + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Detect output from all processes + Given an executable named "bin/cli1" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + puts 'This is cli1' + """ + And an executable named "bin/cli2" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + puts 'This is cli2' + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli1` + When I run `cli2` + Then the stdout should contain exactly: + \"\"\" + This is cli1 + This is cli2 + + \"\"\" + """ + When I run `cucumber` + Then the features should all pass diff --git a/features/commands/output/stdout.feature b/features/commands/output/stdout.feature new file mode 100644 index 000000000..485d8b075 --- /dev/null +++ b/features/commands/output/stdout.feature @@ -0,0 +1,66 @@ +Feature: Stdout of commands which were executed + + In order to specify expected output + As a developer using Cucumber + I want to use the "the output should contain" step + + Background: + Given I use a fixture named "cli-app" + + Scenario: Match output in stdout + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts "hello\nworld" + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the stdout should contain "hello" + Then the stderr should not contain "hello" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Match stdout on several lines + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts 'GET /' + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the stdout should contain: + \"\"\" + GET / + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Match output on several lines where stdout contains quotes + Given a file named "bin/cli" with: + """ + #!/usr/bin/env ruby + + puts 'GET "/"' + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli` + Then the stdout should contain: + \"\"\" + GET "/" + \"\"\" + """ + When I run `cucumber` + Then the features should all pass diff --git a/features/core/cleanup_aruba_directory.feature b/features/core/cleanup_aruba_directory.feature new file mode 100644 index 000000000..31088bc81 --- /dev/null +++ b/features/core/cleanup_aruba_directory.feature @@ -0,0 +1,52 @@ +Feature: No clobber + + By default Aruba removes its scratch directory before + every scenario. This isn't always the right thing + to do, especially when the path to the default directory + has been changed. Use @no-clobber to stop Aruba from + cleaning up after itself. + + Background: + Given I use a fixture named "cli-app" + + Scenario: Changes in the filesystem + Given a file named "tmp/aruba/file.txt" with "content" + And a directory named "tmp/aruba/dir.d" + And a file named "features/flushing.feature" with: + """ + Feature: Check + Scenario: Check + Then a file named "file.txt" does not exist + And a directory named "dir.d" does not exist + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Do not clobber before run + Given a file named "tmp/aruba/file.txt" with "content" + And a directory named "tmp/aruba/dir.d" + And a file named "features/flushing.feature" with: + """ + Feature: Check + @no-clobber + Scenario: Check + Then a file named "file.txt" should exist + And a directory named "dir.d" should exist + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Cleanup and verify the previous scenario + Given a file named "features/flushing.feature" with: + """ + Feature: Check + Scenario: Check #1 + Given a file named "tmp/aruba/file.txt" with "content" + And a directory named "tmp/aruba/dir.d" + + Scenario: Check #2 + Then a file named "file.txt" should not exist + And a directory named "dir.d" should not exist + """ + When I run `cucumber` + Then the features should all pass diff --git a/features/debug.feature b/features/debug.feature deleted file mode 100644 index e04bf0aa0..000000000 --- a/features/debug.feature +++ /dev/null @@ -1,15 +0,0 @@ -Feature: Debug command execution - - As a developer - I want to use some debugger in my code and therefor need system() to execute my program - In order to find a bug - - @debug - Scenario: Run program with debug code - When I run `true` - Then the exit status should be 0 - - @debug - Scenario: Run failing program with debug code - When I run `false` - Then the exit status should be 1 diff --git a/features/development/build.feature b/features/development/build.feature new file mode 100644 index 000000000..cebb10571 --- /dev/null +++ b/features/development/build.feature @@ -0,0 +1,16 @@ +Feature: Build Aruba Gem + + As a aruba developer + I want to build the `aruba` gem + In order to install it + + Background: + Given I successfully run `git clone https://github.com/cucumber/aruba.git` + And I cd to "aruba" + + Scenario: Building aruba using rake task + + To build the `aruba`-gem you can use the `build`-rake task. + + Given I successfully run `rake build` + Then a file matching %r should exist diff --git a/features/development/test.feature b/features/development/test.feature new file mode 100644 index 000000000..927efbb5b --- /dev/null +++ b/features/development/test.feature @@ -0,0 +1,23 @@ +Feature: Build Aruba Gem + + As a aruba developer + I want to build the `aruba` gem + In order to install it + + Background: + Given the default aruba timeout is 10 seconds + And I successfully run `git clone https://github.com/cucumber/aruba.git` + And I cd to "aruba" + + @ignore + Scenario: Testing user interface + Given I successfully run `cucumber` + Then the features should all pass + + Scenario: Testing compliance to ruby community guide + Given I successfully run `rubocop` + Then the features should all pass + + Scenario: Testing api + Given I successfully run `rspec` + Then the features should all pass diff --git a/features/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb b/features/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb new file mode 100644 index 000000000..dce7c16c8 --- /dev/null +++ b/features/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb @@ -0,0 +1,15 @@ +module SimpleCov + module Formatter + class HTMLFormatter + def format(result) + Dir[File.join(File.dirname(__FILE__), "../public/*")].each do |path| + FileUtils.cp_r(path, asset_output_path) + end + + File.open(File.join(output_path, "index.html"), "wb") do |file| + file.puts template("layout").result(binding) + end + end + end + end +end diff --git a/features/flushing.feature b/features/flushing.feature deleted file mode 100644 index 9810b65d5..000000000 --- a/features/flushing.feature +++ /dev/null @@ -1,26 +0,0 @@ -Feature: Flushing output - - In order to test processes that output a lot of data - As a developer using Aruba - I want to make sure that large amounts of output aren't buffered - - Scenario: A little output - When I run `bash -c 'for ((c=0; c<256; c = c+1)); do echo -n "a"; done'` - Then the output should contain "a" - And the output should be 256 bytes long - And the exit status should be 0 - - Scenario: Tons of output - Given the default aruba timeout is 10 seconds - When I run `bash -c 'for ((c=0; c<65536; c = c+1)); do echo -n "a"; done'` - Then the output should contain "a" - And the output should be 65536 bytes long - And the exit status should be 0 - - Scenario: Tons of interactive output - Given the default aruba timeout is 10 seconds - When I run `bash -c 'read size; for ((c=0; c<$size; c = c+1)); do echo -n "a"; done'` interactively - And I type "65536" - Then the output should contain "a" - And the output should be 65536 bytes long - # And the exit status should be 0 diff --git a/features/interactive.feature b/features/interactive.feature deleted file mode 100644 index 42bc11197..000000000 --- a/features/interactive.feature +++ /dev/null @@ -1,66 +0,0 @@ -Feature: Interactive process control - - In order to test interactive command line applications - As a developer using Cucumber - I want to use the interactive session steps - - @wip-jruby-java-1.6 - Scenario: Running ruby interactively - Given a file named "echo.rb" with: - """ - while res = gets.chomp - break if res == "quit" - puts res.reverse - end - """ - When I run `ruby echo.rb` interactively - And I type "hello, world" - And I type "quit" - Then it should pass with: - """ - dlrow ,olleh - """ - - @posix - Scenario: Running a native binary interactively - When I run `cat` interactively - And I type "Hello, world" - And I type "" - Then the output should contain: - """ - Hello, world - """ - - @posix - Scenario: Pipe in a file - Given a file named "test.txt" with: - """ - line1 - line2 - """ - When I run `cat` interactively - And I pipe in the file "test.txt" - Then the output should contain: - """ - line1 - line2 - """ - - @posix - Scenario: Close stdin stream - When I run `cat` interactively - And I type "Hello, world" - And I close the stdin stream - Then the output should contain: - """ - Hello, world - """ - - @posix - Scenario: Stop processes before checking for filesystem changes - See: http://github.com/aslakhellesoy/aruba/issues#issue/17 for context - - Given a directory named "rename_me" - When I run `mv rename_me renamed` interactively - Then the directory "renamed" should exist - And the directory "rename_me" should not exist diff --git a/features/no_clobber.feature b/features/no_clobber.feature deleted file mode 100644 index 98e547d64..000000000 --- a/features/no_clobber.feature +++ /dev/null @@ -1,25 +0,0 @@ -Feature: No clobber - - By default Aruba removes its scratch directory before - every scenario. This isn't always the right thing - to do, especially when the path to the default directory - has been changed. Use @no-clobber to stop Aruba from - cleaning up after itself. - - Scenario: Change the filesystem - Given a directory named "foo/bar" - And a file named "foo/bar/baz.txt" with: - """ - I don't want to die! - """ - - @no-clobber - Scenario: Verify nothing was clobbered - Then a file named "foo/bar/baz.txt" should exist - And the file "foo/bar/baz.txt" should contain exactly: - """ - I don't want to die! - """ - - Scenario: Cleanup and verify the previous scenario - Then a file named "foo/bar/baz.txt" should not exist diff --git a/features/output.feature b/features/output.feature index 936490a5b..d2169a17c 100644 --- a/features/output.feature +++ b/features/output.feature @@ -1,184 +1,54 @@ -Feature: Output +Feature: All output of commands which were executed In order to specify expected output As a developer using Cucumber I want to use the "the output should contain" step - @posix - Scenario: Detect subset of one-line output - When I run `printf 'hello world'` - Then the output should contain "hello world" + Background: + Given I use a fixture named "cli-app" + + @wip + @debug + Scenario: Detect output from all processes normal and interactive ones + Given an executable named "bin/cli1" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + puts 'This is cli1' + """ + And an executable named "bin/cli2" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + while input = gets do + break if input == "" + puts input + end + """ + And a file named "features/output.feature" with: + """ + @debug + Feature: Run command + Scenario: Run command + When I run `cli1` + When I run `cli2` interactively + And I type "This is cli2" + And I type "" + Then the stdout should contain exactly: + \"\"\" + This is cli1 + This is cli2 + + \"\"\" + """ + When I run `cucumber` + Then the features should all pass - Scenario: Detect absence of one-line output - When I run `printf "hello world"` - Then the output should not contain "good-bye" - - Scenario: Detect subset of multiline output - When I run `printf "hello\nworld"` - Then the output should contain: - """ - hello - """ - - Scenario: Detect absence of multiline output - When I run `printf "hello\nworld"` - Then the output should not contain: - """ - good-bye - """ - - @posix - Scenario: Detect exact one-line output - When I run `printf "hello world"` - Then the output should contain exactly: - """ - hello world - """ - - @ansi - @posix - Scenario: Detect exact one-line output with ANSI output - When I run `printf "\e[36mhello world\e[0m"` - Then the output should contain exactly: - """ - \e[36mhello world\e[0m - """ - - @posix - Scenario: Detect exact one-line output with ANSI output stripped by default - When I run `printf "\e[36mhello world\e[0m"` - Then the output should contain exactly: - """ - hello world - """ - - @posix - Scenario: Detect exact multiline output - When I run `printf "hello\nworld"` - Then the output should contain exactly: - """ - hello - world - """ - - @announce - Scenario: Detect subset of one-line output with regex - When I run `printf "hello, ruby"` - Then the output should contain "ruby" - And the output should match /^hello(, world)?/ - - @announce - @posix - Scenario: Detect subset of multiline output with regex - When I run `printf "hello\nworld\nextra line1\nextra line2\nimportant line"` - Then the output should match: - """ - he..o - wor.d - .* - important line - """ - - @announce - Scenario: Negative matching of one-line output with regex - When I run `printf "hello, ruby"` - Then the output should contain "ruby" - And the output should not match /ruby is a better perl$/ - - @announce - @posix - Scenario: Negative matching of multiline output with regex - When I run `printf "hello\nworld\nextra line1\nextra line2\nimportant line"` - Then the output should not match: - """ - ruby - is - a - .* - perl - """ - - @announce - @posix - Scenario: Match passing exit status and partial output - When I run `printf "hello\nworld"` - Then it should pass with: - """ - hello - """ - - @posix - Scenario: Match passing exit status and exact output - When I run `printf "hello\nworld"` - Then it should pass with exactly: - """ - hello - world - """ - - @announce-stdout - Scenario: Match failing exit status and partial output - When I run `bash -c '(printf "hello\nworld";exit 99)'` - Then it should fail with: - """ - hello - """ - - @posix - Scenario: Match failing exit status and exact output - When I run `bash -c '(printf "hello\nworld";exit 99)'` - Then it should fail with exactly: - """ - hello - world - """ - - @announce-stdout - @posix - Scenario: Match failing exit status and output with regex - When I run `bash -c '(printf "hello\nworld";exit 99)'` - Then it should fail with regex: - """ - hello\s*world - """ - - @announce-cmd - @posix - Scenario: Match output in stdout - When I run `printf "hello\nworld"` - Then the stdout should contain "hello" - Then the stderr should not contain "hello" - - @announce - Scenario: Match output on several lines - When I run `printf 'GET /'` - Then the stdout should contain: - """ - GET / - """ - - @posix - Scenario: Match output on several lines using quotes - When I run `printf 'GET "/"'` - Then the stdout should contain: - """ - GET "/" - """ - - @posix - Scenario: Detect output from all processes - When I run `printf "hello world!\n"` - And I run `cat` interactively - And I type "hola" - And I type "" - Then the output should contain exactly: - """ - hello world! - hola - - """ - - @posix Scenario: Detect stdout from all processes When I run `printf "hello world!\n"` And I run `cat` interactively @@ -192,7 +62,6 @@ Feature: Output """ And the stderr should not contain anything - @posix Scenario: Detect stderr from all processes When I run `bash -c 'printf "hello world!\n" >&2'` And I run `bash -c 'cat >&2 '` interactively diff --git a/features/step_definitions/aruba_dev_steps.rb b/features/step_definitions/aruba_dev_steps.rb index b33d059f3..9eeab23c2 100644 --- a/features/step_definitions/aruba_dev_steps.rb +++ b/features/step_definitions/aruba_dev_steps.rb @@ -25,16 +25,13 @@ expect{steps multiline_step.to_s}.to raise_error(RSpec::Expectations::ExpectationNotMetError) end -Then /^the output should be (\d+) bytes long$/ do |length| - expect(all_output.length).to eq length.to_i -end - Then /^the feature(?:s)? should( not)?(?: all)? pass$/ do |negated| if negated step 'the output should contain " failed)"' step 'the exit status should be 1' else step 'the output should not contain " failed)"' + step 'the output should not contain " undefined)"' step 'the exit status should be 0' end end @@ -45,6 +42,7 @@ step 'the exit status should be 1' else step 'the output should not contain " failed)"' + step 'the output should not contain " undefined)"' step 'the exit status should be 0' end @@ -103,6 +101,7 @@ ) end -Given(/^(?:an|the) executable(?: named)? "([^"]*)" with:$/) do |file_name, file_content| - step %(a file named "#{file_name}" with mode "0755" and with:), file_content +Then(/^aruba should be installed on the local system$/) do + run('gem list aruba') + expect(last_command).to have_output(/aruba/) end diff --git a/features/usage/install.feature b/features/usage/install.feature new file mode 100644 index 000000000..96793359a --- /dev/null +++ b/features/usage/install.feature @@ -0,0 +1,9 @@ +Feature: Install aruba + + Background: + Given the default aruba timeout is 10 seconds + + # @wip + Scenario: Using rubygems + Given I successfully run `gem install aruba` + Then aruba should be installed on the local system From 48b32cc2b0873bb717a88ed8ead9608773544474 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 17:57:23 +0200 Subject: [PATCH 003/118] Added new matchers to check output --- lib/aruba/matchers/command/have_output.rb | 30 +++++ .../matchers/command/have_output_on_stderr.rb | 29 ++++ .../matchers/command/have_output_on_stdout.rb | 30 +++++ .../matchers/command/have_output_size.rb | 28 ++++ lib/aruba/matchers/file/have_file_size.rb | 2 +- .../matchers/command/have_output_size_spec.rb | 25 ++++ spec/aruba/matchers/command_spec.rb | 125 ++++++++++++++++++ 7 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 lib/aruba/matchers/command/have_output.rb create mode 100644 lib/aruba/matchers/command/have_output_on_stderr.rb create mode 100644 lib/aruba/matchers/command/have_output_on_stdout.rb create mode 100644 lib/aruba/matchers/command/have_output_size.rb create mode 100644 spec/aruba/matchers/command/have_output_size_spec.rb diff --git a/lib/aruba/matchers/command/have_output.rb b/lib/aruba/matchers/command/have_output.rb new file mode 100644 index 000000000..d966f4076 --- /dev/null +++ b/lib/aruba/matchers/command/have_output.rb @@ -0,0 +1,30 @@ +# @!method have_output +# This matchers checks if has created output +# +# @return [TrueClass, FalseClass] The result +# +# false: +# * if command has not created output +# true: +# * if command created output +# +# @example Use matcher +# +# RSpec.describe do +# it { expect(last_command).to have_output } +# end +RSpec::Matchers.define :have_output do |expected| + match do |actual| + next false unless actual.respond_to? :output + + @old_actual = actual + @actual = actual.output.chomp + + values_match?(expected, @actual) + end + + diffable + + description { "have output: #{description_of expected}" } +end + diff --git a/lib/aruba/matchers/command/have_output_on_stderr.rb b/lib/aruba/matchers/command/have_output_on_stderr.rb new file mode 100644 index 000000000..627765f54 --- /dev/null +++ b/lib/aruba/matchers/command/have_output_on_stderr.rb @@ -0,0 +1,29 @@ +# @!method have_output_on_stderr +# This matchers checks if has created output on stderr +# +# @return [TrueClass, FalseClass] The result +# +# false: +# * if command has not created output on stderr +# true: +# * if command created output on stderr +# +# @example Use matcher +# +# RSpec.describe do +# it { expect(last_command).to have_output_on_stderr } +# end +RSpec::Matchers.define :have_output_on_stderr do |expected| + match do |actual| + next false unless actual.respond_to? :stderr + + @old_actual = actual + @actual = actual.stderr.chomp + + values_match?(expected, @actual) + end + + diffable + + description { "have output on stderr: #{description_of expected}" } +end diff --git a/lib/aruba/matchers/command/have_output_on_stdout.rb b/lib/aruba/matchers/command/have_output_on_stdout.rb new file mode 100644 index 000000000..9922908b1 --- /dev/null +++ b/lib/aruba/matchers/command/have_output_on_stdout.rb @@ -0,0 +1,30 @@ +# @!method have_output_on_stdout +# This matchers checks if has created output on stdout +# +# @return [TrueClass, FalseClass] The result +# +# false: +# * if command has not created output on stdout +# true: +# * if command created output on stdout +# +# @example Use matcher +# +# RSpec.describe do +# it { expect(last_command).to have_output_on_stdout } +# end +RSpec::Matchers.define :have_output_on_stdout do |expected| + match do |actual| + next false unless actual.respond_to? :stdout + + @old_actual = actual + @actual = actual.stdout.chomp + + values_match?(expected, @actual) + end + + diffable + + description { "have output on stdout: #{description_of expected}" } +end + diff --git a/lib/aruba/matchers/command/have_output_size.rb b/lib/aruba/matchers/command/have_output_size.rb new file mode 100644 index 000000000..69d0ad242 --- /dev/null +++ b/lib/aruba/matchers/command/have_output_size.rb @@ -0,0 +1,28 @@ +# @!method have_output_size(output) +# This matchers checks if output has size. +# +# @param [String] output +# The content which should be checked +# +# @return [TrueClass, FalseClass] The result +# +# false: +# * if output does not have size +# true: +# * if output has size +# +# @example Use matcher +# +# RSpec.describe do +# it { expect(file1).to have_output_size(256) } +# end +RSpec::Matchers.define :have_output_size do |expected| + match do |actual| + next false unless actual.respond_to? :size + + @actual = actual.size + values_match? expected, @actual + end + + description { "output has size #{description_of expected}" } +end diff --git a/lib/aruba/matchers/file/have_file_size.rb b/lib/aruba/matchers/file/have_file_size.rb index 7ecb3edb3..f1c5e6d08 100644 --- a/lib/aruba/matchers/file/have_file_size.rb +++ b/lib/aruba/matchers/file/have_file_size.rb @@ -27,7 +27,7 @@ next false unless file?(actual) @old_actual = actual - @actual = File.size(expand_path(actual)) + @actual = file_size(actual) @expected = expected.to_i values_match?(@expected, @actual) diff --git a/spec/aruba/matchers/command/have_output_size_spec.rb b/spec/aruba/matchers/command/have_output_size_spec.rb new file mode 100644 index 000000000..638a8224a --- /dev/null +++ b/spec/aruba/matchers/command/have_output_size_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +RSpec.describe 'Output Matchers' do + include_context 'uses aruba API' + + def expand_path(*args) + @aruba.expand_path(*args) + end + + describe '#to_have_output_size' do + let(:obj) { 'string' } + + context 'when has size' do + context 'when is string' do + it { expect(obj).to have_output_size 6 } + end + end + + context 'when does not have size' do + let(:obj) { 'string' } + + it { expect(obj).not_to have_output_size(-1) } + end + end +end diff --git a/spec/aruba/matchers/command_spec.rb b/spec/aruba/matchers/command_spec.rb index 78400e50e..9accfadde 100644 --- a/spec/aruba/matchers/command_spec.rb +++ b/spec/aruba/matchers/command_spec.rb @@ -40,4 +40,129 @@ def announcer(*args) it { expect(last_command).not_to be_successfully_executed } end end + + describe '#to_have_output' do + let(:cmd) { "echo #{output}" } + let(:output) { 'hello world' } + + context 'when have output hello world on stdout' do + before(:each) { run(cmd) } + it { expect(last_command).to have_output output } + end + + context 'when multiple commands output hello world on stdout' do + context 'and all comands must have the output' do + before(:each) do + run(cmd) + run(cmd) + end + + it { expect(all_commands).to all have_output output } + end + + context 'and any comand can have the output' do + before(:each) do + run(cmd) + run('echo hello universe') + end + + it { expect(all_commands).to include have_output(output) } + end + end + + context 'when have output hello world on stderr' do + before :each do + File.write expand_path('cmd.sh'), <<-EOS.strip_heredoc + #!/usr/bin/env bash + + echo $* >&2 + EOS + + File.chmod 0755, expand_path('cmd.sh') + prepend_environment_variable 'PATH', "#{expand_path('.')}:" + end + + let(:cmd) { "cmd.sh #{output}" } + + before(:each) { run(cmd) } + + it { expect(last_command).to have_output output } + end + + context 'when not has output' do + before(:each) { run(cmd) } + + it { expect(last_command).not_to have_output 'hello universe' } + end + end + + describe '#to_have_output_on_stdout' do + let(:cmd) { "echo #{output}" } + let(:output) { 'hello world' } + + context 'when have output hello world on stdout' do + before(:each) { run(cmd) } + it { expect(last_command).to have_output_on_stdout output } + end + + context 'when have output hello world on stderr' do + before :each do + File.write expand_path('cmd.sh'), <<-EOS.strip_heredoc + #!/usr/bin/env bash + + echo $* >&2 + EOS + + File.chmod 0755, expand_path('cmd.sh') + prepend_environment_variable 'PATH', "#{expand_path('.')}:" + end + + let(:cmd) { "cmd.sh #{output}" } + + before(:each) { run(cmd) } + + it { expect(last_command).not_to have_output_on_stdout output } + end + + context 'when not has output' do + before(:each) { run(cmd) } + + it { expect(last_command).not_to have_output_on_stdout 'hello universe' } + end + end + + describe '#to_have_output_on_stderr' do + let(:cmd) { "echo #{output}" } + let(:output) { 'hello world' } + + context 'when have output hello world on stdout' do + before(:each) { run(cmd) } + it { expect(last_command).not_to have_output_on_stderr output } + end + + context 'when have output hello world on stderr' do + before :each do + File.write expand_path('cmd.sh'), <<-EOS.strip_heredoc + #!/usr/bin/env bash + + echo $* >&2 + EOS + + File.chmod 0755, expand_path('cmd.sh') + prepend_environment_variable 'PATH', "#{expand_path('.')}:" + end + + let(:cmd) { "cmd.sh #{output}" } + + before(:each) { run(cmd) } + + it { expect(last_command).to have_output_on_stderr output } + end + + context 'when not has output' do + before(:each) { run(cmd) } + + it { expect(last_command).not_to have_output_on_stderr 'hello universe' } + end + end end From da49c59477901c5d26e4c7d38b11afb6c5def485 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:12:21 +0200 Subject: [PATCH 004/118] Improve existing specs --- .../aruba/api/environment/restore_env_spec.rb | 65 +++++++++++++++++++ spec/aruba/api/environment/set_env_spec.rb | 42 ++++++++++++ spec/aruba/api_spec.rb | 2 + 3 files changed, 109 insertions(+) create mode 100644 spec/aruba/api/environment/restore_env_spec.rb create mode 100644 spec/aruba/api/environment/set_env_spec.rb diff --git a/spec/aruba/api/environment/restore_env_spec.rb b/spec/aruba/api/environment/restore_env_spec.rb new file mode 100644 index 000000000..de40b8763 --- /dev/null +++ b/spec/aruba/api/environment/restore_env_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +RSpec.describe 'Command Environment' do + include_context 'uses aruba API' + + around do |example| + old_env = ENV.to_h + example.run + ENV.update(old_env) + end + + describe '#restore_env' do + context 'when non-existing variable' do + before :each do + ENV.delete 'LONG_LONG_ENV_VARIABLE' + end + + context 'when set single' do + before :each do + @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '1' + @aruba.restore_env + end + + it { expect(ENV).not_to be_key 'LONG_LONG_ENV_VARIABLE' } + end + + context 'when set multiple times' do + before :each do + @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '1' + @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '2' + @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '3' + @aruba.restore_env + end + + it { expect(ENV).not_to be_key 'LONG_LONG_ENV_VARIABLE' } + end + end + + context 'when existing variable from outer context' do + before :each do + ENV['LONG_LONG_ENV_VARIABLE'] = '0' + end + + context 'when set single time' do + before :each do + @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '1' + @aruba.restore_env + end + + it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '0' } + end + + context 'when set multiple times' do + before :each do + @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '1' + @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '2' + @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '3' + @aruba.restore_env + end + + it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '0' } + end + end + end +end diff --git a/spec/aruba/api/environment/set_env_spec.rb b/spec/aruba/api/environment/set_env_spec.rb new file mode 100644 index 000000000..af2e5e914 --- /dev/null +++ b/spec/aruba/api/environment/set_env_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +RSpec.describe 'Command Environment' do + include_context 'uses aruba API' + + around do |example| + old_env = ENV.to_h + example.run + ENV.update(old_env) + end + + describe '#set_env' do + context 'when non-existing variable' do + before :each do + ENV.delete('LONG_LONG_ENV_VARIABLE') + end + + context 'when string' do + before :each do + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1' + end + + it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '1' } + end + end + + context 'when existing variable set by aruba' do + before :each do + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1' + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2' + end + + it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '2' } + end + + context 'when existing variable by outer context' do + before :each do + ENV['LONG_LONG_ENV_VARIABLE'] = '1' + end + end + end +end diff --git a/spec/aruba/api_spec.rb b/spec/aruba/api_spec.rb index 133f08847..08b5d03fd 100644 --- a/spec/aruba/api_spec.rb +++ b/spec/aruba/api_spec.rb @@ -1197,11 +1197,13 @@ def root_directory @aruba.stop_processes! @aruba.restore_env end + it "set environment variable" do @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true' @aruba.run "env" expect(@aruba.all_output).to include("LONG_LONG_ENV_VARIABLE=true") end + it "overwrites environment variable" do @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true' @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'false' From 8cc322bba16db610360426f5e230c649b2758dc0 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:14:37 +0200 Subject: [PATCH 005/118] Move disk usage to separate class --- lib/aruba/api/filesystem.rb | 14 +++++--------- lib/aruba/platform/determine_disk_usage.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 lib/aruba/platform/determine_disk_usage.rb diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index bd3e6765f..a7231524e 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -4,7 +4,8 @@ require 'aruba/platforms/aruba_file_creator' require 'aruba/platforms/aruba_fixed_size_file_creator' -require 'aruba/disk_usage_calculator' +require 'aruba/platform/determine_disk_usage' + require 'aruba/aruba_path' Aruba.platform.require_matching_files('../matchers/file/*.rb', __FILE__) @@ -316,14 +317,9 @@ def with_file_content(file, &block) # @result [FileSize] # Bytes on disk def disk_usage(*paths) - size = paths.flatten.map do |p| - DiskUsageCalculator.new.calc( - ArubaPath.new(expand_path(p)).blocks, - aruba.config.physical_block_size - ) - end.inject(0, &:+) - - FileSize.new(size) + expect(paths).to all be_an_existing_path + + DetermineDiskUsage.new.use paths.flatten.map { |p| ArubaPath.new(expand_path(p)) } end end end diff --git a/lib/aruba/platform/determine_disk_usage.rb b/lib/aruba/platform/determine_disk_usage.rb new file mode 100644 index 000000000..7aa979d3a --- /dev/null +++ b/lib/aruba/platform/determine_disk_usage.rb @@ -0,0 +1,16 @@ +module Aruba + module Platform + class DetermineDiskUsage + def use(paths) + size = paths.map do |p| + DiskUsageCalculator.new.calc( + p.blocks, + aruba.config.physical_block_size + ) + end.inject(0, &:+) + + FileSize.new(size) + end + end + end +end From 8e470bdc13a5eee7f48e459924a6eb4851357006 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:17:09 +0200 Subject: [PATCH 006/118] Determine file size of a given file --- lib/aruba/api/filesystem.rb | 13 +++++++++- lib/aruba/platform/determine_file_size.rb | 13 ++++++++++ spec/aruba/api/filesystem/file_size_spec.rb | 28 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 lib/aruba/platform/determine_file_size.rb create mode 100644 spec/aruba/api/filesystem/file_size_spec.rb diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index a7231524e..167c718a1 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -5,6 +5,7 @@ require 'aruba/platforms/aruba_file_creator' require 'aruba/platforms/aruba_fixed_size_file_creator' require 'aruba/platform/determine_disk_usage' +require 'aruba/platform/determine_file_size' require 'aruba/aruba_path' @@ -318,9 +319,19 @@ def with_file_content(file, &block) # Bytes on disk def disk_usage(*paths) expect(paths).to all be_an_existing_path - + DetermineDiskUsage.new.use paths.flatten.map { |p| ArubaPath.new(expand_path(p)) } end + + # Get size of file + # + # @return [Numeric] + # The size of the file + def file_size(name) + expect(name).to be_an_existing_file + + DetermineFileSize.new.use expand_path(name) + end end end end diff --git a/lib/aruba/platform/determine_file_size.rb b/lib/aruba/platform/determine_file_size.rb new file mode 100644 index 000000000..ea63f4c62 --- /dev/null +++ b/lib/aruba/platform/determine_file_size.rb @@ -0,0 +1,13 @@ +module Aruba + module Platform + class DetermineFileSize + def use(path) + return -1 unless File.file? path + + FileSize.new( + File.size(path) + ) + end + end + end +end diff --git a/spec/aruba/api/filesystem/file_size_spec.rb b/spec/aruba/api/filesystem/file_size_spec.rb new file mode 100644 index 000000000..ea64e0d3f --- /dev/null +++ b/spec/aruba/api/filesystem/file_size_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +RSpec.describe 'Filesystem Api' do + include_context 'uses aruba API' + + def expand_path(*args) + @aruba.expand_path(*args) + end + + describe '#file_size' do + let(:name) { @file_name } + let(:path) { @file_path } + let(:size) { file_size(name) } + + context 'when file exist' do + before :each do + File.write(path, 'a') + end + + it { expect(size).to eq 1 } + end + + context 'when file does not exist' do + let(:name) { 'non_existing_file' } + it { expect { size }.to raise_error } + end + end +end From 0d57780a805378b282140b190854f651b9595b83 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:17:22 +0200 Subject: [PATCH 007/118] Added tasks to TODO file --- TODO.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index cec9a4b18..15f6afa1e 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,8 @@ - * Replace check filesystem permissons through a better rspec matcher * Improve documentation for matchers in file +* Cleanup stdout/stderr in spawn process: + It should be enough to use 'open(@process.io.stdout).read' and 'open(@process.io.stderr).read'. There's no need to rewind them. +* Ensure that all processes are kill after cucumber is finished +* Add variation of check and stop of command if output contains + Add something like `(?: of last command)?`. If this is true, just check the last command. +* Use aruba.config.exit_timeout everywhere From 425c29eba09a7cffb095ba1fb7ec3eb4ea113a6d Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:17:57 +0200 Subject: [PATCH 008/118] Ignore flagged features --- cucumber.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cucumber.yml b/cucumber.yml index 49bad1838..b27d69acc 100644 --- a/cucumber.yml +++ b/cucumber.yml @@ -2,7 +2,7 @@ require 'ffi' java_version = (RUBY_DESCRIPTION.match(/.*?on.*?(1\.[\d]\..*? )/))[1] if defined?(JRUBY_VERSION) -std_opts = "--color --exclude features/fixtures --require features" +std_opts = "--color --exclude features/fixtures --require features --tags ~@ignore" java_default_opts = "--tags ~@wip-jruby-java-1.6" if defined?(JRUBY_VERSION) && (java_version < '1.7.0') java_wip_opts = "--tags @wip-jruby-java-1.6:3" if defined?(JRUBY_VERSION) && (java_version < '1.7.0') From 3fd848056654e643707531a90992005d4a853f2f Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:19:38 +0200 Subject: [PATCH 009/118] Improve announcer --- lib/aruba/announcer.rb | 10 +++++++--- lib/aruba/api/core.rb | 3 +++ lib/aruba/cucumber/hooks.rb | 5 +++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/aruba/announcer.rb b/lib/aruba/announcer.rb index 59c630aca..f1ad0307d 100644 --- a/lib/aruba/announcer.rb +++ b/lib/aruba/announcer.rb @@ -1,3 +1,5 @@ +require 'shellwords' + module Aruba # Announcer # @@ -78,10 +80,12 @@ def initialize(_, options) def after_init output_format :directory, '$ cd %s' output_format :command, '$ %s' - output_format :environment, '$ export %s=%s"' - output_format :modified_environment, '$ export %s=%s"' - output_format :full_environment, proc { |h| Aruba.platform.simple_table(h) } + output_format :environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) } + output_format :modified_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) } + output_format :full_environment, proc { |h| Aruba::Platform.simple_table(h) } output_format :timeout, '# %s-timeout: %s seconds' + output_format :stderr, "<<-STDERR\n%s\nSTDERR" + output_format :stdout, "<<-STDOUT\n%s\nSTDOUT" # rubocop:disable Metrics/LineLength if @options[:stdout] diff --git a/lib/aruba/api/core.rb b/lib/aruba/api/core.rb index 285b16fab..d998cf3b2 100644 --- a/lib/aruba/api/core.rb +++ b/lib/aruba/api/core.rb @@ -53,6 +53,8 @@ def cd(dir, &block) fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory? expand_path(dir) aruba.current_directory << dir + announcer.announce :directory, expand_path(dir) + old_dir = Aruba.platform.getwd old_oldpwd = ENV['OLDPWD'] @@ -77,6 +79,7 @@ def cd(dir, &block) fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory? expand_path(dir) aruba.current_directory << dir + announcer.announce :directory, expand_path(dir) self end diff --git a/lib/aruba/cucumber/hooks.rb b/lib/aruba/cucumber/hooks.rb index 1838ea7ab..9d0aaf447 100644 --- a/lib/aruba/cucumber/hooks.rb +++ b/lib/aruba/cucumber/hooks.rb @@ -52,6 +52,11 @@ announcer.activate :command end +Before('@announce-output') do + announcer.activate :stdout + announcer.activate :stderr +end + Before('@announce-stdout') do announcer.activate :stdout end From c1d247c20e62990951d3ee04aa9d752a9337d5dd Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:21:04 +0200 Subject: [PATCH 010/118] Added method to return all commands --- lib/aruba/api/command.rb | 8 ++++++++ lib/aruba/process_monitor.rb | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/aruba/api/command.rb b/lib/aruba/api/command.rb index d32402ab2..37fedc19c 100644 --- a/lib/aruba/api/command.rb +++ b/lib/aruba/api/command.rb @@ -75,6 +75,14 @@ def output_from(cmd) process_monitor.output_from(cmd) end + # Return all commands + # + # @return [Array] + # List of commands + def all_commands + process_monitor.all_commands + end + # Fetch stdout from command # # @param [String] cmd diff --git a/lib/aruba/process_monitor.rb b/lib/aruba/process_monitor.rb index dd502b205..02588ff9a 100644 --- a/lib/aruba/process_monitor.rb +++ b/lib/aruba/process_monitor.rb @@ -124,6 +124,15 @@ def all_output all_stdout << all_stderr end + # Return all commands + # + # @return [Array] + # A list of all commands + def all_commands + processes.collect{ |_, process| process } + end + + # Clear list of processes def clear processes.clear end From 05784e426254066de992eb9c7f9e7fcec6b7ffc6 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:23:45 +0200 Subject: [PATCH 011/118] Remove first assert methods from cucumber api --- lib/aruba/cucumber.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index 67dda50c2..8a5a608b0 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -188,12 +188,17 @@ end end +Then /^the output should be (\d+) bytes long$/ do |size| + expect(all_output).to have_output_size size.to_i +end + Then /^the output should contain "([^"]*)"$/ do |expected| - assert_partial_output(expected, all_output) + expect(all_commands).to include have_content(Regexp.new(Aruba::Utils.unescape(expected))) end Then /^the output from "([^"]*)" should contain "([^"]*)"$/ do |cmd, expected| assert_partial_output(expected, output_from(cmd)) + expect(all_commands).to include have_content(Regexp.new(Aruba::Utils.unescape(expected))) end Then /^the output from "([^"]*)" should not contain "([^"]*)"$/ do |cmd, unexpected| @@ -204,12 +209,12 @@ assert_no_partial_output(unexpected, all_output) end -Then /^the output should contain:$/ do |expected| - assert_partial_output(expected, all_output) -end - -Then /^the output should not contain:$/ do |unexpected| - assert_no_partial_output(unexpected, all_output) +Then /^the output should( not)? contain:$/ do |fail, string| + if fail + expect(all_output).not_to include(string) + else + expect(all_output).to include(string) + end end ## the output should contain exactly "output" From 544ac7c32d4f26fae9bdc4def42d2e420d4503b0 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:24:05 +0200 Subject: [PATCH 012/118] Return self after clearance --- lib/aruba/process_monitor.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/aruba/process_monitor.rb b/lib/aruba/process_monitor.rb index 02588ff9a..cfc5e5364 100644 --- a/lib/aruba/process_monitor.rb +++ b/lib/aruba/process_monitor.rb @@ -135,6 +135,8 @@ def all_commands # Clear list of processes def clear processes.clear + + self end end end From cdbee618ece20ec119ddc18210e778eded3c53aa Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:24:45 +0200 Subject: [PATCH 013/118] Starting a command is not a suprising action, no need to use ! here --- lib/aruba/processes/basic_process.rb | 8 ++++++++ lib/aruba/processes/debug_process.rb | 10 +++++++++- lib/aruba/processes/spawn_process.rb | 14 +++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index 3a50e301d..8028a2d67 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -54,6 +54,14 @@ def timed_out? @timed_out == true end + # @deprecated + # @private + def run! + Aruba::Platform.deprecated('The use of "command#run!" is deprecated. You can simply use "command#start" instead.') + + start + end + # Hook which is run before command is run def before_run; end diff --git a/lib/aruba/processes/debug_process.rb b/lib/aruba/processes/debug_process.rb index da9b18362..71900e231 100644 --- a/lib/aruba/processes/debug_process.rb +++ b/lib/aruba/processes/debug_process.rb @@ -9,9 +9,17 @@ def self.match?(mode) mode == :debug || (mode.is_a?(Class) && mode <= DebugProcess) end + # @deprecated + # @private + def run! + Aruba::Platform.deprecated('The use of "command#run!" is deprecated. You can simply use "command#start" instead.') + + start + end + # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/CyclomaticComplexity - def run! + def start # rubocop:disable Metrics/LineLength fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) unless which(command) # rubocop:enable Metrics/LineLength diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 027dbacf2..683ae6daa 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -37,6 +37,14 @@ def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV. @error_cache = nil end + # @deprecated + # @private + def run! + Aruba::Platform.deprecated('The use of "command#run!" is deprecated. You can simply use "command#start" instead.') + + start + end + # Run the command # # @yield [SpawnProcess] @@ -44,7 +52,7 @@ def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV. # # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/CyclomaticComplexity - def run! + def start # gather fully qualified path cmd = which(command) # rubocop:disable Metrics/LineLength @@ -105,11 +113,15 @@ def read_stdout end def write(input) + return if @process.nil? + @process.io.stdin.write(input) @process.io.stdin.flush end def close_io(name) + return if @process.nil? + if RUBY_VERSION < '1.9' @process.io.send(name.to_sym).close else From 3318deea6e018c261ab1ec7a80de47553b389866 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:33:26 +0200 Subject: [PATCH 014/118] Improve handling of io --- lib/aruba/processes/spawn_process.rb | 40 +++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 683ae6daa..57b234318 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -90,25 +90,38 @@ def start # rubocop:enable Metrics/CyclomaticComplexity def stdin + return if @process.nil? + @process.io.stdin end - def stdout - wait_for_io do + def stdout(opts = {}) + return @output_cache if @process.nil? + + wait_for_io = opts.fetch(:wait_for_io, @io_wait) + + wait_for_io wait_for_io do @process.io.stdout.flush - read(@out) - end || @output_cache + open(@err).read + end end - def stderr - wait_for_io do + def stderr(opts = {}) + return @error_cache if @process.nil? + + wait_for_io = opts.fetch(:wait_for_io, @io_wait) + + wait_for_io wait_for_io do @process.io.stderr.flush - read(@err) - end || @error_cache + open(@err).read + end end def read_stdout - warn('The use of "#read_stdout" is deprecated. Use "#stdout" instead.') + # rubocop:disable Metrics/LineLength + Aruba::Platform.deprecated('The use of "#read_stdout" is deprecated. Use "#stdout" instead. To reduce the time to wait for io, pass `:wait_for_io => 0` or some suitable for your use case') + # rubocop:enable Metrics/LineLength + stdout end @@ -117,6 +130,8 @@ def write(input) @process.io.stdin.write(input) @process.io.stdin.flush + + self end def close_io(name) @@ -164,10 +179,11 @@ def terminate private - def wait_for_io(&block) - return unless @process + def wait_for_io(time_to_wait, &block) + return if @process.nil? + + sleep time_to_wait - sleep @io_wait yield end From e899c855f5b451be232c16f221f1e8358075636a Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 19:05:26 +0200 Subject: [PATCH 015/118] Better name for last_command --- lib/aruba/api/command.rb | 11 ++++++++--- lib/aruba/api/deprecated.rb | 7 +++++++ lib/aruba/process_monitor.rb | 15 ++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/aruba/api/command.rb b/lib/aruba/api/command.rb index 37fedc19c..1ed0fd2d9 100644 --- a/lib/aruba/api/command.rb +++ b/lib/aruba/api/command.rb @@ -293,9 +293,14 @@ def terminate_processes! process_monitor.terminate_processes! end - # @private - def last_command - processes.last[1] + # Last command started + def last_command_started + process_monitor.last_command_started + end + + # Last command stopped + def last_command_stopped + process_monitor.last_command_stopped end # @private diff --git a/lib/aruba/api/deprecated.rb b/lib/aruba/api/deprecated.rb index b307347dc..045bd86d9 100644 --- a/lib/aruba/api/deprecated.rb +++ b/lib/aruba/api/deprecated.rb @@ -531,6 +531,13 @@ def check_for_deprecated_variables end # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/MethodLength + + # Last command started + def last_command + Aruba::Platform.deprecated('The use of "#last_command" is deprecated. Use "#last_command_started"') + + process_monitor.last_command + end end end end diff --git a/lib/aruba/process_monitor.rb b/lib/aruba/process_monitor.rb index cfc5e5364..92a991374 100644 --- a/lib/aruba/process_monitor.rb +++ b/lib/aruba/process_monitor.rb @@ -17,8 +17,21 @@ def last_exit_status @last_exit_status end + def last_command_stopped + return @last_command_stopped if @last_command_stopped + + stop_processes! + + @last_command_stopped + end + + def last_command_started + processes.last[1] + end + def stop_process(process) - @last_exit_status = process.stop(announcer) + @last_command_stopped = process + @last_exit_status = process.stop(announcer) end def terminate_process!(process) From 4b14cc67553b200527bbd5b6e1a13908fd72774c Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 19:05:55 +0200 Subject: [PATCH 016/118] Some minor improvements --- lib/aruba/api/core.rb | 1 - lib/aruba/matchers/command/have_output.rb | 5 ++++- lib/aruba/matchers/command/have_output_on_stdout.rb | 1 - spec/aruba/matchers/command_spec.rb | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/aruba/api/core.rb b/lib/aruba/api/core.rb index d998cf3b2..492a2ea49 100644 --- a/lib/aruba/api/core.rb +++ b/lib/aruba/api/core.rb @@ -55,7 +55,6 @@ def cd(dir, &block) aruba.current_directory << dir announcer.announce :directory, expand_path(dir) - old_dir = Aruba.platform.getwd old_oldpwd = ENV['OLDPWD'] old_pwd = ENV['PWD'] diff --git a/lib/aruba/matchers/command/have_output.rb b/lib/aruba/matchers/command/have_output.rb index d966f4076..4709b30f0 100644 --- a/lib/aruba/matchers/command/have_output.rb +++ b/lib/aruba/matchers/command/have_output.rb @@ -18,7 +18,7 @@ next false unless actual.respond_to? :output @old_actual = actual - @actual = actual.output.chomp + @actual = Aruba::Platform.unescape(actual.output.chomp, aruba.config.keep_ansi) values_match?(expected, @actual) end @@ -28,3 +28,6 @@ description { "have output: #{description_of expected}" } end +if RSpec::Expectations::Version::STRING >= '3.0' + RSpec::Matchers.alias_matcher :a_command_having_output, :have_output +end diff --git a/lib/aruba/matchers/command/have_output_on_stdout.rb b/lib/aruba/matchers/command/have_output_on_stdout.rb index 9922908b1..75f638f45 100644 --- a/lib/aruba/matchers/command/have_output_on_stdout.rb +++ b/lib/aruba/matchers/command/have_output_on_stdout.rb @@ -27,4 +27,3 @@ description { "have output on stdout: #{description_of expected}" } end - diff --git a/spec/aruba/matchers/command_spec.rb b/spec/aruba/matchers/command_spec.rb index 9accfadde..24d6161c5 100644 --- a/spec/aruba/matchers/command_spec.rb +++ b/spec/aruba/matchers/command_spec.rb @@ -109,7 +109,7 @@ def announcer(*args) before :each do File.write expand_path('cmd.sh'), <<-EOS.strip_heredoc #!/usr/bin/env bash - + echo $* >&2 EOS From 85cae625a58480b008f7376a1b65f33ad25e1465 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sun, 19 Jul 2015 18:21:54 +0200 Subject: [PATCH 017/118] Added some new steps to for cucumber --- lib/aruba/cucumber.rb | 201 +++++++++++++++++++++++++++++++++--------- lib/aruba/rspec.rb | 1 - 2 files changed, 157 insertions(+), 45 deletions(-) diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index 8a5a608b0..229deac90 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -43,6 +43,14 @@ write_file(file_name, file_content) end +Given /^(?:an|the) executable(?: named)? "([^"]*)" with:$/ do |file_name, file_content| + step %(a file named "#{file_name}" with mode "0755" and with:), file_content +end + +Given /^(?:a|the) file(?: named)? "([^"]*)" with "([^"]*)"$/ do |file_name, file_content| + write_file(file_name, file_content) +end + Given /^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/ do |file_name, file_mode, file_content| write_file(file_name, file_content) chmod(file_mode, file_name) @@ -101,7 +109,7 @@ cd(dir) end -Given /^I set the environment variables to:/ do |table| +Given /^I set the environment variables? to:/ do |table| table.hashes.each do |row| variable = row['variable'].to_s.upcase value = row['value'].to_s @@ -110,7 +118,7 @@ end end -Given /^I append the value to the environment variable:/ do |table| +Given /^I append the values? to the environment variables?:/ do |table| table.hashes.each do |row| variable = row['variable'].to_s.upcase value = row['value'].to_s @@ -119,6 +127,15 @@ end end +Given /^I prepend the values? to the environment variables?:/ do |table| + table.hashes.each do |row| + variable = row['variable'].to_s.upcase + value = row['value'].to_s + + prepend_environment_variable(variable, value) + end +end + When /^I run "(.*)"$/ do |cmd| warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) @@ -179,11 +196,52 @@ close_input end +When /^I stop the last command if (?:output|stdout) contains:$/ do |expected| + begin + Timeout.timeout(exit_timeout) do + loop do + if Aruba::Utils.unescape(last_command.output).include? Aruba::Utils.unescape(expected) + last_command.terminate + break + end + + sleep 0.1 + end + end + rescue ChildProcess::TimeoutError, TimeoutError + last_command.terminate + ensure + announcer.stdout last_command.stdout + announcer.stderr last_command.stderr + end +end + +When /^I wait for (?:output|stdout) to contain:$/ do |expected| + Timeout.timeout(exit_timeout) do + loop do + begin + expect(last_command).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) + rescue ExpectationError + sleep 0.1 + retry + end + + break + end + end +end + When /^I wait for (?:output|stdout) to contain "([^"]*)"$/ do |expected| Timeout.timeout(exit_timeout) do loop do - break if assert_partial_output_interactive(expected) - sleep 0.1 + begin + expect(last_command).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) + rescue ExpectationError + sleep 0.1 + retry + end + + break end end end @@ -193,86 +251,141 @@ end Then /^the output should contain "([^"]*)"$/ do |expected| - expect(all_commands).to include have_content(Regexp.new(Aruba::Utils.unescape(expected))) + expect(all_commands).to include have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) end -Then /^the output from "([^"]*)" should contain "([^"]*)"$/ do |cmd, expected| - assert_partial_output(expected, output_from(cmd)) - expect(all_commands).to include have_content(Regexp.new(Aruba::Utils.unescape(expected))) -end +Then /^the output from "([^"]*)" should( not)? contain "([^"]*)"$/ do |cmd, negated, expected| + command = process_monitor.get_process(Platform.detect_ruby(cmd)) -Then /^the output from "([^"]*)" should not contain "([^"]*)"$/ do |cmd, unexpected| - assert_no_partial_output(unexpected, output_from(cmd)) + if negated + expect(command).not_to have_output Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + else + expect(command).to have_output Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + end end -Then /^the output should not contain "([^"]*)"$/ do |unexpected| - assert_no_partial_output(unexpected, all_output) +Then /^the output should( not)? contain "([^"]*)"$/ do |negated, expected| + if negated + expect(all_commands).not_to include have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + else + expect(all_commands).to include have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + end end -Then /^the output should( not)? contain:$/ do |fail, string| - if fail - expect(all_output).not_to include(string) +Then /^the output should( not)? contain:$/ do |negated, expected| + if negated + expect(all_commands).not_to include have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) else - expect(all_output).to include(string) + expect(all_commands).to include have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) end end ## the output should contain exactly "output" ## the output from `echo -n "Hello"` should contain exactly "Hello" -Then /^the output(?: from "(.*?)")? should contain exactly "(.*?)"$/ do |cmd, expected| - assert_exact_output(expected, cmd ? output_from(cmd) : all_output) +Then /^the output(?: from "(.*?)")? should( not)? contain exactly "(.*?)"$/ do |cmd, negated, expected| + commands = if cmd + [process_monitor.get_process(Platform.detect_ruby(cmd))] + else + all_commands + end + + if negated + expect(commands).not_to have_output Aruba::Utils.unescape(expected) + else + expect(commands).to have_output Aruba::Utils.unescape(expected) + end end ## the output should contain exactly: ## the output from `echo -n "Hello"` should contain exactly: -Then /^the output(?: from "(.*?)")? should contain exactly:$/ do |cmd, expected| - assert_exact_output(expected, cmd ? output_from(cmd) : all_output) +Then /^the output(?: from "(.*?)")? should( not)? contain exactly:$/ do |cmd, negated, expected| + commands = if cmd + [process_monitor.get_process(Platform.detect_ruby(cmd))] + else + all_commands + end + + if negated + expect(commands).not_to have_output Aruba::Utils.unescape(expected) + else + expect(commands).to have_output Aruba::Utils.unescape(expected) + end end # "the output should match" allows regex in the partial_output, if # you don't need regex, use "the output should contain" instead since # that way, you don't have to escape regex characters that # appear naturally in the output -Then /^the output should match \/([^\/]*)\/$/ do |expected| - assert_matching_output(expected, all_output) -end - -Then /^the output should match %r<([^>]*)>$/ do |expected| - assert_matching_output(expected, all_output) -end - -Then /^the output should match:$/ do |expected| - assert_matching_output(expected, all_output) +Then /^the output should( not)? match \/([^\/]*)\/$/ do |negated, expected| + if negated + expect(all_commands).not_to include have_output Regexp.new(expected) + else + expect(all_commands).to include have_output Regexp.new(expected) + end end -# The previous two steps antagonists -Then /^the output should not match \/([^\/]*)\/$/ do |expected| - assert_not_matching_output(expected, all_output) +Then /^the output should( not)? match %r<([^>]*)>$/ do |negated, expected| + if negated + expect(all_commands).not_to include have_output Regexp.new(expected) + else + expect(all_commands).to include have_output Regexp.new(expected) + end end -Then /^the output should not match:$/ do |expected| - assert_not_matching_output(expected, all_output) +Then /^the output should( not)? match:$/ do |negated, expected| + if negated + expect(all_commands).not_to include have_output Regexp.new(expected) + else + expect(all_commands).to include have_output Regexp.new(expected) + end end -Then /^the exit (?:status|code) should be (\d+)$/ do |exit_status| - assert_exit_status(exit_status.to_i) +Then /^the exit (?:status|code) should( not)? be (\d+)$/ do |negated, exit_status| + if negated + expect(last_command_stopped).not_to have_exit_status exit_status.to_i + else + expect(last_command_stopped).to have_exit_status exit_status.to_i + end end -Then /^the exit (?:status|code) not be (\d+)$/ do |exit_status| - assert_not_exit_status(exit_status.to_i) +Then /^it should (pass|fail) with "(.*?)"$/ do |pass_fail, partial_output| + if pass_fail == 'pass' + expect(last_command_stopped).to be_successfully_executed + expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + else + expect(last_command_stopped).not_to be_successfully_executed + expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + end end Then /^it should (pass|fail) with:$/ do |pass_fail, partial_output| - self.__send__("assert_#{pass_fail}ing_with", partial_output) + if pass_fail == 'pass' + expect(last_command_stopped).to be_successfully_executed + expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + else + expect(last_command_stopped).not_to be_successfully_executed + expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + end end Then /^it should (pass|fail) with exactly:$/ do |pass_fail, exact_output| - assert_exit_status_and_output(pass_fail == "pass", exact_output, true) + if pass_fail == 'pass' + expect(last_command_stopped).to be_successfully_executed + expect(last_command_stopped).to have_content Aruba::Utils.unescape(expected) + else + expect(last_command_stopped).not_to be_successfully_executed + expect(last_command_stopped).to have_content Aruba::Utils.unescape(expected) + end end Then /^it should (pass|fail) with regexp?:$/ do |pass_fail, expected| - assert_matching_output(expected, all_output) - assert_success(pass_fail == 'pass') + if pass_fail == 'pass' + expect(last_command_stopped).to be_successfully_executed + expect(last_command_stopped).to have_content Regexp.new(expected) + else + expect(last_command_stopped).not_to be_successfully_executed + expect(last_command_stopped).to have_content Regexp.new(expected) + end end ## the stderr should contain "hello" diff --git a/lib/aruba/rspec.rb b/lib/aruba/rspec.rb index 550d093b5..3d068fe24 100644 --- a/lib/aruba/rspec.rb +++ b/lib/aruba/rspec.rb @@ -35,7 +35,6 @@ end end - # Use rspec metadata as option for aruba config.before :each do |example| next unless self.class.include? Aruba::Api From d7b48a4cf489fb59b23addadf9f99ca33051c369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 09:12:33 +0200 Subject: [PATCH 018/118] Use new name for last_command everywhere --- features/api/command/run.feature | 2 +- .../append_environment_variable.feature | 6 ++-- .../prepend_environment_variable.feature | 6 ++-- .../set_environment_variable.feature | 14 +++++----- features/api/filesystem/cd.feature | 8 +++--- features/hooks/after/command.feature | 2 +- features/hooks/before/command.feature | 4 +-- features/matchers/timeouts.feature | 4 +-- features/step_definitions/aruba_dev_steps.rb | 2 +- lib/aruba/api/command.rb | 14 +++++----- lib/aruba/api/deprecated.rb | 10 +++---- lib/aruba/cucumber.rb | 14 +++++----- .../command/be_successfully_executed.rb | 6 ++-- .../matchers/command/have_exit_status.rb | 2 +- .../matchers/command/have_finished_in_time.rb | 6 ++-- lib/aruba/matchers/command/have_output.rb | 2 +- .../matchers/command/have_output_on_stderr.rb | 2 +- .../matchers/command/have_output_on_stdout.rb | 2 +- spec/aruba/matchers/command_spec.rb | 28 +++++++++---------- 19 files changed, 67 insertions(+), 67 deletions(-) diff --git a/features/api/command/run.feature b/features/api/command/run.feature index 7f11bd2c5..f4d1c2b4b 100644 --- a/features/api/command/run.feature +++ b/features/api/command/run.feature @@ -17,7 +17,7 @@ Feature: Run command RSpec.describe 'Run command', :type => :aruba do before(:each) { run('cli') } - it { expect(last_command).to be_successfully_executed } + it { expect(last_command_started).to be_successfully_executed } end """ When I run `rspec` diff --git a/features/api/environment/append_environment_variable.feature b/features/api/environment/append_environment_variable.feature index 8ba4cd76f..3658ca4f0 100644 --- a/features/api/environment/append_environment_variable.feature +++ b/features/api/environment/append_environment_variable.feature @@ -22,7 +22,7 @@ Feature: Append environment variable before(:each) { append_environment_variable 'LONG_LONG_VARIABLE', 'a' } before(:each) { run('env') } - it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=a' } + it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=a' } end """ When I run `rspec` @@ -38,7 +38,7 @@ Feature: Append environment variable before(:each) { append_environment_variable 'LONG_LONG_VARIABLE', 'b' } before(:each) { run('env') } - it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=ab' } + it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=ab' } end """ When I run `rspec` @@ -56,7 +56,7 @@ Feature: Append environment variable before(:each) { append_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' } before(:each) { run('env') } - it { expect(last_command.output).to include 'REALLY_LONG_LONG_VARIABLE=ab' } + it { expect(last_command_started.output).to include 'REALLY_LONG_LONG_VARIABLE=ab' } # Has no effect here, is not in block and not a command `run` it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' } diff --git a/features/api/environment/prepend_environment_variable.feature b/features/api/environment/prepend_environment_variable.feature index 10f8c13cb..6710e2d93 100644 --- a/features/api/environment/prepend_environment_variable.feature +++ b/features/api/environment/prepend_environment_variable.feature @@ -22,7 +22,7 @@ Feature: Prepend environment variable before(:each) { prepend_environment_variable 'LONG_LONG_VARIABLE', 'a' } before(:each) { run('env') } - it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=a' } + it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=a' } end """ When I run `rspec` @@ -38,7 +38,7 @@ Feature: Prepend environment variable before(:each) { prepend_environment_variable 'LONG_LONG_VARIABLE', 'b' } before(:each) { run('env') } - it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=ba' } + it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=ba' } end """ When I run `rspec` @@ -56,7 +56,7 @@ Feature: Prepend environment variable before(:each) { prepend_environment_variable 'REALLY_LONG_LONG_VARIABLE', 'b' } before(:each) { run('env') } - it { expect(last_command.output).to include 'REALLY_LONG_LONG_VARIABLE=ba' } + it { expect(last_command_started.output).to include 'REALLY_LONG_LONG_VARIABLE=ba' } # Has no effect here, is not in block and not a command `run` it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq 'a' } diff --git a/features/api/environment/set_environment_variable.feature b/features/api/environment/set_environment_variable.feature index 8ebc14b60..74bf90464 100644 --- a/features/api/environment/set_environment_variable.feature +++ b/features/api/environment/set_environment_variable.feature @@ -21,7 +21,7 @@ Feature: Set environment variable via API-method before(:each) { set_environment_variable 'LONG_LONG_VARIABLE', '1' } before(:each) { run('env') } - it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=1' } + it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=1' } end """ When I run `rspec` @@ -37,7 +37,7 @@ Feature: Set environment variable via API-method before(:each) { set_environment_variable 'LONG_LONG_VARIABLE', '2' } before(:each) { run('env') } - it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=2' } + it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=2' } end """ When I run `rspec` @@ -56,7 +56,7 @@ Feature: Set environment variable via API-method before(:each) { set_environment_variable 'REALLY_LONG_LONG_VARIABLE', '2' } before(:each) { run('env') } - it { expect(last_command.output).to include 'REALLY_LONG_LONG_VARIABLE=2' } + it { expect(last_command_started.output).to include 'REALLY_LONG_LONG_VARIABLE=2' } it { expect(ENV['REALLY_LONG_LONG_VARIABLE']).to eq '1' } end """ @@ -133,14 +133,14 @@ Feature: Set environment variable via API-method describe 'Method XX' do before(:each) { run('env') } - it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=1' } + it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=1' } end describe 'Method YY' do before(:each) { set_environment_variable 'LONG_LONG_VARIABLE', '2' } before(:each) { run('env') } - it { expect(last_command.output).to include 'LONG_LONG_VARIABLE=2' } + it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=2' } end end """ @@ -230,7 +230,7 @@ Feature: Set environment variable via API-method before(:each) { run('env') } - it { expect(last_command.output).to include 'REALLY_LONG_LONG_VARIABLE=1' } + it { expect(last_command_started.output).to include 'REALLY_LONG_LONG_VARIABLE=1' } end context 'when arguments given' do @@ -244,7 +244,7 @@ Feature: Set environment variable via API-method before(:each) { run('env') } - it { expect(last_command.output).to include 'REALLY_LONG_LONG_VARIABLE=1' } + it { expect(last_command_started.output).to include 'REALLY_LONG_LONG_VARIABLE=1' } end end """ diff --git a/features/api/filesystem/cd.feature b/features/api/filesystem/cd.feature index dbffadfc6..2f2eab55a 100644 --- a/features/api/filesystem/cd.feature +++ b/features/api/filesystem/cd.feature @@ -26,7 +26,7 @@ Feature: Change current working directory before(:each) { run_simple 'pwd' } - it { expect(last_command.output).to include 'new_dir.d' } + it { expect(last_command_started.output).to include 'new_dir.d' } end """ When I run `rspec` @@ -41,8 +41,8 @@ Feature: Change current working directory before(:each) { cd 'new_dir.d' } before(:each) { run_simple 'pwd' } - it { expect(last_command.output).to include 'new_dir.d' } - it { expect(last_command).to be_executed_in_time } + it { expect(last_command_started.output).to include 'new_dir.d' } + it { expect(last_command_started).to be_executed_in_time } end """ When I run `rspec` @@ -167,7 +167,7 @@ Feature: Change current working directory end end - it { expect(last_command.output.to_s).to include 'subdir.d' } + it { expect(last_command_started.output.to_s).to include 'subdir.d' } end """ When I run `rspec` diff --git a/features/hooks/after/command.feature b/features/hooks/after/command.feature index 7152567ff..8c7bb9f60 100644 --- a/features/hooks/after/command.feature +++ b/features/hooks/after/command.feature @@ -22,7 +22,7 @@ Feature: After command hooks RSpec.describe 'Hooks', :type => :aruba do before(:each) { run_simple 'echo running' } - it { expect(last_command.stdout.chomp).to eq 'running' } + it { expect(last_command_started.stdout.chomp).to eq 'running' } end """ When I run `rspec` diff --git a/features/hooks/before/command.feature b/features/hooks/before/command.feature index 958e6e44e..91736d88b 100644 --- a/features/hooks/before/command.feature +++ b/features/hooks/before/command.feature @@ -24,7 +24,7 @@ Feature: before_cmd hooks RSpec.describe 'Hooks', :type => :aruba do before(:each) { run_simple 'echo running' } - it { expect(last_command.stdout.chomp).to eq 'running' } + it { expect(last_command_started.stdout.chomp).to eq 'running' } end """ When I run `rspec` @@ -50,7 +50,7 @@ Feature: before_cmd hooks RSpec.describe 'Hooks', :type => :aruba do before(:each) { run_simple 'echo running' } - it { expect(last_command.stdout.chomp).to eq 'running' } + it { expect(last_command_started.stdout.chomp).to eq 'running' } end """ When I run `rspec` diff --git a/features/matchers/timeouts.feature b/features/matchers/timeouts.feature index ba5c3198d..012c2c829 100644 --- a/features/matchers/timeouts.feature +++ b/features/matchers/timeouts.feature @@ -20,7 +20,7 @@ Feature: Check if a timeout occured during command execution before(:each) { run('cli') } - it { expect(last_command).to run_too_long } + it { expect(last_command_started).to run_too_long } end """ When I run `rspec` @@ -41,7 +41,7 @@ Feature: Check if a timeout occured during command execution before(:each) { run('cli') } - it { expect(last_command).to have_finished_in_time } + it { expect(last_command_started).to have_finished_in_time } end """ When I run `rspec` diff --git a/features/step_definitions/aruba_dev_steps.rb b/features/step_definitions/aruba_dev_steps.rb index 9eeab23c2..c3343ace0 100644 --- a/features/step_definitions/aruba_dev_steps.rb +++ b/features/step_definitions/aruba_dev_steps.rb @@ -103,5 +103,5 @@ Then(/^aruba should be installed on the local system$/) do run('gem list aruba') - expect(last_command).to have_output(/aruba/) + expect(last_command_started).to have_output(/aruba/) end diff --git a/lib/aruba/api/command.rb b/lib/aruba/api/command.rb index 1ed0fd2d9..d40e34657 100644 --- a/lib/aruba/api/command.rb +++ b/lib/aruba/api/command.rb @@ -63,7 +63,7 @@ def pipe_in_file(file_name) file_name = expand_path(file_name) File.open(file_name, 'r').each_line do |line| - last_command.write(line) + last_command_started.write(line) end end @@ -214,7 +214,7 @@ def assert_no_partial_output(unexpected, actual) # @return [TrueClass, FalseClass] # If output of interactive command includes arg1 return true, otherwise false def assert_partial_output_interactive(expected) - actual = unescape_text(last_command.stdout) + actual = unescape_text(last_command_started.stdout) actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences expected = unescape_text(expected) @@ -248,15 +248,15 @@ def assert_failing_with(expected) # If arg1 is false, return true if command failed def assert_success(success) if success - expect(last_command).to be_successfully_executed + expect(last_command_started).to be_successfully_executed else - expect(last_command).not_to be_successfully_executed + expect(last_command_started).not_to be_successfully_executed end end # @private def assert_exit_status(status) - expect(last_command).to have_exit_status(status) + expect(last_command_started).to have_exit_status(status) end # @private @@ -434,12 +434,12 @@ def run_simple(cmd, fail_on_error = true, timeout = nil) # The input for the command def type(input) return close_input if "" == input - last_command.write(input << "\n") + last_command_started.write(input << "\n") end # Close stdin def close_input - last_command.close_io(:stdin) + last_command_started.close_io(:stdin) end # Only processes diff --git a/lib/aruba/api/deprecated.rb b/lib/aruba/api/deprecated.rb index 045bd86d9..661005553 100644 --- a/lib/aruba/api/deprecated.rb +++ b/lib/aruba/api/deprecated.rb @@ -75,9 +75,9 @@ def absolute_path(*args) # @deprecated def _read_interactive - Aruba.platform.deprecated('The use of "#_read_interactive" is deprecated. Please use "last_command.stdout" instead') + Aruba.platform.deprecated('The use of "#_read_interactive" is deprecated. Please use "last_command_started.stdout" instead') - last_command.stdout + last_command_started.stdout end # @deprecated @@ -93,9 +93,9 @@ def announce_or_puts(msg) # @deprecated def _write_interactive(input) - Aruba.platform.deprecated('The use of "#_write_interactive" is deprecated. Please use "#last_command.write()" instead') + Aruba.platform.deprecated('The use of "#_write_interactive" is deprecated. Please use "#last_command_started.write()" instead') - last_command.write(input) + last_command_started.write(input) end # @deprecated @@ -534,7 +534,7 @@ def check_for_deprecated_variables # Last command started def last_command - Aruba::Platform.deprecated('The use of "#last_command" is deprecated. Use "#last_command_started"') + Aruba.platform.deprecated('The use of "#last_command" is deprecated. Use "#last_command_started"') process_monitor.last_command end diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index 229deac90..8f14da9f6 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -200,8 +200,8 @@ begin Timeout.timeout(exit_timeout) do loop do - if Aruba::Utils.unescape(last_command.output).include? Aruba::Utils.unescape(expected) - last_command.terminate + if Aruba::Utils.unescape(last_command_started.output).include? Aruba::Utils.unescape(expected) + last_command_started.terminate break end @@ -209,10 +209,10 @@ end end rescue ChildProcess::TimeoutError, TimeoutError - last_command.terminate + last_command_started.terminate ensure - announcer.stdout last_command.stdout - announcer.stderr last_command.stderr + announcer.stdout last_command_started.stdout + announcer.stderr last_command_started.stderr end end @@ -220,7 +220,7 @@ Timeout.timeout(exit_timeout) do loop do begin - expect(last_command).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) + expect(last_command_started).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) rescue ExpectationError sleep 0.1 retry @@ -235,7 +235,7 @@ Timeout.timeout(exit_timeout) do loop do begin - expect(last_command).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) + expect(last_command_started).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) rescue ExpectationError sleep 0.1 retry diff --git a/lib/aruba/matchers/command/be_successfully_executed.rb b/lib/aruba/matchers/command/be_successfully_executed.rb index d20d733e7..bd6997c41 100644 --- a/lib/aruba/matchers/command/be_successfully_executed.rb +++ b/lib/aruba/matchers/command/be_successfully_executed.rb @@ -16,9 +16,9 @@ # @example Use matcher # # RSpec.describe do -# it { expect(last_command).to be_successfully_executed } -# it { expect(last_command).not_to be_successfully_executed } -# it { expect(last_command).to have_failed_running } +# it { expect(last_command_started).to be_successfully_executed } +# it { expect(last_command_started).not_to be_successfully_executed } +# it { expect(last_command_started).to have_failed_running } # end RSpec::Matchers.define :be_successfully_executed do match do |actual| diff --git a/lib/aruba/matchers/command/have_exit_status.rb b/lib/aruba/matchers/command/have_exit_status.rb index f3c176a9d..ffffa01f4 100644 --- a/lib/aruba/matchers/command/have_exit_status.rb +++ b/lib/aruba/matchers/command/have_exit_status.rb @@ -14,7 +14,7 @@ # @example Use matcher # # RSpec.describe do -# it { expect(last_command).to have_exit_status(0) } +# it { expect(last_command_started).to have_exit_status(0) } # end RSpec::Matchers.define :have_exit_status do |expected| match do |actual| diff --git a/lib/aruba/matchers/command/have_finished_in_time.rb b/lib/aruba/matchers/command/have_finished_in_time.rb index 5baa0cc46..05547f7a4 100644 --- a/lib/aruba/matchers/command/have_finished_in_time.rb +++ b/lib/aruba/matchers/command/have_finished_in_time.rb @@ -14,9 +14,9 @@ # @example Use matcher # # RSpec.describe do -# it { expect(last_command).to run_too_long } -# it { expect(last_command).not_to run_too_long } -# it { expect(last_command).to finish_its_run_in_time } +# it { expect(last_command_started).to run_too_long } +# it { expect(last_command_started).not_to run_too_long } +# it { expect(last_command_started).to finish_its_run_in_time } # end # RSpec::Matchers.define :run_too_long do RSpec::Matchers.define :have_finished_in_time do diff --git a/lib/aruba/matchers/command/have_output.rb b/lib/aruba/matchers/command/have_output.rb index 4709b30f0..0fe5577f6 100644 --- a/lib/aruba/matchers/command/have_output.rb +++ b/lib/aruba/matchers/command/have_output.rb @@ -11,7 +11,7 @@ # @example Use matcher # # RSpec.describe do -# it { expect(last_command).to have_output } +# it { expect(last_command_started).to have_output } # end RSpec::Matchers.define :have_output do |expected| match do |actual| diff --git a/lib/aruba/matchers/command/have_output_on_stderr.rb b/lib/aruba/matchers/command/have_output_on_stderr.rb index 627765f54..94c60357c 100644 --- a/lib/aruba/matchers/command/have_output_on_stderr.rb +++ b/lib/aruba/matchers/command/have_output_on_stderr.rb @@ -11,7 +11,7 @@ # @example Use matcher # # RSpec.describe do -# it { expect(last_command).to have_output_on_stderr } +# it { expect(last_command_started).to have_output_on_stderr } # end RSpec::Matchers.define :have_output_on_stderr do |expected| match do |actual| diff --git a/lib/aruba/matchers/command/have_output_on_stdout.rb b/lib/aruba/matchers/command/have_output_on_stdout.rb index 75f638f45..24a87e12d 100644 --- a/lib/aruba/matchers/command/have_output_on_stdout.rb +++ b/lib/aruba/matchers/command/have_output_on_stdout.rb @@ -11,7 +11,7 @@ # @example Use matcher # # RSpec.describe do -# it { expect(last_command).to have_output_on_stdout } +# it { expect(last_command_started).to have_output_on_stdout } # end RSpec::Matchers.define :have_output_on_stdout do |expected| match do |actual| diff --git a/spec/aruba/matchers/command_spec.rb b/spec/aruba/matchers/command_spec.rb index 24d6161c5..2548acd58 100644 --- a/spec/aruba/matchers/command_spec.rb +++ b/spec/aruba/matchers/command_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +REquire 'spec_helper' RSpec.describe 'Command Matchers' do include_context 'uses aruba API' @@ -17,12 +17,12 @@ def announcer(*args) before(:each) { run(cmd) } context 'when has exit 0' do - it { expect(last_command).to have_exit_status 0 } + it { expect(last_command_started).to have_exit_status 0 } end context 'when has exit 0' do let(:cmd) { 'false' } - it { expect(last_command).not_to have_exit_status 0 } + it { expect(last_command_started).not_to have_exit_status 0 } end end @@ -32,12 +32,12 @@ def announcer(*args) before(:each) { run(cmd) } context 'when has exit 0' do - it { expect(last_command).to be_successfully_executed } + it { expect(last_command_started).to be_successfully_executed } end context 'when has exit 0' do let(:cmd) { 'false' } - it { expect(last_command).not_to be_successfully_executed } + it { expect(last_command_started).not_to be_successfully_executed } end end @@ -47,7 +47,7 @@ def announcer(*args) context 'when have output hello world on stdout' do before(:each) { run(cmd) } - it { expect(last_command).to have_output output } + it { expect(last_command_started).to have_output output } end context 'when multiple commands output hello world on stdout' do @@ -86,13 +86,13 @@ def announcer(*args) before(:each) { run(cmd) } - it { expect(last_command).to have_output output } + it { expect(last_command_started).to have_output output } end context 'when not has output' do before(:each) { run(cmd) } - it { expect(last_command).not_to have_output 'hello universe' } + it { expect(last_command_started).not_to have_output 'hello universe' } end end @@ -102,7 +102,7 @@ def announcer(*args) context 'when have output hello world on stdout' do before(:each) { run(cmd) } - it { expect(last_command).to have_output_on_stdout output } + it { expect(last_command_started).to have_output_on_stdout output } end context 'when have output hello world on stderr' do @@ -121,13 +121,13 @@ def announcer(*args) before(:each) { run(cmd) } - it { expect(last_command).not_to have_output_on_stdout output } + it { expect(last_command_started).not_to have_output_on_stdout output } end context 'when not has output' do before(:each) { run(cmd) } - it { expect(last_command).not_to have_output_on_stdout 'hello universe' } + it { expect(last_command_started).not_to have_output_on_stdout 'hello universe' } end end @@ -137,7 +137,7 @@ def announcer(*args) context 'when have output hello world on stdout' do before(:each) { run(cmd) } - it { expect(last_command).not_to have_output_on_stderr output } + it { expect(last_command_started).not_to have_output_on_stderr output } end context 'when have output hello world on stderr' do @@ -156,13 +156,13 @@ def announcer(*args) before(:each) { run(cmd) } - it { expect(last_command).to have_output_on_stderr output } + it { expect(last_command_started).to have_output_on_stderr output } end context 'when not has output' do before(:each) { run(cmd) } - it { expect(last_command).not_to have_output_on_stderr 'hello universe' } + it { expect(last_command_started).not_to have_output_on_stderr 'hello universe' } end end end From c98b7cd2dc101a2855cbfd75a379860a5c63d446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 09:41:36 +0200 Subject: [PATCH 019/118] Fix wrong namespace for platform --- lib/aruba/api/filesystem.rb | 4 ++-- lib/aruba/cucumber.rb | 38 +++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index 167c718a1..e8a85072a 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -320,7 +320,7 @@ def with_file_content(file, &block) def disk_usage(*paths) expect(paths).to all be_an_existing_path - DetermineDiskUsage.new.use paths.flatten.map { |p| ArubaPath.new(expand_path(p)) } + Platform::DetermineDiskUsage.new.use paths.flatten.map { |p| ArubaPath.new(expand_path(p)) } end # Get size of file @@ -330,7 +330,7 @@ def disk_usage(*paths) def file_size(name) expect(name).to be_an_existing_file - DetermineFileSize.new.use expand_path(name) + Platform::DetermineFileSize.new.use expand_path(name) end end end diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index 8f14da9f6..9403b350a 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -200,7 +200,7 @@ begin Timeout.timeout(exit_timeout) do loop do - if Aruba::Utils.unescape(last_command_started.output).include? Aruba::Utils.unescape(expected) + if Aruba::Platform.unescape(last_command_started.output).include? Aruba::Platform.unescape(expected) last_command_started.terminate break end @@ -250,33 +250,29 @@ expect(all_output).to have_output_size size.to_i end -Then /^the output should contain "([^"]*)"$/ do |expected| - expect(all_commands).to include have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) -end - Then /^the output from "([^"]*)" should( not)? contain "([^"]*)"$/ do |cmd, negated, expected| command = process_monitor.get_process(Platform.detect_ruby(cmd)) if negated - expect(command).not_to have_output Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + expect(command).not_to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else - expect(command).to have_output Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + expect(command).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end Then /^the output should( not)? contain "([^"]*)"$/ do |negated, expected| if negated - expect(all_commands).not_to include have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + expect(all_commands).not_to include have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else - expect(all_commands).to include have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + expect(all_commands).to include have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end Then /^the output should( not)? contain:$/ do |negated, expected| if negated - expect(all_commands).not_to include have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + expect(all_commands).not_to include have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else - expect(all_commands).to include have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + expect(all_commands).to include have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end @@ -290,9 +286,9 @@ end if negated - expect(commands).not_to have_output Aruba::Utils.unescape(expected) + expect(commands).not_to have_output Aruba::Platform.unescape(expected) else - expect(commands).to have_output Aruba::Utils.unescape(expected) + expect(commands).to have_output Aruba::Platform.unescape(expected) end end @@ -306,9 +302,9 @@ end if negated - expect(commands).not_to have_output Aruba::Utils.unescape(expected) + expect(commands).not_to have_output Aruba::Platform.unescape(expected) else - expect(commands).to have_output Aruba::Utils.unescape(expected) + expect(commands).to have_output Aruba::Platform.unescape(expected) end end @@ -351,30 +347,30 @@ Then /^it should (pass|fail) with "(.*?)"$/ do |pass_fail, partial_output| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end Then /^it should (pass|fail) with:$/ do |pass_fail, partial_output| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Utils.unescape(expected))) + expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end Then /^it should (pass|fail) with exactly:$/ do |pass_fail, exact_output| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_content Aruba::Utils.unescape(expected) + expect(last_command_stopped).to have_content Aruba::Platform.unescape(expected) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_content Aruba::Utils.unescape(expected) + expect(last_command_stopped).to have_content Aruba::Platform.unescape(expected) end end From b9ee7388b0ecc634d2d5e099196a9fce7963b761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 09:41:50 +0200 Subject: [PATCH 020/118] Fixed bugs for reading and specs --- lib/aruba/processes/spawn_process.rb | 2 +- spec/aruba/matchers/command_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 57b234318..a91050db6 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -102,7 +102,7 @@ def stdout(opts = {}) wait_for_io wait_for_io do @process.io.stdout.flush - open(@err).read + open(@out).read end end diff --git a/spec/aruba/matchers/command_spec.rb b/spec/aruba/matchers/command_spec.rb index 2548acd58..344fe4056 100644 --- a/spec/aruba/matchers/command_spec.rb +++ b/spec/aruba/matchers/command_spec.rb @@ -1,4 +1,4 @@ -REquire 'spec_helper' +require 'spec_helper' RSpec.describe 'Command Matchers' do include_context 'uses aruba API' From 03a3d6dcf6afee22f9d4fa6b3fd7a61d6cf3011c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 09:56:19 +0200 Subject: [PATCH 021/118] Environment variables from leaking into other specs --- spec/aruba/api/environment/restore_env_spec.rb | 17 +++++++++-------- spec/aruba/api/environment/set_env_spec.rb | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/spec/aruba/api/environment/restore_env_spec.rb b/spec/aruba/api/environment/restore_env_spec.rb index de40b8763..4f833f684 100644 --- a/spec/aruba/api/environment/restore_env_spec.rb +++ b/spec/aruba/api/environment/restore_env_spec.rb @@ -6,6 +6,7 @@ around do |example| old_env = ENV.to_h example.run + ENV.clear ENV.update(old_env) end @@ -17,7 +18,7 @@ context 'when set single' do before :each do - @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '1' + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1' @aruba.restore_env end @@ -26,9 +27,9 @@ context 'when set multiple times' do before :each do - @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '1' - @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '2' - @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '3' + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1' + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2' + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '3' @aruba.restore_env end @@ -43,7 +44,7 @@ context 'when set single time' do before :each do - @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '1' + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1' @aruba.restore_env end @@ -52,9 +53,9 @@ context 'when set multiple times' do before :each do - @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '1' - @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '2' - @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', '3' + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1' + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2' + @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '3' @aruba.restore_env end diff --git a/spec/aruba/api/environment/set_env_spec.rb b/spec/aruba/api/environment/set_env_spec.rb index af2e5e914..9f45b9fac 100644 --- a/spec/aruba/api/environment/set_env_spec.rb +++ b/spec/aruba/api/environment/set_env_spec.rb @@ -6,6 +6,7 @@ around do |example| old_env = ENV.to_h example.run + ENV.clear ENV.update(old_env) end From 1b59c433e720822c958b9a322f2fc32d8f62a9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 10:01:33 +0200 Subject: [PATCH 022/118] Use the correct matcher. Have Content is something different from Have Output --- lib/aruba/cucumber.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index 9403b350a..7b9cc2fc5 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -262,17 +262,17 @@ Then /^the output should( not)? contain "([^"]*)"$/ do |negated, expected| if negated - expect(all_commands).not_to include have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(all_commands).not_to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else - expect(all_commands).to include have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(all_commands).to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end Then /^the output should( not)? contain:$/ do |negated, expected| if negated - expect(all_commands).not_to include have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(all_commands).not_to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else - expect(all_commands).to include have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(all_commands).to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end @@ -347,40 +347,40 @@ Then /^it should (pass|fail) with "(.*?)"$/ do |pass_fail, partial_output| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end Then /^it should (pass|fail) with:$/ do |pass_fail, partial_output| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_content Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end Then /^it should (pass|fail) with exactly:$/ do |pass_fail, exact_output| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_content Aruba::Platform.unescape(expected) + expect(last_command_stopped).to have_output Aruba::Platform.unescape(expected) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_content Aruba::Platform.unescape(expected) + expect(last_command_stopped).to have_output Aruba::Platform.unescape(expected) end end Then /^it should (pass|fail) with regexp?:$/ do |pass_fail, expected| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_content Regexp.new(expected) + expect(last_command_stopped).to have_output Regexp.new(expected) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_content Regexp.new(expected) + expect(last_command_stopped).to have_output Regexp.new(expected) end end From b245fbf9ca2939f91d77c5694151e28a43e8a167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 14:32:05 +0200 Subject: [PATCH 023/118] Use new start method instead of deprecated run-hone --- lib/aruba/api/command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/aruba/api/command.rb b/lib/aruba/api/command.rb index d40e34657..32eb41f97 100644 --- a/lib/aruba/api/command.rb +++ b/lib/aruba/api/command.rb @@ -374,7 +374,7 @@ def run(cmd, timeout = nil) aruba.config.before(:command, self, command) process_monitor.register_process(cmd, command) - command.run! + command.start aruba.config.after(:command, self, command) From 5e36183a407d9b9d1600a7563581cf952789d29d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 14:32:44 +0200 Subject: [PATCH 024/118] Use the new last_command_*-methods --- lib/aruba/api/deprecated.rb | 2 +- lib/aruba/cucumber.rb | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/aruba/api/deprecated.rb b/lib/aruba/api/deprecated.rb index 661005553..061c8121a 100644 --- a/lib/aruba/api/deprecated.rb +++ b/lib/aruba/api/deprecated.rb @@ -536,7 +536,7 @@ def check_for_deprecated_variables def last_command Aruba.platform.deprecated('The use of "#last_command" is deprecated. Use "#last_command_started"') - process_monitor.last_command + process_monitor.last_command_started end end end diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index 7b9cc2fc5..a109c41e4 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -250,29 +250,31 @@ expect(all_output).to have_output_size size.to_i end -Then /^the output from "([^"]*)" should( not)? contain "([^"]*)"$/ do |cmd, negated, expected| - command = process_monitor.get_process(Platform.detect_ruby(cmd)) +Then /^the output(?: from "([^"]*)")? should( not)? contain "([^"]*)"$/ do |cmd, negated, expected| + commands = if cmd + [process_monitor.get_process(Platform.detect_ruby(cmd))] + else + all_commands + end if negated - expect(command).not_to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(commands).not_to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else - expect(command).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(commands).to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end -Then /^the output should( not)? contain "([^"]*)"$/ do |negated, expected| - if negated - expect(all_commands).not_to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) - else - expect(all_commands).to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) - end -end +Then /^the output(?: from "([^"]*)")? should( not)? contain:$/ do |cmd, negated, expected| + commands = if cmd + [process_monitor.get_process(Platform.detect_ruby(cmd))] + else + all_commands + end -Then /^the output should( not)? contain:$/ do |negated, expected| if negated - expect(all_commands).not_to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(commands).not_to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else - expect(all_commands).to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(commands).to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end From 0a78ed59358a62a011a158f863bef948c980f205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 14:33:12 +0200 Subject: [PATCH 025/118] Fixed bug while determining disk usage --- lib/aruba/api/filesystem.rb | 4 ++-- lib/aruba/platform/determine_disk_usage.rb | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index e8a85072a..e06020799 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -318,9 +318,9 @@ def with_file_content(file, &block) # @result [FileSize] # Bytes on disk def disk_usage(*paths) - expect(paths).to all be_an_existing_path + expect(paths.flatten).to all be_an_existing_path - Platform::DetermineDiskUsage.new.use paths.flatten.map { |p| ArubaPath.new(expand_path(p)) } + Platform::DetermineDiskUsage.new.use paths.flatten.map { |p| ArubaPath.new(expand_path(p)) }, aruba.config.physical_block_size end # Get size of file diff --git a/lib/aruba/platform/determine_disk_usage.rb b/lib/aruba/platform/determine_disk_usage.rb index 7aa979d3a..28da1825c 100644 --- a/lib/aruba/platform/determine_disk_usage.rb +++ b/lib/aruba/platform/determine_disk_usage.rb @@ -1,11 +1,16 @@ module Aruba module Platform class DetermineDiskUsage - def use(paths) - size = paths.map do |p| + def use(*args) + args = args.flatten + + physical_block_size = args.pop + paths = args + + size = paths.flatten.map do |p| DiskUsageCalculator.new.calc( p.blocks, - aruba.config.physical_block_size + physical_block_size ) end.inject(0, &:+) From 8365445474152470bac3a89634313ceda5a8e92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 14:33:32 +0200 Subject: [PATCH 026/118] Refactor matchers a bit --- .../matchers/command/have_finished_in_time.rb | 4 ++-- lib/aruba/matchers/command/have_output.rb | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/aruba/matchers/command/have_finished_in_time.rb b/lib/aruba/matchers/command/have_finished_in_time.rb index 05547f7a4..9286a362c 100644 --- a/lib/aruba/matchers/command/have_finished_in_time.rb +++ b/lib/aruba/matchers/command/have_finished_in_time.rb @@ -24,6 +24,8 @@ @old_actual = actual @actual = @old_actual.commandline + next false unless @old_actual.respond_to? :timed_out? + @announcer ||= Aruba::Announcer.new( self, :stdout => @announce_stdout, @@ -35,8 +37,6 @@ @old_actual.stop(@announcer) unless @old_actual.stopped? - next false unless @old_actual.respond_to? :timed_out? - @old_actual.timed_out? == false end end diff --git a/lib/aruba/matchers/command/have_output.rb b/lib/aruba/matchers/command/have_output.rb index 0fe5577f6..702b8081e 100644 --- a/lib/aruba/matchers/command/have_output.rb +++ b/lib/aruba/matchers/command/have_output.rb @@ -15,9 +15,21 @@ # end RSpec::Matchers.define :have_output do |expected| match do |actual| - next false unless actual.respond_to? :output - @old_actual = actual + + next false unless @old_actual.respond_to? :output + + @announcer ||= Aruba::Announcer.new( + self, + :stdout => @announce_stdout, + :stderr => @announce_stderr, + :dir => @announce_dir, + :cmd => @announce_cmd, + :env => @announce_env + ) + + @old_actual.stop(@announcer) unless @old_actual.stopped? + @actual = Aruba::Platform.unescape(actual.output.chomp, aruba.config.keep_ansi) values_match?(expected, @actual) From a142895ee4bf80d389ffa55e062941889bbdcab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 14:34:13 +0200 Subject: [PATCH 027/118] Get rid of which in processes by setting the ENV from output side of system, childprocess etc. --- lib/aruba/processes/basic_process.rb | 10 ++++++++-- lib/aruba/processes/debug_process.rb | 26 +++++++------------------- lib/aruba/processes/spawn_process.rb | 12 ++++-------- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index 8028a2d67..aa8c90d76 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -70,8 +70,14 @@ def after_run; end private - def which(program) - Aruba.platform.which(program, environment['PATH']) + def with_local_env(e, &block) + old_env = ENV.to_hash + ENV.update e + + block.call + ensure + ENV.clear + ENV.update old_env end def command diff --git a/lib/aruba/processes/debug_process.rb b/lib/aruba/processes/debug_process.rb index 71900e231..484d2c9da 100644 --- a/lib/aruba/processes/debug_process.rb +++ b/lib/aruba/processes/debug_process.rb @@ -20,28 +20,16 @@ def run! # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/CyclomaticComplexity def start - # rubocop:disable Metrics/LineLength - fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) unless which(command) - # rubocop:enable Metrics/LineLength - - if RUBY_VERSION < '1.9' - begin - old_env = ENV.to_hash.dup - ENV.update environment - - Dir.chdir @working_directory do - @exit_status = system(@cmd) ? 0 : 1 - end - ensure - ENV.clear - ENV.update old_env - end - elsif RUBY_VERSION < '2' + if RUBY_VERSION < '2' Dir.chdir @working_directory do - @exit_status = system(environment, @cmd) ? 0 : 1 + with_local_env(environment) do + @exit_status = system(command, *arguments) ? 0 : 1 + end end else - @exit_status = system(environment, @cmd, :chdir => @working_directory) ? 0 : 1 + with_local_env(environment) do + @exit_status = system(command, *arguments, :chdir => @working_directory) ? 0 : 1 + end end end # rubocop:enable Metrics/CyclomaticComplexity diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index a91050db6..cee5d727a 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -53,13 +53,7 @@ def run! # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/CyclomaticComplexity def start - # gather fully qualified path - cmd = which(command) - # rubocop:disable Metrics/LineLength - fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) if cmd.nil? - # rubocop:enable Metrics/LineLength - - cmd = Aruba.platform.command_string.new(cmd) + cmd = Aruba.platform.command_string.new(command) @process = ChildProcess.build(*[cmd.to_a, arguments].flatten) @out = Tempfile.new("aruba-out") @@ -77,7 +71,9 @@ def start @process.environment.update(environment) begin - @process.start + with_local_env(environment) do + @process.start + end rescue ChildProcess::LaunchError => e raise LaunchError, "It tried to start #{cmd}. " + e.message end From 0bb0ac3753303fb133e2c59b02c0162b71082771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 15:55:47 +0200 Subject: [PATCH 028/118] Fixed bugs in output features --- features/api/command/run.feature | 2 +- features/commands/output/all_output.feature | 10 ++----- lib/aruba/cucumber.rb | 30 ++++++++++----------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/features/api/command/run.feature b/features/api/command/run.feature index f4d1c2b4b..7f4f54920 100644 --- a/features/api/command/run.feature +++ b/features/api/command/run.feature @@ -30,7 +30,7 @@ Feature: Run command require 'spec_helper' RSpec.describe 'Find path for command', :type => :aruba do - it { expect { run('cli') }.to raise_error Aruba::LaunchError, /Command "cli" not found in PATH-variable/ } + it { expect { run('cli') }.to raise_error Aruba::LaunchError, /No such file or directory - cli/ } end """ When I run `rspec` diff --git a/features/commands/output/all_output.feature b/features/commands/output/all_output.feature index 37bde8fa8..0cc20f6f5 100644 --- a/features/commands/output/all_output.feature +++ b/features/commands/output/all_output.feature @@ -61,7 +61,6 @@ Feature: All output of commands which were executed When I run `cucumber` Then the features should all pass - @debug Scenario: Detect absence of subset of multiline output Given a file named "bin/cli" with: """ @@ -82,7 +81,7 @@ Feature: All output of commands which were executed When I run `cucumber` Then the features should all pass - @posix + @posix Scenario: Detect exact one-line output for posix commands Given a file named "features/output.feature" with: """ @@ -120,12 +119,6 @@ Feature: All output of commands which were executed When I run `cucumber` Then the features should all pass - When I run `printf "\e[36mhello world\e[0m"` - Then the output should contain exactly: - """ - """ - - @ansi Scenario: Detect exact one-line output with ANSI output Given a file named "bin/cli" with: """ @@ -139,6 +132,7 @@ Feature: All output of commands which were executed And a file named "features/output.feature" with: """ Feature: Run command + @keep-ansi-escape-sequences Scenario: Run command When I run `cli` Then the output should contain exactly: diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index a109c41e4..424de815b 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -288,9 +288,9 @@ end if negated - expect(commands).not_to have_output Aruba::Platform.unescape(expected) + expect(commands).not_to include have_output Aruba::Platform.unescape(expected) else - expect(commands).to have_output Aruba::Platform.unescape(expected) + expect(commands).to include have_output Aruba::Platform.unescape(expected) end end @@ -304,9 +304,9 @@ end if negated - expect(commands).not_to have_output Aruba::Platform.unescape(expected) + expect(commands).not_to include have_output Aruba::Platform.unescape(expected) else - expect(commands).to have_output Aruba::Platform.unescape(expected) + expect(commands).to include have_output Aruba::Platform.unescape(expected) end end @@ -316,25 +316,25 @@ # appear naturally in the output Then /^the output should( not)? match \/([^\/]*)\/$/ do |negated, expected| if negated - expect(all_commands).not_to include have_output Regexp.new(expected) + expect(all_commands).not_to include have_output Regexp.new(expected, Regexp::MULTILINE) else - expect(all_commands).to include have_output Regexp.new(expected) + expect(all_commands).to include have_output Regexp.new(expected, Regexp::MULTILINE) end end Then /^the output should( not)? match %r<([^>]*)>$/ do |negated, expected| if negated - expect(all_commands).not_to include have_output Regexp.new(expected) + expect(all_commands).not_to include have_output Regexp.new(expected, Regexp::MULTILINE) else - expect(all_commands).to include have_output Regexp.new(expected) + expect(all_commands).to include have_output Regexp.new(expected, Regexp::MULTILINE) end end Then /^the output should( not)? match:$/ do |negated, expected| if negated - expect(all_commands).not_to include have_output Regexp.new(expected) + expect(all_commands).not_to include have_output Regexp.new(expected, Regexp::MULTILINE) else - expect(all_commands).to include have_output Regexp.new(expected) + expect(all_commands).to include have_output Regexp.new(expected, Regexp::MULTILINE) end end @@ -346,7 +346,7 @@ end end -Then /^it should (pass|fail) with "(.*?)"$/ do |pass_fail, partial_output| +Then /^it should (pass|fail) with "(.*?)"$/ do |pass_fail, expected| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) @@ -356,7 +356,7 @@ end end -Then /^it should (pass|fail) with:$/ do |pass_fail, partial_output| +Then /^it should (pass|fail) with:$/ do |pass_fail, expected| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) @@ -366,7 +366,7 @@ end end -Then /^it should (pass|fail) with exactly:$/ do |pass_fail, exact_output| +Then /^it should (pass|fail) with exactly:$/ do |pass_fail, expected| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed expect(last_command_stopped).to have_output Aruba::Platform.unescape(expected) @@ -379,10 +379,10 @@ Then /^it should (pass|fail) with regexp?:$/ do |pass_fail, expected| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(expected) + expect(last_command_stopped).to have_output Regexp.new(expected, Regexp::MULTILINE) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(expected) + expect(last_command_stopped).to have_output Regexp.new(expected, Regexp::MULTILINE) end end From b4d5f32938359cdef83771f1687cfdc6153a20ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Mon, 20 Jul 2015 16:24:09 +0200 Subject: [PATCH 029/118] Fixed some other bugs in feature tests --- features/commands/debug_command.feature | 2 +- lib/aruba/cucumber.rb | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/features/commands/debug_command.feature b/features/commands/debug_command.feature index 312681321..43517beb1 100644 --- a/features/commands/debug_command.feature +++ b/features/commands/debug_command.feature @@ -75,7 +75,7 @@ Feature: Debug your command in cucumber-test-run Then the exit status should be 0 """ When I run `cucumber` interactively - And I stop the command if output contains: + And I stop the command started last if output contains: """ pry """ diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index 424de815b..b7f08c086 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -196,12 +196,21 @@ close_input end -When /^I stop the last command if (?:output|stdout) contains:$/ do |expected| +When /^I stop the command(?: started last)? if (output|stdout|stderr) contains:$/ do |channel, expected| + fail %(Invalid output channel "#{channel}" chosen. Please choose one of "output, stdout or stderr") unless %w(output stdout stderr).include? channel + begin Timeout.timeout(exit_timeout) do loop do - if Aruba::Platform.unescape(last_command_started.output).include? Aruba::Platform.unescape(expected) + output = if RUBY_VERSION < '1.9.3' + last_command_started.send channel.to_sym + else + last_command_started.public_send channel.to_sym + end + + if Aruba::Platform.unescape(output).include? Aruba::Platform.unescape(expected) last_command_started.terminate + break end @@ -211,8 +220,8 @@ rescue ChildProcess::TimeoutError, TimeoutError last_command_started.terminate ensure - announcer.stdout last_command_started.stdout - announcer.stderr last_command_started.stderr + announcer.announce :stdout, last_command_started.stdout + announcer.announce :stderr, last_command_started.stderr end end @@ -252,7 +261,7 @@ Then /^the output(?: from "([^"]*)")? should( not)? contain "([^"]*)"$/ do |cmd, negated, expected| commands = if cmd - [process_monitor.get_process(Platform.detect_ruby(cmd))] + [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] else all_commands end @@ -266,7 +275,7 @@ Then /^the output(?: from "([^"]*)")? should( not)? contain:$/ do |cmd, negated, expected| commands = if cmd - [process_monitor.get_process(Platform.detect_ruby(cmd))] + [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] else all_commands end @@ -282,7 +291,7 @@ ## the output from `echo -n "Hello"` should contain exactly "Hello" Then /^the output(?: from "(.*?)")? should( not)? contain exactly "(.*?)"$/ do |cmd, negated, expected| commands = if cmd - [process_monitor.get_process(Platform.detect_ruby(cmd))] + [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] else all_commands end @@ -298,7 +307,7 @@ ## the output from `echo -n "Hello"` should contain exactly: Then /^the output(?: from "(.*?)")? should( not)? contain exactly:$/ do |cmd, negated, expected| commands = if cmd - [process_monitor.get_process(Platform.detect_ruby(cmd))] + [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] else all_commands end From eacf5257edf003de73c48f5d3fffdfd95300448c Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Mon, 20 Jul 2015 19:31:08 +0200 Subject: [PATCH 030/118] Fixed offense due to deprecation warning --- lib/aruba/cucumber/hooks.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/aruba/cucumber/hooks.rb b/lib/aruba/cucumber/hooks.rb index 9d0aaf447..a9c7b0afa 100644 --- a/lib/aruba/cucumber/hooks.rb +++ b/lib/aruba/cucumber/hooks.rb @@ -119,7 +119,9 @@ # end Before('@ansi') do - Aruba.platform.deprecated('The use of "@ansi" is deprecated. Use "@keep-ansi-escape-sequences" instead') + # rubocop:disable Metrics/LineLength + Aruba::Platform.deprecated('The use of "@ansi" is deprecated. Use "@keep-ansi-escape-sequences" instead. But be aware, that this hook uses the aruba configuration and not an instance variable') + # rubocop:enable Metrics/LineLength aruba.config.remove_ansi_escape_sequences = false end From df8b35afd6176b446f0fbbb26f412c8eeac6dfef Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Mon, 20 Jul 2015 20:09:29 +0200 Subject: [PATCH 031/118] Relax the use of steps in cucumber --- lib/aruba/cucumber.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index b7f08c086..0a53c8f39 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -524,7 +524,7 @@ end end -Then /^(?:a|the) file "([^"]*)" should (not )?contain "([^"]*)"$/ do |file, negated, content| +Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain "([^"]*)"$/ do |file, negated, content| if negated expect(file).not_to have_file_content Regexp.new(Regexp.escape(content)) else @@ -532,7 +532,7 @@ end end -Then /^(?:a|the) file "([^"]*)" should (not )?contain:$/ do |file, negated, content| +Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain:$/ do |file, negated, content| if negated expect(file).not_to have_file_content Regexp.new(Regexp.escape(content.chomp)) else @@ -540,7 +540,7 @@ end end -Then /^(?:a|the) file "([^"]*)" should (not )?contain exactly:$/ do |file, negated, content| +Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain exactly:$/ do |file, negated, content| if negated expect(file).not_to have_file_content content else @@ -548,7 +548,7 @@ end end -Then /^(?:a|the) file "([^"]*)" should (not )?match %r<([^\/]*)>$/ do |file, negated, content| +Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?match %r<([^\/]*)>$/ do |file, negated, content| if negated expect(file).not_to have_file_content Regexp.new(content) else @@ -556,7 +556,7 @@ end end -Then /^(?:a|the) file "([^"]*)" should (not )?match \/([^\/]*)\/$/ do |file, negated, content| +Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?match \/([^\/]*)\/$/ do |file, negated, content| if negated expect(file).not_to have_file_content Regexp.new(content) else @@ -564,7 +564,7 @@ end end -Then /^(?:a|the) file "([^"]*)" should (not )?be equal to file "([^"]*)"/ do |file, negated, reference_file| +Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?be equal to file "([^"]*)"/ do |file, negated, reference_file| if negated expect(file).not_to have_same_file_content_like(reference_file) else @@ -579,3 +579,11 @@ expect(file).to have_permissions(permissions) end end + +Then /^the (?:file|directory)(?: named)? "([^"]*)" should have permissions "([^"]*)"$/ do |path, negated, permissions| + if negated + expect(path).not_to have_permissions(permissions) + else + expect(path).to have_permissions(permissions) + end +end From b8398aee0714df77f9b656496a9cd09b299b9e35 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Tue, 21 Jul 2015 06:41:57 +0200 Subject: [PATCH 032/118] Remove app_spec. It's not really helpful and makes some tests for collection any fail because it modifies the amount of tests run which is not obvious to see from the outside. --- features/fixtures/cli-app/spec/cli/app_spec.rb | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 features/fixtures/cli-app/spec/cli/app_spec.rb diff --git a/features/fixtures/cli-app/spec/cli/app_spec.rb b/features/fixtures/cli-app/spec/cli/app_spec.rb deleted file mode 100644 index ad1bf32c9..000000000 --- a/features/fixtures/cli-app/spec/cli/app_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' - -describe Cli::App do - it 'has a version number' do - expect(Cli::App::VERSION).not_to be nil - end -end From 0b7c85416e575009a2b73f06fe444620c36c6faa Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Tue, 21 Jul 2015 09:09:54 +0200 Subject: [PATCH 033/118] Better error message if an object is/is not included by using a custom matcher --- .../collection/include_an_object.feature | 72 +++++++++++++++ lib/aruba/cucumber.rb | 42 ++++++--- lib/aruba/matchers/collection.rb | 1 + .../matchers/collection/include_an_object.rb | 88 +++++++++++++++++++ 4 files changed, 189 insertions(+), 14 deletions(-) create mode 100644 features/matchers/collection/include_an_object.feature create mode 100644 lib/aruba/matchers/collection.rb create mode 100644 lib/aruba/matchers/collection/include_an_object.rb diff --git a/features/matchers/collection/include_an_object.feature b/features/matchers/collection/include_an_object.feature new file mode 100644 index 000000000..74eb4626c --- /dev/null +++ b/features/matchers/collection/include_an_object.feature @@ -0,0 +1,72 @@ +Feature: `include_an_object` Matcher + + Use the `include_an_object` matcher to specify that a collection's objects include_an_object pass an expected matcher. + This works on include_an_object enumerable object. + + ```ruby + expect([1, 4, 5]).to include_an_object( be_odd ) + expect([1, 3, 'a']).to include_an_object( be_an(Integer) ) + expect([1, 3, 11]).to include_an_object( be < 10 ) + ``` + + The matcher also supports compound matchers: + + ```ruby + expect([1, 'a', 11]).to include_an_object( be_odd.and be < 10 ) + ``` + + Background: + Given I use a fixture named "cli-app" + + Scenario: Array usage + Given a file named "spec/array_include_an_object_matcher_spec.rb" with: + """ruby + require 'spec_helper' + + RSpec.describe [1, 4, 'a', 11] do + it { is_expected.to include_an_object( be_odd ) } + it { is_expected.to include_an_object( be_an(Integer) ) } + it { is_expected.to include_an_object( be < 10 ) } + it { is_expected.not_to include_an_object( eq 'b' ) } + end + + RSpec.describe [14, 'a'] do + it { is_expected.to include_an_object( be_odd ) } + it { is_expected.to include_an_object( be_an(Symbol) ) } + it { is_expected.to include_an_object( be < 10 ) } + it { is_expected.not_to include_an_object( eq 'a' ) } + end + """ + When I run `rspec` + Then the output should contain all of these: + | 8 examples, 4 failures | + | expected [14, "a"] to include an object be odd | + | expected [14, "a"] to include an object be a kind of Symbol | + | expected [14, "a"] to include an object be < 10 | + | expected [14, "a"] not to include an object eq "a" | + + Scenario: Compound Matcher Usage + Given a file named "spec/compound_include_an_object_matcher_spec.rb" with: + """ruby + require 'spec_helper' + + RSpec.describe [1, 'anything', 'something'] do + it { is_expected.to include_an_object( be_a(String).and include("thing") ) } + it { is_expected.to include_an_object( be_a(String).and end_with("g") ) } + it { is_expected.to include_an_object( start_with("s").or include("y") ) } + it { is_expected.not_to include_an_object( start_with("b").or include("b") ) } + end + + RSpec.describe ['anything', 'something'] do + it { is_expected.to include_an_object( be_a(Integer).and include("thing") ) } + it { is_expected.to include_an_object( be_a(Integer).and end_with("z") ) } + it { is_expected.to include_an_object( start_with("z").or include("1") ) } + it { is_expected.not_to include_an_object( start_with("a").or include("some") ) } + end + """ + When I run `rspec` + Then the output should contain all of these: + | 8 examples, 4 failures | + | expected ["anything", "something"] to include an object be a kind of Integer and include "thing" | + | expected ["anything", "something"] to include an object be a kind of Integer and end with "z" | + | expected ["anything", "something"] to include an object start with "z" or include "1" | diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index 0a53c8f39..c71a1ff5f 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -267,9 +267,9 @@ end if negated - expect(commands).not_to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(commands).not_to include_an_object have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else - expect(commands).to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(commands).to include_an_object have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end @@ -281,9 +281,9 @@ end if negated - expect(commands).not_to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(commands).not_to include_an_object have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) else - expect(commands).to include have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(commands).to include_an_object have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end end @@ -297,9 +297,9 @@ end if negated - expect(commands).not_to include have_output Aruba::Platform.unescape(expected) + expect(commands).not_to include_an_object have_output Aruba::Platform.unescape(expected) else - expect(commands).to include have_output Aruba::Platform.unescape(expected) + expect(commands).to include_an_object have_output Aruba::Platform.unescape(expected) end end @@ -313,9 +313,9 @@ end if negated - expect(commands).not_to include have_output Aruba::Platform.unescape(expected) + expect(commands).not_to include_an_object have_output Aruba::Platform.unescape(expected) else - expect(commands).to include have_output Aruba::Platform.unescape(expected) + expect(commands).to include_an_object have_output Aruba::Platform.unescape(expected) end end @@ -325,25 +325,25 @@ # appear naturally in the output Then /^the output should( not)? match \/([^\/]*)\/$/ do |negated, expected| if negated - expect(all_commands).not_to include have_output Regexp.new(expected, Regexp::MULTILINE) + expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) else - expect(all_commands).to include have_output Regexp.new(expected, Regexp::MULTILINE) + expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) end end Then /^the output should( not)? match %r<([^>]*)>$/ do |negated, expected| if negated - expect(all_commands).not_to include have_output Regexp.new(expected, Regexp::MULTILINE) + expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) else - expect(all_commands).to include have_output Regexp.new(expected, Regexp::MULTILINE) + expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) end end Then /^the output should( not)? match:$/ do |negated, expected| if negated - expect(all_commands).not_to include have_output Regexp.new(expected, Regexp::MULTILINE) + expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) else - expect(all_commands).to include have_output Regexp.new(expected, Regexp::MULTILINE) + expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) end end @@ -587,3 +587,17 @@ expect(path).to have_permissions(permissions) end end + +Then /^(?:the )?(output|stdout|stderr) should contain all of these:$/ do |channel, table| + table.raw.flatten.each do |string| + if channel == 'output' + expect(all_commands).to include_an_object have_output Regexp.new(Regexp.escape(string)) + elsif channel == 'stdout' + expect(all_commands).to include_an_object have_output_on_stdout Regexp.new(Regexp.escape(string)) + elsif channel == 'stderr' + expect(all_commands).to include_an_object have_output_on_stderr Regexp.new(Regexp.escape(string)) + else + fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stdout" and "stderr" are supported.) + end + end +end diff --git a/lib/aruba/matchers/collection.rb b/lib/aruba/matchers/collection.rb new file mode 100644 index 000000000..4490a4e5a --- /dev/null +++ b/lib/aruba/matchers/collection.rb @@ -0,0 +1 @@ +Aruba::Platform.require_matching_files('../collection/**/*.rb', __FILE__) diff --git a/lib/aruba/matchers/collection/include_an_object.rb b/lib/aruba/matchers/collection/include_an_object.rb new file mode 100644 index 000000000..93bb5b65a --- /dev/null +++ b/lib/aruba/matchers/collection/include_an_object.rb @@ -0,0 +1,88 @@ +require 'rspec/matchers/built_in/all' + +module Aruba + module Matchers + # @api private + # Provides the implementation for `all`. + # Not intended to be instantiated directly. + class IncludeAnObject < RSpec::Matchers::BuiltIn::All + # @private + attr_reader :matcher, :failed_objects, :succeeded_objects + + def initialize(matcher) + @matcher = matcher + @failed_objects = {} + @succeeded_objects = {} + end + + # @api private + # @return [String] + def description + improve_hash_formatting "include an object #{description_of matcher}" + end + + def does_not_match?(actual) + @actual = actual + + return false unless iterable? + + index_objects + + succeeded_objects.empty? + end + + private + + def match(expected, actual) + @actual = actual + @expected = expected + + return false unless iterable? + + index_objects + + !succeeded_objects.empty? + end + + def index_objects + actual.each_with_index do |actual_item, index| + cloned_matcher = matcher.clone + begin + matches = cloned_matcher.matches?(actual_item) + rescue StandardError + matches = nil + end + + if matches + succeeded_objects[index] = cloned_matcher.failure_message + break + else + failed_objects[index] = cloned_matcher.failure_message + end + end + end + end + end +end + +module RSpec + module Matchers + # Passes if the provided matcher passes when checked against any + # element of the collection. + # + # @example + # expect([1, 4, 5]).to any be_odd + # + # @note The negative form `not_to any` is not supported. Instead + # use `not_to include` or pass a negative form of a matcher + # as the argument (e.g. `all exclude(:foo)` - mind it's `all` here). + # + # @note You can also use this with compound matchers as well. + # + # @example + # expect([1, 4, 'a']).to any( be_odd.and be_an(Integer) ) + def include_an_object(expected) + ::Aruba::Matchers::IncludeAnObject.new(expected) + end + end +end From 1d6a0ef4b4ae98dce14e6ec17485ce11a588e10d Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Tue, 21 Jul 2015 09:10:56 +0200 Subject: [PATCH 034/118] Reduced output if checking an started process, by redefining inspect and to_s for *Processes --- lib/aruba/processes/basic_process.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index aa8c90d76..56e4e15da 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -68,6 +68,16 @@ def before_run; end # Hook which is run after command is run def after_run; end + def inspect + out = if output.length > 76 + output[0, 75] + ' ...' + else + output + end + format '#<%s:%s commandline="%s": output="%s">', self.class, self.object_id, commandline, out + end + alias_method :to_s, :inspect + private def with_local_env(e, &block) From ac09f0bc364c95dcc9284bb5516f3fb0d006ce5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 09:19:31 +0200 Subject: [PATCH 035/118] Update history --- History.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/History.md b/History.md index 95b0cd07c..07dc4ee08 100644 --- a/History.md +++ b/History.md @@ -366,6 +366,8 @@ * First release (David Chelimsky and Aslak Hellesøy) +# Upcoming un-released versions + ## [v1.0.0](https://github.com/cucumber/aruba/compare/v0.11.0...v1.0.0) * Support for rubies older than 1.9.3 is discontinued - e.g 1.8.7 and 1.9.2 From cc13f8e74d80fe15644b44615a625a995e6673e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 10:54:46 +0200 Subject: [PATCH 036/118] Fixed bug with new run-method for commands --- lib/aruba/processes/debug_process.rb | 8 -------- lib/aruba/processes/in_process.rb | 3 ++- lib/aruba/processes/spawn_process.rb | 8 -------- 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/lib/aruba/processes/debug_process.rb b/lib/aruba/processes/debug_process.rb index 484d2c9da..d82b649e0 100644 --- a/lib/aruba/processes/debug_process.rb +++ b/lib/aruba/processes/debug_process.rb @@ -9,14 +9,6 @@ def self.match?(mode) mode == :debug || (mode.is_a?(Class) && mode <= DebugProcess) end - # @deprecated - # @private - def run! - Aruba::Platform.deprecated('The use of "command#run!" is deprecated. You can simply use "command#start" instead.') - - start - end - # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/CyclomaticComplexity def start diff --git a/lib/aruba/processes/in_process.rb b/lib/aruba/processes/in_process.rb index cb83a8fed..6bf0a679f 100644 --- a/lib/aruba/processes/in_process.rb +++ b/lib/aruba/processes/in_process.rb @@ -29,6 +29,7 @@ class << self attr_accessor :main_class end + # @private attr_reader :main_class def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil) @@ -42,7 +43,7 @@ def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV. super end - def run! + def start fail "You need to call aruba.config.main_class = YourMainClass" unless main_class Dir.chdir @working_directory do diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index cee5d727a..0ed0895bf 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -37,14 +37,6 @@ def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV. @error_cache = nil end - # @deprecated - # @private - def run! - Aruba::Platform.deprecated('The use of "command#run!" is deprecated. You can simply use "command#start" instead.') - - start - end - # Run the command # # @yield [SpawnProcess] From 955e6f7c4f6908d534fcb3a69088047ae0c3a2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 13:12:40 +0200 Subject: [PATCH 037/118] Split up cucumber.rb in multiple files --- lib/aruba/cucumber.rb | 601 +----------------------------- lib/aruba/cucumber/command.rb | 269 +++++++++++++ lib/aruba/cucumber/core.rb | 14 + lib/aruba/cucumber/environment.rb | 30 ++ lib/aruba/cucumber/file.rb | 195 ++++++++++ lib/aruba/cucumber/rvm.rb | 3 + 6 files changed, 516 insertions(+), 596 deletions(-) create mode 100644 lib/aruba/cucumber/command.rb create mode 100644 lib/aruba/cucumber/core.rb create mode 100644 lib/aruba/cucumber/environment.rb create mode 100644 lib/aruba/cucumber/file.rb create mode 100644 lib/aruba/cucumber/rvm.rb diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index c71a1ff5f..f6a74ecb7 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -4,600 +4,9 @@ World(Aruba::Api) require 'aruba/cucumber/hooks' +require 'aruba/cucumber/command' +require 'aruba/cucumber/core' +require 'aruba/cucumber/environment' +require 'aruba/cucumber/file' +require 'aruba/cucumber/rvm' require 'aruba/reporting' - -if Aruba::VERSION >= '1.0.0' - Aruba.configure do |config| - config.working_directory = 'tmp/cucumber' - end -end - -Given /the default aruba timeout is (\d+) seconds/ do |seconds| - aruba.config.exit_timeout = seconds.to_i -end - -Given /I use (?:a|the) fixture(?: named)? "([^"]*)"/ do |name| - copy File.join(aruba.config.fixtures_path_prefix, name), name - cd name -end - -Given /The default aruba timeout is (\d+) seconds/ do |seconds| - warn(%{\e[35m The /^The default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use the one with `the` and not `The` at the beginning.\e[0m}) - aruba.config.exit_timeout = seconds.to_i -end - -Given /^I'm using a clean gemset "([^"]*)"$/ do |gemset| - use_clean_gemset(gemset) -end - -Given /^(?:a|the) directory(?: named)? "([^"]*)"$/ do |dir_name| - create_directory(dir_name) -end - -Given /^(?:a|the) directory(?: named)? "([^"]*)" with mode "([^"]*)"$/ do |dir_name, dir_mode| - create_directory(dir_name) - chmod(dir_mode, dir_name) -end - -Given /^(?:a|the) file(?: named)? "([^"]*)" with:$/ do |file_name, file_content| - write_file(file_name, file_content) -end - -Given /^(?:an|the) executable(?: named)? "([^"]*)" with:$/ do |file_name, file_content| - step %(a file named "#{file_name}" with mode "0755" and with:), file_content -end - -Given /^(?:a|the) file(?: named)? "([^"]*)" with "([^"]*)"$/ do |file_name, file_content| - write_file(file_name, file_content) -end - -Given /^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/ do |file_name, file_mode, file_content| - write_file(file_name, file_content) - chmod(file_mode, file_name) -end - -Given /^(?:a|the) (\d+) byte file(?: named)? "([^"]*)"$/ do |file_size, file_name| - write_fixed_size_file(file_name, file_size.to_i) -end - -Given /^(?:an|the) empty file(?: named)? "([^"]*)"$/ do |file_name| - write_file(file_name, "") -end - -Given /^(?:an|the) empty file(?: named)? "([^"]*)" with mode "([^"]*)"$/ do |file_name, file_mode| - write_file(file_name, "") - chmod(file_mode, file_name) -end - -Given /^a mocked home directory$/ do - set_environment_variable 'HOME', expand_path('.') -end - -Given /^(?:a|the) directory(?: named)? "([^"]*)" does not exist$/ do |directory_name| - remove(directory_name, :force => true) -end - -When /^I write to "([^"]*)" with:$/ do |file_name, file_content| - write_file(file_name, file_content) -end - -When /^I overwrite "([^"]*)" with:$/ do |file_name, file_content| - overwrite_file(file_name, file_content) -end - -When /^I append to "([^"]*)" with:$/ do |file_name, file_content| - append_to_file(file_name, file_content) -end - -When /^I append to "([^"]*)" with "([^"]*)"$/ do |file_name, file_content| - append_to_file(file_name, file_content) -end - -When /^I remove (?:a|the) file(?: named)? "([^"]*)"$/ do |file_name| - remove(file_name) -end - -Given /^(?:a|the) file(?: named)? "([^"]*)" does not exist$/ do |file_name| - remove(file_name, :force => true) -end - -When(/^I remove (?:a|the) directory(?: named)? "(.*?)"$/) do |directory_name| - remove(directory_name) -end - -When /^I cd to "([^"]*)"$/ do |dir| - cd(dir) -end - -Given /^I set the environment variables? to:/ do |table| - table.hashes.each do |row| - variable = row['variable'].to_s.upcase - value = row['value'].to_s - - set_environment_variable(variable, value) - end -end - -Given /^I append the values? to the environment variables?:/ do |table| - table.hashes.each do |row| - variable = row['variable'].to_s.upcase - value = row['value'].to_s - - append_environment_variable(variable, value) - end -end - -Given /^I prepend the values? to the environment variables?:/ do |table| - table.hashes.each do |row| - variable = row['variable'].to_s.upcase - value = row['value'].to_s - - prepend_environment_variable(variable, value) - end -end - -When /^I run "(.*)"$/ do |cmd| - warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) - - cmd = unescape_text(cmd) - cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - run_simple(cmd, false) -end - -When /^I run `([^`]*)`$/ do |cmd| - cmd = unescape_text(cmd) - cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - run_simple(cmd, false) -end - -When /^I successfully run "(.*)"$/ do |cmd| - warn(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) - - cmd = unescape_text(cmd) - cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - run_simple(cmd) -end - -## I successfully run `echo -n "Hello"` -## I successfully run `sleep 29` for up to 30 seconds -When /^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/ do |cmd, secs| - cmd = unescape_text(cmd) - cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - run_simple(cmd, true, secs && secs.to_i) -end - -When /^I run "([^"]*)" interactively$/ do |cmd| - warn(%{\e[35m The /^I run "([^"]*)" interactively$/ step definition is deprecated. Please use the `backticks` version\e[0m}) - step %(I run `#{cmd}` interactively) -end - -When /^I run `([^`]*)` interactively$/ do |cmd| - cmd = unescape_text(cmd) - cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - @interactive = run(cmd) -end - -When /^I type "([^"]*)"$/ do |input| - type(unescape_text(input)) -end - -When /^I close the stdin stream$/ do - close_input -end - -When /^I pipe in (?:a|the) file(?: named)? "([^"]*)"$/ do |file| - pipe_in_file(file) - - close_input -end - -When /^I stop the command(?: started last)? if (output|stdout|stderr) contains:$/ do |channel, expected| - fail %(Invalid output channel "#{channel}" chosen. Please choose one of "output, stdout or stderr") unless %w(output stdout stderr).include? channel - - begin - Timeout.timeout(exit_timeout) do - loop do - output = if RUBY_VERSION < '1.9.3' - last_command_started.send channel.to_sym - else - last_command_started.public_send channel.to_sym - end - - if Aruba::Platform.unescape(output).include? Aruba::Platform.unescape(expected) - last_command_started.terminate - - break - end - - sleep 0.1 - end - end - rescue ChildProcess::TimeoutError, TimeoutError - last_command_started.terminate - ensure - announcer.announce :stdout, last_command_started.stdout - announcer.announce :stderr, last_command_started.stderr - end -end - -When /^I wait for (?:output|stdout) to contain:$/ do |expected| - Timeout.timeout(exit_timeout) do - loop do - begin - expect(last_command_started).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) - rescue ExpectationError - sleep 0.1 - retry - end - - break - end - end -end - -When /^I wait for (?:output|stdout) to contain "([^"]*)"$/ do |expected| - Timeout.timeout(exit_timeout) do - loop do - begin - expect(last_command_started).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) - rescue ExpectationError - sleep 0.1 - retry - end - - break - end - end -end - -Then /^the output should be (\d+) bytes long$/ do |size| - expect(all_output).to have_output_size size.to_i -end - -Then /^the output(?: from "([^"]*)")? should( not)? contain "([^"]*)"$/ do |cmd, negated, expected| - commands = if cmd - [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] - else - all_commands - end - - if negated - expect(commands).not_to include_an_object have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) - else - expect(commands).to include_an_object have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) - end -end - -Then /^the output(?: from "([^"]*)")? should( not)? contain:$/ do |cmd, negated, expected| - commands = if cmd - [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] - else - all_commands - end - - if negated - expect(commands).not_to include_an_object have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) - else - expect(commands).to include_an_object have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) - end -end - -## the output should contain exactly "output" -## the output from `echo -n "Hello"` should contain exactly "Hello" -Then /^the output(?: from "(.*?)")? should( not)? contain exactly "(.*?)"$/ do |cmd, negated, expected| - commands = if cmd - [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] - else - all_commands - end - - if negated - expect(commands).not_to include_an_object have_output Aruba::Platform.unescape(expected) - else - expect(commands).to include_an_object have_output Aruba::Platform.unescape(expected) - end -end - -## the output should contain exactly: -## the output from `echo -n "Hello"` should contain exactly: -Then /^the output(?: from "(.*?)")? should( not)? contain exactly:$/ do |cmd, negated, expected| - commands = if cmd - [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] - else - all_commands - end - - if negated - expect(commands).not_to include_an_object have_output Aruba::Platform.unescape(expected) - else - expect(commands).to include_an_object have_output Aruba::Platform.unescape(expected) - end -end - -# "the output should match" allows regex in the partial_output, if -# you don't need regex, use "the output should contain" instead since -# that way, you don't have to escape regex characters that -# appear naturally in the output -Then /^the output should( not)? match \/([^\/]*)\/$/ do |negated, expected| - if negated - expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) - else - expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) - end -end - -Then /^the output should( not)? match %r<([^>]*)>$/ do |negated, expected| - if negated - expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) - else - expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) - end -end - -Then /^the output should( not)? match:$/ do |negated, expected| - if negated - expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) - else - expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) - end -end - -Then /^the exit (?:status|code) should( not)? be (\d+)$/ do |negated, exit_status| - if negated - expect(last_command_stopped).not_to have_exit_status exit_status.to_i - else - expect(last_command_stopped).to have_exit_status exit_status.to_i - end -end - -Then /^it should (pass|fail) with "(.*?)"$/ do |pass_fail, expected| - if pass_fail == 'pass' - expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) - else - expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) - end -end - -Then /^it should (pass|fail) with:$/ do |pass_fail, expected| - if pass_fail == 'pass' - expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) - else - expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) - end -end - -Then /^it should (pass|fail) with exactly:$/ do |pass_fail, expected| - if pass_fail == 'pass' - expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Aruba::Platform.unescape(expected) - else - expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Aruba::Platform.unescape(expected) - end -end - -Then /^it should (pass|fail) with regexp?:$/ do |pass_fail, expected| - if pass_fail == 'pass' - expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(expected, Regexp::MULTILINE) - else - expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(expected, Regexp::MULTILINE) - end -end - -## the stderr should contain "hello" -## the stderr from "echo -n 'Hello'" should contain "hello" -## the stderr should contain exactly: -## the stderr from "echo -n 'Hello'" should contain exactly: -Then /^the stderr(?: from "(.*?)")? should contain( exactly)? "(.*?)"$/ do |cmd, exact, expected| - if exact - assert_exact_output(expected, cmd ? stderr_from(cmd) : all_stderr) - else - assert_partial_output(expected, cmd ? stderr_from(cmd) : all_stderr) - end -end - -## the stderr should contain: -## the stderr from "echo -n 'Hello'" should contain: -## the stderr should contain exactly: -## the stderr from "echo -n 'Hello'" should contain exactly: -Then /^the stderr(?: from "(.*?)")? should contain( exactly)?:$/ do |cmd, exact, expected| - if exact - assert_exact_output(expected, cmd ? stderr_from(cmd) : all_stderr) - else - assert_partial_output(expected, cmd ? stderr_from(cmd) : all_stderr) - end -end - -## the stdout should contain "hello" -## the stdout from "echo -n 'Hello'" should contain "hello" -## the stdout should contain exactly: -## the stdout from "echo -n 'Hello'" should contain exactly: -Then /^the stdout(?: from "(.*?)")? should contain( exactly)? "(.*?)"$/ do |cmd, exact, expected| - if exact - assert_exact_output(expected, cmd ? stdout_from(cmd) : all_stdout) - else - assert_partial_output(expected, cmd ? stdout_from(cmd) : all_stdout) - end -end - -## the stdout should contain: -## the stdout from "echo -n 'Hello'" should contain: -## the stdout should contain exactly: -## the stdout from "echo -n 'Hello'" should contain exactly: -Then /^the stdout(?: from "(.*?)")? should contain( exactly)?:$/ do |cmd, exact, expected| - if exact - assert_exact_output(expected, cmd ? stdout_from(cmd) : all_stdout) - else - assert_partial_output(expected, cmd ? stdout_from(cmd) : all_stdout) - end -end - -Then /^the stderr should not contain "([^"]*)"$/ do |unexpected| - assert_no_partial_output(unexpected, all_stderr) -end - -Then /^the stderr should not contain:$/ do |unexpected| - assert_no_partial_output(unexpected, all_stderr) -end - -Then /^the (stderr|stdout) should not contain anything$/ do |stream_name| - stream = self.send("all_#{stream_name}") - expect(stream).to be_empty -end - -Then /^the stdout should not contain "([^"]*)"$/ do |unexpected| - assert_no_partial_output(unexpected, all_stdout) -end - -Then /^the stdout should not contain:$/ do |unexpected| - assert_no_partial_output(unexpected, all_stdout) -end - -Then /^the stdout from "([^"]*)" should not contain "([^"]*)"$/ do |cmd, unexpected| - assert_no_partial_output(unexpected, stdout_from(cmd)) -end - -Then /^the stderr from "([^"]*)" should not contain "([^"]*)"$/ do |cmd, unexpected| - assert_no_partial_output(unexpected, stderr_from(cmd)) -end - -Then /^the following files should (not )?exist:$/ do |negated, files| - files = files.rows.flatten - - if negated - expect(files).not_to include an_existing_file - else - expect(files).to all be_an_existing_file - end -end - -Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?exist$/ do |file, expect_match| - if expect_match - expect(file).not_to be_an_existing_file - else - expect(file).to be_an_existing_file - end -end - -Then /^(?:a|the) file matching %r<(.*?)> should (not )?exist$/ do |pattern, expect_match| - if expect_match - expect(all_paths).not_to include match Regexp.new(pattern) - else - expect(all_paths).to include match Regexp.new(pattern) - end -end - -Then /^(?:a|the) (\d+) byte file(?: named)? "([^"]*)" should (not )?exist$/ do |size, file, negated| - if negated - expect(file).not_to have_file_size(size) - else - expect(file).to have_file_size(size) - end -end - -Then /^the following directories should (not )?exist:$/ do |negated, directories| - directories = directories.rows.flatten - - if negated - expect(directories).not_to include an_existing_directory - else - expect(directories).to all be_an_existing_directory - end -end - -Then /^(?:a|the) directory(?: named)? "([^"]*)" should (not )?exist$/ do |directory, negated| - if negated - expect(directory).not_to be_an_existing_directory - else - expect(directory).to be_an_existing_directory - end -end - -Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain "([^"]*)"$/ do |file, negated, content| - if negated - expect(file).not_to have_file_content Regexp.new(Regexp.escape(content)) - else - expect(file).to have_file_content Regexp.new(Regexp.escape(content)) - end -end - -Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain:$/ do |file, negated, content| - if negated - expect(file).not_to have_file_content Regexp.new(Regexp.escape(content.chomp)) - else - expect(file).to have_file_content Regexp.new(Regexp.escape(content.chomp)) - end -end - -Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain exactly:$/ do |file, negated, content| - if negated - expect(file).not_to have_file_content content - else - expect(file).to have_file_content content - end -end - -Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?match %r<([^\/]*)>$/ do |file, negated, content| - if negated - expect(file).not_to have_file_content Regexp.new(content) - else - expect(file).to have_file_content Regexp.new(content) - end -end - -Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?match \/([^\/]*)\/$/ do |file, negated, content| - if negated - expect(file).not_to have_file_content Regexp.new(content) - else - expect(file).to have_file_content Regexp.new(content) - end -end - -Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?be equal to file "([^"]*)"/ do |file, negated, reference_file| - if negated - expect(file).not_to have_same_file_content_like(reference_file) - else - expect(file).to have_same_file_content_like(reference_file) - end -end - -Then /^the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)"$/ do |file, negated, permissions| - if negated - expect(file).not_to have_permissions(permissions) - else - expect(file).to have_permissions(permissions) - end -end - -Then /^the (?:file|directory)(?: named)? "([^"]*)" should have permissions "([^"]*)"$/ do |path, negated, permissions| - if negated - expect(path).not_to have_permissions(permissions) - else - expect(path).to have_permissions(permissions) - end -end - -Then /^(?:the )?(output|stdout|stderr) should contain all of these:$/ do |channel, table| - table.raw.flatten.each do |string| - if channel == 'output' - expect(all_commands).to include_an_object have_output Regexp.new(Regexp.escape(string)) - elsif channel == 'stdout' - expect(all_commands).to include_an_object have_output_on_stdout Regexp.new(Regexp.escape(string)) - elsif channel == 'stderr' - expect(all_commands).to include_an_object have_output_on_stderr Regexp.new(Regexp.escape(string)) - else - fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stdout" and "stderr" are supported.) - end - end -end diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb new file mode 100644 index 000000000..53cf8ef59 --- /dev/null +++ b/lib/aruba/cucumber/command.rb @@ -0,0 +1,269 @@ +When(/^I run "(.*)"$/) do |cmd| + warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), false) +end + +When(/^I run `([^`]*)`$/) do |cmd| + run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), false) +end + +When(/^I successfully run "(.*)"$/) do |cmd| + warn(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi)) +end + +## I successfully run `echo -n "Hello"` +## I successfully run `sleep 29` for up to 30 seconds +When(/^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/) do |cmd, secs| + run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), true, secs && secs.to_i) +end + +When(/^I run "([^"]*)" interactively$/) do |cmd| + warn(%{\e[35m The /^I run "([^"]*)" interactively$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + step %(I run `#{cmd}` interactively) +end + +When(/^I run `([^`]*)` interactively$/) do |cmd| + @interactive = run(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi)) +end + +When(/^I type "([^"]*)"$/) do |input| + type(unescape_text(input)) +end + +When(/^I close the stdin stream$/) do + close_input +end + +When(/^I pipe in (?:a|the) file(?: named)? "([^"]*)"$/) do |file| + pipe_in_file(file) + + close_input +end + +When(/^I stop the command(?: started last)? if (output|stdout|stderr) contains:$/) do |channel, expected| + fail %(Invalid output channel "#{channel}" chosen. Please choose one of "output, stdout or stderr") unless %w(output stdout stderr).include? channel + + begin + Timeout.timeout(exit_timeout) do + loop do + output = if RUBY_VERSION < '1.9.3' + last_command_started.send channel.to_sym + else + last_command_started.public_send channel.to_sym + end + + if Aruba::Platform.unescape(output).include? Aruba::Platform.unescape(expected) + last_command_started.terminate + + break + end + + sleep 0.1 + end + end + rescue ChildProcess::TimeoutError, TimeoutError + last_command_started.terminate + ensure + announcer.announce :stdout, last_command_started.stdout + announcer.announce :stderr, last_command_started.stderr + end +end + +When(/^I wait for (?:output|stdout) to contain:$/) do |expected| + Timeout.timeout(exit_timeout) do + loop do + begin + expect(last_command_started).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) + rescue ExpectationError + sleep 0.1 + retry + end + + break + end + end +end + +When(/^I wait for (?:output|stdout) to contain "([^"]*)"$/) do |expected| + Timeout.timeout(exit_timeout) do + loop do + begin + expect(last_command_started).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) + rescue ExpectationError + sleep 0.1 + retry + end + + break + end + end +end + +Then(/^the output should be (\d+) bytes long$/) do |size| + expect(all_output).to have_output_size size.to_i +end + +Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain( exactly)? "([^"]*)"$/) do |channel, cmd, negated, exactly, expected| + matcher = case channel.to_sym + when :output + :have_output + when :stderr + :have_output_on_stderr + when :stdout + :have_output_on_stdout + end + + commands = if cmd + [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] + else + all_commands + end + + expected = if exactly + Aruba::Platform.unescape(expected) + else + Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + end + + if negated + expect(commands).not_to include_an_object send(matcher, expected) + else + expect(commands).to include_an_object send(matcher, expected) + end +end + +## the stderr should contain "hello" +## the stderr from "echo -n 'Hello'" should contain "hello" +## the stderr should contain exactly: +## the stderr from "echo -n 'Hello'" should contain exactly: +Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain( exactly)?:$/) do |channel, cmd, negated, exactly, expected| + matcher = case channel.to_sym + when :output + :have_output + when :stderr + :have_output_on_stderr + when :stdout + :have_output_on_stdout + end + + commands = if cmd + [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] + else + all_commands + end + + expected = if exactly + Aruba::Platform.unescape(expected) + else + Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + end + + if negated + expect(commands).not_to include_an_object send(matcher, expected) + else + expect(commands).to include_an_object send(matcher, expected) + end +end + +# "the output should match" allows regex in the partial_output, if +# you don't need regex, use "the output should contain" instead since +# that way, you don't have to escape regex characters that +# appear naturally in the output +Then(/^the output should( not)? match \/([^\/]*)\/$/) do |negated, expected| + if negated + expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) + else + expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) + end +end + +Then(/^the output should( not)? match %r<([^>]*)>$/) do |negated, expected| + if negated + expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) + else + expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) + end +end + +Then(/^the output should( not)? match:$/) do |negated, expected| + if negated + expect(all_commands).not_to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) + else + expect(all_commands).to include_an_object have_output Regexp.new(expected, Regexp::MULTILINE) + end +end + +Then(/^the exit status should( not)? be (\d+)$/) do |negated, exit_status| + if negated + expect(last_command_stopped).not_to have_exit_status exit_status.to_i + else + expect(last_command_stopped).to have_exit_status exit_status.to_i + end +end + +Then(/^it should (pass|fail) with "(.*?)"$/) do |pass_fail, expected| + if pass_fail == 'pass' + expect(last_command_stopped).to be_successfully_executed + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + else + expect(last_command_stopped).not_to be_successfully_executed + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + end +end + +Then(/^it should (pass|fail) with:$/) do |pass_fail, expected| + if pass_fail == 'pass' + expect(last_command_stopped).to be_successfully_executed + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + else + expect(last_command_stopped).not_to be_successfully_executed + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + end +end + +Then(/^it should (pass|fail) with exactly:$/) do |pass_fail, expected| + if pass_fail == 'pass' + expect(last_command_stopped).to be_successfully_executed + expect(last_command_stopped).to have_output Aruba::Platform.unescape(expected) + else + expect(last_command_stopped).not_to be_successfully_executed + expect(last_command_stopped).to have_output Aruba::Platform.unescape(expected) + end +end + +Then(/^it should (pass|fail) with regexp?:$/) do |pass_fail, expected| + if pass_fail == 'pass' + expect(last_command_stopped).to be_successfully_executed + expect(last_command_stopped).to have_output Regexp.new(expected, Regexp::MULTILINE) + else + expect(last_command_stopped).not_to be_successfully_executed + expect(last_command_stopped).to have_output Regexp.new(expected, Regexp::MULTILINE) + end +end + +Then(/^(?:the )?(output|stderr|stdout) should not contain anything$/) do |channel| + matcher = case channel.to_sym + when :output + :have_output + when :stderr + :have_output_on_stderr + when :stdout + :have_output_on_stderr + end + expect(all_commands).to all send(matcher, be_nil.or(be_empty)) +end + +Then(/^(?:the )?(output|stdout|stderr) should contain all of these lines:$/) do |channel, table| + table.raw.flatten.each do |string| + if channel == 'output' + expect(all_commands).to include_an_object have_output Regexp.new(Regexp.escape(string)) + elsif channel == 'stdout' + expect(all_commands).to include_an_object have_output_on_stdout Regexp.new(Regexp.escape(string)) + elsif channel == 'stderr' + expect(all_commands).to include_an_object have_output_on_stderr Regexp.new(Regexp.escape(string)) + else + fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stdout" and "stderr" are supported.) + end + end +end diff --git a/lib/aruba/cucumber/core.rb b/lib/aruba/cucumber/core.rb new file mode 100644 index 000000000..d0d89e06d --- /dev/null +++ b/lib/aruba/cucumber/core.rb @@ -0,0 +1,14 @@ +if Aruba::VERSION >= '1.0.0' + Aruba.configure do |config| + config.working_directory = 'tmp/cucumber' + end +end + +Given(/the default aruba timeout is (\d+) seconds/) do |seconds| + aruba.config.exit_timeout = seconds.to_i +end + +Given(/The default aruba timeout is (\d+) seconds/) do |seconds| + warn(%{\e[35m The /^The default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use the one with `the` and not `The` at the beginning.\e[0m}) + aruba.config.exit_timeout = seconds.to_i +end diff --git a/lib/aruba/cucumber/environment.rb b/lib/aruba/cucumber/environment.rb new file mode 100644 index 000000000..ba6c71db7 --- /dev/null +++ b/lib/aruba/cucumber/environment.rb @@ -0,0 +1,30 @@ +Given(/^a mocked home directory$/)do + set_environment_variable 'HOME', expand_path('.') +end + +Given(/^I set the environment variables? to:/) do |table| + table.hashes.each do |row| + variable = row['variable'].to_s.upcase + value = row['value'].to_s + + set_environment_variable(variable, value) + end +end + +Given(/^I append the values? to the environment variables?:/) do |table| + table.hashes.each do |row| + variable = row['variable'].to_s.upcase + value = row['value'].to_s + + append_environment_variable(variable, value) + end +end + +Given(/^I prepend the values? to the environment variables?:/) do |table| + table.hashes.each do |row| + variable = row['variable'].to_s.upcase + value = row['value'].to_s + + prepend_environment_variable(variable, value) + end +end diff --git a/lib/aruba/cucumber/file.rb b/lib/aruba/cucumber/file.rb new file mode 100644 index 000000000..6f4597345 --- /dev/null +++ b/lib/aruba/cucumber/file.rb @@ -0,0 +1,195 @@ +Given(/I use (?:a|the) fixture(?: named)? "([^"]*)"/) do |name| + copy File.join(aruba.config.fixtures_path_prefix, name), name + cd name +end + +Given(/^(?:a|the) directory(?: named)? "([^"]*)"$/) do |dir_name| + create_directory(dir_name) +end + +Given(/^(?:a|the) directory(?: named)? "([^"]*)" with mode "([^"]*)"$/) do |dir_name, dir_mode| + create_directory(dir_name) + chmod(dir_mode, dir_name) +end + +Given(/^(?:a|the) file(?: named)? "([^"]*)" with:$/) do |file_name, file_content| + write_file(file_name, file_content) +end + +Given(/^(?:an|the) executable(?: named)? "([^"]*)" with:$/) do |file_name, file_content| + step %(a file named "#{file_name}" with mode "0755" and with:), file_content +end + +Given(/^(?:a|the) file(?: named)? "([^"]*)" with "([^"]*)"$/) do |file_name, file_content| + write_file(file_name, file_content) +end + +Given(/^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/) do |file_name, file_mode, file_content| + write_file(file_name, file_content) + chmod(file_mode, file_name) +end + +Given(/^(?:a|the) (\d+) byte file(?: named)? "([^"]*)"$/) do |file_size, file_name| + write_fixed_size_file(file_name, file_size.to_i) +end + +Given(/^(?:an|the) empty file(?: named)? "([^"]*)"$/) do |file_name| + write_file(file_name, "") +end + +Given(/^(?:an|the) empty file(?: named)? "([^"]*)" with mode "([^"]*)"$/) do |file_name, file_mode| + write_file(file_name, "") + chmod(file_mode, file_name) +end + +Given(/^(?:a|the) directory(?: named)? "([^"]*)" does not exist$/) do |directory_name| + remove(directory_name, :force => true) +end + +When(/^I write to "([^"]*)" with:$/) do |file_name, file_content| + write_file(file_name, file_content) +end + +When(/^I overwrite "([^"]*)" with:$/) do |file_name, file_content| + overwrite_file(file_name, file_content) +end + +When(/^I append to "([^"]*)" with:$/) do |file_name, file_content| + append_to_file(file_name, file_content) +end + +When(/^I append to "([^"]*)" with "([^"]*)"$/) do |file_name, file_content| + append_to_file(file_name, file_content) +end + +When(/^I remove (?:a|the) file(?: named)? "([^"]*)"$/) do |file_name| + remove(file_name) +end + +Given(/^(?:a|the) file(?: named)? "([^"]*)" does not exist$/) do |file_name| + remove(file_name, :force => true) +end + +When(/^I remove (?:a|the) directory(?: named)? "(.*?)"$/) do |directory_name| + remove(directory_name) +end + +When(/^I cd to "([^"]*)"$/) do |dir| + cd(dir) +end + +Then(/^the following files should (not )?exist:$/) do |negated, files| + files = files.rows.flatten + + if negated + expect(files).not_to include an_existing_file + else + expect(files).to all be_an_existing_file + end +end + +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?exist$/) do |file, expect_match| + if expect_match + expect(file).not_to be_an_existing_file + else + expect(file).to be_an_existing_file + end +end + +Then(/^(?:a|the) file matching %r<(.*?)> should (not )?exist$/) do |pattern, expect_match| + if expect_match + expect(all_paths).not_to include match Regexp.new(pattern) + else + expect(all_paths).to include match Regexp.new(pattern) + end +end + +Then(/^(?:a|the) (\d+) byte file(?: named)? "([^"]*)" should (not )?exist$/) do |size, file, negated| + if negated + expect(file).not_to have_file_size(size) + else + expect(file).to have_file_size(size) + end +end + +Then(/^the following directories should (not )?exist:$/) do |negated, directories| + directories = directories.rows.flatten + + if negated + expect(directories).not_to include an_existing_directory + else + expect(directories).to all be_an_existing_directory + end +end + +Then(/^(?:a|the) directory(?: named)? "([^"]*)" should (not )?exist$/) do |directory, negated| + if negated + expect(directory).not_to be_an_existing_directory + else + expect(directory).to be_an_existing_directory + end +end + +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain "([^"]*)"$/) do |file, negated, content| + if negated + expect(file).not_to have_file_content Regexp.new(Regexp.escape(content)) + else + expect(file).to have_file_content Regexp.new(Regexp.escape(content)) + end +end + +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain:$/) do |file, negated, content| + if negated + expect(file).not_to have_file_content Regexp.new(Regexp.escape(content.chomp)) + else + expect(file).to have_file_content Regexp.new(Regexp.escape(content.chomp)) + end +end + +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain exactly:$/) do |file, negated, content| + if negated + expect(file).not_to have_file_content content + else + expect(file).to have_file_content content + end +end + +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?match %r<([^\/]*)>$/) do |file, negated, content| + if negated + expect(file).not_to have_file_content Regexp.new(content) + else + expect(file).to have_file_content Regexp.new(content) + end +end + +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?match \/([^\/]*)\/$/) do |file, negated, content| + if negated + expect(file).not_to have_file_content Regexp.new(content) + else + expect(file).to have_file_content Regexp.new(content) + end +end + +Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?be equal to file "([^"]*)"/) do |file, negated, reference_file| + if negated + expect(file).not_to have_same_file_content_like(reference_file) + else + expect(file).to have_same_file_content_like(reference_file) + end +end + +Then(/^the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)"$/) do |file, negated, permissions| + if negated + expect(file).not_to have_permissions(permissions) + else + expect(file).to have_permissions(permissions) + end +end + +Then(/^the (?:file|directory)(?: named)? "([^"]*)" should have permissions "([^"]*)"$/) do |path, negated, permissions| + if negated + expect(path).not_to have_permissions(permissions) + else + expect(path).to have_permissions(permissions) + end +end diff --git a/lib/aruba/cucumber/rvm.rb b/lib/aruba/cucumber/rvm.rb new file mode 100644 index 000000000..8121ce9d5 --- /dev/null +++ b/lib/aruba/cucumber/rvm.rb @@ -0,0 +1,3 @@ +Given(/^I'm using a clean gemset "([^"]*)"$/) do |gemset| + use_clean_gemset(gemset) +end From 877c9f55ea50a38c057e04e06c3ff8cd67af9cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 13:14:18 +0200 Subject: [PATCH 038/118] Refactor internals of SpawnProcess --- lib/aruba/processes/spawn_process.rb | 36 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 0ed0895bf..5f23153cc 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -33,8 +33,8 @@ def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV. @exit_timeout = exit_timeout @io_wait = io_wait @process = nil - @output_cache = nil - @error_cache = nil + @stdout_cache = nil + @stderr_cache = nil end # Run the command @@ -48,15 +48,15 @@ def start cmd = Aruba.platform.command_string.new(command) @process = ChildProcess.build(*[cmd.to_a, arguments].flatten) - @out = Tempfile.new("aruba-out") - @err = Tempfile.new("aruba-err") + @stdout_file = Tempfile.new("aruba-stdout") + @stderr_file = Tempfile.new("aruba-stderr") @exit_status = nil - @duplex = true + @duplex = true before_run - @process.io.stdout = @out - @process.io.stderr = @err + @process.io.stdout = @stdout_file + @process.io.stderr = @stderr_file @process.duplex = @duplex @process.cwd = @working_directory @@ -84,24 +84,24 @@ def stdin end def stdout(opts = {}) - return @output_cache if @process.nil? + return @stdout_cache if @process.nil? wait_for_io = opts.fetch(:wait_for_io, @io_wait) wait_for_io wait_for_io do @process.io.stdout.flush - open(@out).read + open(@stdout_file).read end end def stderr(opts = {}) - return @error_cache if @process.nil? + return @stderr_cache if @process.nil? wait_for_io = opts.fetch(:wait_for_io, @io_wait) wait_for_io wait_for_io do @process.io.stderr.flush - open(@err).read + open(@stderr_file).read end end @@ -110,7 +110,7 @@ def read_stdout Aruba::Platform.deprecated('The use of "#read_stdout" is deprecated. Use "#stdout" instead. To reduce the time to wait for io, pass `:wait_for_io => 0` or some suitable for your use case') # rubocop:enable Metrics/LineLength - stdout + stdout(:wait_for_io => 0) end def write(input) @@ -181,15 +181,15 @@ def read(io) end def close_and_cache_out - @output_cache = read @out - @out.close - @out = nil + @stdout_cache = read @stdout_file + @stdout_file.close + @stdout_file = nil end def close_and_cache_err - @error_cache = read @err - @err.close - @err = nil + @stderr_cache = read @stderr_file + @stderr_file.close + @stderr_file = nil end end end From 274b33264abeb2eea41b4778a4b35bc2cffe01c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 13:17:17 +0200 Subject: [PATCH 039/118] Use wait_for_io to reduce the waiting time --- lib/aruba/processes/basic_process.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index 56e4e15da..4ba855f0a 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -69,11 +69,14 @@ def before_run; end def after_run; end def inspect - out = if output.length > 76 - output[0, 75] + ' ...' + out = stdout(:wait_for_io => 0) + stderr(:wait_for_io => 0) + + out = if out.length > 76 + out[0, 75] + ' ...' else - output + out end + format '#<%s:%s commandline="%s": output="%s">', self.class, self.object_id, commandline, out end alias_method :to_s, :inspect From 3fc75242af9c1bd5ac330195655c0d70a5a28ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 13:21:28 +0200 Subject: [PATCH 040/118] Add some documentation for SpawnProcess --- lib/aruba/processes/spawn_process.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 5f23153cc..cbb2caf96 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -77,12 +77,23 @@ def start # rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/CyclomaticComplexity + # Access to stdout of process def stdin return if @process.nil? @process.io.stdin end + # Access to stdout of process + # + # @param [Hash] opts + # Options + # + # @option [Integer] wait_for_io + # Wait for IO to be finished + # + # @return [String] + # The content of stdout def stdout(opts = {}) return @stdout_cache if @process.nil? @@ -94,6 +105,16 @@ def stdout(opts = {}) end end + # Access to stderr of process + # + # @param [Hash] opts + # Options + # + # @option [Integer] wait_for_io + # Wait for IO to be finished + # + # @return [String] + # The content of stderr def stderr(opts = {}) return @stderr_cache if @process.nil? From 6cfe60968c0b7745fab49b044254e0ddfb4747f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 15:29:45 +0200 Subject: [PATCH 041/118] Updated history --- History.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/History.md b/History.md index 07dc4ee08..5d5bfbaf2 100644 --- a/History.md +++ b/History.md @@ -397,3 +397,27 @@ * Use different working directories based on test suite - RSpec, Cucumber. It's `tmp/rspec` and `tmp/cucumber` now to make sure they do not overwrite the test results from each other. +* The use of `@interactive` is discontinued. You need to use + `#last_command_started`-method to get access to the interactively started + command. +* If multiple commands have been started, each output has to be check + separately + + ```cucumber + Scenario: Detect stdout from all processes + When I run `printf "hello world!\n"` + And I run `cat` interactively + And I type "hola" + And I type "" + Then the stdout should contain: + """ + hello world! + """ + And the stdout should contain: + """ + hola + """ + And the stderr should not contain anything + ``` + + From cb9b2866c35542a06df9c3aa562bc90ee71cb9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 15:30:47 +0200 Subject: [PATCH 042/118] Improved features and steps --- features/commands/output/all_output.feature | 36 ++++++++++++++ .../collection/include_an_object.feature | 4 +- features/output.feature | 29 +++++++++--- lib/aruba/cucumber/command.rb | 47 ++++++++++++++----- lib/aruba/cucumber/core.rb | 17 ++++++- lib/aruba/matchers/command/have_output.rb | 1 - .../matchers/command/have_output_on_stderr.rb | 17 +++++-- .../matchers/command/have_output_on_stdout.rb | 17 +++++-- 8 files changed, 140 insertions(+), 28 deletions(-) diff --git a/features/commands/output/all_output.feature b/features/commands/output/all_output.feature index 0cc20f6f5..d35783809 100644 --- a/features/commands/output/all_output.feature +++ b/features/commands/output/all_output.feature @@ -434,8 +434,44 @@ Feature: All output of commands which were executed Then the stdout should contain exactly: \"\"\" This is cli1 + \"\"\" + And the stdout should contain exactly: + \"\"\" This is cli2 + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Detect output from all processes (deprecated) + Given an executable named "bin/cli1" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + + puts 'This is cli1' + """ + And an executable named "bin/cli2" with: + """ + #!/usr/bin/env ruby + + $LOAD_PATH << File.expand_path('../../lib', __FILE__) + require 'cli/app' + puts 'This is cli2' + """ + And a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `cli1` + When I run `cli2` + Then the stdout should contain exactly: + \"\"\" + This is cli1 + This is cli2 \"\"\" """ When I run `cucumber` diff --git a/features/matchers/collection/include_an_object.feature b/features/matchers/collection/include_an_object.feature index 74eb4626c..b61cfbb37 100644 --- a/features/matchers/collection/include_an_object.feature +++ b/features/matchers/collection/include_an_object.feature @@ -38,7 +38,7 @@ Feature: `include_an_object` Matcher end """ When I run `rspec` - Then the output should contain all of these: + Then the output should contain all of these lines: | 8 examples, 4 failures | | expected [14, "a"] to include an object be odd | | expected [14, "a"] to include an object be a kind of Symbol | @@ -65,7 +65,7 @@ Feature: `include_an_object` Matcher end """ When I run `rspec` - Then the output should contain all of these: + Then the output should contain all of these lines: | 8 examples, 4 failures | | expected ["anything", "something"] to include an object be a kind of Integer and include "thing" | | expected ["anything", "something"] to include an object be a kind of Integer and end with "z" | diff --git a/features/output.feature b/features/output.feature index d2169a17c..5ea604168 100644 --- a/features/output.feature +++ b/features/output.feature @@ -8,7 +8,6 @@ Feature: All output of commands which were executed Given I use a fixture named "cli-app" @wip - @debug Scenario: Detect output from all processes normal and interactive ones Given an executable named "bin/cli1" with: """ @@ -43,7 +42,6 @@ Feature: All output of commands which were executed \"\"\" This is cli1 This is cli2 - \"\"\" """ When I run `cucumber` @@ -57,8 +55,10 @@ Feature: All output of commands which were executed Then the stdout should contain: """ hello world! + """ + And the stdout should contain: + """ hola - """ And the stderr should not contain anything @@ -68,10 +68,25 @@ Feature: All output of commands which were executed And I type "hola" And I type "" Then the stderr should contain: - """ - hello world! - hola - """ + """ + hello world! + """ + And the stderr should contain: + """ + hola + """ + And the stdout should not contain anything + + Scenario: Detect stderr from all processes (deprecated) + When I run `bash -c 'printf "hello world!\n" >&2'` + And I run `bash -c 'cat >&2 '` interactively + And I type "hola" + And I type "" + Then the stderr should contain: + """ + hello world! + hola + """ And the stdout should not contain anything Scenario: Detect output from named source diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index 53cf8ef59..9ad9b1cc3 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -1,5 +1,5 @@ When(/^I run "(.*)"$/) do |cmd| - warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + Aruba::Platform.deprecated(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), false) end @@ -8,7 +8,8 @@ end When(/^I successfully run "(.*)"$/) do |cmd| - warn(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + Aruba::Platform.deprecated(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi)) end @@ -19,7 +20,8 @@ end When(/^I run "([^"]*)" interactively$/) do |cmd| - warn(%{\e[35m The /^I run "([^"]*)" interactively$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + Aruba::Platform.deprecated(%{\e[35m The /^I run "([^"]*)" interactively$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + step %(I run `#{cmd}` interactively) end @@ -126,10 +128,20 @@ Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end - if negated - expect(commands).not_to include_an_object send(matcher, expected) + if Aruba::VERSION < '1.0' + combined_output = commands.map { |c| c.send(channel.to_sym).chomp }.join("\n") + + if negated + expect(combined_output).not_to match expected + else + expect(combined_output).to match expected + end else - expect(commands).to include_an_object send(matcher, expected) + if negated + expect(commands).not_to include_an_object send(matcher, expected) + else + expect(commands).to include_an_object send(matcher, expected) + end end end @@ -145,6 +157,8 @@ :have_output_on_stderr when :stdout :have_output_on_stdout + else + fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stderr" or "stdout" are allowed.) end commands = if cmd @@ -159,10 +173,20 @@ Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) end - if negated - expect(commands).not_to include_an_object send(matcher, expected) + if Aruba::VERSION < '1.0' + combined_output = commands.map { |c| c.send(channel.to_sym).chomp }.join("\n") + + if negated + expect(combined_output).not_to match expected + else + expect(combined_output).to match expected + end else - expect(commands).to include_an_object send(matcher, expected) + if negated + expect(commands).not_to include_an_object send(matcher, expected) + else + expect(commands).to include_an_object send(matcher, expected) + end end end @@ -249,9 +273,10 @@ when :stderr :have_output_on_stderr when :stdout - :have_output_on_stderr + :have_output_on_stdout end - expect(all_commands).to all send(matcher, be_nil.or(be_empty)) + + expect(all_commands).to include_an_object send(matcher, be_nil.or(be_empty)) end Then(/^(?:the )?(output|stdout|stderr) should contain all of these lines:$/) do |channel, table| diff --git a/lib/aruba/cucumber/core.rb b/lib/aruba/cucumber/core.rb index d0d89e06d..4f7a3c633 100644 --- a/lib/aruba/cucumber/core.rb +++ b/lib/aruba/cucumber/core.rb @@ -5,10 +5,25 @@ end Given(/the default aruba timeout is (\d+) seconds/) do |seconds| + # rubocop:disable Metrics/LineLength + Aruba::Platform.deprecated(%{The /^the default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use /^the default aruba exit timeout is (\d+) seconds/ step definition is deprecated.}) + # rubocop:enable Metrics/LineLength + aruba.config.exit_timeout = seconds.to_i end Given(/The default aruba timeout is (\d+) seconds/) do |seconds| - warn(%{\e[35m The /^The default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use the one with `the` and not `The` at the beginning.\e[0m}) + # rubocop:disable Metrics/LineLength + Aruba::Platform.deprecated(%{The /^The default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use /^the default aruba exit timeout is (\d+) seconds/ step definition is deprecated.}) + # rubocop:enable Metrics/LineLength + + aruba.config.exit_timeout = seconds.to_i +end + +Given(/the default aruba io wait timeout is (\d+) seconds/) do |seconds| + aruba.config.io_wait_timeout = seconds.to_i +end + +Given(/the default aruba exit timeout is (\d+) seconds/) do |seconds| aruba.config.exit_timeout = seconds.to_i end diff --git a/lib/aruba/matchers/command/have_output.rb b/lib/aruba/matchers/command/have_output.rb index 702b8081e..b84e7d2f5 100644 --- a/lib/aruba/matchers/command/have_output.rb +++ b/lib/aruba/matchers/command/have_output.rb @@ -29,7 +29,6 @@ ) @old_actual.stop(@announcer) unless @old_actual.stopped? - @actual = Aruba::Platform.unescape(actual.output.chomp, aruba.config.keep_ansi) values_match?(expected, @actual) diff --git a/lib/aruba/matchers/command/have_output_on_stderr.rb b/lib/aruba/matchers/command/have_output_on_stderr.rb index 94c60357c..4648172d1 100644 --- a/lib/aruba/matchers/command/have_output_on_stderr.rb +++ b/lib/aruba/matchers/command/have_output_on_stderr.rb @@ -15,10 +15,21 @@ # end RSpec::Matchers.define :have_output_on_stderr do |expected| match do |actual| - next false unless actual.respond_to? :stderr - @old_actual = actual - @actual = actual.stderr.chomp + + next false unless @old_actual.respond_to? :stderr + + @announcer ||= Aruba::Announcer.new( + self, + :stdout => @announce_stdout, + :stderr => @announce_stderr, + :dir => @announce_dir, + :cmd => @announce_cmd, + :env => @announce_env + ) + + @old_actual.stop(@announcer) unless @old_actual.stopped? + @actual = Aruba::Platform.unescape(actual.stderr.chomp, aruba.config.keep_ansi) values_match?(expected, @actual) end diff --git a/lib/aruba/matchers/command/have_output_on_stdout.rb b/lib/aruba/matchers/command/have_output_on_stdout.rb index 24a87e12d..e92988767 100644 --- a/lib/aruba/matchers/command/have_output_on_stdout.rb +++ b/lib/aruba/matchers/command/have_output_on_stdout.rb @@ -15,10 +15,21 @@ # end RSpec::Matchers.define :have_output_on_stdout do |expected| match do |actual| - next false unless actual.respond_to? :stdout - @old_actual = actual - @actual = actual.stdout.chomp + + next false unless @old_actual.respond_to? :stdout + + @announcer ||= Aruba::Announcer.new( + self, + :stdout => @announce_stdout, + :stderr => @announce_stderr, + :dir => @announce_dir, + :cmd => @announce_cmd, + :env => @announce_env + ) + + @old_actual.stop(@announcer) unless @old_actual.stopped? + @actual = Aruba::Platform.unescape(actual.stdout.chomp, aruba.config.keep_ansi) values_match?(expected, @actual) end From 35bc2983ff9c74fcca594632ff7d8d4475648396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 16:17:46 +0200 Subject: [PATCH 043/118] This was not supported by ChildProcess --- features/steps/commands/run.feature | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/features/steps/commands/run.feature b/features/steps/commands/run.feature index 471dd0b63..ec99c0b3a 100644 --- a/features/steps/commands/run.feature +++ b/features/steps/commands/run.feature @@ -19,18 +19,3 @@ Feature: Run commands """ When I run `cucumber` Then the features should all pass - - Scenario: Relative command - Given an executable named "bin/cli" with: - """ - #!/bin/bash - exit 0 - """ - And a file named "features/run.feature" with: - """ - Feature: Run it - Scenario: Run command - When I run `bin/cli` - """ - When I run `cucumber` - Then the features should all pass From d82e5313bfd59a7e0c62d544726323a87486b2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 16:18:29 +0200 Subject: [PATCH 044/118] Make sure not content is put to stderr/stdout which will cause a failure --- features/steps/filesystem/file_content.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/steps/filesystem/file_content.feature b/features/steps/filesystem/file_content.feature index fc1497002..883f7a3d7 100644 --- a/features/steps/filesystem/file_content.feature +++ b/features/steps/filesystem/file_content.feature @@ -42,7 +42,7 @@ Feature: Check file content \"\"\" """ - When I run `cucumber` + When I run `cucumber --format progress` Then the features should all pass Scenario: Trailing white space is ignored From 01e179cf4057729327fba894d46decd63420dd82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 16:18:57 +0200 Subject: [PATCH 045/118] Remove \n at the end to make it easier for users to compare things --- lib/aruba/cucumber/command.rb | 8 ++++---- lib/aruba/cucumber/file.rb | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index 9ad9b1cc3..8b0f6fab9 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -123,9 +123,9 @@ end expected = if exactly - Aruba::Platform.unescape(expected) + Aruba::Platform.unescape(expected.chomp) else - Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected.chomp))) end if Aruba::VERSION < '1.0' @@ -168,9 +168,9 @@ end expected = if exactly - Aruba::Platform.unescape(expected) + Aruba::Platform.unescape(expected.chomp) else - Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected.chomp))) end if Aruba::VERSION < '1.0' diff --git a/lib/aruba/cucumber/file.rb b/lib/aruba/cucumber/file.rb index 6f4597345..74435eed2 100644 --- a/lib/aruba/cucumber/file.rb +++ b/lib/aruba/cucumber/file.rb @@ -21,7 +21,7 @@ end Given(/^(?:a|the) file(?: named)? "([^"]*)" with "([^"]*)"$/) do |file_name, file_content| - write_file(file_name, file_content) + write_file(file_name, Aruba::Platform.unescape(file_content)) end Given(/^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/) do |file_name, file_mode, file_content| @@ -132,9 +132,9 @@ Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain "([^"]*)"$/) do |file, negated, content| if negated - expect(file).not_to have_file_content Regexp.new(Regexp.escape(content)) + expect(file).not_to have_file_content Regexp.new(Regexp.escape(content.chomp)) else - expect(file).to have_file_content Regexp.new(Regexp.escape(content)) + expect(file).to have_file_content Regexp.new(Regexp.escape(content.chomp)) end end From d0f5907ed0b77aeb0d0aa140b7c8a5ef1c0f324a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 16:49:28 +0200 Subject: [PATCH 046/118] Update history --- History.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index 5d5bfbaf2..650a9de0b 100644 --- a/History.md +++ b/History.md @@ -368,6 +368,16 @@ # Upcoming un-released versions +## [v0.10.0](https://github.com/cucumber/aruba/compare/v0.8.1...v0.9.0) + +* Redefine #to_s and #inspect for BasicProcess to reduce the sheer amount of + information, if a command produces a lot of output +* Added new matcher to check if an object is included + a error message for + failures which is similar to the `#all`-matcher of `RSpec` +* Add `have_output`-, `have_output_on_stderr`, `have_output_on_stdout`-matchers +* Replace all `assert_*` and `check_*`-methods through expectations +* Add hook `@announce-output` to output both, stderr and stdout + ## [v1.0.0](https://github.com/cucumber/aruba/compare/v0.11.0...v1.0.0) * Support for rubies older than 1.9.3 is discontinued - e.g 1.8.7 and 1.9.2 @@ -419,5 +429,3 @@ """ And the stderr should not contain anything ``` - - From 123a54d2bb4862a4d447fe93e9f31e14f86dd5b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Tue, 21 Jul 2015 16:59:10 +0200 Subject: [PATCH 047/118] Make it compatible with ruby 1.9.2 --- spec/aruba/api/environment/restore_env_spec.rb | 2 +- spec/aruba/api/environment/set_env_spec.rb | 2 +- spec/aruba/api/filesystem/file_size_spec.rb | 2 +- spec/aruba/matchers/command_spec.rb | 12 +++++++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/aruba/api/environment/restore_env_spec.rb b/spec/aruba/api/environment/restore_env_spec.rb index 4f833f684..c8c95f38a 100644 --- a/spec/aruba/api/environment/restore_env_spec.rb +++ b/spec/aruba/api/environment/restore_env_spec.rb @@ -4,7 +4,7 @@ include_context 'uses aruba API' around do |example| - old_env = ENV.to_h + old_env = ENV.to_hash example.run ENV.clear ENV.update(old_env) diff --git a/spec/aruba/api/environment/set_env_spec.rb b/spec/aruba/api/environment/set_env_spec.rb index 9f45b9fac..b2b719c8f 100644 --- a/spec/aruba/api/environment/set_env_spec.rb +++ b/spec/aruba/api/environment/set_env_spec.rb @@ -4,7 +4,7 @@ include_context 'uses aruba API' around do |example| - old_env = ENV.to_h + old_env = ENV.to_hash example.run ENV.clear ENV.update(old_env) diff --git a/spec/aruba/api/filesystem/file_size_spec.rb b/spec/aruba/api/filesystem/file_size_spec.rb index ea64e0d3f..f5fbf4c26 100644 --- a/spec/aruba/api/filesystem/file_size_spec.rb +++ b/spec/aruba/api/filesystem/file_size_spec.rb @@ -14,7 +14,7 @@ def expand_path(*args) context 'when file exist' do before :each do - File.write(path, 'a') + File.open(path, 'w') { |f| f.print 'a' } end it { expect(size).to eq 1 } diff --git a/spec/aruba/matchers/command_spec.rb b/spec/aruba/matchers/command_spec.rb index 344fe4056..922b7541b 100644 --- a/spec/aruba/matchers/command_spec.rb +++ b/spec/aruba/matchers/command_spec.rb @@ -72,12 +72,14 @@ def announcer(*args) context 'when have output hello world on stderr' do before :each do - File.write expand_path('cmd.sh'), <<-EOS.strip_heredoc + string = <<-EOS.strip_heredoc #!/usr/bin/env bash echo $* >&2 EOS + File.open(expand_path('cmd.sh'), 'w') { |f| f.puts string } + File.chmod 0755, expand_path('cmd.sh') prepend_environment_variable 'PATH', "#{expand_path('.')}:" end @@ -107,12 +109,14 @@ def announcer(*args) context 'when have output hello world on stderr' do before :each do - File.write expand_path('cmd.sh'), <<-EOS.strip_heredoc + string = <<-EOS.strip_heredoc #!/usr/bin/env bash echo $* >&2 EOS + File.open(expand_path('cmd.sh'), 'w') { |f| f.puts string } + File.chmod 0755, expand_path('cmd.sh') prepend_environment_variable 'PATH', "#{expand_path('.')}:" end @@ -142,12 +146,14 @@ def announcer(*args) context 'when have output hello world on stderr' do before :each do - File.write expand_path('cmd.sh'), <<-EOS.strip_heredoc + string = <<-EOS.strip_heredoc #!/usr/bin/env bash echo $* >&2 EOS + File.open(expand_path('cmd.sh'), 'w') { |f| f.puts string } + File.chmod 0755, expand_path('cmd.sh') prepend_environment_variable 'PATH', "#{expand_path('.')}:" end From 0d28f4bcaac97cd9672491b24814c334de795802 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Wed, 22 Jul 2015 07:09:38 +0200 Subject: [PATCH 048/118] Move deprecated methods to correct namespace and add warnings. For some of them we need a replacement first before we really can deprecate them --- lib/aruba/api/command.rb | 256 ------------- lib/aruba/api/deprecated.rb | 350 +++++++++++++++++- lib/aruba/api/filesystem.rb | 2 +- lib/aruba/cucumber/hooks.rb | 2 +- .../directory/be_an_existing_directory.rb | 2 +- .../matchers/file/be_an_existing_file.rb | 2 +- lib/aruba/matchers/file/have_file_content.rb | 2 +- lib/aruba/matchers/file/have_file_size.rb | 2 +- .../matchers/file/have_same_file_content.rb | 2 +- lib/aruba/matchers/path/have_permissions.rb | 2 +- lib/aruba/process_monitor.rb | 16 +- spec/aruba/api_spec.rb | 13 +- 12 files changed, 367 insertions(+), 284 deletions(-) diff --git a/lib/aruba/api/command.rb b/lib/aruba/api/command.rb index 32eb41f97..17d50576a 100644 --- a/lib/aruba/api/command.rb +++ b/lib/aruba/api/command.rb @@ -67,14 +67,6 @@ def pipe_in_file(file_name) end end - # Fetch output (stdout, stderr) from command - # - # @param [String] cmd - # The command - def output_from(cmd) - process_monitor.output_from(cmd) - end - # Return all commands # # @return [Array] @@ -83,193 +75,7 @@ def all_commands process_monitor.all_commands end - # Fetch stdout from command - # - # @param [String] cmd - # The command - def stdout_from(cmd) - process_monitor.stdout_from(cmd) - end - - # Fetch stderr from command - # - # @param [String] cmd - # The command - def stderr_from(cmd) - process_monitor.stderr_from(cmd) - end - - # Get stdout of all processes - # - # @return [String] - # The stdout of all process which have run before - def all_stdout - process_monitor.all_stdout - end - - # Get stderr of all processes - # - # @return [String] - # The stderr of all process which have run before - def all_stderr - process_monitor.all_stderr - end - - # Get stderr and stdout of all processes - # - # @return [String] - # The stderr and stdout of all process which have run before - def all_output - process_monitor.all_output - end - - # Full compare arg1 and arg2 - # - # @return [TrueClass, FalseClass] - # If arg1 is exactly the same as arg2 return true, otherwise false - def assert_exact_output(expected, actual) - actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9" - - actual = unescape_text(actual) - actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - expected = unescape_text(expected) - expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - expect(actual).to eq expected - end - - # Partial compare arg1 and arg2 - # - # @return [TrueClass, FalseClass] - # If arg2 contains arg1 return true, otherwise false - def assert_partial_output(expected, actual) - actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9" - - actual = unescape_text(actual) - actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - expected = unescape_text(expected) - expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - expect(actual).to include expected - end - - # Regex Compare arg1 and arg2 - # - # @return [TrueClass, FalseClass] - # If arg2 matches arg1 return true, otherwise false - def assert_matching_output(expected, actual) - actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9" - - actual = unescape_text(actual) - actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - expected = unescape_text(expected) - expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - expect(actual).to match Regexp.new(expected, Regexp::MULTILINE) - end - - # Negative regex compare arg1 and arg2 - # - # @return [TrueClass, FalseClass] - # If arg2 does not match arg1 return true, otherwise false - def assert_not_matching_output(expected, actual) - actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9" - - actual = unescape_text(actual) - actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - expected = unescape_text(expected) - expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - expect(actual).not_to match Regexp.new(expected, Regexp::MULTILINE) - end - - # Negative partial compare arg1 and arg2 - # - # @return [TrueClass, FalseClass] - # If arg2 does not match/include arg1 return true, otherwise false - # rubocop:disable Metrics/CyclomaticComplexity - def assert_no_partial_output(unexpected, actual) - actual.force_encoding(unexpected.encoding) if RUBY_VERSION >= "1.9" - - actual = unescape_text(actual) - actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - if Regexp === unexpected - expect(actual).not_to match unexpected - else - unexpected = unescape_text(unexpected) - unexpected = extract_text(unexpected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - expect(actual).not_to include(unexpected) - end - end - # rubocop:enable Metrics/CyclomaticComplexity - - # Partial compare output of interactive command and arg1 - # - # @return [TrueClass, FalseClass] - # If output of interactive command includes arg1 return true, otherwise false - def assert_partial_output_interactive(expected) - actual = unescape_text(last_command_started.stdout) - actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - expected = unescape_text(expected) - expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences - - actual.include?(expected) ? true : false - end - - # Check if command succeeded and if arg1 is included in output - # - # @return [TrueClass, FalseClass] - # If exit status is 0 and arg1 is included in output return true, otherwise false - def assert_passing_with(expected) - assert_success(true) - assert_partial_output(expected, all_output) - end - - # Check if command failed and if arg1 is included in output - # - # @return [TrueClass, FalseClass] - # If exit status is not equal 0 and arg1 is included in output return true, otherwise false - def assert_failing_with(expected) - assert_success(false) - assert_partial_output(expected, all_output) - end - - # Check exit status of process - # - # @return [TrueClass, FalseClass] - # If arg1 is true, return true if command was successful - # If arg1 is false, return true if command failed - def assert_success(success) - if success - expect(last_command_started).to be_successfully_executed - else - expect(last_command_started).not_to be_successfully_executed - end - end - # @private - def assert_exit_status(status) - expect(last_command_started).to have_exit_status(status) - end - - # @private - def assert_not_exit_status(status) - expect(last_exit_status).not_to eq(status), - append_output_to("Exit status was #{last_exit_status} which was not expected.") - end - - # @private - def append_output_to(message) - "#{message} Output:\n\n#{all_output}\n" - end - def process_monitor return @process_monitor if defined? @process_monitor @@ -283,16 +89,6 @@ def processes process_monitor.send(:processes) end - # @private - def stop_processes! - process_monitor.stop_processes! - end - - # Terminate all running processes - def terminate_processes! - process_monitor.terminate_processes! - end - # Last command started def last_command_started process_monitor.last_command_started @@ -303,16 +99,6 @@ def last_command_stopped process_monitor.last_command_stopped end - # @private - def register_process(*args) - process_monitor.register_process(*args) - end - - # @private - def get_process(wanted) - process_monitor.get_process(wanted) - end - # Run given command and stop it if timeout is reached # # @param [String] cmd @@ -382,27 +168,6 @@ def run(cmd, timeout = nil) end # rubocop:enable Metrics/MethodLength - # Default exit timeout for running commands with aruba - # - # Overwrite this method if you want a different timeout or set - # `@aruba_timeout_seconds`. - def exit_timeout - aruba.config.exit_timeout - end - - # Default io wait timeout - # - # Overwrite this method if you want a different timeout or set - # `@aruba_io_wait_seconds - def io_wait - aruba.config.io_wait_timeout - end - - # The root directory of aruba - def root_directory - aruba.config.root_directory - end - # Run a command with aruba # # Checks for error during command execution and checks the output to detect @@ -441,27 +206,6 @@ def type(input) def close_input last_command_started.close_io(:stdin) end - - # Only processes - def only_processes - process_monitor.only_processes - end - - # TODO: move some more methods under here! - - private - - def last_exit_status - process_monitor.last_exit_status - end - - def stop_process(process) - @last_exit_status = process_monitor.stop_process(process) - end - - def terminate_process(process) - process_monitor.terminate_process(process) - end end end end diff --git a/lib/aruba/api/deprecated.rb b/lib/aruba/api/deprecated.rb index 061c8121a..bea04bbe8 100644 --- a/lib/aruba/api/deprecated.rb +++ b/lib/aruba/api/deprecated.rb @@ -181,7 +181,7 @@ def remove_dir(*args) def check_file_presence(paths, expect_presence = true) Aruba.platform.deprecated('The use of "check_file_presence" is deprecated. Use "expect().to be_an_existing_file" or "expect(all_paths).to all match /pattern/" instead') - stop_processes! + all_commands.each { |c| c.stop(announcer) } Array(paths).each do |path| if path.kind_of? Regexp @@ -216,7 +216,8 @@ def check_file_presence(paths, expect_presence = true) # def check_file_size(paths_and_sizes) Aruba.platform.deprecated('The use of "#check_file_size" is deprecated. Use "expect(file).to have_file_size(size)", "expect(all_files).to all have_file_size(1)", "expect(all_files).to include a_file_with_size(1)" instead') - stop_processes! + + all_commands.each { |c| c.stop(announcer) } paths_and_sizes.each do |path, size| expect(path).to have_file_size size @@ -244,7 +245,7 @@ def check_exact_file_content(file, exact_content, expect_match = true) def check_binary_file_content(file, reference_file, expect_match = true) Aruba.platform.deprecated('The use of "#check_binary_file_content" is deprecated. Use "expect(file).to have_same_file_content_like(file)"') - stop_processes! + all_commands.each { |c| c.stop(announcer) } if expect_match expect(file).to have_same_file_content_like reference_file @@ -264,7 +265,7 @@ def check_binary_file_content(file, reference_file, expect_match = true) def check_directory_presence(paths, expect_presence) Aruba.platform.deprecated('The use of "#check_directory_presence" is deprecated. Use "expect(directory).to be_an_existing_directory"') - stop_processes! + all_commands.each { |c| c.stop(announcer) } paths.each do |path| path = expand_path(path) @@ -281,8 +282,9 @@ def check_directory_presence(paths, expect_presence) def prep_for_fs_check(&block) Aruba.platform.deprecated('The use of "prep_for_fs_check" is deprecated. Use apropriate methods and the new rspec matchers instead') - process_monitor.stop_processes! - cd('.') { block.call } + all_commands.each { |c| c.stop(announcer) } + + cd('') { block.call } end # @deprecated @@ -322,7 +324,7 @@ def assert_exit_status_and_output(expect_to_pass, expected_output, expect_exact_ def check_file_content(file, content, expect_match = true) Aruba.platform.deprecated('The use of "#check_file_content" is deprecated. Use "expect(file).to have_file_content(content)" instead. For eq match use string, for partial match use /regex/') - stop_processes! + all_commands.each { |c| c.stop(announcer) } if expect_match expect(file).to have_file_content content @@ -499,6 +501,7 @@ def root_directory aruba.root_directory end + # The path to the directory which contains fixtures # You might want to overwrite this method to place your data else where. # @@ -521,11 +524,13 @@ def check_for_deprecated_variables if defined? @keep_ansi Aruba.platform.deprecated('The use of "@aruba_keep_ansi" is deprecated. Use "#aruba.config.remove_ansi_escape_sequences = " instead. Be aware that it uses an inverted logic') + aruba.config.remove_ansi_escape_sequences = false end if defined? @aruba_root_directory Aruba.platform.deprecated('The use of "@aruba_root_directory" is deprecated. Use "#aruba.config.root_directory = " instead') + aruba.config.root_directory = @aruba_root_directory.to_s end end @@ -538,6 +543,337 @@ def last_command process_monitor.last_command_started end + + # @deprecated + # + # Full compare arg1 and arg2 + # + # @return [TrueClass, FalseClass] + # If arg1 is exactly the same as arg2 return true, otherwise false + def assert_exact_output(expected, actual) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_exact_output" is deprecated. Use "expect(command).to have_output \'exact\'" instead. There are also special matchers for "stdout" and "stderr"') + # rubocop:enable Metrics/LineLength + + actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9" + expect(Aruba.platform.unescape(actual, aruba.config.keep_ansi)).to eq Aruba.platform.unescape(expected, aruba.config.keep_ansi) + end + + # @deprecated + # + # Partial compare arg1 and arg2 + # + # @return [TrueClass, FalseClass] + # If arg2 contains arg1 return true, otherwise false + def assert_partial_output(expected, actual) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_partial_output" is deprecated. Use "expect(command).to have_output /partial/" instead. There are also special matchers for "stdout" and "stderr"') + # rubocop:enable Metrics/LineLength + + actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9" + expect(Aruba.platform.unescape(actual, aruba.config.keep_ansi)).to include(Aruba.platform.unescape(expected, aruba.config.keep_ansi)) + end + + # @deprecated + # + # Regex Compare arg1 and arg2 + # + # @return [TrueClass, FalseClass] + # If arg2 matches arg1 return true, otherwise false + def assert_matching_output(expected, actual) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_matching_output" is deprecated. Use "expect(command).to have_output /partial/" instead. There are also special matchers for "stdout" and "stderr"') + # rubocop:enable Metrics/LineLength + + actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9" + expect(Aruba.platform.unescape(actual, aruba.config.keep_ansi)).to match(/#{Aruba.platform.unescape(expected, aruba.config.keep_ansi)}/m) + end + + # @deprecated + # + # Negative regex compare arg1 and arg2 + # + # @return [TrueClass, FalseClass] + # If arg2 does not match arg1 return true, otherwise false + def assert_not_matching_output(expected, actual) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_not_matching_output" is deprecated. Use "expect(command).not_to have_output /partial/" instead. There are also special matchers for "stdout" and "stderr"') + # rubocop:enable Metrics/LineLength + + actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9" + expect(Aruba.platform.unescape(actual, aruba.config.keep_ansi)).not_to match(/#{Aruba.platform.unescape(expected, aruba.config.keep_ansi)}/m) + end + + # @deprecated + # + # Negative partial compare arg1 and arg2 + # + # @return [TrueClass, FalseClass] + # If arg2 does not match/include arg1 return true, otherwise false + def assert_no_partial_output(unexpected, actual) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_no_partial_output" is deprecated. Use "expect(command).not_to have_output /partial/" instead. There are also special matchers for "stdout" and "stderr"') + # rubocop:enable Metrics/LineLength + + actual.force_encoding(unexpected.encoding) if RUBY_VERSION >= "1.9" + if Regexp === unexpected + expect(Aruba.platform.unescape(actual, aruba.config.keep_ansi)).not_to match unexpected + else + expect(Aruba.platform.unescape(actual, aruba.config.keep_ansi)).not_to include(unexpected) + end + end + + # @deprecated + # + # Partial compare output of interactive command and arg1 + # + # @return [TrueClass, FalseClass] + # If output of interactive command includes arg1 return true, otherwise false + def assert_partial_output_interactive(expected) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_partial_output_interactive" is deprecated. Use "expect(last_command_started).to have_output /partial/" instead. There are also special matchers for "stdout" and "stderr"') + # rubocop:enable Metrics/LineLength + + Aruba.platform.unescape(last_command_started.stdout, aruba.config.keep_ansi).include?(Aruba.platform.unescape(expected, aruba.config.keep_ansi)) ? true : false + end + + # @deprecated + # + # Check if command succeeded and if arg1 is included in output + # + # @return [TrueClass, FalseClass] + # If exit status is 0 and arg1 is included in output return true, otherwise false + def assert_passing_with(expected) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_passing_with" is deprecated. Use "expect(all_commands).to all(be_successfully_executed).and include_an_object(have_output(/partial/))" or something similar instead. There are also special matchers for "stdout" and "stderr"') + # rubocop:enable Metrics/LineLength + + assert_success(true) + assert_partial_output(expected, all_output) + end + + # @deprecated + # + # Check if command failed and if arg1 is included in output + # + # @return [TrueClass, FalseClass] + # If exit status is not equal 0 and arg1 is included in output return true, otherwise false + def assert_failing_with(expected) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_passing_with" is deprecated. Use "expect(all_commands).not_to include_an_object(be_successfully_executed).and include_an_object(have_output(/partial/))" or something similar instead. There are also special matchers for "stdout" and "stderr"') + # rubocop:enable Metrics/LineLength + + assert_success(false) + assert_partial_output(expected, all_output) + end + + # @deprecated + # + # Check exit status of process + # + # @return [TrueClass, FalseClass] + # If arg1 is true, return true if command was successful + # If arg1 is false, return true if command failed + def assert_success(success) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_success" is deprecated. Use "expect(last_command_started).to be_successfully_executed" or with "not_to" or the negative form "have_failed_running" (requires rspec >= 3.1)') + # rubocop:enable Metrics/LineLength + + if success + expect(last_command_started).to be_successfully_executed + else + expect(last_command_started).not_to be_successfully_executed + end + end + + # @deprecated + def assert_exit_status(status) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_success" is deprecated. Use "expect(last_command_started).to have_exit_status(status)"') + # rubocop:enable Metrics/LineLength + + expect(last_command_started).to have_exit_status(status) + end + + # @deprecated + def assert_not_exit_status(status) + # rubocop:disable Metrics/LineLength + Aruba.platform.deprecated('The use of "#assert_success" is deprecated. Use "expect(last_command_started).not_to have_exit_status(status)"') + # rubocop:enable Metrics/LineLength + + expect(last_exit_status).not_to eq(status), + append_output_to("Exit status was #{last_exit_status} which was not expected.") + end + + # @deprecated + def append_output_to(message) + Aruba.platform.deprecated('The use of "#append_output_to" is deprecated') + + "#{message} Output:\n\n#{all_output}\n" + end + + # @deprecated + def register_process(*args) + # Aruba.platform.deprecated('The use of "#register_process" is deprecated') + + process_monitor.register_process(*args) + end + + # @deprecated + def get_process(wanted) + # Aruba.platform.deprecated('The use of "#get_process" is deprecated') + + process_monitor.get_process(wanted) + end + + # @deprecated + # + # Fetch output (stdout, stderr) from command + # + # @param [String] cmd + # The command + def output_from(cmd) + # Aruba.platform.deprecated('The use of "#output_from" is deprecated') + + process_monitor.output_from(cmd) + end + + # @deprecated + # + # Fetch stdout from command + # + # @param [String] cmd + # The command + def stdout_from(cmd) + # Aruba.platform.deprecated('The use of "#stdout_from" is deprecated') + + process_monitor.stdout_from(cmd) + end + + # @deprecated + # + # Fetch stderr from command + # + # @param [String] cmd + # The command + def stderr_from(cmd) + # Aruba.platform.deprecated('The use of "#stderr_from" is deprecated') + + process_monitor.stderr_from(cmd) + end + + # @deprecated + # + # Get stdout of all processes + # + # @return [String] + # The stdout of all process which have run before + def all_stdout + Aruba.platform.deprecated('The use of "#all_stdout" is deprecated. Use `all_commands.map { |c| c.stdout }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output_on_stdout /output/" instead') + + process_monitor.all_stdout + end + + # @deprecated + # + # Get stderr of all processes + # + # @return [String] + # The stderr of all process which have run before + def all_stderr + Aruba.platform.deprecated('The use of "#all_stderr" is deprecated. Use `all_commands.map { |c| c.stderr }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output_on_stderr /output/" instead') + + process_monitor.all_stderr + end + + # @deprecated + # + # Get stderr and stdout of all processes + # + # @return [String] + # The stderr and stdout of all process which have run before + def all_output + Aruba.platform.deprecated('The use of "#all_output" is deprecated. Use `all_commands.map { |c| c.output }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output /output/" instead') + + process_monitor.all_output + end + + # @deprecated + # + # Default exit timeout for running commands with aruba + # + # Overwrite this method if you want a different timeout or set + # `@aruba_timeout_seconds`. + def exit_timeout + Aruba.platform.deprecated('The use of "#exit_timeout" is deprecated. Use "aruba.config.exit_timeout" instead.') + + aruba.config.exit_timeout + end + + # @deprecated + # + # Default io wait timeout + # + # Overwrite this method if you want a different timeout or set + # `@aruba_io_wait_seconds + def io_wait + Aruba.platform.deprecated('The use of "#io_wait" is deprecated. Use "aruba.config.io_wait_timeout" instead.') + + aruba.config.io_wait_timeout + end + + # @deprecated + # The root directory of aruba + def root_directory + Aruba.platform.deprecated('The use of "#root_directory" is deprecated. Use "aruba.root_directory" instead.') + + aruba.config.root_directory + end + + # @deprecated + # Only processes + def only_processes + # Aruba.platform.deprecated('The use of "#only_processes" is deprecated.') + + process_monitor.only_processes + end + + # @deprecated + def last_exit_status + Aruba.platform.deprecated('The use of "#last_exit_status" is deprecated. Use "#last_command_(started|stopped).exit_status" instead') + + process_monitor.last_exit_status + end + + # @deprecated + def stop_process(process) + # Aruba.platform.deprecated('The use of "#stop_process" is deprecated. Use "#last_command_(started|stopped).stop" instead') + + @last_exit_status = process_monitor.stop_process(process) + end + + # @deprecated + def terminate_process(process) + # Aruba.platform.deprecated('The use of "#terminate_process" is deprecated. Use "#last_command_(started|stopped).terminate" instead') + + process_monitor.terminate_process(process) + end + + # @deprecated + def stop_processes! + Aruba.platform.deprecated('The use of "#stop_processes!" is deprecated. Use "all_commands.each(&:stop)" instead') + + all_commands.each { |c| c.stop(announcer) } + end + + # @deprecated + # + # Terminate all running processes + def terminate_processes! + Aruba.platform.deprecated('The use of "#stop_processes!" is deprecated. Use "all_commands.each(&:terminate)" instead') + + all_commands.each(&:terminate) + end end end end diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index e06020799..1808de6ea 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -300,7 +300,7 @@ def remove(*args) # @yield # Pass the content of the given file to this block def with_file_content(file, &block) - stop_processes! + expect(file).to all be_an_existing_path content = read(file).join("\n") diff --git a/lib/aruba/cucumber/hooks.rb b/lib/aruba/cucumber/hooks.rb index a9c7b0afa..ad97631b7 100644 --- a/lib/aruba/cucumber/hooks.rb +++ b/lib/aruba/cucumber/hooks.rb @@ -30,7 +30,7 @@ After do restore_env - process_monitor.stop_processes! + all_commands.each { |c| c.stop(announcer) } process_monitor.clear end diff --git a/lib/aruba/matchers/directory/be_an_existing_directory.rb b/lib/aruba/matchers/directory/be_an_existing_directory.rb index 891e2a48e..be40866db 100644 --- a/lib/aruba/matchers/directory/be_an_existing_directory.rb +++ b/lib/aruba/matchers/directory/be_an_existing_directory.rb @@ -17,7 +17,7 @@ # end RSpec::Matchers.define :be_an_existing_directory do |_| match do |actual| - stop_processes! + all_commands.each { |c| c.stop(announcer) } next false unless actual.is_a? String diff --git a/lib/aruba/matchers/file/be_an_existing_file.rb b/lib/aruba/matchers/file/be_an_existing_file.rb index 3fce5cc5c..06c20c941 100644 --- a/lib/aruba/matchers/file/be_an_existing_file.rb +++ b/lib/aruba/matchers/file/be_an_existing_file.rb @@ -17,7 +17,7 @@ # end RSpec::Matchers.define :be_an_existing_file do |_| match do |actual| - stop_processes! + all_commands.each { |c| c.stop(announcer) } next false unless actual.is_a? String diff --git a/lib/aruba/matchers/file/have_file_content.rb b/lib/aruba/matchers/file/have_file_content.rb index a4203f439..7023d17b2 100644 --- a/lib/aruba/matchers/file/have_file_content.rb +++ b/lib/aruba/matchers/file/have_file_content.rb @@ -40,7 +40,7 @@ # end RSpec::Matchers.define :have_file_content do |expected| match do |actual| - stop_processes! + all_commands.each { |c| c.stop(announcer) } next false unless file? actual diff --git a/lib/aruba/matchers/file/have_file_size.rb b/lib/aruba/matchers/file/have_file_size.rb index f1c5e6d08..265982924 100644 --- a/lib/aruba/matchers/file/have_file_size.rb +++ b/lib/aruba/matchers/file/have_file_size.rb @@ -22,7 +22,7 @@ # end RSpec::Matchers.define :have_file_size do |expected| match do |actual| - stop_processes! + all_commands.each { |c| c.stop(announcer) } next false unless file?(actual) diff --git a/lib/aruba/matchers/file/have_same_file_content.rb b/lib/aruba/matchers/file/have_same_file_content.rb index 75214ba21..94688fa27 100644 --- a/lib/aruba/matchers/file/have_same_file_content.rb +++ b/lib/aruba/matchers/file/have_same_file_content.rb @@ -24,7 +24,7 @@ # end RSpec::Matchers.define :have_same_file_content_like do |expected| match do |actual| - stop_processes! + all_commands.each { |c| c.stop(announcer) } next false unless file?(actual) && file?(expected) diff --git a/lib/aruba/matchers/path/have_permissions.rb b/lib/aruba/matchers/path/have_permissions.rb index 30d3d1b0f..0ee3d8776 100644 --- a/lib/aruba/matchers/path/have_permissions.rb +++ b/lib/aruba/matchers/path/have_permissions.rb @@ -34,7 +34,7 @@ def permissions(file) end match do |actual| - stop_processes! + all_commands.each { |c| c.stop(announcer) } @old_actual = actual @actual = permissions(expand_path(@old_actual)) diff --git a/lib/aruba/process_monitor.rb b/lib/aruba/process_monitor.rb index 92a991374..3341fdf2c 100644 --- a/lib/aruba/process_monitor.rb +++ b/lib/aruba/process_monitor.rb @@ -13,14 +13,14 @@ def initialize(announcer) def last_exit_status return @last_exit_status if @last_exit_status - stop_processes! + all_commands.each { |c| c.stop(announcer) } @last_exit_status end def last_command_stopped return @last_command_stopped if @last_command_stopped - stop_processes! + all_commands.each { |c| c.stop(announcer) } @last_command_stopped end @@ -39,13 +39,15 @@ def terminate_process!(process) end def stop_processes! - processes.each do |_, process| - @last_exit_status = stop_process(process) - end + Aruba::Platform.deprecated('The use of "#stop_processes!" is deprecated. Use "#all_commands.each { |c| c.stop(announcer) }" instead') + + all_commands.each(&:stop) end # Terminate all running processes def terminate_processes + Aruba::Platform.deprecated('The use of "#terminate_processes" is deprecated. Use "#all_commands.each(&:terminate)" instead') + processes.each do |_, process| terminate_process(process) stop_process(process) @@ -100,7 +102,7 @@ def stderr_from(cmd) # @return [String] # The stdout of all process which have run before def all_stdout - stop_processes! + all_commands.each(&:stop) if RUBY_VERSION < '1.9' out = '' @@ -117,7 +119,7 @@ def all_stdout # @return [String] # The stderr of all process which have run before def all_stderr - stop_processes! + all_commands.each(&:stop) if RUBY_VERSION < '1.9' out = '' diff --git a/spec/aruba/api_spec.rb b/spec/aruba/api_spec.rb index 08b5d03fd..bb160c825 100644 --- a/spec/aruba/api_spec.rb +++ b/spec/aruba/api_spec.rb @@ -1096,7 +1096,8 @@ def actual_permissions describe 'tags' do describe '@announce_stdout' do - after(:each){@aruba.stop_processes!} + after(:each) { @aruba.all_commands.each(&:stop) } + context 'enabled' do before :each do @aruba.send(:announcer).activate(:stdout) @@ -1127,7 +1128,7 @@ def actual_permissions describe "#assert_not_matching_output" do before(:each){ @aruba.run_simple("echo foo", false) } - after(:each){ @aruba.stop_processes! } + after(:each) { @aruba.all_commands.each(&:stop) } it "passes when the output doesn't match a regexp" do @aruba.assert_not_matching_output "bar", @aruba.all_output @@ -1141,7 +1142,7 @@ def actual_permissions describe '#run' do before(:each){@aruba.run "cat"} - after(:each){@aruba.stop_processes!} + after(:each) { @aruba.all_commands.each(&:stop) } it "respond to input" do @aruba.type "Hello" @aruba.type "" @@ -1164,7 +1165,7 @@ def actual_permissions describe "#run_simple" do before(:each){@aruba.run_simple "true"} - after(:each){@aruba.stop_processes!} + after(:each) { @aruba.all_commands.each(&:stop) } describe "get_process" do it "returns a process" do expect(@aruba.get_process("true")).not_to be(nil) @@ -1194,7 +1195,7 @@ def root_directory describe "#set_environment_variable" do after(:each) do - @aruba.stop_processes! + @aruba.all_commands.each(&:stop) @aruba.restore_env end @@ -1213,7 +1214,7 @@ def root_directory end describe "#restore_env" do - after(:each){@aruba.stop_processes!} + after(:each) { @aruba.all_commands.each(&:stop) } it "restores environment variable" do @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true' @aruba.restore_env From 7f8a155c890b3aee2a9f72775e6c6f69379ac230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Wed, 22 Jul 2015 08:10:01 +0200 Subject: [PATCH 049/118] Use correct api for stopping commands --- lib/aruba/api.rb | 16 ---------------- lib/aruba/api/deprecated.rb | 18 ++++++++++++++++++ spec/aruba/api_spec.rb | 14 +++++++------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/aruba/api.rb b/lib/aruba/api.rb index 3dda5392d..b863a9d43 100644 --- a/lib/aruba/api.rb +++ b/lib/aruba/api.rb @@ -26,21 +26,5 @@ module Api include Aruba::Api::Filesystem include Aruba::Api::Rvm include Aruba::Api::Deprecated - - # Access to announcer - def announcer - @announcer ||= Announcer.new( - self, - :stdout => defined?(@announce_stdout), - :stderr => defined?(@announce_stderr), - :dir => defined?(@announce_dir), - :cmd => defined?(@announce_cmd), - :env => defined?(@announce_env) - ) - - @announcer - end - - module_function :announcer end end diff --git a/lib/aruba/api/deprecated.rb b/lib/aruba/api/deprecated.rb index bea04bbe8..6ecf9846e 100644 --- a/lib/aruba/api/deprecated.rb +++ b/lib/aruba/api/deprecated.rb @@ -874,6 +874,24 @@ def terminate_processes! all_commands.each(&:terminate) end + + # @deprecated + # + # Access to announcer + def announcer + # Aruba::Platform.deprecated('The use of "#announcer" is deprecated. Use "aruba.announcer" instead') + + @announcer ||= Announcer.new( + self, + :stdout => defined?(@announce_stdout), + :stderr => defined?(@announce_stderr), + :dir => defined?(@announce_dir), + :cmd => defined?(@announce_cmd), + :env => defined?(@announce_env) + ) + + @announcer + end end end end diff --git a/spec/aruba/api_spec.rb b/spec/aruba/api_spec.rb index bb160c825..97f9e3f48 100644 --- a/spec/aruba/api_spec.rb +++ b/spec/aruba/api_spec.rb @@ -1096,11 +1096,11 @@ def actual_permissions describe 'tags' do describe '@announce_stdout' do - after(:each) { @aruba.all_commands.each(&:stop) } + after(:each) { @aruba.all_commands.each { |c| c.stop(@aruba.announcer) } } context 'enabled' do before :each do - @aruba.send(:announcer).activate(:stdout) + @aruba.announcer.activate(:stdout) end it "should announce to stdout exactly once" do @@ -1128,7 +1128,7 @@ def actual_permissions describe "#assert_not_matching_output" do before(:each){ @aruba.run_simple("echo foo", false) } - after(:each) { @aruba.all_commands.each(&:stop) } + after(:each) { @aruba.all_commands.each { |c| c.stop(@aruba.announcer) } } it "passes when the output doesn't match a regexp" do @aruba.assert_not_matching_output "bar", @aruba.all_output @@ -1142,7 +1142,7 @@ def actual_permissions describe '#run' do before(:each){@aruba.run "cat"} - after(:each) { @aruba.all_commands.each(&:stop) } + after(:each) { @aruba.all_commands.each { |c| c.stop(@aruba.announcer) } } it "respond to input" do @aruba.type "Hello" @aruba.type "" @@ -1165,7 +1165,7 @@ def actual_permissions describe "#run_simple" do before(:each){@aruba.run_simple "true"} - after(:each) { @aruba.all_commands.each(&:stop) } + after(:each) { @aruba.all_commands.each { |c| c.stop(@aruba.announcer) } } describe "get_process" do it "returns a process" do expect(@aruba.get_process("true")).not_to be(nil) @@ -1195,7 +1195,7 @@ def root_directory describe "#set_environment_variable" do after(:each) do - @aruba.all_commands.each(&:stop) + @aruba.all_commands.each { |c| c.stop(@aruba.announcer) } @aruba.restore_env end @@ -1214,7 +1214,7 @@ def root_directory end describe "#restore_env" do - after(:each) { @aruba.all_commands.each(&:stop) } + after(:each) { @aruba.all_commands.each { |c| c.stop(@aruba.announcer) } } it "restores environment variable" do @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true' @aruba.restore_env From c86a775ba1b9bceee1c8f1d8d1e87469b0854033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Wed, 22 Jul 2015 08:10:23 +0200 Subject: [PATCH 050/118] Fixing deprecation warnings --- lib/aruba/api/deprecated.rb | 8 ++++---- lib/aruba/process_monitor.rb | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/aruba/api/deprecated.rb b/lib/aruba/api/deprecated.rb index 6ecf9846e..8507c67ed 100644 --- a/lib/aruba/api/deprecated.rb +++ b/lib/aruba/api/deprecated.rb @@ -817,7 +817,7 @@ def exit_timeout # Overwrite this method if you want a different timeout or set # `@aruba_io_wait_seconds def io_wait - Aruba.platform.deprecated('The use of "#io_wait" is deprecated. Use "aruba.config.io_wait_timeout" instead.') + Aruba.platform.deprecated('The use of "#io_wait" is deprecated. Use "aruba.config.io_wait_timeout" instead') aruba.config.io_wait_timeout end @@ -825,7 +825,7 @@ def io_wait # @deprecated # The root directory of aruba def root_directory - Aruba.platform.deprecated('The use of "#root_directory" is deprecated. Use "aruba.root_directory" instead.') + Aruba.platform.deprecated('The use of "#root_directory" is deprecated. Use "aruba.root_directory" instead') aruba.config.root_directory end @@ -833,7 +833,7 @@ def root_directory # @deprecated # Only processes def only_processes - # Aruba.platform.deprecated('The use of "#only_processes" is deprecated.') + Aruba.platform.deprecated('The use of "#only_processes" is deprecated. Use "#all_commands" instead') process_monitor.only_processes end @@ -879,7 +879,7 @@ def terminate_processes! # # Access to announcer def announcer - # Aruba::Platform.deprecated('The use of "#announcer" is deprecated. Use "aruba.announcer" instead') + # Aruba.platform.deprecated('The use of "#announcer" is deprecated. Use "aruba.announcer" instead') @announcer ||= Announcer.new( self, diff --git a/lib/aruba/process_monitor.rb b/lib/aruba/process_monitor.rb index 3341fdf2c..af1e4dcf2 100644 --- a/lib/aruba/process_monitor.rb +++ b/lib/aruba/process_monitor.rb @@ -12,6 +12,8 @@ def initialize(announcer) end def last_exit_status + Aruba::Platform.deprecated('The use of "#last_exit_status" is deprecated. Use "last_command_(started|stopped).exit_status" instead') + return @last_exit_status if @last_exit_status all_commands.each { |c| c.stop(announcer) } @last_exit_status @@ -67,6 +69,8 @@ def get_process(wanted) end def only_processes + Aruba::Platform.deprecated('The use of "#only_processes" is deprecated. Use "#all_commands" instead') + processes.collect{ |_, process| process } end @@ -102,7 +106,11 @@ def stderr_from(cmd) # @return [String] # The stdout of all process which have run before def all_stdout - all_commands.each(&:stop) + # rubocop:disable Metrics/LineLength + Aruba::Platform.deprecated('The use of "#all_stdout" is deprecated. Use `all_commands.map { |c| c.stdout }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output_on_stdout /output/" instead') + # rubocop:enable Metrics/LineLength + + all_commands.each { |c| c.stop(announcer) } if RUBY_VERSION < '1.9' out = '' @@ -119,7 +127,11 @@ def all_stdout # @return [String] # The stderr of all process which have run before def all_stderr - all_commands.each(&:stop) + # rubocop:disable Metrics/LineLength + Aruba::Platform.deprecated('The use of "#all_stderr" is deprecated. Use `all_commands.map { |c| c.stderr }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output_on_stderr /output/" instead') + # rubocop:enable Metrics/LineLength + + all_commands.each { |c| c.stop(announcer) } if RUBY_VERSION < '1.9' out = '' @@ -136,6 +148,10 @@ def all_stderr # @return [String] # The stderr and stdout of all process which have run before def all_output + # rubocop:disable Metrics/LineLength + Aruba::Platform.deprecated('The use of "#all_output" is deprecated. Use `all_commands.map { |c| c.output }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output /output/" instead') + # rubocop:enable Metrics/LineLength + all_stdout << all_stderr end From 66648df841b0a7ee49588e28b97b4e50babd5ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Wed, 22 Jul 2015 08:10:40 +0200 Subject: [PATCH 051/118] Fix offenses --- lib/aruba/api/filesystem.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index 1808de6ea..bd8d55f29 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -300,7 +300,7 @@ def remove(*args) # @yield # Pass the content of the given file to this block def with_file_content(file, &block) - expect(file).to all be_an_existing_path + expect(file).to be_an_existing_path content = read(file).join("\n") From a484c0a59a50c540d115dbdf688ae67bac088827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Wed, 22 Jul 2015 08:21:16 +0200 Subject: [PATCH 052/118] Fix the use of timeouts --- README.md | 16 ++++++++++------ lib/aruba/api/command.rb | 2 +- lib/aruba/api/deprecated.rb | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 60b059491..4589705cc 100644 --- a/README.md +++ b/README.md @@ -115,15 +115,19 @@ can test those commands as though the gem were already installed. If you need other directories to be added to the `PATH`, you can put the following in `features/support/env.rb`: - ENV['PATH'] = "/my/special/bin/path#{File::PATH_SEPARATOR}#{ENV['PATH']}" +```ruby +Aruba.configure do |config| + config.command_search_paths = config.command_search_paths << '/my/special/bin/path' +end +``` ### Increasing timeouts -A process sometimes takes longer than expected to terminate, and Aruba will kill them off (and fail your scenario) if it is still alive after 3 seconds. If you need more time you can modify the timeout by assigning a different value to `@aruba_timeout_seconds` in a `Before` block: +A process sometimes takes longer than expected to terminate, and Aruba will kill them off (and fail your scenario) if it is still alive after 3 seconds. If you need more time you can modify the timeout by assigning a different value to `#exit_timeout` in a `Aruba.configure` block: ```ruby -Before do - @aruba_timeout_seconds = 5 +Aruba.configure do |config| + config.exit_timeout = 5 end ``` @@ -132,11 +136,11 @@ end Running processes interactively can result in race conditions when Aruba executes an IO-related step but the interactive process has not yet flushed or read some content. To help prevent this Aruba waits before reading or writing to the process if it is still running. You can control the wait by setting -`@aruba_io_wait_seconds` to an appropriate value. This is particularly useful with tags: +`aruba.config.io_wait_timeout` to an appropriate value. This is particularly useful with tags: ```ruby Before('@slow_process') do - @aruba_io_wait_seconds = 5 + aruba.config.io_wait_timeout = 5 end ``` diff --git a/lib/aruba/api/command.rb b/lib/aruba/api/command.rb index 17d50576a..1127d3119 100644 --- a/lib/aruba/api/command.rb +++ b/lib/aruba/api/command.rb @@ -112,7 +112,7 @@ def last_command_stopped # # rubocop:disable Metrics/MethodLength def run(cmd, timeout = nil) - timeout ||= exit_timeout + timeout ||= exit_timeout # we need to use it here otherwise overwritten "exit_timeout" is not used @commands ||= [] @commands << cmd diff --git a/lib/aruba/api/deprecated.rb b/lib/aruba/api/deprecated.rb index 8507c67ed..c1fb253ee 100644 --- a/lib/aruba/api/deprecated.rb +++ b/lib/aruba/api/deprecated.rb @@ -805,9 +805,12 @@ def all_output # Overwrite this method if you want a different timeout or set # `@aruba_timeout_seconds`. def exit_timeout - Aruba.platform.deprecated('The use of "#exit_timeout" is deprecated. Use "aruba.config.exit_timeout" instead.') - - aruba.config.exit_timeout + if defined? @aruba_exit_timeout + Aruba::Platform.deprecated('The use of "#exit_timeout" is deprecated. Use "aruba.config.exit_timeout" instead.') + @aruba_exit_timeout + else + aruba.config.exit_timeout + end end # @deprecated @@ -817,9 +820,12 @@ def exit_timeout # Overwrite this method if you want a different timeout or set # `@aruba_io_wait_seconds def io_wait - Aruba.platform.deprecated('The use of "#io_wait" is deprecated. Use "aruba.config.io_wait_timeout" instead') - - aruba.config.io_wait_timeout + if defined? @aruba_io_wait_seconds + Aruba::Platform.deprecated('The use of "#io_wait" is deprecated. Use "aruba.config.io_wait_timeout" instead') + @aruba_io_wait_seconds + else + aruba.config.io_wait_timeout + end end # @deprecated From 5b3fcc1cfc48d66085e18045ab233e16d0c9dd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Wed, 22 Jul 2015 09:44:19 +0200 Subject: [PATCH 053/118] Improved include_an_object-matcher and include methods from All-matchers based on feedback on Github (https://github.com/rspec/rspec-expectations/issues/823#issuecomment-123740654) --- .../matchers/collection/include_an_object.rb | 73 ++++++++++++++----- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/lib/aruba/matchers/collection/include_an_object.rb b/lib/aruba/matchers/collection/include_an_object.rb index 93bb5b65a..3e63bbc36 100644 --- a/lib/aruba/matchers/collection/include_an_object.rb +++ b/lib/aruba/matchers/collection/include_an_object.rb @@ -1,18 +1,36 @@ -require 'rspec/matchers/built_in/all' +require 'rspec/matchers/built_in/base_matcher' module Aruba module Matchers # @api private - # Provides the implementation for `all`. + # Provides the implementation for `include_an_object`. # Not intended to be instantiated directly. - class IncludeAnObject < RSpec::Matchers::BuiltIn::All - # @private - attr_reader :matcher, :failed_objects, :succeeded_objects + class IncludeAnObject < ::RSpec::Matchers::BuiltIn::BaseMatcher + protected + + attr_reader :matcher, :failed_objects + attr_accessor :any_succeeded_object + + public def initialize(matcher) - @matcher = matcher - @failed_objects = {} - @succeeded_objects = {} + @matcher = matcher + @failed_objects = {} + @any_succeeded_object = false + end + + # @api private + # @return [String] + def failure_message + unless iterable? + return "#{improve_hash_formatting(super)}, but was not iterable" + end + + all_messages = [improve_hash_formatting(super)] + failed_objects.each do |index, matcher_failure_message| + all_messages << failure_message_for_item(index, matcher_failure_message) + end + all_messages.join("\n\n") end # @api private @@ -28,7 +46,7 @@ def does_not_match?(actual) index_objects - succeeded_objects.empty? + any_succeeded_object == false end private @@ -41,7 +59,7 @@ def match(expected, actual) index_objects - !succeeded_objects.empty? + any_succeeded_object == true end def index_objects @@ -54,13 +72,38 @@ def index_objects end if matches - succeeded_objects[index] = cloned_matcher.failure_message + self.any_succeeded_object = true break else failed_objects[index] = cloned_matcher.failure_message end end end + + def failure_message_for_item(index, failure_message) + failure_message = indent_multiline_message(add_new_line_if_needed(failure_message)) + indent_multiline_message("object at index #{index} failed to match:#{failure_message}") + end + + def add_new_line_if_needed(message) + message.start_with?("\n") ? message : "\n#{message}" + end + + def indent_multiline_message(message) + message = message.sub(/\n+\z/, '') + message.lines.map do |line| + line =~ /\S/ ? ' ' + line : line + end.join + end + + def initialize_copy(other) + @matcher = @matcher.clone + super + end + + def iterable? + @actual.respond_to?(:each_with_index) + end end end end @@ -71,16 +114,12 @@ module Matchers # element of the collection. # # @example - # expect([1, 4, 5]).to any be_odd - # - # @note The negative form `not_to any` is not supported. Instead - # use `not_to include` or pass a negative form of a matcher - # as the argument (e.g. `all exclude(:foo)` - mind it's `all` here). + # expect([1, 4, 5]).to include_an_object be_odd # # @note You can also use this with compound matchers as well. # # @example - # expect([1, 4, 'a']).to any( be_odd.and be_an(Integer) ) + # expect([1, 4, 'a']).to include_an_object( be_odd.and be_an(Integer) ) def include_an_object(expected) ::Aruba::Matchers::IncludeAnObject.new(expected) end From 93715c5eb71a5ecca03f2b4aceac71f51caa1400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Wed, 22 Jul 2015 09:44:35 +0200 Subject: [PATCH 054/118] Improve handling of announcer --- lib/aruba/matchers/command/have_exit_status.rb | 11 +---------- lib/aruba/process_monitor.rb | 8 ++++---- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/aruba/matchers/command/have_exit_status.rb b/lib/aruba/matchers/command/have_exit_status.rb index ffffa01f4..8ba2963e1 100644 --- a/lib/aruba/matchers/command/have_exit_status.rb +++ b/lib/aruba/matchers/command/have_exit_status.rb @@ -20,16 +20,7 @@ match do |actual| @old_actual = actual - @announcer ||= Aruba::Announcer.new( - self, - :stdout => @announce_stdout, - :stderr => @announce_stderr, - :dir => @announce_dir, - :cmd => @announce_cmd, - :env => @announce_env - ) - - @old_actual.stop(@announcer) unless @old_actual.stopped? + @old_actual.stop(announcer) unless @old_actual.stopped? @actual = actual.exit_status next false unless @old_actual.respond_to? :exit_status diff --git a/lib/aruba/process_monitor.rb b/lib/aruba/process_monitor.rb index af1e4dcf2..5d492b93f 100644 --- a/lib/aruba/process_monitor.rb +++ b/lib/aruba/process_monitor.rb @@ -15,14 +15,14 @@ def last_exit_status Aruba::Platform.deprecated('The use of "#last_exit_status" is deprecated. Use "last_command_(started|stopped).exit_status" instead') return @last_exit_status if @last_exit_status - all_commands.each { |c| c.stop(announcer) } + all_commands.each { |c| stop_process(c) } @last_exit_status end def last_command_stopped return @last_command_stopped if @last_command_stopped - all_commands.each { |c| c.stop(announcer) } + all_commands.each { |c| stop_process(c) } @last_command_stopped end @@ -43,7 +43,7 @@ def terminate_process!(process) def stop_processes! Aruba::Platform.deprecated('The use of "#stop_processes!" is deprecated. Use "#all_commands.each { |c| c.stop(announcer) }" instead') - all_commands.each(&:stop) + all_commands.each { |c| stop_process(c) } end # Terminate all running processes @@ -160,7 +160,7 @@ def all_output # @return [Array] # A list of all commands def all_commands - processes.collect{ |_, process| process } + processes.collect { |_, process| process } end # Clear list of processes From 3f13d6728ec6529c5804cff18d2e6c83f2108e89 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Wed, 22 Jul 2015 21:13:43 +0200 Subject: [PATCH 055/118] Disable io buffering for feature test --- features/commands/debug_command.feature | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/commands/debug_command.feature b/features/commands/debug_command.feature index 43517beb1..8c4e2465f 100644 --- a/features/commands/debug_command.feature +++ b/features/commands/debug_command.feature @@ -60,6 +60,9 @@ Feature: Debug your command in cucumber-test-run """ #!/usr/bin/env ruby + $stderr.sync = true + $stdout.sync = true + require 'pry' binding.pry From 89dbfcfbe5500901533fbbaf5e0cf6946a62676b Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Wed, 22 Jul 2015 21:20:01 +0200 Subject: [PATCH 056/118] Make aruba accept options on output as well and pass them on --- lib/aruba/cucumber/command.rb | 4 ++-- lib/aruba/processes/basic_process.rb | 7 +++++-- lib/aruba/processes/in_process.rb | 4 ++-- lib/aruba/processes/spawn_process.rb | 2 -- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index 8b0f6fab9..d49ed256a 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -50,9 +50,9 @@ Timeout.timeout(exit_timeout) do loop do output = if RUBY_VERSION < '1.9.3' - last_command_started.send channel.to_sym + last_command_started.send channel.to_sym, :wait_for_io => 0 else - last_command_started.public_send channel.to_sym + last_command_started.public_send channel.to_sym, :wait_for_io => 0 end if Aruba::Platform.unescape(output).include? Aruba::Platform.unescape(expected) diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index 4ba855f0a..3713258b9 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -12,6 +12,9 @@ def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV. @environment = environment @main_class = main_class @exit_status = nil + + @exit_timeout = exit_timeout + @io_wait = io_wait end # Return command line @@ -20,8 +23,8 @@ def commandline end # Output stderr and stdout - def output - stdout + stderr + def output(opts = {}) + stdout(opts) + stderr(opts) end def write(*) diff --git a/lib/aruba/processes/in_process.rb b/lib/aruba/processes/in_process.rb index 6bf0a679f..ffd14d766 100644 --- a/lib/aruba/processes/in_process.rb +++ b/lib/aruba/processes/in_process.rb @@ -68,11 +68,11 @@ def stdin @stdin.string end - def stdout + def stdout(*) @stdout.string end - def stderr + def stderr(*) @stderr.string end diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index cbb2caf96..6a41577bd 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -30,8 +30,6 @@ def self.match?(mode) def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil) super - @exit_timeout = exit_timeout - @io_wait = io_wait @process = nil @stdout_cache = nil @stderr_cache = nil From 4549ffd89299fd3488f0d415e7dbf0b97c0b6983 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Wed, 22 Jul 2015 21:20:23 +0200 Subject: [PATCH 057/118] Make it obvious that the debug launcher does not capture STDERR/STDOUT --- lib/aruba/processes/debug_process.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/aruba/processes/debug_process.rb b/lib/aruba/processes/debug_process.rb index d82b649e0..9d4b3a6e7 100644 --- a/lib/aruba/processes/debug_process.rb +++ b/lib/aruba/processes/debug_process.rb @@ -30,11 +30,11 @@ def start def stdin(*); end def stdout(*) - '' + 'This is the debug launcher on STDOUT. If this output is unexpected, please check your setup.' end def stderr(*) - '' + 'This is the debug launcher on STDERR. If this output is unexpected, please check your setup.' end def stop(_reader) From b90a01411f3dc6d21a12ad9e64a40fc3789cf3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 08:13:29 +0200 Subject: [PATCH 058/118] Add some more documentation for filesystem commands --- features/file_system_commands.feature | 24 +++---- features/step_definitions/aruba_dev_steps.rb | 16 +++-- .../steps/filesystem/create_directory.feature | 36 ++++++++++ features/steps/filesystem/create_file.feature | 35 +++++++++ .../steps/filesystem/overwrite_file.feature | 72 +++++++++++++++++++ lib/aruba/cucumber/file.rb | 2 +- 6 files changed, 168 insertions(+), 17 deletions(-) create mode 100644 features/steps/filesystem/create_directory.feature create mode 100644 features/steps/filesystem/create_file.feature create mode 100644 features/steps/filesystem/overwrite_file.feature diff --git a/features/file_system_commands.feature b/features/file_system_commands.feature index 516cd125c..d913e7a41 100644 --- a/features/file_system_commands.feature +++ b/features/file_system_commands.feature @@ -4,18 +4,18 @@ Feature: file system commands As a developer using Cucumber I want to create temporary files - Scenario: create a dir - Given a directory named "foo/bar" - When I run `file foo/bar` - Then the stdout should contain "foo/bar: directory" - - Scenario: create a file - Given a file named "foo/bar/example.txt" with: - """ - hello world - """ - When I run `cat foo/bar/example.txt` - Then the output should contain exactly "hello world" + # Scenario: create a dir + # Given a directory named "foo/bar" + # When I run `file foo/bar` + # Then the stdout should contain "foo/bar: directory" + + # Scenario: create a file + # Given a file named "foo/bar/example.txt" with: + # """ + # hello world + # """ + # When I run `cat foo/bar/example.txt` + # Then the output should contain exactly "hello world" Scenario: a file does not exist Given a file named "example.txt" does not exist diff --git a/features/step_definitions/aruba_dev_steps.rb b/features/step_definitions/aruba_dev_steps.rb index c3343ace0..039683058 100644 --- a/features/step_definitions/aruba_dev_steps.rb +++ b/features/step_definitions/aruba_dev_steps.rb @@ -36,7 +36,7 @@ end end -Then /^the feature(?:s)? should( not)?(?: all)? pass with:$/ do |negated, string| +Then /^the feature(?:s)? should( not)?(?: all)? pass with( regex)?:$/ do |negated, regex, string| if negated step 'the output should contain " failed)"' step 'the exit status should be 1' @@ -46,7 +46,11 @@ step 'the exit status should be 0' end - step 'the output should contain:', string if string + if regex + step "the output should match %r<#{string}>" + else + step 'the output should contain:', string + end end Then /^the spec(?:s)? should( not)?(?: all)? pass(?: with (\d+) failures?)?$/ do |negated, count_failures| @@ -64,7 +68,7 @@ end end -Then /^the spec(?:s)? should( not)?(?: all)? pass with:$/ do |negated, string| +Then /^the spec(?:s)? should( not)?(?: all)? pass with( regex)?:$/ do |negated, regex, string| if negated step 'the output should contain " failed)"' step 'the exit status should be 1' @@ -73,7 +77,11 @@ step 'the exit status should be 0' end - step 'the output should contain:', string if string + if regex + step "the output should match %r<#{string}>" + else + step 'the output should contain:', string + end end Given(/^the default executable$/) do diff --git a/features/steps/filesystem/create_directory.feature b/features/steps/filesystem/create_directory.feature new file mode 100644 index 000000000..f0d598454 --- /dev/null +++ b/features/steps/filesystem/create_directory.feature @@ -0,0 +1,36 @@ +Feature: Create Directory + + As a user of aruba + I want to create directories + + Background: + Given I use a fixture named "cli-app" + + Scenario: Non-existing directory + Given a file named "features/create_directory.feature" with: + """ + Feature: Create directory + Scenario: Create directory + Given a directory named "dir1" + Given the directory "dir2" + Given the directory named "dir3" + Then a directory named "dir1" should exist + And a directory named "dir2" should exist + And a directory named "dir3" should exist + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Existing directory + + It doesn't matter if a directory already exist. + + Given a file named "features/create_directory.feature" with: + """ + Feature: Create directory + Scenario: Create directory + Given a directory named "dir1" + And a directory named "dir1" + """ + When I run `cucumber` + Then the features should all pass diff --git a/features/steps/filesystem/create_file.feature b/features/steps/filesystem/create_file.feature new file mode 100644 index 000000000..6a7945acc --- /dev/null +++ b/features/steps/filesystem/create_file.feature @@ -0,0 +1,35 @@ +Feature: Create new File + + As a user of aruba + I want to create files + + Background: + Given I use a fixture named "cli-app" + + Scenario: Create empty file + Given a file named "features/create_file.feature" with: + """ + Feature: Create file + Scenario: Create file + Given an empty file named "file1.txt" + Then a file named "file1.txt" should exist + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Create file with content + Given a file named "features/create_file.feature" with: + """ + Feature: Create file + Scenario: Create file + Given a file named "file1.txt" with: + \"\"\" + Hello World + \"\"\" + Then the file named "file1.txt" should contain: + \"\"\" + Hello World + \"\"\" + """ + When I run `cucumber` + Then the features should all pass diff --git a/features/steps/filesystem/overwrite_file.feature b/features/steps/filesystem/overwrite_file.feature new file mode 100644 index 000000000..4f6576d96 --- /dev/null +++ b/features/steps/filesystem/overwrite_file.feature @@ -0,0 +1,72 @@ +Feature: Overwrite a file + + As a user of aruba + I want to overwrite a file + + Background: + Given I use a fixture named "cli-app" + + Scenario: Overwrite an existing file + Given a file named "features/create_file.feature" with: + """ + Feature: Overwrite file + Scenario: Overwrite file + Given a file named "file1.txt" with: + \"\"\" + Hello World + \"\"\" + And a file named "file2.txt" with: + \"\"\" + Hello World + \"\"\" + And a file named "file3.txt" with: + \"\"\" + Hello World + \"\"\" + When I overwrite "file1.txt" with: + \"\"\" + Hello Universe + \"\"\" + When I overwrite the file "file2.txt" with: + \"\"\" + Hello Universe + \"\"\" + When I overwrite a file named "file3.txt" with: + \"\"\" + Hello Universe + \"\"\" + Then the file named "file1.txt" should contain: + \"\"\" + Hello Universe + \"\"\" + And the file named "file2.txt" should contain: + \"\"\" + Hello Universe + \"\"\" + And the file named "file3.txt" should contain: + \"\"\" + Hello Universe + \"\"\" + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Overwrite a non-existing file + Given a file named "features/create_file.feature" with: + """ + Feature: Overwrite file + Scenario: Overwrite file + When I overwrite "file1.txt" with: + \"\"\" + Hello Universe + \"\"\" + Then the file named "file1.txt" should contain: + \"\"\" + Hello Universe + \"\"\" + """ + When I run `cucumber` + Then the features should not all pass with regex: + """ + Expected [^ ]+ to be present + """ diff --git a/lib/aruba/cucumber/file.rb b/lib/aruba/cucumber/file.rb index 74435eed2..f03bcf836 100644 --- a/lib/aruba/cucumber/file.rb +++ b/lib/aruba/cucumber/file.rb @@ -50,7 +50,7 @@ write_file(file_name, file_content) end -When(/^I overwrite "([^"]*)" with:$/) do |file_name, file_content| +When(/^I overwrite(?: (?:a|the) file(?: named)?)? "([^"]*)" with:$/) do |file_name, file_content| overwrite_file(file_name, file_content) end From ffbeea5c30ba26eca43e8f6f7321aeff604c50d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 08:12:25 +0200 Subject: [PATCH 059/118] Add pry to different group to make it installed on travis as well. We need it to demonstrate interactive debugging --- Gemfile | 13 +++++++------ features/commands/debug_command.feature | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 519c38abd..09ea58739 100644 --- a/Gemfile +++ b/Gemfile @@ -5,12 +5,6 @@ gemspec # Debug aruba group :debug do - if RUBY_VERSION >= '2' - gem 'pry', '~> 0.10.1' - else - gem 'pry', '~>0.9.12' - end - if RUBY_VERSION >= '2' && !RUBY_PLATFORM.include?('java') gem 'byebug', '~> 4.0.5' gem 'pry-byebug', '~> 3.1.0' @@ -29,6 +23,13 @@ group :debug do end group :development, :test do + # we use this to demonstrate interactive debugging within our feature tests + if RUBY_VERSION >= '2' + gem 'pry', '~> 0.10.1' + else + gem 'pry', '~>0.9.12' + end + # Run development tasks gem 'rake', '~> 10.4.2' diff --git a/features/commands/debug_command.feature b/features/commands/debug_command.feature index 8c4e2465f..600a67cfe 100644 --- a/features/commands/debug_command.feature +++ b/features/commands/debug_command.feature @@ -56,6 +56,9 @@ Feature: Debug your command in cucumber-test-run Otherwise you might not get an interactive shell, because your program will just exit. + We are going to demonstrate this using `pry`, but any other interactive + debugger for any other programming language should also work. + Given a file named "bin/cli" with: """ #!/usr/bin/env ruby From d2047ad2e820189dac3e9305b9593ed0f1d86649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 08:12:49 +0200 Subject: [PATCH 060/118] Add documentation for fixtures --- features/steps/filesystem/use_fixture.feature | 63 +++++++++++++++++++ lib/aruba/config.rb | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 features/steps/filesystem/use_fixture.feature diff --git a/features/steps/filesystem/use_fixture.feature b/features/steps/filesystem/use_fixture.feature new file mode 100644 index 000000000..e43adc616 --- /dev/null +++ b/features/steps/filesystem/use_fixture.feature @@ -0,0 +1,63 @@ +Feature: Use a fixture + + As a user of aruba + I want to use a fixture + + Background: + Given I use a fixture named "cli-app" + + Scenario: Use the fixture if fixtures directory is in root directory + Given a file named "features/use_fixtures.feature" with: + """ + Feature: Use Fixture + Scenario: Use Fixture + Given I use a fixture named "my-app" + Then a file named "MY-APP-README.md" should exist + """ + And a directory named "fixtures" + And a directory named "fixtures/my-app" + And an empty file named "fixtures/my-app/MY-APP-README.md" + When I run `cucumber` + Then the features should all pass + + Scenario: Use the fixture if fixtures directory is in features-directory + Given a file named "features/use_fixtures.feature" with: + """ + Feature: Use Fixture + Scenario: Use Fixture + Given I use a fixture named "my-app" + Then a file named "MY-APP-README.md" should exist + """ + And a directory named "features/fixtures" + And a directory named "features/fixtures/my-app" + And an empty file named "features/fixtures/my-app/MY-APP-README.md" + When I run `cucumber` + Then the features should all pass + + Scenario: Use the fixture if fixtures directory is in spec-directory + Given a file named "features/use_fixtures.feature" with: + """ + Feature: Use Fixture + Scenario: Use Fixture + Given I use a fixture named "my-app" + Then a file named "MY-APP-README.md" should exist + """ + And a directory named "spec/fixtures" + And a directory named "spec/fixtures/my-app" + And an empty file named "spec/fixtures/my-app/MY-APP-README.md" + When I run `cucumber` + Then the features should all pass + + Scenario: Use the fixture if fixtures directory is in test-directory + Given a file named "features/use_fixtures.feature" with: + """ + Feature: Use Fixture + Scenario: Use Fixture + Given I use a fixture named "my-app" + Then a file named "MY-APP-README.md" should exist + """ + And a directory named "test/fixtures" + And a directory named "test/fixtures/my-app" + And an empty file named "test/fixtures/my-app/MY-APP-README.md" + When I run `cucumber` + Then the features should all pass diff --git a/lib/aruba/config.rb b/lib/aruba/config.rb index 24b7b8ba2..a1341a4cc 100644 --- a/lib/aruba/config.rb +++ b/lib/aruba/config.rb @@ -30,7 +30,7 @@ class Configuration < BasicConfiguration option_accessor :exit_timeout, :contract => { Num => Num }, :default => 15 option_accessor :io_wait_timeout, :contract => { Num => Num }, :default => 0.1 - option_accessor :fixtures_directories, :contract => { Array => ArrayOf[String] }, :default => %w(features/fixtures spec/fixtures test/fixtures) + option_accessor :fixtures_directories, :contract => { Array => ArrayOf[String] }, :default => %w(features/fixtures spec/fixtures test/fixtures fixtures) option_accessor :command_runtime_environment, :contract => { Hash => Hash }, :default => ENV.to_hash.dup # rubocop:disable Metrics/LineLength option_accessor(:command_search_paths, :contract => { ArrayOf[String] => ArrayOf[String] }) { |config| [File.join(config.root_directory.value, 'bin')] } From 9abe321cc388431d65da0286e647f960a71fd7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 08:59:59 +0200 Subject: [PATCH 061/118] Improved documentation for file and directory creation --- .../steps/filesystem/create_directory.feature | 11 +++++++++++ features/steps/filesystem/create_file.feature | 18 ++++++++++++++++++ lib/aruba/cucumber/file.rb | 4 +++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/features/steps/filesystem/create_directory.feature b/features/steps/filesystem/create_directory.feature index f0d598454..d6d92f404 100644 --- a/features/steps/filesystem/create_directory.feature +++ b/features/steps/filesystem/create_directory.feature @@ -34,3 +34,14 @@ Feature: Create Directory """ When I run `cucumber` Then the features should all pass + + Scenario: Change mode a long with creation of directory + Given a file named "features/create_directory.feature" with: + """ + Feature: Create directory + Scenario: Create directory + Given a directory named "dir1" with mode "0644" + Then the directory named "dir1" should have permissions "0644" + """ + When I run `cucumber` + Then the features should all pass diff --git a/features/steps/filesystem/create_file.feature b/features/steps/filesystem/create_file.feature index 6a7945acc..1fb4b3fea 100644 --- a/features/steps/filesystem/create_file.feature +++ b/features/steps/filesystem/create_file.feature @@ -33,3 +33,21 @@ Feature: Create new File """ When I run `cucumber` Then the features should all pass + + Scenario: Change mode a long with creation of file + Given a file named "features/create_file.feature" with: + """ + Feature: Create directory + Scenario: Create directory + Given a file named "file1.txt" with mode "0644" and with: + \"\"\" + Hello World + \"\"\" + Then the file named "file1.txt" should have permissions "0644" + And the file named "file1.txt" should contain: + \"\"\" + Hello World + \"\"\" + """ + When I run `cucumber` + Then the features should all pass diff --git a/lib/aruba/cucumber/file.rb b/lib/aruba/cucumber/file.rb index f03bcf836..5a078b2d6 100644 --- a/lib/aruba/cucumber/file.rb +++ b/lib/aruba/cucumber/file.rb @@ -179,6 +179,8 @@ end Then(/^the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)"$/) do |file, negated, permissions| + Aruba::Platform.deprecated('The use of step "the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)" is deprecated. Use "^the (?:file|directory)(?: named)? "([^"]*)" should have permissions "([^"]*)"$" instead') + if negated expect(file).not_to have_permissions(permissions) else @@ -186,7 +188,7 @@ end end -Then(/^the (?:file|directory)(?: named)? "([^"]*)" should have permissions "([^"]*)"$/) do |path, negated, permissions| +Then(/^the (?:file|directory)(?: named)? "([^"]*)" should( not)? have permissions "([^"]*)"$/) do |path, negated, permissions| if negated expect(path).not_to have_permissions(permissions) else From 873f174d58f67b0295793229f00b9dd264638ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 11:57:08 +0200 Subject: [PATCH 062/118] Move fixtures to root to prevent them to litter the relish output --- {features/fixtures => fixtures}/cli-app/.gitignore | 0 {features/fixtures => fixtures}/cli-app/.rspec | 0 {features/fixtures => fixtures}/cli-app/README.md | 0 {features/fixtures => fixtures}/cli-app/Rakefile | 0 {features/fixtures => fixtures}/cli-app/bin/cli | 0 {features/fixtures => fixtures}/cli-app/cli-app.gemspec | 0 {features/fixtures => fixtures}/cli-app/features/support/env.rb | 0 {features/fixtures => fixtures}/cli-app/lib/cli/app.rb | 0 .../cli-app/lib/cli/app/suppress_simple_cov_output.rb | 0 {features/fixtures => fixtures}/cli-app/lib/cli/app/version.rb | 0 {features/fixtures => fixtures}/cli-app/script/console | 0 {features/fixtures => fixtures}/cli-app/spec/spec_helper.rb | 0 {features/fixtures => fixtures}/cli-app/spec/support/aruba.rb | 0 {features/fixtures => fixtures}/copy/file.txt | 0 {features/fixtures => fixtures}/empty-app/.gitignore | 0 {features/fixtures => fixtures}/empty-app/.rspec | 0 {features/fixtures => fixtures}/empty-app/README.md | 0 {features/fixtures => fixtures}/empty-app/Rakefile | 0 {features/fixtures => fixtures}/empty-app/bin/cli | 0 {features/fixtures => fixtures}/empty-app/cli-app.gemspec | 0 {features/fixtures => fixtures}/empty-app/lib/cli/app.rb | 0 {features/fixtures => fixtures}/empty-app/lib/cli/app/version.rb | 0 {features/fixtures => fixtures}/empty-app/script/console | 0 {features/fixtures => fixtures}/empty-app/spec/spec_helper.rb | 0 {features/fixtures => fixtures}/fixtures-app/test.txt | 0 {features/fixtures => fixtures}/spawn_process/stderr.sh | 0 26 files changed, 0 insertions(+), 0 deletions(-) rename {features/fixtures => fixtures}/cli-app/.gitignore (100%) rename {features/fixtures => fixtures}/cli-app/.rspec (100%) rename {features/fixtures => fixtures}/cli-app/README.md (100%) rename {features/fixtures => fixtures}/cli-app/Rakefile (100%) rename {features/fixtures => fixtures}/cli-app/bin/cli (100%) rename {features/fixtures => fixtures}/cli-app/cli-app.gemspec (100%) rename {features/fixtures => fixtures}/cli-app/features/support/env.rb (100%) rename {features/fixtures => fixtures}/cli-app/lib/cli/app.rb (100%) rename {features/fixtures => fixtures}/cli-app/lib/cli/app/suppress_simple_cov_output.rb (100%) rename {features/fixtures => fixtures}/cli-app/lib/cli/app/version.rb (100%) rename {features/fixtures => fixtures}/cli-app/script/console (100%) rename {features/fixtures => fixtures}/cli-app/spec/spec_helper.rb (100%) rename {features/fixtures => fixtures}/cli-app/spec/support/aruba.rb (100%) rename {features/fixtures => fixtures}/copy/file.txt (100%) rename {features/fixtures => fixtures}/empty-app/.gitignore (100%) rename {features/fixtures => fixtures}/empty-app/.rspec (100%) rename {features/fixtures => fixtures}/empty-app/README.md (100%) rename {features/fixtures => fixtures}/empty-app/Rakefile (100%) rename {features/fixtures => fixtures}/empty-app/bin/cli (100%) rename {features/fixtures => fixtures}/empty-app/cli-app.gemspec (100%) rename {features/fixtures => fixtures}/empty-app/lib/cli/app.rb (100%) rename {features/fixtures => fixtures}/empty-app/lib/cli/app/version.rb (100%) rename {features/fixtures => fixtures}/empty-app/script/console (100%) rename {features/fixtures => fixtures}/empty-app/spec/spec_helper.rb (100%) rename {features/fixtures => fixtures}/fixtures-app/test.txt (100%) rename {features/fixtures => fixtures}/spawn_process/stderr.sh (100%) diff --git a/features/fixtures/cli-app/.gitignore b/fixtures/cli-app/.gitignore similarity index 100% rename from features/fixtures/cli-app/.gitignore rename to fixtures/cli-app/.gitignore diff --git a/features/fixtures/cli-app/.rspec b/fixtures/cli-app/.rspec similarity index 100% rename from features/fixtures/cli-app/.rspec rename to fixtures/cli-app/.rspec diff --git a/features/fixtures/cli-app/README.md b/fixtures/cli-app/README.md similarity index 100% rename from features/fixtures/cli-app/README.md rename to fixtures/cli-app/README.md diff --git a/features/fixtures/cli-app/Rakefile b/fixtures/cli-app/Rakefile similarity index 100% rename from features/fixtures/cli-app/Rakefile rename to fixtures/cli-app/Rakefile diff --git a/features/fixtures/cli-app/bin/cli b/fixtures/cli-app/bin/cli similarity index 100% rename from features/fixtures/cli-app/bin/cli rename to fixtures/cli-app/bin/cli diff --git a/features/fixtures/cli-app/cli-app.gemspec b/fixtures/cli-app/cli-app.gemspec similarity index 100% rename from features/fixtures/cli-app/cli-app.gemspec rename to fixtures/cli-app/cli-app.gemspec diff --git a/features/fixtures/cli-app/features/support/env.rb b/fixtures/cli-app/features/support/env.rb similarity index 100% rename from features/fixtures/cli-app/features/support/env.rb rename to fixtures/cli-app/features/support/env.rb diff --git a/features/fixtures/cli-app/lib/cli/app.rb b/fixtures/cli-app/lib/cli/app.rb similarity index 100% rename from features/fixtures/cli-app/lib/cli/app.rb rename to fixtures/cli-app/lib/cli/app.rb diff --git a/features/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb b/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb similarity index 100% rename from features/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb rename to fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb diff --git a/features/fixtures/cli-app/lib/cli/app/version.rb b/fixtures/cli-app/lib/cli/app/version.rb similarity index 100% rename from features/fixtures/cli-app/lib/cli/app/version.rb rename to fixtures/cli-app/lib/cli/app/version.rb diff --git a/features/fixtures/cli-app/script/console b/fixtures/cli-app/script/console similarity index 100% rename from features/fixtures/cli-app/script/console rename to fixtures/cli-app/script/console diff --git a/features/fixtures/cli-app/spec/spec_helper.rb b/fixtures/cli-app/spec/spec_helper.rb similarity index 100% rename from features/fixtures/cli-app/spec/spec_helper.rb rename to fixtures/cli-app/spec/spec_helper.rb diff --git a/features/fixtures/cli-app/spec/support/aruba.rb b/fixtures/cli-app/spec/support/aruba.rb similarity index 100% rename from features/fixtures/cli-app/spec/support/aruba.rb rename to fixtures/cli-app/spec/support/aruba.rb diff --git a/features/fixtures/copy/file.txt b/fixtures/copy/file.txt similarity index 100% rename from features/fixtures/copy/file.txt rename to fixtures/copy/file.txt diff --git a/features/fixtures/empty-app/.gitignore b/fixtures/empty-app/.gitignore similarity index 100% rename from features/fixtures/empty-app/.gitignore rename to fixtures/empty-app/.gitignore diff --git a/features/fixtures/empty-app/.rspec b/fixtures/empty-app/.rspec similarity index 100% rename from features/fixtures/empty-app/.rspec rename to fixtures/empty-app/.rspec diff --git a/features/fixtures/empty-app/README.md b/fixtures/empty-app/README.md similarity index 100% rename from features/fixtures/empty-app/README.md rename to fixtures/empty-app/README.md diff --git a/features/fixtures/empty-app/Rakefile b/fixtures/empty-app/Rakefile similarity index 100% rename from features/fixtures/empty-app/Rakefile rename to fixtures/empty-app/Rakefile diff --git a/features/fixtures/empty-app/bin/cli b/fixtures/empty-app/bin/cli similarity index 100% rename from features/fixtures/empty-app/bin/cli rename to fixtures/empty-app/bin/cli diff --git a/features/fixtures/empty-app/cli-app.gemspec b/fixtures/empty-app/cli-app.gemspec similarity index 100% rename from features/fixtures/empty-app/cli-app.gemspec rename to fixtures/empty-app/cli-app.gemspec diff --git a/features/fixtures/empty-app/lib/cli/app.rb b/fixtures/empty-app/lib/cli/app.rb similarity index 100% rename from features/fixtures/empty-app/lib/cli/app.rb rename to fixtures/empty-app/lib/cli/app.rb diff --git a/features/fixtures/empty-app/lib/cli/app/version.rb b/fixtures/empty-app/lib/cli/app/version.rb similarity index 100% rename from features/fixtures/empty-app/lib/cli/app/version.rb rename to fixtures/empty-app/lib/cli/app/version.rb diff --git a/features/fixtures/empty-app/script/console b/fixtures/empty-app/script/console similarity index 100% rename from features/fixtures/empty-app/script/console rename to fixtures/empty-app/script/console diff --git a/features/fixtures/empty-app/spec/spec_helper.rb b/fixtures/empty-app/spec/spec_helper.rb similarity index 100% rename from features/fixtures/empty-app/spec/spec_helper.rb rename to fixtures/empty-app/spec/spec_helper.rb diff --git a/features/fixtures/fixtures-app/test.txt b/fixtures/fixtures-app/test.txt similarity index 100% rename from features/fixtures/fixtures-app/test.txt rename to fixtures/fixtures-app/test.txt diff --git a/features/fixtures/spawn_process/stderr.sh b/fixtures/spawn_process/stderr.sh similarity index 100% rename from features/fixtures/spawn_process/stderr.sh rename to fixtures/spawn_process/stderr.sh From b66cbfd1c5f02b3371fedfabf82326a37225c302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 11:59:09 +0200 Subject: [PATCH 063/118] Fixed wrong use of ::Platform --- lib/aruba/announcer.rb | 2 +- lib/aruba/api/deprecated.rb | 4 +- lib/aruba/cucumber/command.rb | 46 +++++++++---------- lib/aruba/cucumber/core.rb | 4 +- lib/aruba/cucumber/file.rb | 4 +- lib/aruba/matchers/collection.rb | 2 +- lib/aruba/matchers/command/have_output.rb | 2 +- .../matchers/command/have_output_on_stderr.rb | 2 +- .../matchers/command/have_output_on_stdout.rb | 2 +- lib/aruba/platforms/unix_platform.rb | 2 +- lib/aruba/platforms/windows_platform.rb | 2 +- lib/aruba/process_monitor.rb | 14 +++--- lib/aruba/processes/basic_process.rb | 2 +- lib/aruba/processes/spawn_process.rb | 2 +- 14 files changed, 45 insertions(+), 45 deletions(-) diff --git a/lib/aruba/announcer.rb b/lib/aruba/announcer.rb index f1ad0307d..c9c91f4ef 100644 --- a/lib/aruba/announcer.rb +++ b/lib/aruba/announcer.rb @@ -82,7 +82,7 @@ def after_init output_format :command, '$ %s' output_format :environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) } output_format :modified_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) } - output_format :full_environment, proc { |h| Aruba::Platform.simple_table(h) } + output_format :full_environment, proc { |h| Aruba.platform.simple_table(h) } output_format :timeout, '# %s-timeout: %s seconds' output_format :stderr, "<<-STDERR\n%s\nSTDERR" output_format :stdout, "<<-STDOUT\n%s\nSTDOUT" diff --git a/lib/aruba/api/deprecated.rb b/lib/aruba/api/deprecated.rb index c1fb253ee..674089556 100644 --- a/lib/aruba/api/deprecated.rb +++ b/lib/aruba/api/deprecated.rb @@ -806,7 +806,7 @@ def all_output # `@aruba_timeout_seconds`. def exit_timeout if defined? @aruba_exit_timeout - Aruba::Platform.deprecated('The use of "#exit_timeout" is deprecated. Use "aruba.config.exit_timeout" instead.') + Aruba.platform.deprecated('The use of "#exit_timeout" is deprecated. Use "aruba.config.exit_timeout" instead.') @aruba_exit_timeout else aruba.config.exit_timeout @@ -821,7 +821,7 @@ def exit_timeout # `@aruba_io_wait_seconds def io_wait if defined? @aruba_io_wait_seconds - Aruba::Platform.deprecated('The use of "#io_wait" is deprecated. Use "aruba.config.io_wait_timeout" instead') + Aruba.platform.deprecated('The use of "#io_wait" is deprecated. Use "aruba.config.io_wait_timeout" instead') @aruba_io_wait_seconds else aruba.config.io_wait_timeout diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index d49ed256a..aacbfde79 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -1,32 +1,32 @@ When(/^I run "(.*)"$/) do |cmd| - Aruba::Platform.deprecated(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) - run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), false) + Aruba.platform.deprecated(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + run_simple(Aruba.platform.unescape(cmd, aruba.config.keep_ansi), false) end When(/^I run `([^`]*)`$/) do |cmd| - run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), false) + run_simple(Aruba.platform.unescape(cmd, aruba.config.keep_ansi), false) end When(/^I successfully run "(.*)"$/) do |cmd| - Aruba::Platform.deprecated(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + Aruba.platform.deprecated(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) - run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi)) + run_simple(Aruba.platform.unescape(cmd, aruba.config.keep_ansi)) end ## I successfully run `echo -n "Hello"` ## I successfully run `sleep 29` for up to 30 seconds When(/^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/) do |cmd, secs| - run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), true, secs && secs.to_i) + run_simple(Aruba.platform.unescape(cmd, aruba.config.keep_ansi), true, secs && secs.to_i) end When(/^I run "([^"]*)" interactively$/) do |cmd| - Aruba::Platform.deprecated(%{\e[35m The /^I run "([^"]*)" interactively$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + Aruba.platform.deprecated(%{\e[35m The /^I run "([^"]*)" interactively$/ step definition is deprecated. Please use the `backticks` version\e[0m}) step %(I run `#{cmd}` interactively) end When(/^I run `([^`]*)` interactively$/) do |cmd| - @interactive = run(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi)) + @interactive = run(Aruba.platform.unescape(cmd, aruba.config.keep_ansi)) end When(/^I type "([^"]*)"$/) do |input| @@ -55,7 +55,7 @@ last_command_started.public_send channel.to_sym, :wait_for_io => 0 end - if Aruba::Platform.unescape(output).include? Aruba::Platform.unescape(expected) + if Aruba.platform.unescape(output).include? Aruba.platform.unescape(expected) last_command_started.terminate break @@ -76,7 +76,7 @@ Timeout.timeout(exit_timeout) do loop do begin - expect(last_command_started).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) + expect(last_command_started).to have_output Regexp.new(Aruba.platform.unescape(expected, aruba.config.keep_ansi)) rescue ExpectationError sleep 0.1 retry @@ -91,7 +91,7 @@ Timeout.timeout(exit_timeout) do loop do begin - expect(last_command_started).to have_output Regexp.new(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) + expect(last_command_started).to have_output Regexp.new(Aruba.platform.unescape(expected, aruba.config.keep_ansi)) rescue ExpectationError sleep 0.1 retry @@ -117,15 +117,15 @@ end commands = if cmd - [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] + [process_monitor.get_process(Aruba.platform.detect_ruby(cmd))] else all_commands end expected = if exactly - Aruba::Platform.unescape(expected.chomp) + Aruba.platform.unescape(expected.chomp) else - Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected.chomp))) + Regexp.new(Regexp.escape(Aruba.platform.unescape(expected.chomp))) end if Aruba::VERSION < '1.0' @@ -162,15 +162,15 @@ end commands = if cmd - [process_monitor.get_process(Aruba::Platform.detect_ruby(cmd))] + [process_monitor.get_process(Aruba.platform.detect_ruby(cmd))] else all_commands end expected = if exactly - Aruba::Platform.unescape(expected.chomp) + Aruba.platform.unescape(expected.chomp) else - Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected.chomp))) + Regexp.new(Regexp.escape(Aruba.platform.unescape(expected.chomp))) end if Aruba::VERSION < '1.0' @@ -229,30 +229,30 @@ Then(/^it should (pass|fail) with "(.*?)"$/) do |pass_fail, expected| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba.platform.unescape(expected))) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba.platform.unescape(expected))) end end Then(/^it should (pass|fail) with:$/) do |pass_fail, expected| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba.platform.unescape(expected))) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba::Platform.unescape(expected))) + expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba.platform.unescape(expected))) end end Then(/^it should (pass|fail) with exactly:$/) do |pass_fail, expected| if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Aruba::Platform.unescape(expected) + expect(last_command_stopped).to have_output Aruba.platform.unescape(expected) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Aruba::Platform.unescape(expected) + expect(last_command_stopped).to have_output Aruba.platform.unescape(expected) end end diff --git a/lib/aruba/cucumber/core.rb b/lib/aruba/cucumber/core.rb index 4f7a3c633..c93a80430 100644 --- a/lib/aruba/cucumber/core.rb +++ b/lib/aruba/cucumber/core.rb @@ -6,7 +6,7 @@ Given(/the default aruba timeout is (\d+) seconds/) do |seconds| # rubocop:disable Metrics/LineLength - Aruba::Platform.deprecated(%{The /^the default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use /^the default aruba exit timeout is (\d+) seconds/ step definition is deprecated.}) + Aruba.platform.deprecated(%{The /^the default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use /^the default aruba exit timeout is (\d+) seconds/ step definition is deprecated.}) # rubocop:enable Metrics/LineLength aruba.config.exit_timeout = seconds.to_i @@ -14,7 +14,7 @@ Given(/The default aruba timeout is (\d+) seconds/) do |seconds| # rubocop:disable Metrics/LineLength - Aruba::Platform.deprecated(%{The /^The default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use /^the default aruba exit timeout is (\d+) seconds/ step definition is deprecated.}) + Aruba.platform.deprecated(%{The /^The default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use /^the default aruba exit timeout is (\d+) seconds/ step definition is deprecated.}) # rubocop:enable Metrics/LineLength aruba.config.exit_timeout = seconds.to_i diff --git a/lib/aruba/cucumber/file.rb b/lib/aruba/cucumber/file.rb index 5a078b2d6..e7acf57af 100644 --- a/lib/aruba/cucumber/file.rb +++ b/lib/aruba/cucumber/file.rb @@ -21,7 +21,7 @@ end Given(/^(?:a|the) file(?: named)? "([^"]*)" with "([^"]*)"$/) do |file_name, file_content| - write_file(file_name, Aruba::Platform.unescape(file_content)) + write_file(file_name, Aruba.platform.unescape(file_content)) end Given(/^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/) do |file_name, file_mode, file_content| @@ -179,7 +179,7 @@ end Then(/^the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)"$/) do |file, negated, permissions| - Aruba::Platform.deprecated('The use of step "the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)" is deprecated. Use "^the (?:file|directory)(?: named)? "([^"]*)" should have permissions "([^"]*)"$" instead') + Aruba.platform.deprecated('The use of step "the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)" is deprecated. Use "^the (?:file|directory)(?: named)? "([^"]*)" should have permissions "([^"]*)"$" instead') if negated expect(file).not_to have_permissions(permissions) diff --git a/lib/aruba/matchers/collection.rb b/lib/aruba/matchers/collection.rb index 4490a4e5a..2bc8e638d 100644 --- a/lib/aruba/matchers/collection.rb +++ b/lib/aruba/matchers/collection.rb @@ -1 +1 @@ -Aruba::Platform.require_matching_files('../collection/**/*.rb', __FILE__) +Aruba.platform.require_matching_files('../collection/**/*.rb', __FILE__) diff --git a/lib/aruba/matchers/command/have_output.rb b/lib/aruba/matchers/command/have_output.rb index b84e7d2f5..85ee69b49 100644 --- a/lib/aruba/matchers/command/have_output.rb +++ b/lib/aruba/matchers/command/have_output.rb @@ -29,7 +29,7 @@ ) @old_actual.stop(@announcer) unless @old_actual.stopped? - @actual = Aruba::Platform.unescape(actual.output.chomp, aruba.config.keep_ansi) + @actual = Aruba.platform.unescape(actual.output.chomp, aruba.config.keep_ansi) values_match?(expected, @actual) end diff --git a/lib/aruba/matchers/command/have_output_on_stderr.rb b/lib/aruba/matchers/command/have_output_on_stderr.rb index 4648172d1..9929b1ff9 100644 --- a/lib/aruba/matchers/command/have_output_on_stderr.rb +++ b/lib/aruba/matchers/command/have_output_on_stderr.rb @@ -29,7 +29,7 @@ ) @old_actual.stop(@announcer) unless @old_actual.stopped? - @actual = Aruba::Platform.unescape(actual.stderr.chomp, aruba.config.keep_ansi) + @actual = Aruba.platform.unescape(actual.stderr.chomp, aruba.config.keep_ansi) values_match?(expected, @actual) end diff --git a/lib/aruba/matchers/command/have_output_on_stdout.rb b/lib/aruba/matchers/command/have_output_on_stdout.rb index e92988767..67595680a 100644 --- a/lib/aruba/matchers/command/have_output_on_stdout.rb +++ b/lib/aruba/matchers/command/have_output_on_stdout.rb @@ -29,7 +29,7 @@ ) @old_actual.stop(@announcer) unless @old_actual.stopped? - @actual = Aruba::Platform.unescape(actual.stdout.chomp, aruba.config.keep_ansi) + @actual = Aruba.platform.unescape(actual.stdout.chomp, aruba.config.keep_ansi) values_match?(expected, @actual) end diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb index 3445ea025..8032d24e5 100644 --- a/lib/aruba/platforms/unix_platform.rb +++ b/lib/aruba/platforms/unix_platform.rb @@ -17,7 +17,7 @@ module Platforms # This includes all methods for the UNIX platform class UnixPlatform def self.match? - !FFI::Platform.windows? + !FFI.platform.windows? end def environment_variables diff --git a/lib/aruba/platforms/windows_platform.rb b/lib/aruba/platforms/windows_platform.rb index bd4f55bf4..05a8d6e92 100644 --- a/lib/aruba/platforms/windows_platform.rb +++ b/lib/aruba/platforms/windows_platform.rb @@ -17,7 +17,7 @@ module Platforms # This includes all methods for the Windows platform class WindowsPlatform < UnixPlatform def self.match? - FFI::Platform.windows? + FFI.platform.windows? end # @see UnixPlatform#command_string diff --git a/lib/aruba/process_monitor.rb b/lib/aruba/process_monitor.rb index 5d492b93f..f382855b8 100644 --- a/lib/aruba/process_monitor.rb +++ b/lib/aruba/process_monitor.rb @@ -12,7 +12,7 @@ def initialize(announcer) end def last_exit_status - Aruba::Platform.deprecated('The use of "#last_exit_status" is deprecated. Use "last_command_(started|stopped).exit_status" instead') + Aruba.platform.deprecated('The use of "#last_exit_status" is deprecated. Use "last_command_(started|stopped).exit_status" instead') return @last_exit_status if @last_exit_status all_commands.each { |c| stop_process(c) } @@ -41,14 +41,14 @@ def terminate_process!(process) end def stop_processes! - Aruba::Platform.deprecated('The use of "#stop_processes!" is deprecated. Use "#all_commands.each { |c| c.stop(announcer) }" instead') + Aruba.platform.deprecated('The use of "#stop_processes!" is deprecated. Use "#all_commands.each { |c| c.stop(announcer) }" instead') all_commands.each { |c| stop_process(c) } end # Terminate all running processes def terminate_processes - Aruba::Platform.deprecated('The use of "#terminate_processes" is deprecated. Use "#all_commands.each(&:terminate)" instead') + Aruba.platform.deprecated('The use of "#terminate_processes" is deprecated. Use "#all_commands.each(&:terminate)" instead') processes.each do |_, process| terminate_process(process) @@ -69,7 +69,7 @@ def get_process(wanted) end def only_processes - Aruba::Platform.deprecated('The use of "#only_processes" is deprecated. Use "#all_commands" instead') + Aruba.platform.deprecated('The use of "#only_processes" is deprecated. Use "#all_commands" instead') processes.collect{ |_, process| process } end @@ -107,7 +107,7 @@ def stderr_from(cmd) # The stdout of all process which have run before def all_stdout # rubocop:disable Metrics/LineLength - Aruba::Platform.deprecated('The use of "#all_stdout" is deprecated. Use `all_commands.map { |c| c.stdout }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output_on_stdout /output/" instead') + Aruba.platform.deprecated('The use of "#all_stdout" is deprecated. Use `all_commands.map { |c| c.stdout }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output_on_stdout /output/" instead') # rubocop:enable Metrics/LineLength all_commands.each { |c| c.stop(announcer) } @@ -128,7 +128,7 @@ def all_stdout # The stderr of all process which have run before def all_stderr # rubocop:disable Metrics/LineLength - Aruba::Platform.deprecated('The use of "#all_stderr" is deprecated. Use `all_commands.map { |c| c.stderr }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output_on_stderr /output/" instead') + Aruba.platform.deprecated('The use of "#all_stderr" is deprecated. Use `all_commands.map { |c| c.stderr }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output_on_stderr /output/" instead') # rubocop:enable Metrics/LineLength all_commands.each { |c| c.stop(announcer) } @@ -149,7 +149,7 @@ def all_stderr # The stderr and stdout of all process which have run before def all_output # rubocop:disable Metrics/LineLength - Aruba::Platform.deprecated('The use of "#all_output" is deprecated. Use `all_commands.map { |c| c.output }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output /output/" instead') + Aruba.platform.deprecated('The use of "#all_output" is deprecated. Use `all_commands.map { |c| c.output }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output /output/" instead') # rubocop:enable Metrics/LineLength all_stdout << all_stderr diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index 3713258b9..6aefc77e5 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -60,7 +60,7 @@ def timed_out? # @deprecated # @private def run! - Aruba::Platform.deprecated('The use of "command#run!" is deprecated. You can simply use "command#start" instead.') + Aruba.platform.deprecated('The use of "command#run!" is deprecated. You can simply use "command#start" instead.') start end diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 6a41577bd..7255deb7c 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -126,7 +126,7 @@ def stderr(opts = {}) def read_stdout # rubocop:disable Metrics/LineLength - Aruba::Platform.deprecated('The use of "#read_stdout" is deprecated. Use "#stdout" instead. To reduce the time to wait for io, pass `:wait_for_io => 0` or some suitable for your use case') + Aruba.platform.deprecated('The use of "#read_stdout" is deprecated. Use "#stdout" instead. To reduce the time to wait for io, pass `:wait_for_io => 0` or some suitable for your use case') # rubocop:enable Metrics/LineLength stdout(:wait_for_io => 0) From f878b192886b221f66a74e03d947aa179336be45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 12:00:00 +0200 Subject: [PATCH 064/118] Remove duplicated method --- lib/aruba/api/deprecated.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/aruba/api/deprecated.rb b/lib/aruba/api/deprecated.rb index 674089556..bcae0c6ee 100644 --- a/lib/aruba/api/deprecated.rb +++ b/lib/aruba/api/deprecated.rb @@ -828,14 +828,6 @@ def io_wait end end - # @deprecated - # The root directory of aruba - def root_directory - Aruba.platform.deprecated('The use of "#root_directory" is deprecated. Use "aruba.root_directory" instead') - - aruba.config.root_directory - end - # @deprecated # Only processes def only_processes From 04d1e3a130478081c7105b73908b0a216c471eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 12:02:16 +0200 Subject: [PATCH 065/118] Reverted the fix for ::Platforms for those --- lib/aruba/platforms/unix_platform.rb | 2 +- lib/aruba/platforms/windows_platform.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb index 8032d24e5..3445ea025 100644 --- a/lib/aruba/platforms/unix_platform.rb +++ b/lib/aruba/platforms/unix_platform.rb @@ -17,7 +17,7 @@ module Platforms # This includes all methods for the UNIX platform class UnixPlatform def self.match? - !FFI.platform.windows? + !FFI::Platform.windows? end def environment_variables diff --git a/lib/aruba/platforms/windows_platform.rb b/lib/aruba/platforms/windows_platform.rb index 05a8d6e92..bd4f55bf4 100644 --- a/lib/aruba/platforms/windows_platform.rb +++ b/lib/aruba/platforms/windows_platform.rb @@ -17,7 +17,7 @@ module Platforms # This includes all methods for the Windows platform class WindowsPlatform < UnixPlatform def self.match? - FFI.platform.windows? + FFI::Platform.windows? end # @see UnixPlatform#command_string From b7f9bc9f74fc1c5f35da5066ab7383f14476bfe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 12:11:55 +0200 Subject: [PATCH 066/118] Move platform specific stuff to the correct directory --- lib/aruba/api/filesystem.rb | 15 +++++--------- lib/aruba/cucumber/file.rb | 2 ++ lib/aruba/platforms/aruba_file_creator.rb | 5 ++--- .../aruba_fixed_size_file_creator.rb | 5 ++--- .../determine_disk_usage.rb | 4 ++-- .../determine_file_size.rb | 4 ++-- lib/aruba/platforms/unix_platform.rb | 20 +++++++++++++++++++ 7 files changed, 35 insertions(+), 20 deletions(-) rename lib/aruba/{platform => platforms}/determine_disk_usage.rb (89%) rename lib/aruba/{platform => platforms}/determine_file_size.rb (80%) diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index bd8d55f29..764612796 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -2,11 +2,6 @@ require 'aruba/extensions/string/strip' -require 'aruba/platforms/aruba_file_creator' -require 'aruba/platforms/aruba_fixed_size_file_creator' -require 'aruba/platform/determine_disk_usage' -require 'aruba/platform/determine_file_size' - require 'aruba/aruba_path' Aruba.platform.require_matching_files('../matchers/file/*.rb', __FILE__) @@ -126,7 +121,7 @@ def read(name) # @param [String] file_content # The content which should be written to the file def write_file(name, content) - Creators::ArubaFileCreator.new.write(expand_path(name), content, false) + Aruba.platform.create_file(expand_path(name), content, false) self end @@ -203,7 +198,7 @@ def copy(*args) # @param [Integer] file_size # The size of the file def write_fixed_size_file(name, size) - Creators::ArubaFixedSizeFileCreator.new.write(expand_path(name), size, false) + Aruba.platform.create_fixed_size_file(expand_path(name), size, false) self end @@ -214,7 +209,7 @@ def write_fixed_size_file(name, size) # missing. If the file name is a path the method will create all neccessary # directories. def overwrite_file(name, content) - Creators::ArubaFileCreator.new.write(expand_path(name), content, true) + Aruba.platform.create_file(expand_path(name), content, true) self end @@ -320,7 +315,7 @@ def with_file_content(file, &block) def disk_usage(*paths) expect(paths.flatten).to all be_an_existing_path - Platform::DetermineDiskUsage.new.use paths.flatten.map { |p| ArubaPath.new(expand_path(p)) }, aruba.config.physical_block_size + Aruba.platform.determine_disk_usage.new.call paths.flatten.map { |p| ArubaPath.new(expand_path(p)) }, aruba.config.physical_block_size end # Get size of file @@ -330,7 +325,7 @@ def disk_usage(*paths) def file_size(name) expect(name).to be_an_existing_file - Platform::DetermineFileSize.new.use expand_path(name) + Aruba.platform.determine_file_size expand_path(name) end end end diff --git a/lib/aruba/cucumber/file.rb b/lib/aruba/cucumber/file.rb index e7acf57af..e198d6fbd 100644 --- a/lib/aruba/cucumber/file.rb +++ b/lib/aruba/cucumber/file.rb @@ -179,7 +179,9 @@ end Then(/^the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)"$/) do |file, negated, permissions| + # rubocop:disable Metrics/LineLength Aruba.platform.deprecated('The use of step "the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)" is deprecated. Use "^the (?:file|directory)(?: named)? "([^"]*)" should have permissions "([^"]*)"$" instead') + # rubocop:enable Metrics/LineLength if negated expect(file).not_to have_permissions(permissions) diff --git a/lib/aruba/platforms/aruba_file_creator.rb b/lib/aruba/platforms/aruba_file_creator.rb index 6502ba2a7..c15fa3d87 100644 --- a/lib/aruba/platforms/aruba_file_creator.rb +++ b/lib/aruba/platforms/aruba_file_creator.rb @@ -1,6 +1,5 @@ module Aruba - # Create things to make aruba work - module Creators + module Platforms # Normal File Creator # This class is not meant to be used directly by users. class ArubaFileCreator @@ -14,7 +13,7 @@ class ArubaFileCreator # # @param [TrueClass, FalseClass] check_presence (false) # Check if file exist - def write(path, content, check_presence = false) + def call(path, content, check_presence = false) fail "Expected #{path} to be present" if check_presence && !Aruba.platform.file?(path) Aruba.platform.mkdir(File.dirname(path)) diff --git a/lib/aruba/platforms/aruba_fixed_size_file_creator.rb b/lib/aruba/platforms/aruba_fixed_size_file_creator.rb index f56346d3c..714f94a11 100644 --- a/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +++ b/lib/aruba/platforms/aruba_fixed_size_file_creator.rb @@ -1,6 +1,5 @@ module Aruba - # Create things to make aruba work - module Creators + module Platforms # Create files with fixed size # # This class is not meant to be used directly by users. @@ -18,7 +17,7 @@ class ArubaFixedSizeFileCreator # # @param [TrueClass, FalseClass] check_presence (false) # Check if file exist - def write(path, size, check_presence) + def call(path, size, check_presence) fail "Expected #{path} to be present" if check_presence && !Aruba.platform.file?(path) Aruba.platform.mkdir(File.dirname(path)) diff --git a/lib/aruba/platform/determine_disk_usage.rb b/lib/aruba/platforms/determine_disk_usage.rb similarity index 89% rename from lib/aruba/platform/determine_disk_usage.rb rename to lib/aruba/platforms/determine_disk_usage.rb index 28da1825c..576f480f1 100644 --- a/lib/aruba/platform/determine_disk_usage.rb +++ b/lib/aruba/platforms/determine_disk_usage.rb @@ -1,7 +1,7 @@ module Aruba - module Platform + module Platforms class DetermineDiskUsage - def use(*args) + def call(*args) args = args.flatten physical_block_size = args.pop diff --git a/lib/aruba/platform/determine_file_size.rb b/lib/aruba/platforms/determine_file_size.rb similarity index 80% rename from lib/aruba/platform/determine_file_size.rb rename to lib/aruba/platforms/determine_file_size.rb index ea63f4c62..db21d6bbb 100644 --- a/lib/aruba/platform/determine_file_size.rb +++ b/lib/aruba/platforms/determine_file_size.rb @@ -1,7 +1,7 @@ module Aruba - module Platform + module Platforms class DetermineFileSize - def use(path) + def call(path) return -1 unless File.file? path FileSize.new( diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb index 3445ea025..05dfd4a55 100644 --- a/lib/aruba/platforms/unix_platform.rb +++ b/lib/aruba/platforms/unix_platform.rb @@ -4,6 +4,10 @@ require 'aruba/platforms/simple_table' require 'aruba/platforms/unix_command_string' require 'aruba/platforms/unix_which' +require 'aruba/platforms/determine_file_size' +require 'aruba/platforms/determine_disk_usage' +require 'aruba/platforms/aruba_file_creator' +require 'aruba/platforms/aruba_fixed_size_file_creator' module Aruba # This abstracts OS-specific things @@ -28,6 +32,22 @@ def command_string UnixCommandString end + def determine_file_size(*args) + DetermineFileSize.new.call(*args) + end + + def determine_disk_usage(*args) + DetermineDiskUsage.new.call(*args) + end + + def create_file(*args) + ArubaFileCreator.new.call(*args) + end + + def create_fixed_size_file(*args) + ArubaFixedSizeFileCreator.new.call(*args) + end + def detect_ruby(cmd) if cmd =~ /^ruby\s/ cmd.gsub(/^ruby\s/, "#{current_ruby} ") From 679dfc5d0acc99cd3e79ab72d68050a57af0b143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 12:47:53 +0200 Subject: [PATCH 067/118] Use aruba path to check if command is relative --- lib/aruba/platforms/unix_platform.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb index 05dfd4a55..d62c21ced 100644 --- a/lib/aruba/platforms/unix_platform.rb +++ b/lib/aruba/platforms/unix_platform.rb @@ -1,6 +1,8 @@ require 'rbconfig' require 'pathname' +require 'aruba/aruba_path' + require 'aruba/platforms/simple_table' require 'aruba/platforms/unix_command_string' require 'aruba/platforms/unix_which' @@ -179,8 +181,8 @@ def relative_path?(path) # * /bin/command.sh # * command.sh def relative_command?(path) - p = Pathname.new(path) - p.relative? && p.basename != p + p = ArubaPath.new(path) + p.relative? && p.depth > 1 end # Check if command is relative From 833bec3c3575c5a94bb6024fd443452597a1e8e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 12:48:07 +0200 Subject: [PATCH 068/118] Minor fixes --- spec/aruba/spawn_process_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/aruba/spawn_process_spec.rb b/spec/aruba/spawn_process_spec.rb index f3698ddfc..2a1c9e0e2 100644 --- a/spec/aruba/spawn_process_spec.rb +++ b/spec/aruba/spawn_process_spec.rb @@ -23,7 +23,7 @@ end describe "#stderr" do - let(:command) { 'features/fixtures/spawn_process/stderr.sh yo' } + let(:command) { 'fixtures/spawn_process/stderr.sh yo' } before(:each) { process.run! } From 7da18fbc44eefa8f12f1e199f38e374e303af783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 12:50:46 +0200 Subject: [PATCH 069/118] Use new exit timeout step --- features/commands/flushing.feature | 4 ++-- features/commands/output/all_output.feature | 2 +- features/development/test.feature | 2 +- features/steps/commands/exit_statuses.feature | 6 +++--- features/usage/install.feature | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/features/commands/flushing.feature b/features/commands/flushing.feature index a8851fe93..79204022e 100644 --- a/features/commands/flushing.feature +++ b/features/commands/flushing.feature @@ -29,7 +29,7 @@ Feature: Flushing the output of your application Then the features should all pass Scenario: Tons of output - Given the default aruba timeout is 10 seconds + Given the default aruba exit timeout is 10 seconds And a file named "bin/cli" with: """ #!/usr/bin/env bash @@ -51,7 +51,7 @@ Feature: Flushing the output of your application Then the features should all pass Scenario: Tons of interactive output - Given the default aruba timeout is 10 seconds + Given the default aruba exit timeout is 10 seconds And a file named "bin/cli" with: """ #!/usr/bin/env bash diff --git a/features/commands/output/all_output.feature b/features/commands/output/all_output.feature index d35783809..c5eed9f3f 100644 --- a/features/commands/output/all_output.feature +++ b/features/commands/output/all_output.feature @@ -144,7 +144,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Detect exact one-line output with ANSI output stripped by default - Given the default aruba timeout is 12 seconds + Given the default aruba exit timeout is 12 seconds Given a file named "bin/cli" with: """ #!/usr/bin/env ruby diff --git a/features/development/test.feature b/features/development/test.feature index 927efbb5b..eff32ef12 100644 --- a/features/development/test.feature +++ b/features/development/test.feature @@ -5,7 +5,7 @@ Feature: Build Aruba Gem In order to install it Background: - Given the default aruba timeout is 10 seconds + Given the default aruba exit timeout is 10 seconds And I successfully run `git clone https://github.com/cucumber/aruba.git` And I cd to "aruba" diff --git a/features/steps/commands/exit_statuses.feature b/features/steps/commands/exit_statuses.feature index 0433bd730..9a4014c29 100644 --- a/features/steps/commands/exit_statuses.feature +++ b/features/steps/commands/exit_statuses.feature @@ -94,7 +94,7 @@ Feature: Check exit status of commands """ Feature: Failing program Scenario: Run command - Given the default aruba timeout is 2 seconds + Given the default aruba exit timeout is 2 seconds When I successfully run `cli` """ When I run `cucumber` @@ -110,7 +110,7 @@ Feature: Check exit status of commands """ Feature: Failing program Scenario: Run command - Given the default aruba timeout is 0 seconds + Given the default aruba exit timeout is 0 seconds When I successfully run `cli` for up to 2 seconds """ When I run `cucumber` @@ -126,7 +126,7 @@ Feature: Check exit status of commands """ Feature: Failing program Scenario: Run command - Given the default aruba timeout is 0 seconds + Given the default aruba exit timeout is 0 seconds When I successfully run `cli` for up to 1 seconds """ When I run `cucumber` diff --git a/features/usage/install.feature b/features/usage/install.feature index 96793359a..f35c59b32 100644 --- a/features/usage/install.feature +++ b/features/usage/install.feature @@ -1,7 +1,7 @@ Feature: Install aruba Background: - Given the default aruba timeout is 10 seconds + Given the default aruba exit timeout is 10 seconds # @wip Scenario: Using rubygems From aee0489989825dd88e9635d53f5757c46967c8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 12:52:39 +0200 Subject: [PATCH 070/118] Document the new default value for the fixtures directory --- features/configuration/fixtures_directories.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/configuration/fixtures_directories.feature b/features/configuration/fixtures_directories.feature index 424b000df..ddf435c12 100644 --- a/features/configuration/fixtures_directories.feature +++ b/features/configuration/fixtures_directories.feature @@ -17,7 +17,7 @@ Feature: Configure directory where to look for fixtures When I successfully run `cucumber` Then the output should contain: """ - The default value is "%w(features/fixtures spec/fixtures test/fixtures)" + The default value is "%w(features/fixtures spec/fixtures test/fixtures fixtures)" """ Scenario: Modify value From a8e54ae2090b7f44ef2efb642209b12220b70a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 12:52:49 +0200 Subject: [PATCH 071/118] Use the correct implementation for disk usage --- lib/aruba/api/filesystem.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index 764612796..94c4ddb8b 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -315,7 +315,7 @@ def with_file_content(file, &block) def disk_usage(*paths) expect(paths.flatten).to all be_an_existing_path - Aruba.platform.determine_disk_usage.new.call paths.flatten.map { |p| ArubaPath.new(expand_path(p)) }, aruba.config.physical_block_size + Aruba.platform.determine_disk_usage paths.flatten.map { |p| ArubaPath.new(expand_path(p)) }, aruba.config.physical_block_size end # Get size of file From 09842bce9672277eafe7e7658ce18ede25df52e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 12:55:32 +0200 Subject: [PATCH 072/118] Migrate that code also to Platform --- lib/aruba/disk_usage_calculator.rb | 7 ------- lib/aruba/platforms/determine_disk_usage.rb | 4 +++- lib/aruba/platforms/disk_usage_calculator.rb | 11 +++++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) delete mode 100644 lib/aruba/disk_usage_calculator.rb create mode 100644 lib/aruba/platforms/disk_usage_calculator.rb diff --git a/lib/aruba/disk_usage_calculator.rb b/lib/aruba/disk_usage_calculator.rb deleted file mode 100644 index 8b5422faf..000000000 --- a/lib/aruba/disk_usage_calculator.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Aruba - class DiskUsageCalculator - def calc(blocks, block_size) - FileSize.new(blocks * block_size) - end - end -end diff --git a/lib/aruba/platforms/determine_disk_usage.rb b/lib/aruba/platforms/determine_disk_usage.rb index 576f480f1..74e88d884 100644 --- a/lib/aruba/platforms/determine_disk_usage.rb +++ b/lib/aruba/platforms/determine_disk_usage.rb @@ -1,3 +1,5 @@ +require 'aruba/platforms/disk_usage_calculator' + module Aruba module Platforms class DetermineDiskUsage @@ -8,7 +10,7 @@ def call(*args) paths = args size = paths.flatten.map do |p| - DiskUsageCalculator.new.calc( + DiskUsageCalculator.new.call( p.blocks, physical_block_size ) diff --git a/lib/aruba/platforms/disk_usage_calculator.rb b/lib/aruba/platforms/disk_usage_calculator.rb new file mode 100644 index 000000000..fe60e40b9 --- /dev/null +++ b/lib/aruba/platforms/disk_usage_calculator.rb @@ -0,0 +1,11 @@ +require 'aruba/file_size' + +module Aruba + module Platforms + class DiskUsageCalculator + def call(blocks, block_size) + Aruba::FileSize.new(blocks * block_size) + end + end + end +end From 9e2385331c0988af99b68e61c28fa1825e8f5df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 13:07:58 +0200 Subject: [PATCH 073/118] Better structure for documentation --- .nav | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/.nav b/.nav index ae1a4d1a9..5f364721b 100644 --- a/.nav +++ b/.nav @@ -1,12 +1,77 @@ -README.md -# before_cmd_hooks.feature -# command_environment_variables.feature -# configuration-rspec.feature -# custom_ruby_process.feature -# exit_statuses.feature -# file_system_commands.feature -# flushing.feature -# interactive.feature -# no_clobber.feature -# output.feature -# utf-8.feature +- README.md +- Getting Started: + - usage/install.feature +- Ruby API: + - Core: + - api/core/expand_path.feature + - core/cleanup_aruba_directory.feature + - Commands: + - api/command/run.feature + - api/command/which.feature + - Environment Variables: + - api/environment/append_environment_variable.feature + - api/environment/prepend_environment_variable.feature + - api/environment/set_environment_variable.feature + - Filesystem: + - api/filesystem/cd.feature + - api/filesystem/create_directory.feature + - api/filesystem/disk_usage.feature + - api/filesystem/does_exist.feature + - api/filesystem/is_absolute.feature + - api/filesystem/is_directory.feature + - api/filesystem/is_file.feature + - api/filesystem/is_relative.feature + - file_system_commands.feature + - Hooks: + - hooks/after/command.feature + - hooks/before/command.feature +- Cucumber: + - commands/debug_command.feature + - commands/environment_variables.feature + - commands/flushing.feature + - commands/interactive.feature + - commands/output/all_output.feature + - commands/output/stdout.feature +- Configuration: + - configuration/exit_timeout.feature + - configuration/fixtures_directories.feature + - configuration/fixtures_path_prefix.feature + - configuration/home_directory.feature + - configuration/io_timeout.feature + - configuration/keep_ansi.feature + - configuration/log_level.feature + - configuration/physical_block_size.feature + - configuration/root_directory.feature + - configuration/working_directory.feature +- RSpec: + - Integration: + - integration/rspec/getting_started.feature + - Matchers: + - matchers/collection/include_an_object.feature + - matchers/directory/have_sub_directory.feature + - matchers/file/be_existing_file.feature + - matchers/file/have_file_content.feature + - matchers/file/have_file_size.feature + - matchers/path/be_an_absolute_path.feature + - matchers/path/be_an_existing_path.feature + - matchers/path/have_permissions.feature + - matchers/timeouts.feature +- Cucumber: + - Tags: + - announce.feature + - Steps: + - steps/commands/exit_statuses.feature + - steps/commands/in_process.feature + - steps/commands/run.feature + - steps/environment/home_variable.feature + - steps/environment/set_environment_variable.feature + - steps/filesystem/create_directory.feature + - steps/filesystem/create_file.feature + - steps/filesystem/file_content.feature + - steps/filesystem/overwrite_file.feature + - steps/filesystem/use_fixture.feature + - output.feature + - utf-8.feature +- Development: + - development/build.feature + - development/test.feature From 300bf169992977019d026ea98dee335951655405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 13:29:10 +0200 Subject: [PATCH 074/118] Enable syntax highlighting on relish --- features/announce.feature | 28 +++--- features/api/command/run.feature | 6 +- features/api/command/which.feature | 6 +- features/api/core/expand_path.feature | 8 +- .../append_environment_variable.feature | 10 +-- .../prepend_environment_variable.feature | 10 +-- .../set_environment_variable.feature | 18 ++-- features/api/filesystem/cd.feature | 14 +-- .../api/filesystem/create_directory.feature | 4 +- features/api/filesystem/disk_usage.feature | 12 +-- features/api/filesystem/does_exist.feature | 4 +- features/api/filesystem/is_absolute.feature | 4 +- features/api/filesystem/is_directory.feature | 4 +- features/api/filesystem/is_file.feature | 4 +- features/api/filesystem/is_relative.feature | 4 +- features/commands/debug_command.feature | 12 +-- .../commands/environment_variables.feature | 12 +-- features/commands/flushing.feature | 12 +-- features/commands/interactive.feature | 12 +-- features/commands/output/all_output.feature | 86 +++++++++---------- features/commands/output/stdout.feature | 12 +-- features/configuration/exit_timeout.feature | 10 +-- .../fixtures_directories.feature | 4 +- .../fixtures_path_prefix.feature | 2 +- features/configuration/home_directory.feature | 8 +- features/configuration/io_timeout.feature | 4 +- features/configuration/keep_ansi.feature | 4 +- features/configuration/log_level.feature | 6 +- .../configuration/physical_block_size.feature | 6 +- features/development/test.feature | 2 +- 30 files changed, 164 insertions(+), 164 deletions(-) diff --git a/features/announce.feature b/features/announce.feature index df8fc8ad0..bcae5479e 100644 --- a/features/announce.feature +++ b/features/announce.feature @@ -9,7 +9,7 @@ Feature: Announce output during test run Scenario: Announce change of directory (deprecated) Given a file named "features/exit_status.feature" with: - """ + """cucumber Feature: Announce @announce-dir Scenario: Run command @@ -29,7 +29,7 @@ Feature: Announce output during test run Scenario: Announce change of directory Given a file named "features/exit_status.feature" with: - """ + """cucumber Feature: Announce @announce-directory Scenario: Run command @@ -49,7 +49,7 @@ Feature: Announce output during test run Scenario: Announce stdout Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -58,7 +58,7 @@ Feature: Announce output during test run puts 'Hello World' """ And a file named "features/exit_status.feature" with: - """ + """cucumber Feature: Announce @announce-stdout Scenario: Run command @@ -77,7 +77,7 @@ Feature: Announce output during test run Scenario: Announce stderr Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -86,7 +86,7 @@ Feature: Announce output during test run $stderr.puts 'Hello World' """ And a file named "features/exit_status.feature" with: - """ + """cucumber Feature: Announce @announce-stderr Scenario: Run command @@ -105,7 +105,7 @@ Feature: Announce output during test run Scenario: Announce both stderr and stdout Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -115,7 +115,7 @@ Feature: Announce output during test run puts 'World' """ And a file named "features/exit_status.feature" with: - """ + """cucumber Feature: Announce @announce-output Scenario: Run command @@ -141,14 +141,14 @@ Feature: Announce output during test run Scenario: Announce command Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $stderr.puts 'Hello' puts 'World' """ And a file named "features/exit_status.feature" with: - """ + """cucumber Feature: Announce @announce-cmd Scenario: Run command @@ -164,13 +164,13 @@ Feature: Announce output during test run Scenario: Announce change of environment variable Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts 'World' """ And a file named "features/exit_status.feature" with: - """ + """cucumber Feature: Announce @announce-env Scenario: Run command @@ -189,13 +189,13 @@ Feature: Announce output during test run Scenario: Announce change of environment variable which contains special characters Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts 'World' """ And a file named "features/exit_status.feature" with: - """ + """cucumber Feature: Announce @announce-env Scenario: Run command diff --git a/features/api/command/run.feature b/features/api/command/run.feature index 7f4f54920..55d75bd9c 100644 --- a/features/api/command/run.feature +++ b/features/api/command/run.feature @@ -7,12 +7,12 @@ Feature: Run command Scenario: Existing executable Given an executable named "bin/cli" with: - """ + """bash #!/bin/bash exit 0 """ And a file named "spec/which_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Run command', :type => :aruba do @@ -26,7 +26,7 @@ Feature: Run command Scenario: Non-existing executable Given a file named "bin/cli" does not exist And a file named "spec/which_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Find path for command', :type => :aruba do diff --git a/features/api/command/which.feature b/features/api/command/which.feature index 7e65a1405..9a36802cc 100644 --- a/features/api/command/which.feature +++ b/features/api/command/which.feature @@ -8,12 +8,12 @@ Feature: Get path to command Scenario: Existing executable Given an executable named "bin/cli" with: - """ + """bash #!/bin/bash exit 0 """ And a file named "spec/which_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Find path for command', :type => :aruba do @@ -26,7 +26,7 @@ Feature: Get path to command Scenario: Non-existing executable Given a file named "bin/cli" does not exist And a file named "spec/which_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Find path for command', :type => :aruba do diff --git a/features/api/core/expand_path.feature b/features/api/core/expand_path.feature index 35f4bacf5..94097a9c7 100644 --- a/features/api/core/expand_path.feature +++ b/features/api/core/expand_path.feature @@ -9,7 +9,7 @@ Feature: Expand paths with aruba Scenario: Use relative path Given a file named "spec/expand_path_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Expand path', :type => :aruba do @@ -22,7 +22,7 @@ Feature: Expand paths with aruba Scenario: Change directory using cd Given a file named "spec/expand_path_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Expand path', :type => :aruba do @@ -40,7 +40,7 @@ Feature: Expand paths with aruba Scenario: Warn if aruba's working directory does not exist Given a file named "spec/expand_path_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Expand path', :type => :aruba do @@ -62,7 +62,7 @@ Feature: Expand paths with aruba you need to configure it explicitly via `Aruba.configure {}`. Given a file named "spec/expand_path_spec.rb" with: - """ + """ruby require 'spec_helper' # Old before 1.0.0 diff --git a/features/api/environment/append_environment_variable.feature b/features/api/environment/append_environment_variable.feature index 3658ca4f0..d9482b058 100644 --- a/features/api/environment/append_environment_variable.feature +++ b/features/api/environment/append_environment_variable.feature @@ -15,7 +15,7 @@ Feature: Append environment variable Scenario: Non-existing variable Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Long running command', :type => :aruba do @@ -30,7 +30,7 @@ Feature: Append environment variable Scenario: Existing inner variable Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Long running command', :type => :aruba do @@ -47,7 +47,7 @@ Feature: Append environment variable Scenario: Existing outer variable Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['REALLY_LONG_LONG_VARIABLE'] = 'a' @@ -67,7 +67,7 @@ Feature: Append environment variable Scenario: Run some ruby code with previously set environment Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['REALLY_LONG_LONG_VARIABLE'] = 'a' @@ -95,7 +95,7 @@ Feature: Append environment variable overwrites the variable Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['REALLY_LONG_LONG_VARIABLE'] = 'a' diff --git a/features/api/environment/prepend_environment_variable.feature b/features/api/environment/prepend_environment_variable.feature index 6710e2d93..f3d940ab1 100644 --- a/features/api/environment/prepend_environment_variable.feature +++ b/features/api/environment/prepend_environment_variable.feature @@ -15,7 +15,7 @@ Feature: Prepend environment variable Scenario: Non-existing variable Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Long running command', :type => :aruba do @@ -30,7 +30,7 @@ Feature: Prepend environment variable Scenario: Existing inner variable Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Long running command', :type => :aruba do @@ -47,7 +47,7 @@ Feature: Prepend environment variable Scenario: Existing outer variable Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['REALLY_LONG_LONG_VARIABLE'] = 'a' @@ -67,7 +67,7 @@ Feature: Prepend environment variable Scenario: Run some ruby code with previously set environment Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['REALLY_LONG_LONG_VARIABLE'] = 'a' @@ -95,7 +95,7 @@ Feature: Prepend environment variable overwrites the variable Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['REALLY_LONG_LONG_VARIABLE'] = 'a' diff --git a/features/api/environment/set_environment_variable.feature b/features/api/environment/set_environment_variable.feature index 74bf90464..70f59db07 100644 --- a/features/api/environment/set_environment_variable.feature +++ b/features/api/environment/set_environment_variable.feature @@ -14,7 +14,7 @@ Feature: Set environment variable via API-method Scenario: Non-existing variable Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Long running command', :type => :aruba do @@ -29,7 +29,7 @@ Feature: Set environment variable via API-method Scenario: Existing variable set from within the test Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Long running command', :type => :aruba do @@ -47,7 +47,7 @@ Feature: Set environment variable via API-method Scenario: Existing variable set by some outer parent process Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['REALLY_LONG_LONG_VARIABLE'] = '1' @@ -69,7 +69,7 @@ Feature: Set environment variable via API-method avaiable for the code run within the block. Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['REALLY_LONG_LONG_VARIABLE'] = '1' @@ -97,7 +97,7 @@ Feature: Set environment variable via API-method Pass it an `Hash` containing the environment variables. Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['REALLY_LONG_LONG_VARIABLE'] = '1' @@ -124,7 +124,7 @@ Feature: Set environment variable via API-method scope, when you are using `RSpec`. Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Long running command', :type => :aruba do @@ -149,7 +149,7 @@ Feature: Set environment variable via API-method Scenario: When an error occures the ENV is not polluted Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['REALLY_LONG_LONG_VARIABLE'] = '1' @@ -182,7 +182,7 @@ Feature: Set environment variable via API-method the most inner block. Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' ENV['LONG_LONG_VARIABLE'] = '1' @@ -212,7 +212,7 @@ Feature: Set environment variable via API-method run. Given a file named "spec/environment_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Long running command', :type => :aruba do diff --git a/features/api/filesystem/cd.feature b/features/api/filesystem/cd.feature index 2f2eab55a..31de34b63 100644 --- a/features/api/filesystem/cd.feature +++ b/features/api/filesystem/cd.feature @@ -15,7 +15,7 @@ Feature: Change current working directory Scenario: Existing directory Given a file named "spec/cd_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'cd to directory', :type => :aruba do @@ -34,7 +34,7 @@ Feature: Change current working directory Scenario: Non-Existing directory Given a file named "spec/cd_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'cd to directory', :type => :aruba do @@ -50,7 +50,7 @@ Feature: Change current working directory Scenario: With block in it-block Given a file named "spec/cd_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'cd to directory', :type => :aruba do @@ -74,7 +74,7 @@ Feature: Change current working directory \* Aruba's current directory Given a file named "spec/cd_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'cd to directory', :type => :aruba do @@ -101,7 +101,7 @@ Feature: Change current working directory block-notation of `cd`. Given a file named "spec/cd_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'cd to directory', :type => :aruba do @@ -125,7 +125,7 @@ Feature: Change current working directory block-notation of `cd`. Given a file named "spec/cd_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'cd to directory', :type => :aruba do @@ -153,7 +153,7 @@ Feature: Change current working directory block-notation of `cd`. Given a file named "spec/cd_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'cd to directory', :type => :aruba do diff --git a/features/api/filesystem/create_directory.feature b/features/api/filesystem/create_directory.feature index cc48d85e1..add784993 100644 --- a/features/api/filesystem/create_directory.feature +++ b/features/api/filesystem/create_directory.feature @@ -23,7 +23,7 @@ Feature: Create Directory Scenario: New directory Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Create directory', :type => :aruba do @@ -41,7 +41,7 @@ Feature: Create Directory It does not complain if a directory already exists. Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Create directory', :type => :aruba do diff --git a/features/api/filesystem/disk_usage.feature b/features/api/filesystem/disk_usage.feature index f290c5525..f20ffef18 100644 --- a/features/api/filesystem/disk_usage.feature +++ b/features/api/filesystem/disk_usage.feature @@ -21,7 +21,7 @@ Feature: Report disk usage Scenario: Show disk usage for file Given a file named "spec/disk_usage_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'disk usage', :type => :aruba do @@ -44,7 +44,7 @@ Feature: Report disk usage `#disk_usage` creates the sum of all given objects' sizes. Given a file named "spec/disk_usage_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'disk usage', :type => :aruba do @@ -67,7 +67,7 @@ Feature: Report disk usage Scenario: Convert reported disk usage to KibiByte Given a file named "spec/disk_usage_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'disk usage', :type => :aruba do @@ -87,7 +87,7 @@ Feature: Report disk usage Scenario: Convert reported disk usage to MebiByte Given a file named "spec/disk_usage_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'disk usage', :type => :aruba do @@ -107,7 +107,7 @@ Feature: Report disk usage Scenario: Convert reported disk usage to GibiByte Given a file named "spec/disk_usage_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'disk usage', :type => :aruba do @@ -127,7 +127,7 @@ Feature: Report disk usage Scenario: Compare two repored disk usages Given a file named "spec/disk_usage_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'disk usage', :type => :aruba do diff --git a/features/api/filesystem/does_exist.feature b/features/api/filesystem/does_exist.feature index 9786836fb..442e3e663 100644 --- a/features/api/filesystem/does_exist.feature +++ b/features/api/filesystem/does_exist.feature @@ -28,7 +28,7 @@ Feature: Check existence of files and directories Scenario: Is file or directory and exists Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Check if directory and file exist', :type => :aruba do @@ -47,7 +47,7 @@ Feature: Check existence of files and directories Scenario: Is file or directory and does not exist Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Check if directory and file exist', :type => :aruba do diff --git a/features/api/filesystem/is_absolute.feature b/features/api/filesystem/is_absolute.feature index 9e251839f..dbea5d3f0 100644 --- a/features/api/filesystem/is_absolute.feature +++ b/features/api/filesystem/is_absolute.feature @@ -21,7 +21,7 @@ Feature: Check if path is absolute Scenario: Is path absolute Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Check if directory or file is absolute', :type => :aruba do @@ -35,7 +35,7 @@ Feature: Check if path is absolute Scenario: Path should be absolute, but it's relative Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Check if directory or file is absolute', :type => :aruba do diff --git a/features/api/filesystem/is_directory.feature b/features/api/filesystem/is_directory.feature index eb2d47edc..7dcd9985f 100644 --- a/features/api/filesystem/is_directory.feature +++ b/features/api/filesystem/is_directory.feature @@ -24,7 +24,7 @@ Feature: Check existence of directories Scenario: Is directory and exist Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Check if directory and file exist', :type => :aruba do @@ -39,7 +39,7 @@ Feature: Check existence of directories Scenario: Is file, but should be directory and exist Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Check if directory and file exist', :type => :aruba do diff --git a/features/api/filesystem/is_file.feature b/features/api/filesystem/is_file.feature index dec74284e..0fdd5ac79 100644 --- a/features/api/filesystem/is_file.feature +++ b/features/api/filesystem/is_file.feature @@ -24,7 +24,7 @@ Feature: Check existence of files Scenario: Is file and exist Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Check if directory and file exist', :type => :aruba do @@ -40,7 +40,7 @@ Feature: Check existence of files Scenario: Is directory, but should be file and exist Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Check if directory and file exist', :type => :aruba do diff --git a/features/api/filesystem/is_relative.feature b/features/api/filesystem/is_relative.feature index 1cdbf7400..633e6802c 100644 --- a/features/api/filesystem/is_relative.feature +++ b/features/api/filesystem/is_relative.feature @@ -21,7 +21,7 @@ Feature: Check if path is relative Scenario: Is path relative Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Check if directory or file is relative', :type => :aruba do @@ -35,7 +35,7 @@ Feature: Check if path is relative Scenario: Path should be relative, but it's relative Given a file named "spec/create_directory_spec.rb" with: - """ + """ruby require 'spec_helper' RSpec.describe 'Check if directory or file is relative', :type => :aruba do diff --git a/features/commands/debug_command.feature b/features/commands/debug_command.feature index 600a67cfe..291fa3cfb 100644 --- a/features/commands/debug_command.feature +++ b/features/commands/debug_command.feature @@ -9,13 +9,13 @@ Feature: Debug your command in cucumber-test-run Scenario: Can handle exit status 0 Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby exit 0 """ And a file named "features/debug.feature" with: - """ + """cucumber Feature: Exit status in debug environment @debug @@ -28,13 +28,13 @@ Feature: Debug your command in cucumber-test-run Scenario: Can handle exit status 1 Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby exit 1 """ And a file named "features/debug.feature" with: - """ + """cucumber Feature: Exit status in debug environment @debug @@ -60,7 +60,7 @@ Feature: Debug your command in cucumber-test-run debugger for any other programming language should also work. Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $stderr.sync = true @@ -72,7 +72,7 @@ Feature: Debug your command in cucumber-test-run exit 0 """ And a file named "features/debug.feature" with: - """ + """cucumber Feature: Exit status in debug environment @debug diff --git a/features/commands/environment_variables.feature b/features/commands/environment_variables.feature index 25f764760..c9d858cf3 100644 --- a/features/commands/environment_variables.feature +++ b/features/commands/environment_variables.feature @@ -9,13 +9,13 @@ Feature: Modify environment variables Scenario: Change/Set value of arbitrary environment variable Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts ENV['LONG_LONG_VARIABLE'] """ And a file named "features/environment_variable.feature" with: - """ + """cucumber Feature: Flushing output Scenario: Run command Given I set the environment variables to: @@ -29,13 +29,13 @@ Feature: Modify environment variables Scenario: Change the HOME-variable of current user during test using custom step Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts File.expand_path('~/') """ And a file named "features/home_directory.feature" with: - """ + """cucumber Feature: Run command with different home directory Scenario: Run command Given a mocked home directory @@ -47,13 +47,13 @@ Feature: Modify environment variables Scenario: Change the HOME-variable of current user during test using tag Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts File.expand_path('~/') """ And a file named "features/home_directory.feature" with: - """ + """cucumber Feature: Run command @mocked_home_directory Scenario: Run command diff --git a/features/commands/flushing.feature b/features/commands/flushing.feature index 79204022e..33b82a141 100644 --- a/features/commands/flushing.feature +++ b/features/commands/flushing.feature @@ -9,7 +9,7 @@ Feature: Flushing the output of your application Scenario: A little output Given a file named "bin/cli" with: - """ + """bash #!/usr/bin/env bash for ((c=0; c<256; c = c+1)); do @@ -17,7 +17,7 @@ Feature: Flushing the output of your application done """ And a file named "features/flushing.feature" with: - """ + """cucumber Feature: Flushing output Scenario: Run command When I run `cli` @@ -31,7 +31,7 @@ Feature: Flushing the output of your application Scenario: Tons of output Given the default aruba exit timeout is 10 seconds And a file named "bin/cli" with: - """ + """bash #!/usr/bin/env bash for ((c=0; c<65536; c = c+1)); do @@ -39,7 +39,7 @@ Feature: Flushing the output of your application done """ And a file named "features/flushing.feature" with: - """ + """cucumber Feature: Flushing output Scenario: Run command When I run `cli` @@ -53,7 +53,7 @@ Feature: Flushing the output of your application Scenario: Tons of interactive output Given the default aruba exit timeout is 10 seconds And a file named "bin/cli" with: - """ + """bash #!/usr/bin/env bash read size; for ((c=0; c<$size; c = c+1)); do @@ -61,7 +61,7 @@ Feature: Flushing the output of your application done """ And a file named "features/flushing.feature" with: - """ + """cucumber Feature: Flushing output Scenario: Run command When I run `cli` interactively diff --git a/features/commands/interactive.feature b/features/commands/interactive.feature index 9512ff50d..c53df22a9 100644 --- a/features/commands/interactive.feature +++ b/features/commands/interactive.feature @@ -10,7 +10,7 @@ Feature: Interactive process control @wip-jruby-java-1.6 Scenario: Running ruby interactively Given a file named "bin/cli" with: - """ + """bash #!/usr/bin/env ruby while res = gets.chomp @@ -19,7 +19,7 @@ Feature: Interactive process control end """ And a file named "features/interactive.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` interactively @@ -33,7 +33,7 @@ Feature: Interactive process control @posix Scenario: Running a native binary interactively Given a file named "features/interactive.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cat` interactively @@ -47,7 +47,7 @@ Feature: Interactive process control @posix Scenario: Pipe in a file Given a file named "features/interactive.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command Given a file named "test.txt" with "line1\nline2" @@ -61,7 +61,7 @@ Feature: Interactive process control @posix Scenario: Close stdin stream Given a file named "features/interactive.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cat` interactively @@ -78,7 +78,7 @@ Feature: Interactive process control See: http://github.com/aslakhellesoy/aruba/issues#issue/17 for context Given a file named "features/interactive.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command Given a directory named "rename_me" diff --git a/features/commands/output/all_output.feature b/features/commands/output/all_output.feature index c5eed9f3f..6ab285291 100644 --- a/features/commands/output/all_output.feature +++ b/features/commands/output/all_output.feature @@ -9,13 +9,13 @@ Feature: All output of commands which were executed Scenario: Detect subset of one-line output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts 'hello world' """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -26,13 +26,13 @@ Feature: All output of commands which were executed Scenario: Detect absence of one-line output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts 'hello world' """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -43,13 +43,13 @@ Feature: All output of commands which were executed Scenario: Detect subset of multiline output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts "hello\nworld" """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -63,13 +63,13 @@ Feature: All output of commands which were executed Scenario: Detect absence of subset of multiline output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts "hello\nworld" """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -84,7 +84,7 @@ Feature: All output of commands which were executed @posix Scenario: Detect exact one-line output for posix commands Given a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `printf 'hello world'` @@ -98,7 +98,7 @@ Feature: All output of commands which were executed Scenario: Detect exact one-line output for ruby commands Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -107,7 +107,7 @@ Feature: All output of commands which were executed print "hello world" """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -121,7 +121,7 @@ Feature: All output of commands which were executed Scenario: Detect exact one-line output with ANSI output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -130,7 +130,7 @@ Feature: All output of commands which were executed print "\e[36mhello world\e[0m" """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command @keep-ansi-escape-sequences Scenario: Run command @@ -146,7 +146,7 @@ Feature: All output of commands which were executed Scenario: Detect exact one-line output with ANSI output stripped by default Given the default aruba exit timeout is 12 seconds Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -155,7 +155,7 @@ Feature: All output of commands which were executed print "\e[36mhello world\e[0m" """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -169,7 +169,7 @@ Feature: All output of commands which were executed Scenario: Detect exact multiline output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -178,7 +178,7 @@ Feature: All output of commands which were executed print "hello\nworld" """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -193,13 +193,13 @@ Feature: All output of commands which were executed Scenario: Detect subset of one-line output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts 'hello world' """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -210,13 +210,13 @@ Feature: All output of commands which were executed Scenario: Detect subset of one-line output with regex Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts 'hello, ruby' """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -227,13 +227,13 @@ Feature: All output of commands which were executed Scenario: Detect subset of multiline output with regex Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts "hello\nworld\nextra line1\nextra line2\nimportant line" """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -250,13 +250,13 @@ Feature: All output of commands which were executed Scenario: Negative matching of one-line output with regex Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts "hello, ruby" """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -267,13 +267,13 @@ Feature: All output of commands which were executed Scenario: Negative matching of multiline output with regex Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts "hello\nworld\nextra line1\nextra line2\nimportant line" """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -291,14 +291,14 @@ Feature: All output of commands which were executed Scenario: Match passing exit status and partial output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts "hello world" exit 0 """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -312,7 +312,7 @@ Feature: All output of commands which were executed Scenario: Match passing exit status and exact output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -322,7 +322,7 @@ Feature: All output of commands which were executed exit 0 """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -337,14 +337,14 @@ Feature: All output of commands which were executed Scenario: Match failing exit status and partial output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts "hello\nworld" exit 1 """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -359,7 +359,7 @@ Feature: All output of commands which were executed Scenario: Match failing exit status and exact output Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -369,7 +369,7 @@ Feature: All output of commands which were executed exit 1 """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -384,7 +384,7 @@ Feature: All output of commands which were executed Scenario: Match failing exit status and output with regex Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -394,7 +394,7 @@ Feature: All output of commands which were executed exit 1 """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -408,7 +408,7 @@ Feature: All output of commands which were executed Scenario: Detect output from all processes Given an executable named "bin/cli1" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -417,7 +417,7 @@ Feature: All output of commands which were executed puts 'This is cli1' """ And an executable named "bin/cli2" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -426,7 +426,7 @@ Feature: All output of commands which were executed puts 'This is cli2' """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli1` @@ -445,7 +445,7 @@ Feature: All output of commands which were executed Scenario: Detect output from all processes (deprecated) Given an executable named "bin/cli1" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -454,7 +454,7 @@ Feature: All output of commands which were executed puts 'This is cli1' """ And an executable named "bin/cli2" with: - """ + """ruby #!/usr/bin/env ruby $LOAD_PATH << File.expand_path('../../lib', __FILE__) @@ -463,7 +463,7 @@ Feature: All output of commands which were executed puts 'This is cli2' """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli1` diff --git a/features/commands/output/stdout.feature b/features/commands/output/stdout.feature index 485d8b075..5ff3e3f44 100644 --- a/features/commands/output/stdout.feature +++ b/features/commands/output/stdout.feature @@ -9,13 +9,13 @@ Feature: Stdout of commands which were executed Scenario: Match output in stdout Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts "hello\nworld" """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -27,13 +27,13 @@ Feature: Stdout of commands which were executed Scenario: Match stdout on several lines Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts 'GET /' """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` @@ -47,13 +47,13 @@ Feature: Stdout of commands which were executed Scenario: Match output on several lines where stdout contains quotes Given a file named "bin/cli" with: - """ + """ruby #!/usr/bin/env ruby puts 'GET "/"' """ And a file named "features/output.feature" with: - """ + """cucumber Feature: Run command Scenario: Run command When I run `cli` diff --git a/features/configuration/exit_timeout.feature b/features/configuration/exit_timeout.feature index acbc81d11..b1406ab3a 100644 --- a/features/configuration/exit_timeout.feature +++ b/features/configuration/exit_timeout.feature @@ -9,7 +9,7 @@ Feature: Configure timeout for command execution Scenario: Default value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| puts %(The default value is "#{config.exit_timeout}") end @@ -22,12 +22,12 @@ Feature: Configure timeout for command execution Scenario: Modify value Given an executable named "bin/cli" with: - """ + """bash #!/bin/bash sleep 1 """ And a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| config.exit_timeout = 2 end @@ -37,12 +37,12 @@ Feature: Configure timeout for command execution Scenario: Fails if takes longer Given an executable named "bin/cli" with: - """ + """ruby #!/bin/bash sleep 2 """ And a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| config.exit_timeout = 1 end diff --git a/features/configuration/fixtures_directories.feature b/features/configuration/fixtures_directories.feature index ddf435c12..055c76540 100644 --- a/features/configuration/fixtures_directories.feature +++ b/features/configuration/fixtures_directories.feature @@ -9,7 +9,7 @@ Feature: Configure directory where to look for fixtures Scenario: Default value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| puts %(The default value is "%w(#{config.fixtures_directories.join(" ")})") end @@ -22,7 +22,7 @@ Feature: Configure directory where to look for fixtures Scenario: Modify value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| config.fixtures_directories = %w(spec/fixtures) end diff --git a/features/configuration/fixtures_path_prefix.feature b/features/configuration/fixtures_path_prefix.feature index 728d9334a..e2aa6c54c 100644 --- a/features/configuration/fixtures_path_prefix.feature +++ b/features/configuration/fixtures_path_prefix.feature @@ -9,7 +9,7 @@ Feature: Use fixtures path prefix of aruba Scenario: Default value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| puts "The prefix is \"#{config.fixtures_path_prefix}\"." end diff --git a/features/configuration/home_directory.feature b/features/configuration/home_directory.feature index 734069c87..dc1836670 100644 --- a/features/configuration/home_directory.feature +++ b/features/configuration/home_directory.feature @@ -14,7 +14,7 @@ Feature: Configure the home directory to be used with aruba Scenario: Default value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| puts %(The default value is "#{config.home_directory}") end @@ -27,7 +27,7 @@ Feature: Configure the home directory to be used with aruba Scenario: Set to current working directory Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| # use current working directory config.home_directory = '.' @@ -45,7 +45,7 @@ Feature: Configure the home directory to be used with aruba Scenario: Set to aruba's working directory Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| # Use aruba working directory config.home_directory = File.join(config.root_directory, config.working_directory) @@ -63,7 +63,7 @@ Feature: Configure the home directory to be used with aruba Scenario: Set to some other path (deprecated) Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| # use current working directory config.home_directory = '/tmp/home' diff --git a/features/configuration/io_timeout.feature b/features/configuration/io_timeout.feature index e8158a80a..b89d79805 100644 --- a/features/configuration/io_timeout.feature +++ b/features/configuration/io_timeout.feature @@ -9,7 +9,7 @@ Feature: Configure timeout for io of commands Scenario: Default value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| puts %(The default value is "#{config.io_wait_timeout}") end @@ -22,7 +22,7 @@ Feature: Configure timeout for io of commands Scenario: Modify value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| config.io_wait_timeout = 2 end diff --git a/features/configuration/keep_ansi.feature b/features/configuration/keep_ansi.feature index 8e935c4ff..548641289 100644 --- a/features/configuration/keep_ansi.feature +++ b/features/configuration/keep_ansi.feature @@ -9,7 +9,7 @@ Feature: Configure if ansi color codes should be stripped off from command outpu Scenario: Default value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| puts %(The default value is "#{config.keep_ansi}") end @@ -22,7 +22,7 @@ Feature: Configure if ansi color codes should be stripped off from command outpu Scenario: Modify value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| config.keep_ansi = true end diff --git a/features/configuration/log_level.feature b/features/configuration/log_level.feature index 0df9cce0c..a7a2436d0 100644 --- a/features/configuration/log_level.feature +++ b/features/configuration/log_level.feature @@ -9,20 +9,20 @@ Feature: Configure Log level of aruba logger Scenario: Default value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| puts %(The default value is "#{config.log_level}") end """ When I successfully run `cucumber` Then the output should contain: - """ + """ruby The default value is "info" """ Scenario: Modify value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| config.log_level = :warn end diff --git a/features/configuration/physical_block_size.feature b/features/configuration/physical_block_size.feature index f2281b66b..b12c23f11 100644 --- a/features/configuration/physical_block_size.feature +++ b/features/configuration/physical_block_size.feature @@ -9,7 +9,7 @@ Feature: Configure the phsical block size of disk Scenario: Default value Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| puts %(The default value is "#{config.physical_block_size}") end @@ -22,7 +22,7 @@ Feature: Configure the phsical block size of disk Scenario: Set the block size to something else which is a power of two Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| # use current working directory config.physical_block_size = 4096 @@ -40,7 +40,7 @@ Feature: Configure the phsical block size of disk Scenario: The value needs to be a power of two, otherwise it will fail Given a file named "features/support/aruba.rb" with: - """ + """ruby Aruba.configure do |config| config.physical_block_size = 3 end diff --git a/features/development/test.feature b/features/development/test.feature index eff32ef12..6d23055e6 100644 --- a/features/development/test.feature +++ b/features/development/test.feature @@ -5,7 +5,7 @@ Feature: Build Aruba Gem In order to install it Background: - Given the default aruba exit timeout is 10 seconds + Given the default aruba exit timeout is 120 seconds And I successfully run `git clone https://github.com/cucumber/aruba.git` And I cd to "aruba" From 81aee039682d2436024314fdf2afc3e1dca69008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 14:56:11 +0200 Subject: [PATCH 075/118] Added move and copy steps to aruba --- features/api/filesystem/move.feature | 119 +++++++++++++++++++++++++ features/steps/filesystem/copy.feature | 45 ++++++++++ features/steps/filesystem/move.feature | 45 ++++++++++ lib/aruba/api/filesystem.rb | 44 +++++++++ lib/aruba/cucumber/file.rb | 10 ++- lib/aruba/platforms/unix_platform.rb | 5 ++ 6 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 features/api/filesystem/move.feature create mode 100644 features/steps/filesystem/copy.feature create mode 100644 features/steps/filesystem/move.feature diff --git a/features/api/filesystem/move.feature b/features/api/filesystem/move.feature new file mode 100644 index 000000000..f70699e0c --- /dev/null +++ b/features/api/filesystem/move.feature @@ -0,0 +1,119 @@ +Feature: Move file/directory + + If you need to move some files/directories you can use the `#move`-method + command. If multiple arguments are given, the last one needs to be a directory. + + Background: + Given I use a fixture named "cli-app" + + Scenario: Non-existing destination + Given a file named "spec/cd_spec.rb" with: + """ruby + require 'spec_helper' + + RSpec.describe 'Move', :type => :aruba do + let(:old_location) { 'old_dir.d' } + let(:new_location) { 'new_dir.d' } + + before(:each) do + create_directory old_location + move old_location, new_location + end + + it { expect(new_location).to be_an_existing_directory } + end + """ + When I run `rspec` + Then the specs should all pass + + Scenario: Existing destination + Given a file named "spec/cd_spec.rb" with: + """ruby + require 'spec_helper' + + RSpec.describe 'Move', :type => :aruba do + let(:old_location) { 'old_dir.d' } + let(:new_location) { 'new_dir.d' } + + before(:each) do + create_directory old_location + create_directory new_location + + move old_location, new_location + end + + it { expect(File.join(new_location, old_location)).to be_an_existing_directory } + end + """ + When I run `rspec` + Then the specs should all pass + + Scenario: Source is fixture path + Given a file named "spec/cd_spec.rb" with: + """ruby + require 'spec_helper' + + RSpec.describe 'Move', :type => :aruba do + let(:old_location) { '%/old_dir.d' } + let(:new_location) { 'new_dir.d' } + + it { expect { move old_location, new_location }.to raise_error ArgumentError, /fixture/ } + end + """ + When I run `rspec` + Then the specs should all pass + + Scenario: Destination is fixture path + Given a file named "spec/cd_spec.rb" with: + """ruby + require 'spec_helper' + + RSpec.describe 'Move', :type => :aruba do + let(:old_location) { 'old_dir.d' } + let(:new_location) { '%/new_dir.d' } + + it { expect { move old_location, new_location }.to raise_error ArgumentError, /fixture/ } + end + """ + When I run `rspec` + Then the specs should all pass + + Scenario: Multiple sources and destination is directory + Given a file named "spec/cd_spec.rb" with: + """ruby + require 'spec_helper' + + RSpec.describe 'Move', :type => :aruba do + let(:old_location) { %w(old_dir1.d old_dir2.d) } + let(:new_location) { 'new_dir.d' } + + before :each do + old_location.each { |l| create_directory l } + move old_location, new_location + end + + it { expect(old_location.map { |l| File.join(new_location, l) }).to all be_an_existing_directory } + end + """ + When I run `rspec` + Then the specs should all pass + + Scenario: Multiple sources and destination is file + Given a file named "spec/cd_spec.rb" with: + """ruby + require 'spec_helper' + + RSpec.describe 'Move', :type => :aruba do + let(:old_location) { %w(old_dir1.d old_dir2.d) } + let(:new_location) { 'new_file.txt' } + + before :each do + old_location.each { |l| create_directory l } + touch new_location + end + + it { expect { move old_location, new_location }.to raise_error ArgumentError, /Multiple sources/ } + end + """ + When I run `rspec` + Then the specs should all pass diff --git a/features/steps/filesystem/copy.feature b/features/steps/filesystem/copy.feature new file mode 100644 index 000000000..647a008d3 --- /dev/null +++ b/features/steps/filesystem/copy.feature @@ -0,0 +1,45 @@ +Feature: Copy file or directory + + As a user of aruba + I want ot copy a file or a directory + To setup my tests + + Background: + Given I use a fixture named "cli-app" + + Scenario: Copy file + Given a file named "features/copy.feature" with: + """ + Feature: Copy + Scenario: Copy + Given an empty file named "file1.txt" + And an empty file named "file2.txt" + And an empty file named "file3.txt" + When I copy a file named "file1.txt" to "new_file1.txt" + When I copy a file from "file2.txt" to "new_file2.txt" + When I copy the file "file3.txt" to "new_file3.txt" + Then a file named "new_file1.txt" should exist + Then a file named "new_file2.txt" should exist + Then a file named "new_file3.txt" should exist + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Copy directory + Given a file named "features/copy.feature" with: + """ + Feature: Copy + Scenario: Copy + Given a directory named "dir1.d" + And a directory named "dir2.d" + And a directory named "dir3.d" + When I copy a directory named "dir1.d" to "new_dir1.d" + When I copy a directory from "dir2.d" to "new_dir2.d" + When I copy the directory "dir3.d" to "new_dir3.d" + Then a directory named "new_dir1.d" should exist + Then a directory named "new_dir2.d" should exist + Then a directory named "new_dir3.d" should exist + """ + When I run `cucumber` + Then the features should all pass + diff --git a/features/steps/filesystem/move.feature b/features/steps/filesystem/move.feature new file mode 100644 index 000000000..55763c39c --- /dev/null +++ b/features/steps/filesystem/move.feature @@ -0,0 +1,45 @@ +Feature: Move file or directory + + As a user of aruba + I want ot move a file or a directory + To setup my tests + + Background: + Given I use a fixture named "cli-app" + + Scenario: Move file + Given a file named "features/move.feature" with: + """ + Feature: Move + Scenario: Move + Given an empty file named "file1.txt" + And an empty file named "file2.txt" + And an empty file named "file3.txt" + When I move a file named "file1.txt" to "new_file1.txt" + When I move a file from "file2.txt" to "new_file2.txt" + When I move the file "file3.txt" to "new_file3.txt" + Then a file named "new_file1.txt" should exist + Then a file named "new_file2.txt" should exist + Then a file named "new_file3.txt" should exist + """ + When I run `cucumber` + Then the features should all pass + + Scenario: Move directory + Given a file named "features/move.feature" with: + """ + Feature: Move + Scenario: Move + Given a directory named "dir1.d" + And a directory named "dir2.d" + And a directory named "dir3.d" + When I move a directory named "dir1.d" to "new_dir1.d" + When I move a directory from "dir2.d" to "new_dir2.d" + When I move the directory "dir3.d" to "new_dir3.d" + Then a directory named "new_dir1.d" should exist + Then a directory named "new_dir2.d" should exist + Then a directory named "new_dir3.d" should exist + """ + When I run `cucumber` + Then the features should all pass + diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index 94c4ddb8b..72e4d1039 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -187,6 +187,50 @@ def copy(*args) end # rubocop:enable Metrics/CyclomaticComplexity + # Move a file and/or directory + # + # @param [String, Array] source + # A single file or directory, multiple files or directories or multiple + # files and directories. If multiple sources are given the destination + # needs to be a directory + # + # @param [String] destination + # A file or directory name. If multiple sources are given the destination + # needs to be a directory + # + # rubocop:disable Metrics/CyclomaticComplexity + def move(*args) + args = args.flatten + destination = args.pop + source = args + + source.each do |s| + raise ArgumentError, "Using a fixture as source (#{source}) is not supported" if s.start_with? aruba.config.fixtures_path_prefix + end + + raise ArgumentError, "Using a fixture as destination (#{destination}) is not supported" if destination.start_with? aruba.config.fixtures_path_prefix + + source.each do |s| + raise ArgumentError, %(The following source "#{s}" does not exist.) unless exist? s + end + + raise ArgumentError, "Multiple sources can only be copied to a directory" if source.count > 1 && exist?(destination) && !directory?(destination) + + source_paths = source.map { |f| expand_path(f) } + destination_path = expand_path(destination) + + if source_paths.count > 1 + Aruba.platform.mkdir(destination_path) + else + Aruba.platform.mkdir(File.dirname(destination_path)) + source_paths = source_paths.first + end + + Aruba.platform.mv source_paths, destination_path + + self + end + # Create a file with the given size # # The method does not check if file already exists. If the file name is a diff --git a/lib/aruba/cucumber/file.rb b/lib/aruba/cucumber/file.rb index e198d6fbd..f0a4058cb 100644 --- a/lib/aruba/cucumber/file.rb +++ b/lib/aruba/cucumber/file.rb @@ -1,8 +1,16 @@ -Given(/I use (?:a|the) fixture(?: named)? "([^"]*)"/) do |name| +Given(/^I use (?:a|the) fixture(?: named)? "([^"]*)"$/) do |name| copy File.join(aruba.config.fixtures_path_prefix, name), name cd name end +Given(/^I copy (?:a|the) (file|directory)(?: (?:named|from))? "([^"]*)" to "([^"]*)"$/) do |file_or_directory, source, destination| + copy source, destination +end + +Given(/^I move (?:a|the) (file|directory)(?: (?:named|from))? "([^"]*)" to "([^"]*)"$/) do |file_or_directory, source, destination| + move source, destination +end + Given(/^(?:a|the) directory(?: named)? "([^"]*)"$/) do |dir_name| create_directory(dir_name) end diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb index d62c21ced..d094ff9fc 100644 --- a/lib/aruba/platforms/unix_platform.rb +++ b/lib/aruba/platforms/unix_platform.rb @@ -131,6 +131,11 @@ def cp(args, options) FileUtils.cp_r(args, options) end + # Move file/directory + def mv(args, options) + FileUtils.mv(args, options) + end + # Change mode of file/directory def chmod(mode, args, options) FileUtils.chmod_R(mode, args, options) From 00c7751700809196a35827c4a66845e17a3fd9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 14:56:29 +0200 Subject: [PATCH 076/118] Now we've got a getting started section --- .../supported_programming_languages.feature | 89 +++++++++++++++++++ fixtures/getting-started-app/.gitignore | 4 + fixtures/getting-started-app/Gemfile | 4 + fixtures/getting-started-app/README.md | 3 + .../features/support/env.rb | 1 + 5 files changed, 101 insertions(+) create mode 100644 features/getting_started/supported_programming_languages.feature create mode 100644 fixtures/getting-started-app/.gitignore create mode 100644 fixtures/getting-started-app/Gemfile create mode 100644 fixtures/getting-started-app/README.md create mode 100644 fixtures/getting-started-app/features/support/env.rb diff --git a/features/getting_started/supported_programming_languages.feature b/features/getting_started/supported_programming_languages.feature new file mode 100644 index 000000000..d237b7f03 --- /dev/null +++ b/features/getting_started/supported_programming_languages.feature @@ -0,0 +1,89 @@ +Feature: Supported programming languages + + As long as you've got the neccessary programs, libraries, runtime + environments, interpreters installed, it doesn't matter in which programming + language your commandline application is implemented. + + Below you find some examples of the "Hello, Aruba!"-application implemented + with different programming languages. This is NOT an exclusive list. Every + commandline application should run with `aruba`. + + Background: + Given I use a fixture named "getting-started-app" + And a file named "features/hello_aruba.feature" with: + """ + Feature: Getting Started With Aruba + Scenario: First Run of Command + Given I successfully run `cli` + Then the output should contain: + \"\"\" + Hello, Aruba! + \"\"\" + """ + + Scenario: Bash Program + Given an executable named "bin/cli" with: + """bash + #!/usr/bin/env bash + + echo "Hello, Aruba!" + """ + When I successfully run `cucumber` + Then the features should all pass + + Scenario: Ruby Program + Given an executable named "bin/cli" with: + """ruby + #!/usr/bin/env ruby + + puts "Hello, Aruba!" + """ + When I successfully run `cucumber` + Then the features should all pass + + Scenario: Python Program + Given an executable named "bin/cli" with: + """python + #!/usr/bin/env python + + print("Hello, Aruba!") + """ + When I successfully run `cucumber` + Then the features should all pass + + Scenario: Perl Program + Given an executable named "bin/cli" with: + """perl + #!/usr/bin/env perl + + print "Hello, Aruba!\n"; + """ + When I successfully run `cucumber` + Then the features should all pass + + Scenario: Java Program + + It's even possible to compile and run Java programs with Aruba. + + Given a file named "features/hello_aruba.feature" with: + """cucumber + Feature: Getting Started With Aruba + Scenario: First Run of Command + Given a file named "tmp/HelloArubaApp.java" with: + \"\"\" + class HelloArubaApp { + public static void main(String[] args) { + System.out.println("Hello, Aruba!"); + } + } + \"\"\" + And I successfully run `javac tmp/HelloArubaApp.java` + And I cd to "tmp/" + And I successfully run `java HelloArubaApp` + Then the output should contain: + \"\"\" + Hello, Aruba! + \"\"\" + """ + When I successfully run `cucumber` + Then the features should all pass diff --git a/fixtures/getting-started-app/.gitignore b/fixtures/getting-started-app/.gitignore new file mode 100644 index 000000000..9b47a2d91 --- /dev/null +++ b/fixtures/getting-started-app/.gitignore @@ -0,0 +1,4 @@ +/coverage/ +/doc/ +/pkg/ +/tmp/ diff --git a/fixtures/getting-started-app/Gemfile b/fixtures/getting-started-app/Gemfile new file mode 100644 index 000000000..8e7e0b5e9 --- /dev/null +++ b/fixtures/getting-started-app/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'cucumber' +gem 'aruba' diff --git a/fixtures/getting-started-app/README.md b/fixtures/getting-started-app/README.md new file mode 100644 index 000000000..7ca666d6c --- /dev/null +++ b/fixtures/getting-started-app/README.md @@ -0,0 +1,3 @@ +# Simple Cli App + +This is a simple app to get started with `aruba`. diff --git a/fixtures/getting-started-app/features/support/env.rb b/fixtures/getting-started-app/features/support/env.rb new file mode 100644 index 000000000..fb0a661b9 --- /dev/null +++ b/fixtures/getting-started-app/features/support/env.rb @@ -0,0 +1 @@ +require 'aruba/cucumber' From 36d09714602d7d8887b1b4f1adda3265fa654069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 14:57:11 +0200 Subject: [PATCH 077/118] Better sorted --- .nav | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.nav b/.nav index 5f364721b..c2f285798 100644 --- a/.nav +++ b/.nav @@ -21,6 +21,7 @@ - api/filesystem/is_directory.feature - api/filesystem/is_file.feature - api/filesystem/is_relative.feature + - api/filesystem/move.feature - file_system_commands.feature - Hooks: - hooks/after/command.feature @@ -65,9 +66,11 @@ - steps/commands/run.feature - steps/environment/home_variable.feature - steps/environment/set_environment_variable.feature + - steps/filesystem/copy.feature - steps/filesystem/create_directory.feature - steps/filesystem/create_file.feature - steps/filesystem/file_content.feature + - steps/filesystem/move.feature - steps/filesystem/overwrite_file.feature - steps/filesystem/use_fixture.feature - output.feature From 2b15204aee8a3f5dfcf0e8ac1a429c8495ea6f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 15:09:45 +0200 Subject: [PATCH 078/118] Fixed offenses --- lib/aruba/api/filesystem.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/aruba/api/filesystem.rb b/lib/aruba/api/filesystem.rb index 72e4d1039..d26dd36b3 100644 --- a/lib/aruba/api/filesystem.rb +++ b/lib/aruba/api/filesystem.rb @@ -199,6 +199,7 @@ def copy(*args) # needs to be a directory # # rubocop:disable Metrics/CyclomaticComplexity + # rubocop:disable Metrics/MethodLength def move(*args) args = args.flatten destination = args.pop @@ -230,6 +231,8 @@ def move(*args) self end + # rubocop:enable Metrics/MethodLength + # rubocop:enable Metrics/CyclomaticComplexity # Create a file with the given size # From 22220c23d287ab30fa74520f63d1d578bbe55c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 15:10:40 +0200 Subject: [PATCH 079/118] Improved documentation --- .nav | 80 ------------------------------- features/.nav | 72 ++++++++++++++++++++++++++++ features/development/test.feature | 6 +-- 3 files changed, 75 insertions(+), 83 deletions(-) delete mode 100644 .nav create mode 100644 features/.nav diff --git a/.nav b/.nav deleted file mode 100644 index c2f285798..000000000 --- a/.nav +++ /dev/null @@ -1,80 +0,0 @@ -- README.md -- Getting Started: - - usage/install.feature -- Ruby API: - - Core: - - api/core/expand_path.feature - - core/cleanup_aruba_directory.feature - - Commands: - - api/command/run.feature - - api/command/which.feature - - Environment Variables: - - api/environment/append_environment_variable.feature - - api/environment/prepend_environment_variable.feature - - api/environment/set_environment_variable.feature - - Filesystem: - - api/filesystem/cd.feature - - api/filesystem/create_directory.feature - - api/filesystem/disk_usage.feature - - api/filesystem/does_exist.feature - - api/filesystem/is_absolute.feature - - api/filesystem/is_directory.feature - - api/filesystem/is_file.feature - - api/filesystem/is_relative.feature - - api/filesystem/move.feature - - file_system_commands.feature - - Hooks: - - hooks/after/command.feature - - hooks/before/command.feature -- Cucumber: - - commands/debug_command.feature - - commands/environment_variables.feature - - commands/flushing.feature - - commands/interactive.feature - - commands/output/all_output.feature - - commands/output/stdout.feature -- Configuration: - - configuration/exit_timeout.feature - - configuration/fixtures_directories.feature - - configuration/fixtures_path_prefix.feature - - configuration/home_directory.feature - - configuration/io_timeout.feature - - configuration/keep_ansi.feature - - configuration/log_level.feature - - configuration/physical_block_size.feature - - configuration/root_directory.feature - - configuration/working_directory.feature -- RSpec: - - Integration: - - integration/rspec/getting_started.feature - - Matchers: - - matchers/collection/include_an_object.feature - - matchers/directory/have_sub_directory.feature - - matchers/file/be_existing_file.feature - - matchers/file/have_file_content.feature - - matchers/file/have_file_size.feature - - matchers/path/be_an_absolute_path.feature - - matchers/path/be_an_existing_path.feature - - matchers/path/have_permissions.feature - - matchers/timeouts.feature -- Cucumber: - - Tags: - - announce.feature - - Steps: - - steps/commands/exit_statuses.feature - - steps/commands/in_process.feature - - steps/commands/run.feature - - steps/environment/home_variable.feature - - steps/environment/set_environment_variable.feature - - steps/filesystem/copy.feature - - steps/filesystem/create_directory.feature - - steps/filesystem/create_file.feature - - steps/filesystem/file_content.feature - - steps/filesystem/move.feature - - steps/filesystem/overwrite_file.feature - - steps/filesystem/use_fixture.feature - - output.feature - - utf-8.feature -- Development: - - development/build.feature - - development/test.feature diff --git a/features/.nav b/features/.nav new file mode 100644 index 000000000..e531d6964 --- /dev/null +++ b/features/.nav @@ -0,0 +1,72 @@ +- README.md +- getting_started (Getting Started): + - install.feature (Install Aruba) + - supported_programming_languages.feature (Supportet Programming Languages) +- ruby_api (Ruby API): + - expand_path.feature (#expand_path) + - cleanup_aruba_directory.feature (#setup_aruba) + - run.feature (#run) + - which.feature (#which) + - append_environment_variable.feature (#append_environment_variable) + - prepend_environment_variable.feature (#prepend_environment_variable) + - set_environment_variable.feature (#set_environment_variable) + - cd.feature (#cd) + - create_directory.feature (#create_directory) + - disk_usage.feature (#disk_usage) + - does_exist.feature (#exist?) + - is_absolute.feature (#absolute?) + - filesystem/is_directory.feature (#directory?) + - is_file.feature (#file?) + - is_relative.feature(#relative?) + - move.feature (#move) + - file_system_commands.feature + - command.feature (Before Hook) + - command.feature (After Hook) +- cucumber (Cucumber): + - debug_command.feature (Debug Commmands) + - environment_variables.feature (Environment Variables) + - flushing.feature (Flush Output) + - interactive.feature (Interactive Commands) + - all_output.feature (Command Output) + - stdout.feature (STDOUT) +- configuration (Configuration): + - exit_timeout.feature (Exit Timeout) + - fixtures_directories.feature (Fixtures Directories) + - fixtures_path_prefix.feature (Fixture Path Prefix) + - home_directory.feature (Home Directory) + - io_timeout.feature (IO Wait Timeout) + - keep_ansi.feature (Keep ANSI output) + - log_level.feature (Log Level) + - physical_block_size.feature (Physical Block Size) + - root_directory.feature (Root Directory) + - working_directory.feature (Working Directory) +- rspec (RSpec): + - getting_started.feature (Integration) + - include_an_object.feature (Matcher: Include an Object) + - have_sub_directory.feature (Matcher: Have Sub Directory) + - be_existing_file.feature (Matcher: Be Existing File) + - have_file_content.feature (Matcher: Have File Content) + - have_file_size.feature (Matcher: Have File Size) + - be_an_absolute_path.feature (Matcher: Be Absolute Path) + - be_an_existing_path.feature (Matcher: Be Existing Path) + - have_permissions.feature (Matcher: Have Permissions) + - timeouts.feature (Matcher: Timeouts) +- cucumber (Cucumber): + - announce.feature (Announce Information to User) + - exit_statuses.feature (Exit Status of Commands) + - in_process.feature (Start Commands in Process) + - run.feature (Run Commands) + - home_variable.feature (Modify HOME-Variable) + - set_environment_variable.feature (Set Environment variables) + - copy.feature (Copy files/directories) + - create_directory.feature (Create Directories) + - create_file.feature (Create Files) + - file_content.feature (Use File Content) + - move.feature (Move files/directories) + - overwrite_file.feature (Overwrite Files) + - use_fixture.feature (Use Fixtures) + - output.feature (Output) + - utf-8.feature (Support for UTF-8-strings) +- development (Development): + - build.feature (Build Aruba) + - test.feature (Test Aruba) diff --git a/features/development/test.feature b/features/development/test.feature index 6d23055e6..28eb4821c 100644 --- a/features/development/test.feature +++ b/features/development/test.feature @@ -1,8 +1,8 @@ -Feature: Build Aruba Gem +Feature: Run test suite of aruba As a aruba developer - I want to build the `aruba` gem - In order to install it + I want to run the test suite of aruba + In order to make changes to it Background: Given the default aruba exit timeout is 120 seconds From 6e6e5bd74d7ffd2de3d92ead4b6672a34c532bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 16:00:48 +0200 Subject: [PATCH 080/118] Make it compatible with 1.8.7 --- lib/aruba/processes/debug_process.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/aruba/processes/debug_process.rb b/lib/aruba/processes/debug_process.rb index 9d4b3a6e7..64503c283 100644 --- a/lib/aruba/processes/debug_process.rb +++ b/lib/aruba/processes/debug_process.rb @@ -12,15 +12,9 @@ def self.match?(mode) # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/CyclomaticComplexity def start - if RUBY_VERSION < '2' - Dir.chdir @working_directory do - with_local_env(environment) do - @exit_status = system(command, *arguments) ? 0 : 1 - end - end - else + Dir.chdir @working_directory do with_local_env(environment) do - @exit_status = system(command, *arguments, :chdir => @working_directory) ? 0 : 1 + @exit_status = system(command, *arguments) ? 0 : 1 end end end From 7bb187b3493c0eeb18aad06882146d5fcb4686b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 16:03:16 +0200 Subject: [PATCH 081/118] Make sure files are executable --- features/announce.feature | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/features/announce.feature b/features/announce.feature index bcae5479e..8353bdcca 100644 --- a/features/announce.feature +++ b/features/announce.feature @@ -48,7 +48,7 @@ Feature: Announce output during test run """ Scenario: Announce stdout - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -76,7 +76,7 @@ Feature: Announce output during test run """ Scenario: Announce stderr - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -104,7 +104,7 @@ Feature: Announce output during test run """ Scenario: Announce both stderr and stdout - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -140,7 +140,7 @@ Feature: Announce output during test run """ Scenario: Announce command - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -163,7 +163,7 @@ Feature: Announce output during test run """ Scenario: Announce change of environment variable - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -188,7 +188,7 @@ Feature: Announce output during test run """ Scenario: Announce change of environment variable which contains special characters - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby From a05fe83fde55d02006b52fdbd28ab9d4122afd51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 23 Jul 2015 16:17:37 +0200 Subject: [PATCH 082/118] Explicit conversion to string --- lib/aruba/processes/spawn_process.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 7255deb7c..f6baaac68 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -99,7 +99,7 @@ def stdout(opts = {}) wait_for_io wait_for_io do @process.io.stdout.flush - open(@stdout_file).read + open(@stdout_file.to_s).read end end @@ -120,7 +120,7 @@ def stderr(opts = {}) wait_for_io wait_for_io do @process.io.stderr.flush - open(@stderr_file).read + open(@stderr_file.to_s).read end end From 7080ce60a0263454ae9708c6b8ddb7c1af84f231 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Thu, 23 Jul 2015 18:25:57 +0200 Subject: [PATCH 083/118] Use path instead of to_s --- lib/aruba/processes/spawn_process.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index f6baaac68..67fc761d0 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -99,7 +99,7 @@ def stdout(opts = {}) wait_for_io wait_for_io do @process.io.stdout.flush - open(@stdout_file.to_s).read + open(@stdout_file.path).read end end @@ -120,7 +120,7 @@ def stderr(opts = {}) wait_for_io wait_for_io do @process.io.stderr.flush - open(@stderr_file.to_s).read + open(@stderr_file.path).read end end From 6f42d5ee9be48bed16fb0268e11633f22395e9b0 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Thu, 23 Jul 2015 19:05:38 +0200 Subject: [PATCH 084/118] Check if an fixture really exist --- features/steps/filesystem/use_fixture.feature | 14 ++++++++++++++ lib/aruba/api/core.rb | 10 ++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/features/steps/filesystem/use_fixture.feature b/features/steps/filesystem/use_fixture.feature index e43adc616..09ae06ce7 100644 --- a/features/steps/filesystem/use_fixture.feature +++ b/features/steps/filesystem/use_fixture.feature @@ -61,3 +61,17 @@ Feature: Use a fixture And an empty file named "test/fixtures/my-app/MY-APP-README.md" When I run `cucumber` Then the features should all pass + + Scenario: Fails if fixture does not exist + Given a file named "features/use_fixtures.feature" with: + """ + Feature: Use Fixture + Scenario: Use Fixture + Given I use a fixture named "my-app" + """ + And a directory named "fixtures" + When I run `cucumber` + Then the features should not all pass with regex: + """ + Fixture "my-app" does not exist in fixtures directory ".+/fixtures" + """ diff --git a/lib/aruba/api/core.rb b/lib/aruba/api/core.rb index 492a2ea49..b74ebbcc4 100644 --- a/lib/aruba/api/core.rb +++ b/lib/aruba/api/core.rb @@ -144,13 +144,19 @@ def expand_path(file_name, dir_string = nil) if aruba.config.fixtures_path_prefix == prefix path = File.join(*[aruba.fixtures_directory, rest].compact) + + # rubocop:disable Metrics/LineLength + fail ArgumentError, %(Fixture "#{rest}" does not exist in fixtures directory "#{aruba.fixtures_directory}". This was the one we found first on your system from all possible candidates: #{aruba.config.fixtures_directories.map { |p| format('"%s"', p) }.join(', ')}.) unless Aruba.platform.exist? path + # rubocop:enable Metrics/LineLength + + path elsif '~' == prefix path = with_environment do ArubaPath.new(File.expand_path(file_name)) end - fail 'Expanding "~/" to "/" is not allowed' if path.to_s == '/' - fail %(Expanding "~/" to a relative path "#{path}" is not allowed) unless path.absolute? + fail ArgumentError, 'Expanding "~/" to "/" is not allowed' if path.to_s == '/' + fail ArgumentError, %(Expanding "~/" to a relative path "#{path}" is not allowed) unless path.absolute? path.to_s else From 57db0f73f0862cb54bb421e34a29f4f248f249b8 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Thu, 23 Jul 2015 19:13:13 +0200 Subject: [PATCH 085/118] Make them all executable --- features/commands/debug_command.feature | 6 ++-- .../commands/environment_variables.feature | 6 ++-- features/commands/flushing.feature | 6 ++-- features/commands/interactive.feature | 2 +- features/commands/output/all_output.feature | 36 +++++++++---------- features/commands/output/stdout.feature | 6 ++-- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/features/commands/debug_command.feature b/features/commands/debug_command.feature index 291fa3cfb..44a7f9f27 100644 --- a/features/commands/debug_command.feature +++ b/features/commands/debug_command.feature @@ -8,7 +8,7 @@ Feature: Debug your command in cucumber-test-run Given I use a fixture named "cli-app" Scenario: Can handle exit status 0 - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -27,7 +27,7 @@ Feature: Debug your command in cucumber-test-run Then the features should all pass Scenario: Can handle exit status 1 - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -59,7 +59,7 @@ Feature: Debug your command in cucumber-test-run We are going to demonstrate this using `pry`, but any other interactive debugger for any other programming language should also work. - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby diff --git a/features/commands/environment_variables.feature b/features/commands/environment_variables.feature index c9d858cf3..895aa802c 100644 --- a/features/commands/environment_variables.feature +++ b/features/commands/environment_variables.feature @@ -8,7 +8,7 @@ Feature: Modify environment variables Given I use a fixture named "cli-app" Scenario: Change/Set value of arbitrary environment variable - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -28,7 +28,7 @@ Feature: Modify environment variables Then the features should all pass Scenario: Change the HOME-variable of current user during test using custom step - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -46,7 +46,7 @@ Feature: Modify environment variables Then the features should all pass Scenario: Change the HOME-variable of current user during test using tag - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby diff --git a/features/commands/flushing.feature b/features/commands/flushing.feature index 33b82a141..dfefd6769 100644 --- a/features/commands/flushing.feature +++ b/features/commands/flushing.feature @@ -8,7 +8,7 @@ Feature: Flushing the output of your application Given I use a fixture named "cli-app" Scenario: A little output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """bash #!/usr/bin/env bash @@ -30,7 +30,7 @@ Feature: Flushing the output of your application Scenario: Tons of output Given the default aruba exit timeout is 10 seconds - And a file named "bin/cli" with: + And an executable named "bin/cli" with: """bash #!/usr/bin/env bash @@ -52,7 +52,7 @@ Feature: Flushing the output of your application Scenario: Tons of interactive output Given the default aruba exit timeout is 10 seconds - And a file named "bin/cli" with: + And an executable named "bin/cli" with: """bash #!/usr/bin/env bash diff --git a/features/commands/interactive.feature b/features/commands/interactive.feature index c53df22a9..d2c7c5266 100644 --- a/features/commands/interactive.feature +++ b/features/commands/interactive.feature @@ -9,7 +9,7 @@ Feature: Interactive process control @wip-jruby-java-1.6 Scenario: Running ruby interactively - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """bash #!/usr/bin/env ruby diff --git a/features/commands/output/all_output.feature b/features/commands/output/all_output.feature index 6ab285291..2f677db08 100644 --- a/features/commands/output/all_output.feature +++ b/features/commands/output/all_output.feature @@ -8,7 +8,7 @@ Feature: All output of commands which were executed Given I use a fixture named "cli-app" Scenario: Detect subset of one-line output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -25,7 +25,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Detect absence of one-line output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -42,7 +42,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Detect subset of multiline output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -62,7 +62,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Detect absence of subset of multiline output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -97,7 +97,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Detect exact one-line output for ruby commands - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -120,7 +120,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Detect exact one-line output with ANSI output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -145,7 +145,7 @@ Feature: All output of commands which were executed Scenario: Detect exact one-line output with ANSI output stripped by default Given the default aruba exit timeout is 12 seconds - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -168,7 +168,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Detect exact multiline output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -192,7 +192,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Detect subset of one-line output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -209,7 +209,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Detect subset of one-line output with regex - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -226,7 +226,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Detect subset of multiline output with regex - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -249,7 +249,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Negative matching of one-line output with regex - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -266,7 +266,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Negative matching of multiline output with regex - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -290,7 +290,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Match passing exit status and partial output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -311,7 +311,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Match passing exit status and exact output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -336,7 +336,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Match failing exit status and partial output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -358,7 +358,7 @@ Feature: All output of commands which were executed Scenario: Match failing exit status and exact output - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -383,7 +383,7 @@ Feature: All output of commands which were executed Then the features should all pass Scenario: Match failing exit status and output with regex - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby diff --git a/features/commands/output/stdout.feature b/features/commands/output/stdout.feature index 5ff3e3f44..5b5f7b8d5 100644 --- a/features/commands/output/stdout.feature +++ b/features/commands/output/stdout.feature @@ -8,7 +8,7 @@ Feature: Stdout of commands which were executed Given I use a fixture named "cli-app" Scenario: Match output in stdout - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -26,7 +26,7 @@ Feature: Stdout of commands which were executed Then the features should all pass Scenario: Match stdout on several lines - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby @@ -46,7 +46,7 @@ Feature: Stdout of commands which were executed Then the features should all pass Scenario: Match output on several lines where stdout contains quotes - Given a file named "bin/cli" with: + Given an executable named "bin/cli" with: """ruby #!/usr/bin/env ruby From 2e6bf6c03ac5a0c637664ce2b8aa499ca1aabdfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Fri, 24 Jul 2015 12:38:59 +0200 Subject: [PATCH 086/118] Refactor code to use one single implementation of with_environment --- features/api/filesystem/cd.feature | 16 +++++++++--- lib/aruba/api/core.rb | 26 +++++-------------- lib/aruba/cucumber/hooks.rb | 14 ++-------- lib/aruba/platforms/local_environment.rb | 15 +++++++++++ lib/aruba/platforms/unix_platform.rb | 18 +++++-------- lib/aruba/processes/basic_process.rb | 10 ------- lib/aruba/processes/debug_process.rb | 2 +- lib/aruba/processes/in_process.rb | 20 ++------------ lib/aruba/processes/spawn_process.rb | 2 +- lib/aruba/rspec.rb | 6 +---- .../aruba/api/environment/restore_env_spec.rb | 7 +++-- spec/aruba/api/environment/set_env_spec.rb | 7 +++-- 12 files changed, 53 insertions(+), 90 deletions(-) create mode 100644 lib/aruba/platforms/local_environment.rb diff --git a/features/api/filesystem/cd.feature b/features/api/filesystem/cd.feature index 31de34b63..78c49ec1e 100644 --- a/features/api/filesystem/cd.feature +++ b/features/api/filesystem/cd.feature @@ -162,12 +162,22 @@ Feature: Change current working directory end before :each do - @pwd = cd('new_dir.d') do - cd('subdir.d') { run_simple('pwd') } + cd('new_dir.d') do + @oldpwd_1 = ENV['OLDPWD'] + @pwd_1 = ENV['PWD'] + + cd('subdir.d') do + @oldpwd_2 = ENV['OLDPWD'] + @pwd_2 = ENV['PWD'] + end end end - it { expect(last_command_started.output.to_s).to include 'subdir.d' } + it { expect(@oldpwd_1).to be_end_with 'cli-app' } + it { expect(@pwd_1).to be_end_with 'new_dir.d' } + + it { expect(@oldpwd_2).to be_end_with 'new_dir.d' } + it { expect(@pwd_2).to be_end_with 'subdir.d' } end """ When I run `rspec` diff --git a/lib/aruba/api/core.rb b/lib/aruba/api/core.rb index b74ebbcc4..c34723ab8 100644 --- a/lib/aruba/api/core.rb +++ b/lib/aruba/api/core.rb @@ -56,20 +56,17 @@ def cd(dir, &block) announcer.announce :directory, expand_path(dir) old_dir = Aruba.platform.getwd - old_oldpwd = ENV['OLDPWD'] - old_pwd = ENV['PWD'] - - ENV['OLDPWD'] = Aruba.platform.getwd - ENV['PWD'] = File.join(aruba.root_directory, aruba.current_directory).sub(%r{/$}, '') Aruba.platform.chdir File.join(aruba.root_directory, aruba.current_directory) - result = block.call + result = Aruba.platform.with_environment( + 'OLDPWD' => old_dir, + 'PWD' => File.join(aruba.root_directory, aruba.current_directory).sub(%r{/$}, ''), + &block + ) ensure aruba.current_directory.pop Aruba.platform.chdir old_dir - ENV['OLDPWD'] = old_oldpwd - ENV['PWD'] = old_pwd end return result @@ -175,23 +172,12 @@ def expand_path(file_name, dir_string = nil) # @yield # The block of code which should be run with the modified environment variables def with_environment(env = {}, &block) - if RUBY_VERSION <= '1.9.3' - old_env = ENV.to_hash.dup - else - old_env = ENV.to_h.dup - end - old_aruba_env = aruba.environment.to_h - ENV.update aruba.environment.update(env).to_h - - block.call if block_given? + Aruba.platform.with_environment aruba.environment.update(env).to_h, &block ensure aruba.environment.clear aruba.environment.update old_aruba_env - - ENV.clear - ENV.update old_env end end end diff --git a/lib/aruba/cucumber/hooks.rb b/lib/aruba/cucumber/hooks.rb index ad97631b7..aa877718a 100644 --- a/lib/aruba/cucumber/hooks.rb +++ b/lib/aruba/cucumber/hooks.rb @@ -1,21 +1,11 @@ require 'aruba/aruba_path' require 'aruba/api' +require 'aruba/platform' World(Aruba::Api) if Aruba::VERSION >= '1.0.0' Around do |_, block| - begin - if RUBY_VERSION < '1.9' - old_env = ENV.to_hash.dup - else - old_env = ENV.to_h.dup - end - - block.call - ensure - ENV.clear - ENV.update old_env - end + Aruba.platform.with_environment(&block) end end diff --git a/lib/aruba/platforms/local_environment.rb b/lib/aruba/platforms/local_environment.rb new file mode 100644 index 000000000..191a06961 --- /dev/null +++ b/lib/aruba/platforms/local_environment.rb @@ -0,0 +1,15 @@ +module Aruba + module Platforms + class LocalEnvironment + def call(env, &block) + old_env = ENV.to_hash.dup + ENV.update env + + block.call if block_given? + ensure + ENV.clear + ENV.update old_env + end + end + end +end diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb index d094ff9fc..80625f21e 100644 --- a/lib/aruba/platforms/unix_platform.rb +++ b/lib/aruba/platforms/unix_platform.rb @@ -10,6 +10,7 @@ require 'aruba/platforms/determine_disk_usage' require 'aruba/platforms/aruba_file_creator' require 'aruba/platforms/aruba_fixed_size_file_creator' +require 'aruba/platforms/local_environment' module Aruba # This abstracts OS-specific things @@ -50,6 +51,10 @@ def create_fixed_size_file(*args) ArubaFixedSizeFileCreator.new.call(*args) end + def with_environment(env = {}, &block) + LocalEnvironment.new.call(env, &block) + end + def detect_ruby(cmd) if cmd =~ /^ruby\s/ cmd.gsub(/^ruby\s/, "#{current_ruby} ") @@ -105,19 +110,8 @@ def getwd def chdir(dir_name, &block) dir_name = ::File.expand_path(dir_name.to_s) - begin - if RUBY_VERSION <= '1.9.3' - old_env = ENV.to_hash.dup - else - old_env = ENV.to_h.dup - end - - ENV['OLDPWD'] = getwd - ENV['PWD'] = dir_name + with_environment 'OLDPWD' => getwd, 'PWD' => dir_name do ::Dir.chdir(dir_name, &block) - ensure - ENV.clear - ENV.update old_env end end diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index 6aefc77e5..3389a4340 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -86,16 +86,6 @@ def inspect private - def with_local_env(e, &block) - old_env = ENV.to_hash - ENV.update e - - block.call - ensure - ENV.clear - ENV.update old_env - end - def command Shellwords.split(commandline).first end diff --git a/lib/aruba/processes/debug_process.rb b/lib/aruba/processes/debug_process.rb index 64503c283..9aac3ce38 100644 --- a/lib/aruba/processes/debug_process.rb +++ b/lib/aruba/processes/debug_process.rb @@ -13,7 +13,7 @@ def self.match?(mode) # rubocop:disable Metrics/CyclomaticComplexity def start Dir.chdir @working_directory do - with_local_env(environment) do + Aruba.platform.with_environment(environment) do @exit_status = system(command, *arguments) ? 0 : 1 end end diff --git a/lib/aruba/processes/in_process.rb b/lib/aruba/processes/in_process.rb index ffd14d766..f59d158c7 100644 --- a/lib/aruba/processes/in_process.rb +++ b/lib/aruba/processes/in_process.rb @@ -1,6 +1,7 @@ require 'shellwords' require 'stringio' require 'aruba/processes/basic_process' +require 'aruba/platform' module Aruba module Processes @@ -49,7 +50,7 @@ def start Dir.chdir @working_directory do before_run - in_environment 'PWD' => @working_directory do + Aruba.platform.with_environment environment.merge('PWD' => @working_directory) do main_class.new(@argv, @stdin, @stdout, @stderr, @kernel).execute! end @@ -89,23 +90,6 @@ def close_io(name) def terminate stop end - - private - - def in_environment(env = {}, &block) - if RUBY_VERSION <= '1.9.3' - old_env = ENV.to_hash - else - old_env = ENV.to_h - end - - ENV.update(environment).update(env) - - block.call if block_given? - ensure - ENV.clear - ENV.update old_env - end end end end diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 67fc761d0..44dd343d0 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -61,7 +61,7 @@ def start @process.environment.update(environment) begin - with_local_env(environment) do + Aruba.platform.with_environment(environment) do @process.start end rescue ChildProcess::LaunchError => e diff --git a/lib/aruba/rspec.rb b/lib/aruba/rspec.rb index 3d068fe24..d6c0cdc4b 100644 --- a/lib/aruba/rspec.rb +++ b/lib/aruba/rspec.rb @@ -25,12 +25,8 @@ if Aruba::VERSION >= '1.0.0' config.around :each do |example| - begin - old_env = ENV.to_hash.dup + Aruba.platform.with_environment do example.run - ensure - ENV.clear - ENV.update old_env end end end diff --git a/spec/aruba/api/environment/restore_env_spec.rb b/spec/aruba/api/environment/restore_env_spec.rb index c8c95f38a..0120e33ec 100644 --- a/spec/aruba/api/environment/restore_env_spec.rb +++ b/spec/aruba/api/environment/restore_env_spec.rb @@ -4,10 +4,9 @@ include_context 'uses aruba API' around do |example| - old_env = ENV.to_hash - example.run - ENV.clear - ENV.update(old_env) + Aruba.platform.with_environment do + example.run + end end describe '#restore_env' do diff --git a/spec/aruba/api/environment/set_env_spec.rb b/spec/aruba/api/environment/set_env_spec.rb index b2b719c8f..1aca3b55a 100644 --- a/spec/aruba/api/environment/set_env_spec.rb +++ b/spec/aruba/api/environment/set_env_spec.rb @@ -4,10 +4,9 @@ include_context 'uses aruba API' around do |example| - old_env = ENV.to_hash - example.run - ENV.clear - ENV.update(old_env) + Aruba.platform.with_environment do + example.run + end end describe '#set_env' do From b1082c0988e1411378fd37679bd8c004c9dcfdf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Fri, 24 Jul 2015 13:59:25 +0200 Subject: [PATCH 087/118] Fixed problem with interactive processes --- features/output.feature | 17 ++++++----------- lib/aruba/cucumber/command.rb | 10 ++++++++-- lib/aruba/processes/debug_process.rb | 3 +++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/features/output.feature b/features/output.feature index 5ea604168..22d6fbfc4 100644 --- a/features/output.feature +++ b/features/output.feature @@ -7,31 +7,23 @@ Feature: All output of commands which were executed Background: Given I use a fixture named "cli-app" - @wip Scenario: Detect output from all processes normal and interactive ones Given an executable named "bin/cli1" with: """ - #!/usr/bin/env ruby - - $LOAD_PATH << File.expand_path('../../lib', __FILE__) - require 'cli/app' - - puts 'This is cli1' + #!/usr/bin/env bash + echo 'This is cli1' """ And an executable named "bin/cli2" with: """ #!/usr/bin/env ruby - $LOAD_PATH << File.expand_path('../../lib', __FILE__) - require 'cli/app' while input = gets do - break if input == "" + break if "" == input puts input end """ And a file named "features/output.feature" with: """ - @debug Feature: Run command Scenario: Run command When I run `cli1` @@ -41,6 +33,9 @@ Feature: All output of commands which were executed Then the stdout should contain exactly: \"\"\" This is cli1 + \"\"\" + And the stdout should contain exactly: + \"\"\" This is cli2 \"\"\" """ diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index aacbfde79..c82bdc45c 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -129,7 +129,10 @@ end if Aruba::VERSION < '1.0' - combined_output = commands.map { |c| c.send(channel.to_sym).chomp }.join("\n") + combined_output = commands.map do |c| + c.stop(announcer) + c.send(channel.to_sym).chomp + end.join("\n") if negated expect(combined_output).not_to match expected @@ -174,7 +177,10 @@ end if Aruba::VERSION < '1.0' - combined_output = commands.map { |c| c.send(channel.to_sym).chomp }.join("\n") + combined_output = commands.map do |c| + c.stop(announcer) + c.send(channel.to_sym).chomp + end.join("\n") if negated expect(combined_output).not_to match expected diff --git a/lib/aruba/processes/debug_process.rb b/lib/aruba/processes/debug_process.rb index 9aac3ce38..0c6a6ccc7 100644 --- a/lib/aruba/processes/debug_process.rb +++ b/lib/aruba/processes/debug_process.rb @@ -31,6 +31,9 @@ def stderr(*) 'This is the debug launcher on STDERR. If this output is unexpected, please check your setup.' end + def write(*); end + def close_io(*); end + def stop(_reader) @stopped = true From 660f50569e691573d7edc583afa18480cd5bd313 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Fri, 24 Jul 2015 17:38:34 +0200 Subject: [PATCH 088/118] Fixed offenses --- lib/aruba/processes/debug_process.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/aruba/processes/debug_process.rb b/lib/aruba/processes/debug_process.rb index 0c6a6ccc7..1b65ead8f 100644 --- a/lib/aruba/processes/debug_process.rb +++ b/lib/aruba/processes/debug_process.rb @@ -21,25 +21,42 @@ def start # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/MethodLength + # Return stdin + # + # @return [NilClass] + # Nothing def stdin(*); end + # Return stdout + # + # @return [String] + # A predefined string to make users aware they are using the DebugProcess def stdout(*) 'This is the debug launcher on STDOUT. If this output is unexpected, please check your setup.' end + # Return stderr + # + # @return [String] + # A predefined string to make users aware they are using the DebugProcess def stderr(*) 'This is the debug launcher on STDERR. If this output is unexpected, please check your setup.' end + # Write to nothing def write(*); end + + # Close nothing def close_io(*); end + # Stop process def stop(_reader) @stopped = true @exit_status end + # Terminate process def terminate(*) stop end From 4fcaa4c1286548171b6a15730d465e253d98b49e Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Fri, 24 Jul 2015 22:32:15 +0200 Subject: [PATCH 089/118] Ignore features on ruby < 1.9.3 --- features/development/test.feature | 1 + features/step_definitions/hooks.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 features/step_definitions/hooks.rb diff --git a/features/development/test.feature b/features/development/test.feature index 28eb4821c..f34ce4e5d 100644 --- a/features/development/test.feature +++ b/features/development/test.feature @@ -14,6 +14,7 @@ Feature: Run test suite of aruba Given I successfully run `cucumber` Then the features should all pass + @requires-ruby-version-193 Scenario: Testing compliance to ruby community guide Given I successfully run `rubocop` Then the features should all pass diff --git a/features/step_definitions/hooks.rb b/features/step_definitions/hooks.rb new file mode 100644 index 000000000..6dd58425a --- /dev/null +++ b/features/step_definitions/hooks.rb @@ -0,0 +1,11 @@ +require 'cucumber/platform' + +Before '@requires-ruby-version-193' do + next unless RUBY_VERSION < '1.9.3' + + if Cucumber::VERSION < '2' + pending + else + skip_this_scenario + end +end From 30523636d9b0c93a8015e2861a78e3203f8c83e0 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Fri, 24 Jul 2015 23:19:54 +0200 Subject: [PATCH 090/118] Longer timeout for rubygems --- features/usage/install.feature | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/features/usage/install.feature b/features/usage/install.feature index f35c59b32..b7799a663 100644 --- a/features/usage/install.feature +++ b/features/usage/install.feature @@ -1,9 +1,8 @@ Feature: Install aruba Background: - Given the default aruba exit timeout is 10 seconds + Given the default aruba exit timeout is 60 seconds - # @wip Scenario: Using rubygems Given I successfully run `gem install aruba` Then aruba should be installed on the local system From 549887d8aacfc0e1eb21c2b1074512787fa13e65 Mon Sep 17 00:00:00 2001 From: Max Meyer Date: Sat, 1 Aug 2015 08:18:38 +0200 Subject: [PATCH 091/118] Remove dots AND trailing slash --- lib/aruba/api/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/aruba/api/core.rb b/lib/aruba/api/core.rb index c34723ab8..c69487f54 100644 --- a/lib/aruba/api/core.rb +++ b/lib/aruba/api/core.rb @@ -61,7 +61,7 @@ def cd(dir, &block) result = Aruba.platform.with_environment( 'OLDPWD' => old_dir, - 'PWD' => File.join(aruba.root_directory, aruba.current_directory).sub(%r{/$}, ''), + 'PWD' => File.expand_path(File.join(aruba.root_directory, aruba.current_directory)), &block ) ensure From 7b59bef038abad0402e018a864dae06ab0d383a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Fri, 7 Aug 2015 08:24:15 +0200 Subject: [PATCH 092/118] Bring back unescape_text etc --- lib/aruba/cucumber/command.rb | 158 +++++++++++++----- lib/aruba/cucumber/file.rb | 5 +- lib/aruba/matchers/command/have_output.rb | 4 +- .../matchers/command/have_output_on_stderr.rb | 4 +- .../matchers/command/have_output_on_stdout.rb | 4 +- 5 files changed, 131 insertions(+), 44 deletions(-) diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index c82bdc45c..5b8b71d28 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -1,22 +1,35 @@ -When(/^I run "(.*)"$/) do |cmd| - Aruba.platform.deprecated(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) - run_simple(Aruba.platform.unescape(cmd, aruba.config.keep_ansi), false) +When(/^I run "(.*)"$/)do |cmd| + warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) + + cmd = unescape_text(cmd) + cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + + run_simple(cmd, false) end -When(/^I run `([^`]*)`$/) do |cmd| - run_simple(Aruba.platform.unescape(cmd, aruba.config.keep_ansi), false) +When(/^I run `([^`]*)`$/)do |cmd| + cmd = unescape_text(cmd) + cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + + run_simple(cmd, false) end -When(/^I successfully run "(.*)"$/) do |cmd| - Aruba.platform.deprecated(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) +When(/^I successfully run "(.*)"$/)do |cmd| + warn(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m}) - run_simple(Aruba.platform.unescape(cmd, aruba.config.keep_ansi)) + cmd = unescape_text(cmd) + cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + + run_simple(cmd) end ## I successfully run `echo -n "Hello"` ## I successfully run `sleep 29` for up to 30 seconds -When(/^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/) do |cmd, secs| - run_simple(Aruba.platform.unescape(cmd, aruba.config.keep_ansi), true, secs && secs.to_i) +When(/^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/)do |cmd, secs| + cmd = unescape_text(cmd) + cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + + run_simple(cmd, true, secs && secs.to_i) end When(/^I run "([^"]*)" interactively$/) do |cmd| @@ -25,8 +38,11 @@ step %(I run `#{cmd}` interactively) end -When(/^I run `([^`]*)` interactively$/) do |cmd| - @interactive = run(Aruba.platform.unescape(cmd, aruba.config.keep_ansi)) +When(/^I run `([^`]*)` interactively$/)do |cmd| + cmd = unescape_text(cmd) + cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + + @interactive = run(cmd) end When(/^I type "([^"]*)"$/) do |input| @@ -55,7 +71,13 @@ last_command_started.public_send channel.to_sym, :wait_for_io => 0 end - if Aruba.platform.unescape(output).include? Aruba.platform.unescape(expected) + output = unescape_text(output) + output = extract_text(output) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + + expected = unescape_text(expected) + expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + + if output.include? expected last_command_started.terminate break @@ -76,7 +98,10 @@ Timeout.timeout(exit_timeout) do loop do begin - expect(last_command_started).to have_output Regexp.new(Aruba.platform.unescape(expected, aruba.config.keep_ansi)) + expected = unescape_text(expected) + expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + + expect(last_command_started).to have_output Regexp.new(expected) rescue ExpectationError sleep 0.1 retry @@ -91,7 +116,10 @@ Timeout.timeout(exit_timeout) do loop do begin - expect(last_command_started).to have_output Regexp.new(Aruba.platform.unescape(expected, aruba.config.keep_ansi)) + expected = unescape_text(expected) + expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + + expect(last_command_started).to have_output Regexp.new(expected) rescue ExpectationError sleep 0.1 retry @@ -122,10 +150,13 @@ all_commands end + expected = unescape_text(expected).chomp + expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + expected = if exactly - Aruba.platform.unescape(expected.chomp) + expected else - Regexp.new(Regexp.escape(Aruba.platform.unescape(expected.chomp))) + Regexp.new(Regexp.escape(expected)) end if Aruba::VERSION < '1.0' @@ -170,10 +201,13 @@ all_commands end + expected = unescape_text(expected).chomp + expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + expected = if exactly - Aruba.platform.unescape(expected.chomp) + expected else - Regexp.new(Regexp.escape(Aruba.platform.unescape(expected.chomp))) + Regexp.new(Regexp.escape(expected)) end if Aruba::VERSION < '1.0' @@ -232,43 +266,74 @@ end end -Then(/^it should (pass|fail) with "(.*?)"$/) do |pass_fail, expected| +Then(/^it should( not)? (pass|fail) with "(.*?)"$/) do |negated, pass_fail, expected| + expected = unescape_text(expected).chomp + expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + expected = Regexp.new(Regexp.escape(expected)) + if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba.platform.unescape(expected))) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba.platform.unescape(expected))) + end + + if negated + expect(last_command_stopped).not_to have_output expected + else + expect(last_command_stopped).to have_output expected end end -Then(/^it should (pass|fail) with:$/) do |pass_fail, expected| +Then(/^it should( not)? (pass|fail) with:$/) do |negated, pass_fail, expected| + expected = unescape_text(expected).chomp + expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + expected = Regexp.new(Regexp.escape(expected)) + if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba.platform.unescape(expected))) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(Regexp.escape(Aruba.platform.unescape(expected))) + end + + if negated + expect(last_command_stopped).not_to have_output expected + else + expect(last_command_stopped).to have_output expected end end -Then(/^it should (pass|fail) with exactly:$/) do |pass_fail, expected| +Then(/^it should( not)? (pass|fail) with exactly:$/) do |negated, pass_fail, expected| + expected = unescape_text(expected).chomp + expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Aruba.platform.unescape(expected) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Aruba.platform.unescape(expected) + end + + if negated + expect(last_command_stopped).not_to have_output expected + else + expect(last_command_stopped).to have_output expected end end -Then(/^it should (pass|fail) with regexp?:$/) do |pass_fail, expected| +Then(/^it should( not)? (pass|fail) with regexp?:$/) do |negated, pass_fail, expected| + expected = unescape_text(expected).chomp + expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + expected = Regexp.new(expected, Regexp::MULTILINE) + if pass_fail == 'pass' expect(last_command_stopped).to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(expected, Regexp::MULTILINE) else expect(last_command_stopped).not_to be_successfully_executed - expect(last_command_stopped).to have_output Regexp.new(expected, Regexp::MULTILINE) + end + + if negated + expect(last_command_stopped).not_to have_output expected + else + expect(last_command_stopped).to have_output expected end end @@ -280,21 +345,34 @@ :have_output_on_stderr when :stdout :have_output_on_stdout + else + fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stdout" and "stderr" are supported.) end expect(all_commands).to include_an_object send(matcher, be_nil.or(be_empty)) end -Then(/^(?:the )?(output|stdout|stderr) should contain all of these lines:$/) do |channel, table| - table.raw.flatten.each do |string| - if channel == 'output' - expect(all_commands).to include_an_object have_output Regexp.new(Regexp.escape(string)) - elsif channel == 'stdout' - expect(all_commands).to include_an_object have_output_on_stdout Regexp.new(Regexp.escape(string)) - elsif channel == 'stderr' - expect(all_commands).to include_an_object have_output_on_stderr Regexp.new(Regexp.escape(string)) +Then(/^(?:the )?(output|stdout|stderr) should( not)? contain all of these lines:$/) do |negated, channel, table| + table.raw.flatten.each do |expected| + expected = unescape_text(expected).chomp + expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + expected = Regexp.new(Regexp.escape(expected)) + + matcher = case channel.to_sym + when :output + :have_output + when :stderr + :have_output_on_stderr + when :stdout + :have_output_on_stdout + else + fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stdout" and "stderr" are supported.) + end + + if negated + expect(all_commands).not_to include_an_object send(matcher, expected) else - fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stdout" and "stderr" are supported.) + expect(all_commands).to include_an_object send(matcher, expected) end end end diff --git a/lib/aruba/cucumber/file.rb b/lib/aruba/cucumber/file.rb index f0a4058cb..1e1b3357e 100644 --- a/lib/aruba/cucumber/file.rb +++ b/lib/aruba/cucumber/file.rb @@ -29,7 +29,10 @@ end Given(/^(?:a|the) file(?: named)? "([^"]*)" with "([^"]*)"$/) do |file_name, file_content| - write_file(file_name, Aruba.platform.unescape(file_content)) + file_content = unescape_text(file_content) + file_content = extract_text(file_content) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences + + write_file(file_name, file_content) end Given(/^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/) do |file_name, file_mode, file_content| diff --git a/lib/aruba/matchers/command/have_output.rb b/lib/aruba/matchers/command/have_output.rb index 85ee69b49..330c5cb5b 100644 --- a/lib/aruba/matchers/command/have_output.rb +++ b/lib/aruba/matchers/command/have_output.rb @@ -29,7 +29,9 @@ ) @old_actual.stop(@announcer) unless @old_actual.stopped? - @actual = Aruba.platform.unescape(actual.output.chomp, aruba.config.keep_ansi) + + @actual = unescape_text(actual.output.chomp) + @actual = extract_text(@actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences values_match?(expected, @actual) end diff --git a/lib/aruba/matchers/command/have_output_on_stderr.rb b/lib/aruba/matchers/command/have_output_on_stderr.rb index 9929b1ff9..36aa3bdf0 100644 --- a/lib/aruba/matchers/command/have_output_on_stderr.rb +++ b/lib/aruba/matchers/command/have_output_on_stderr.rb @@ -29,7 +29,9 @@ ) @old_actual.stop(@announcer) unless @old_actual.stopped? - @actual = Aruba.platform.unescape(actual.stderr.chomp, aruba.config.keep_ansi) + + @actual = unescape_text(actual.stderr.chomp) + @actual = extract_text(@actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences values_match?(expected, @actual) end diff --git a/lib/aruba/matchers/command/have_output_on_stdout.rb b/lib/aruba/matchers/command/have_output_on_stdout.rb index 67595680a..5b38d5419 100644 --- a/lib/aruba/matchers/command/have_output_on_stdout.rb +++ b/lib/aruba/matchers/command/have_output_on_stdout.rb @@ -29,7 +29,9 @@ ) @old_actual.stop(@announcer) unless @old_actual.stopped? - @actual = Aruba.platform.unescape(actual.stdout.chomp, aruba.config.keep_ansi) + + @actual = unescape_text(actual.stdout.chomp) + @actual = extract_text(@actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences values_match?(expected, @actual) end From ff50fbb61347d1c5267f5f1cc7787aba73408076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Fri, 7 Aug 2015 09:04:26 +0200 Subject: [PATCH 093/118] Fixed name of file in feature-test --- features/api/command/run.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/api/command/run.feature b/features/api/command/run.feature index 55d75bd9c..4c65333e4 100644 --- a/features/api/command/run.feature +++ b/features/api/command/run.feature @@ -11,7 +11,7 @@ Feature: Run command #!/bin/bash exit 0 """ - And a file named "spec/which_spec.rb" with: + And a file named "spec/run_spec.rb" with: """ruby require 'spec_helper' @@ -25,7 +25,7 @@ Feature: Run command Scenario: Non-existing executable Given a file named "bin/cli" does not exist - And a file named "spec/which_spec.rb" with: + And a file named "spec/run_spec.rb" with: """ruby require 'spec_helper' From a13ba4c8fe376350af982d5b3e3b8f992e41d000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Fri, 7 Aug 2015 09:04:35 +0200 Subject: [PATCH 094/118] Added documentation for usage of configuration --- features/configuration/usage.feature | 159 +++++++++++++++++++++++++++ lib/aruba/cucumber/command.rb | 2 +- 2 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 features/configuration/usage.feature diff --git a/features/configuration/usage.feature b/features/configuration/usage.feature new file mode 100644 index 000000000..1d4676f25 --- /dev/null +++ b/features/configuration/usage.feature @@ -0,0 +1,159 @@ +Feature: Usage of configuration + + You can configure `aruba` in two ways: + + 1. Using `Aruba.configure`-block + 2. Using `aruba.config.