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: """ 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..9e22c78de 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 0o755, '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..544d10e62 100644 --- a/spec/aruba/api/commands_spec.rb +++ b/spec/aruba/api/commands_spec.rb @@ -43,5 +43,28 @@ expect { @aruba.run_command 'cat' }.to raise_error NotImplementedError end end + + context 'when running a relative command' do + let(:cmd) { FFI::Platform.windows? ? 'bin/testcmd.bat' : 'bin/testcmd' } + + 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 end end