Skip to content
Draft
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
1 change: 1 addition & 0 deletions lib/aruba/api/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def expand_path(file_name, dir_string = nil)

path
elsif prefix == '~'
# FIXME: Can we force use of config.home_directory
path = with_environment do
File.expand_path(file_name)
end
Expand Down
1 change: 1 addition & 0 deletions lib/aruba/platforms/unix_platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def current_ruby
::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
end

# FIXME: Why is this part of platform!? Just use Ruby or just list all files to require.
def require_matching_files(pattern, base)
::Dir.glob(::File.expand_path(pattern, base)).each { |f| require_relative f }
end
Expand Down
38 changes: 13 additions & 25 deletions lib/aruba/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,35 @@
config.include Aruba::Api, type: :aruba

# Setup environment for aruba
config.around :each do |example|
if self.class.include? Aruba::Api
setup_aruba
config.around :each, type: :aruba do |example|
setup_aruba

# Modify PATH to include project/bin
prepend_environment_variable(
'PATH',
aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR
)
# Modify PATH to include project/bin
prepend_environment_variable(
'PATH',
aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR
)

# Use configured home directory as HOME
set_environment_variable 'HOME', aruba.config.home_directory
end
# Use configured home directory as HOME
set_environment_variable 'HOME', aruba.config.home_directory

example.run

next unless self.class.include? Aruba::Api

stop_all_commands
end

config.around :each do |example|
if self.class.include? Aruba::Api
with_environment do
example.run
end
else
config.around :each, type: :aruba do |example|
with_environment do
example.run
end
end

config.before :each do |example|
next unless self.class.include? Aruba::Api

config.before :each, type: :aruba do |example|
example.metadata.each { |k, v| aruba.config.set_if_option(k, v) }
end

# Activate announcers based on rspec metadata
config.before :each do |example|
next unless self.class.include?(Aruba::Api)

config.before :each, type: :aruba do |example|
if example.metadata[:announce_full_environment]
aruba.announcer.activate(:full_environment)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/support/configs/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

config.expect_with :rspec

# FIXME: Right, so we always include Aruba::Api, and all the special matchers
# only work when that's done (and also are not loaded unless that's done?)
config.include Aruba::Api
config.before { setup_aruba }
end
13 changes: 11 additions & 2 deletions spec/support/shared_contexts/aruba.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
require 'fileutils'
require 'securerandom'

# Provide Aruba API via an instance variable, instead of including it into the RSpec class.
RSpec.shared_context 'uses aruba API' do
def random_string(options = {})
options[:prefix].to_s + SecureRandom.hex + options[:suffix].to_s
end

def create_test_files(files, data = 'a')
Array(files).each do |s|
# TODO: Only allow absolute paths here
next if s.to_s[0] == '%'

local_path = @aruba.expand_path(s)
Expand All @@ -19,7 +21,7 @@ def create_test_files(files, data = 'a')
end
end

before do
around do |example|
klass = Class.new do
include Aruba::Api

Expand All @@ -29,14 +31,21 @@ def set_tag(tag_name, value)
end

@aruba = klass.new
@aruba.setup_aruba

@file_name = 'test.txt'
@file_size = 256
@file_path = @aruba.expand_path(@file_name)
@aruba.setup_aruba

if @aruba.aruba.current_directory[0] == '/'
raise 'We must work with relative paths, everything else is dangerous'
end

# Use configured home directory as HOME
@aruba.set_environment_variable "HOME", aruba.config.home_directory

@aruba.with_environment do
example.run
end
end
end
Loading