From 04cb3413f6c0f4e4a8e82f443f2d29ca1b1975ff Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Thu, 15 Mar 2018 10:21:45 +0100 Subject: [PATCH 1/4] Find relative commands from the current directory In an Arabu spec or scenario, files are created relative to the current Aruba directory. When creating an executable in that way, it should be possible to run that executable using the same relative path. This change means that executables in the project under test can no longer be find using the relative path from the project directory. They should be added to the path. This is done automatically by Bundler. --- .../steps/command/run_a_command.feature | 16 ++++++++++++ .../04_aruba_api/command/run_command.feature | 25 +++++++++++-------- lib/aruba/api/commands.rb | 4 ++- spec/aruba/api/commands_spec.rb | 13 ++++++++++ 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/features/03_testing_frameworks/cucumber/steps/command/run_a_command.feature b/features/03_testing_frameworks/cucumber/steps/command/run_a_command.feature index a075df3c4..c4e2e5b5e 100644 --- a/features/03_testing_frameworks/cucumber/steps/command/run_a_command.feature +++ b/features/03_testing_frameworks/cucumber/steps/command/run_a_command.feature @@ -49,6 +49,22 @@ Feature: Run commands STDOUT """ + Scenario: Run command found in "bin"-directory which is found in the current directory + Given a file named "features/run.feature" with: + """ + Feature: Run it + + Scenario: Run command + Given an executable named "bin/local_cli" with: + \"\"\" + #!/bin/bash + exit 0 + \"\"\" + When I successfully run `bin/local_cli` + """ + When I run `cucumber` + Then the features should all pass + Scenario: Run command found in "bin"-directory which is found in the current directory Given a file named "features/run.feature" with: """ diff --git a/features/04_aruba_api/command/run_command.feature b/features/04_aruba_api/command/run_command.feature index 5c7519483..6dd54a6a3 100644 --- a/features/04_aruba_api/command/run_command.feature +++ b/features/04_aruba_api/command/run_command.feature @@ -23,7 +23,7 @@ Feature: Run command Background: Given I use a fixture named "cli-app" - Scenario: Existing executable + Scenario: Executable in the project's path Given an executable named "bin/aruba-test-cli" with: """bash #!/bin/bash @@ -41,19 +41,24 @@ Feature: Run command When I run `rspec` Then the specs should all pass - Scenario: Relative path to executable - Given an executable named "bin/aruba-test-cli" with: - """bash - #!/bin/bash - exit 0 - """ - And a file named "spec/run_spec.rb" with: + Scenario: Executable in a relative path in the Aruba working directory + Given a file named "spec/run_spec.rb" with: """ruby require 'spec_helper' RSpec.describe 'Run command', type: :aruba do - before(:each) { run_command('bin/aruba-test-cli') } - it { expect(last_command_started).to be_successfully_executed } + before do + write_file 'bin/aruba-test-cli', <<~BASH + #!/bin/bash + exit 0 + BASH + chmod 0x755, 'bin/aruba-test-cli' + end + + it "runs the command" do + run_command('bin/aruba-test-cli') + expect(last_command_started).to be_successfully_executed + end end """ When I run `rspec` diff --git a/lib/aruba/api/commands.rb b/lib/aruba/api/commands.rb index 0108ac8cf..45c47c32c 100644 --- a/lib/aruba/api/commands.rb +++ b/lib/aruba/api/commands.rb @@ -261,7 +261,9 @@ def prepare_command(cmd, opts) def start_command(command) aruba.config.before(:command, self, command) - command.start + in_current_directory do + command.start + end stop_signal = command.stop_signal aruba.announcer.announce(:stop_signal, command.pid, stop_signal) if stop_signal diff --git a/spec/aruba/api/commands_spec.rb b/spec/aruba/api/commands_spec.rb index 67c8e2040..cc136fdd3 100644 --- a/spec/aruba/api/commands_spec.rb +++ b/spec/aruba/api/commands_spec.rb @@ -43,5 +43,18 @@ expect { @aruba.run_command 'cat' }.to raise_error NotImplementedError end end + + context 'when running a relative command' do + it 'finds the command from the test directory' do + @aruba.write_file 'bin/aruba-test-cli', <<~BASH + #!/bin/bash + exit 0 + BASH + chmod 0o755, 'bin/aruba-test-cli' + + run_command('bin/aruba-test-cli') + expect(last_command_started).to be_successfully_executed + end + end end end From ef45fd88cd61bc1ba451eb9faef4e7d47366db82 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sat, 25 Jan 2020 17:26:22 +0100 Subject: [PATCH 2/4] Ensure exit timeout is reached in scenario --- .../cucumber/steps/command/check_for_exit_statuses.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/03_testing_frameworks/cucumber/steps/command/check_for_exit_statuses.feature b/features/03_testing_frameworks/cucumber/steps/command/check_for_exit_statuses.feature index 87306823a..ead89af92 100644 --- a/features/03_testing_frameworks/cucumber/steps/command/check_for_exit_statuses.feature +++ b/features/03_testing_frameworks/cucumber/steps/command/check_for_exit_statuses.feature @@ -121,7 +121,7 @@ Feature: Check exit status of commands Given an executable named "bin/aruba-test-cli" with: """ #!/bin/bash - sleep 0.1 + sleep 1 """ And a file named "features/exit_status.feature" with: """ From 95eb6e64fd7e8734d6624a196cdde2f8a3f5e5c9 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sat, 25 Jan 2020 17:31:57 +0100 Subject: [PATCH 3/4] On Windows, test running relative command with bat file --- spec/aruba/api/commands_spec.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/spec/aruba/api/commands_spec.rb b/spec/aruba/api/commands_spec.rb index cc136fdd3..544d10e62 100644 --- a/spec/aruba/api/commands_spec.rb +++ b/spec/aruba/api/commands_spec.rb @@ -45,14 +45,24 @@ end context 'when running a relative command' do - it 'finds the command from the test directory' do - @aruba.write_file 'bin/aruba-test-cli', <<~BASH - #!/bin/bash - exit 0 - BASH - chmod 0o755, 'bin/aruba-test-cli' + let(:cmd) { FFI::Platform.windows? ? 'bin/testcmd.bat' : 'bin/testcmd' } - run_command('bin/aruba-test-cli') + before do + if FFI::Platform.windows? + @aruba.write_file cmd, <<~BAT + exit 0 + BAT + else + @aruba.write_file cmd, <<~BASH + #!/bin/bash + exit 0 + BASH + chmod 0o755, cmd + end + end + + it 'finds the command from the test directory' do + run_command(cmd) expect(last_command_started).to be_successfully_executed end end From d20b964c61b09d21e3fbc3485ce189622075f343 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 26 Jan 2020 23:28:16 +0100 Subject: [PATCH 4/4] Use correct octal access mode --- features/04_aruba_api/command/run_command.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/04_aruba_api/command/run_command.feature b/features/04_aruba_api/command/run_command.feature index 6dd54a6a3..9e22c78de 100644 --- a/features/04_aruba_api/command/run_command.feature +++ b/features/04_aruba_api/command/run_command.feature @@ -52,7 +52,7 @@ Feature: Run command #!/bin/bash exit 0 BASH - chmod 0x755, 'bin/aruba-test-cli' + chmod 0o755, 'bin/aruba-test-cli' end it "runs the command" do