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

Backport fixes #645

Merged
merged 3 commits into from
Jun 10, 2019
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
6 changes: 3 additions & 3 deletions lib/aruba/cucumber/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
end
require 'aruba/generators/script_file'

When(/^I run `([^`]*)`$/)do |cmd|
When(/^I run `([^`]*)`$/) do |cmd|
cmd = sanitize_text(cmd)
run_command_and_stop(cmd, :fail_on_error => false)
end
Expand All @@ -26,13 +26,13 @@
step 'I run `myscript`'
end

When(/^I run `([^`]*)` interactively$/)do |cmd|
When(/^I run `([^`]*)` interactively$/) do |cmd|
cmd = sanitize_text(cmd)
@interactive = run_command(cmd)
end

# Merge interactive and background after refactoring with event queue
When(/^I run `([^`]*)` in background$/)do |cmd|
When(/^I run `([^`]*)` in background$/) do |cmd|
run_command(sanitize_text(cmd))
end

Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/platforms/command_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def last_command_started=(cmd)
@last_command_started = find(cmd)
end

# Set last command started
# Set last command stopped
#
# @param [String] cmd
# The commandline of the command
Expand Down
30 changes: 30 additions & 0 deletions spec/aruba/api/commands_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'
require 'aruba/api'

RSpec.describe Aruba::Api::Commands do
include_context 'uses aruba API'

describe '#run_command' do
before(:each){ @aruba.run_command 'cat' }
after(:each) { @aruba.all_commands.each(&:stop) }

it "responds to input" do
@aruba.type "Hello"
@aruba.type ""
expect(@aruba.last_command_started).to have_output "Hello"
end

it "responds to close_input" do
@aruba.type "Hello"
@aruba.close_input
expect(@aruba.last_command_started).to have_output "Hello"
end

it "pipes data" do
@aruba.write_file(@file_name, "Hello\nWorld!")
@aruba.pipe_in_file(@file_name)
@aruba.close_input
expect(@aruba.last_command_started).to have_output "Hello\nWorld!"
end
end
end
126 changes: 84 additions & 42 deletions spec/aruba/api/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,51 @@
RSpec.describe Aruba::Api::Core do
include_context 'uses aruba API'

describe '#cd' do
before do
@directory_name = 'test_dir'
@directory_path = File.join(@aruba.aruba.current_directory, @directory_name)
end

context 'with a block given' do
it 'runs the passed block in the given directory' do
@aruba.create_directory @directory_name
full_path = File.expand_path(@directory_path)
@aruba.cd @directory_name do
expect(Dir.pwd).to eq full_path
end
expect(Dir.pwd).not_to eq full_path
end

it 'sets directory environment in the passed block' do
@aruba.create_directory @directory_name
old_pwd = ENV['PWD']
full_path = File.expand_path(@directory_path)
@aruba.cd @directory_name do
expect(ENV['PWD']).to eq full_path
expect(ENV['OLDPWD']).to eq old_pwd
end
end

it 'sets aruba environment in the passed block' do
@aruba.create_directory @directory_name
@aruba.set_environment_variable('FOO', 'bar')
@aruba.cd @directory_name do
expect(ENV['FOO']).to eq 'bar'
end
end

it 'does not touch other environment variables in the passed block' do
keys = ENV.keys - ['PWD', 'OLDPWD']
old_values = ENV.values_at(*keys)
@aruba.create_directory @directory_name
@aruba.cd @directory_name do
expect(ENV.values_at(*keys)).to eq old_values
end
end
end
end

describe '#expand_path' do
context 'when file_name is given' do
it { expect(@aruba.expand_path(@file_name)).to eq File.expand_path(@file_path) }
Expand Down Expand Up @@ -82,61 +127,58 @@
end
end

describe '#cd' do
before do
@directory_name = 'test_dir'
@directory_path = File.join(@aruba.aruba.current_directory, @directory_name)
end
describe '#with_environment' do
it 'modifies env for block' do
variable = 'THIS_IS_A_ENV_VAR_1'
ENV[variable] = '1'

context 'with a block given' do
it 'runs the passed block in the given directory' do
@aruba.create_directory @directory_name
full_path = File.expand_path(@directory_path)
@aruba.cd @directory_name do
expect(Dir.pwd).to eq full_path
end
expect(Dir.pwd).not_to eq full_path
@aruba.with_environment variable => '0' do
expect(ENV[variable]).to eq '0'
end

it 'sets directory environment in the passed block' do
@aruba.create_directory @directory_name
old_pwd = ENV['PWD']
full_path = File.expand_path(@directory_path)
@aruba.cd @directory_name do
expect(ENV['PWD']).to eq full_path
expect(ENV['OLDPWD']).to eq old_pwd
end
end
expect(ENV[variable]).to eq '1'
end

it 'sets aruba environment in the passed block' do
@aruba.create_directory @directory_name
@aruba.set_environment_variable('FOO', 'bar')
@aruba.cd @directory_name do
expect(ENV['FOO']).to eq 'bar'
it 'works together with #set_environment_variable' do
variable = 'THIS_IS_A_ENV_VAR_2'
@aruba.set_environment_variable variable, '1'

@aruba.with_environment do
expect(ENV[variable]).to eq '1'
@aruba.set_environment_variable variable, '0'
@aruba.with_environment do
expect(ENV[variable]).to eq '0'
end
expect(ENV[variable]).to eq '1'
end
end

it 'does not touch other environment variables in the passed block' do
keys = ENV.keys - ['PWD', 'OLDPWD']
old_values = ENV.values_at(*keys)
@aruba.create_directory @directory_name
@aruba.cd @directory_name do
expect(ENV.values_at(*keys)).to eq old_values
it 'works with a mix of ENV and #set_environment_variable' do
variable = 'THIS_IS_A_ENV_VAR_3'
@aruba.set_environment_variable variable, '1'
ENV[variable] = '2'
expect(ENV[variable]).to eq '2'

@aruba.with_environment do
expect(ENV[variable]).to eq '1'
@aruba.set_environment_variable variable, '0'
@aruba.with_environment do
expect(ENV[variable]).to eq '0'
end
expect(ENV[variable]).to eq '1'
end
expect(ENV[variable]).to eq '2'
end
end

describe '#with_environment' do
it 'modifies env for block' do
variable = 'THIS_IS_A_ENV_VAR'
ENV[variable] = '1'
it 'keeps values not set in argument' do
variable = 'THIS_IS_A_ENV_VAR_4'
ENV[variable] = '2'
expect(ENV[variable]).to eq '2'

@aruba.with_environment variable => '0' do
expect(ENV[variable]).to eq '0'
@aruba.with_environment do
expect(ENV[variable]).to eq '2'
end

expect(ENV[variable]).to eq '1'
expect(ENV[variable]).to eq '2'
end
end
end
24 changes: 0 additions & 24 deletions spec/aruba/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,6 @@
end
end

describe '#run_command' do
before(:each){ @aruba.run_command 'cat' }
after(:each) { @aruba.all_commands.each(&:stop) }

it "respond to input" do
@aruba.type "Hello"
@aruba.type ""
expect(@aruba.last_command_started).to have_output "Hello"
end

it "respond to close_input" do
@aruba.type "Hello"
@aruba.close_input
expect(@aruba.last_command_started).to have_output "Hello"
end

it "pipes data" do
@aruba.write_file(@file_name, "Hello\nWorld!")
@aruba.pipe_in_file(@file_name)
@aruba.close_input
expect(@aruba.last_command_started).to have_output "Hello\nWorld!"
end
end

describe 'fixtures' do
let(:api) do
klass = Class.new do
Expand Down