Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find relative commands from the current Aruba directory #702

Merged
merged 4 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
25 changes: 15 additions & 10 deletions features/04_aruba_api/command/run_command.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand Down
4 changes: 3 additions & 1 deletion lib/aruba/api/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions spec/aruba/api/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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