Skip to content

Commit

Permalink
Merge pull request #618 from cucumber/improve-appveyor-build-specs
Browse files Browse the repository at this point in the history
Improve appveyor build: Specs part
  • Loading branch information
mvz authored May 19, 2019
2 parents da2be58 + 2f0d91b commit 816e6c1
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 152 deletions.
9 changes: 5 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ install:
- cinst ansicon

test_script:
- bundle exec rake test --trace
- bundle exec rake test:rspec --trace

environment:
matrix:
- ruby_version: '19'
- ruby_version: '20'
- ruby_version: '21'
- ruby_version: '22'
- ruby_version: '23'
- ruby_version: '24'
- ruby_version: '25'
- ruby_version: '26'

10 changes: 5 additions & 5 deletions features/02_configure_aruba/command_runtime_environment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Feature: Define default process environment
ENV['LONG_LONG_VARIABLE'] = 'y'
Aruba.configure do |config|
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
end
RSpec.describe 'Environment command', :type => :aruba do
Expand All @@ -44,7 +44,7 @@ Feature: Define default process environment
ENV['LONG_LONG_VARIABLE'] = 'y'
Aruba.configure do |config|
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
end
RSpec.describe 'Environment command', :type => :aruba do
Expand All @@ -67,7 +67,7 @@ Feature: Define default process environment
ENV['LONG_LONG_VARIABLE'] = 'y'
Aruba.configure do |config|
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
end
RSpec.describe 'Environment command', :type => :aruba do
Expand All @@ -90,7 +90,7 @@ Feature: Define default process environment
ENV['LONG_LONG_VARIABLE'] = 'y'
Aruba.configure do |config|
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
end
RSpec.describe 'Environment command', :type => :aruba do
Expand All @@ -113,7 +113,7 @@ Feature: Define default process environment
ENV['LONG_LONG_VARIABLE'] = 'y'
Aruba.configure do |config|
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
end
RSpec.describe 'Environment command', :type => :aruba do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@unsupported-on-platform-windows
Feature: Check if path has permissions in filesystem

If you need to check if a given path has some permissions in filesystem, you
Expand Down
3 changes: 0 additions & 3 deletions fixtures/spawn_process/stderr.sh

This file was deleted.

2 changes: 1 addition & 1 deletion lib/aruba/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Configuration < BasicConfiguration
option_accessor :io_wait_timeout, contract: { Num => Num }, default: 0.1
option_accessor :startup_wait_time, contract: { Num => Num }, default: 0
option_accessor :fixtures_directories, contract: { Array => ArrayOf[String] }, default: %w(features/fixtures spec/fixtures test/fixtures fixtures)
option_accessor :command_runtime_environment, contract: { Hash => Hash }, default: ENV.to_hash
option_accessor :command_runtime_environment, contract: { Hash => Hash }, default: {}
# rubocop:disable Metrics/LineLength
option_accessor(:command_search_paths, contract: { ArrayOf[String] => ArrayOf[String] }) { |config| [File.join(config.root_directory.value, 'bin'), File.join(config.root_directory.value, 'exe')] }
# rubocop:enable Metrics/LineLength
Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/platforms/local_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LocalEnvironment
# @yield
# The block of code which should with local ENV
def call(env)
old_env = ENV.to_hash.dup
old_env = Aruba.platform.environment_variables.hash_from_env

ENV.clear
ENV.update env
Expand Down
11 changes: 7 additions & 4 deletions lib/aruba/platforms/unix_command_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ module Aruba
# Platforms
module Platforms
# This is a command which should be run
class UnixCommandString < SimpleDelegator
def initialize(cmd)
__setobj__ cmd
#
# @private
class UnixCommandString
def initialize(command, *arguments)
@command = command
@arguments = arguments
end

# Convert to array
def to_a
[__getobj__]
[@command, *@arguments]
end
end
end
Expand Down
20 changes: 8 additions & 12 deletions lib/aruba/platforms/unix_environment_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def initialize(env = ENV)
def update(other_env)
actions << UpdateAction.new(other_env)

UnixEnvironmentVariables.new(to_h)
self
end

# Fetch variable from environment
Expand Down Expand Up @@ -184,11 +184,7 @@ def respond_to_missing?(name, _private)
# @return [Hash]
# A new hash from environment
def to_h
if RUBY_VERSION < '2.0'
Marshal.load(Marshal.dump(prepared_environment.to_hash))
else
Marshal.load(Marshal.dump(prepared_environment.to_h))
end
actions.inject(hash_from_env.merge(env)) { |a, e| e.call(a) }
end

# Reset environment
Expand All @@ -200,14 +196,14 @@ def clear
value
end

def self.hash_from_env
ENV.to_hash
end

private

def prepared_environment
if RUBY_VERSION == '1.9.3'
actions.inject(ENV.to_hash.merge(env)) { |a, e| e.call(a) }
else
actions.each_with_object(ENV.to_hash.merge(env)) { |e, a| a = e.call(a) }
end
def hash_from_env
self.class.hash_from_env
end
end
end
Expand Down
20 changes: 16 additions & 4 deletions lib/aruba/platforms/windows_command_string.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'delegate'

# Aruba
module Aruba
# Platforms
Expand All @@ -9,14 +7,28 @@ module Platforms
# This adds `cmd.exec` in front of commmand
#
# @private
class WindowsCommandString < SimpleDelegator
class WindowsCommandString
def initialize(command, *arguments)
@command = command
@arguments = arguments
end

# Convert to array
def to_a
[cmd_path, '/c', __getobj__]
[cmd_path, '/c', [escaped_command, *escaped_arguments].join(' ')]
end

private

def escaped_arguments
@arguments.map { |arg| arg.gsub(/"/, '"""') }.
map { |arg| arg =~ / / ? "\"#{arg}\"" : arg }
end

def escaped_command
@command.gsub(/ /, '""" """')
end

def cmd_path
Aruba.platform.which('cmd.exe')
end
Expand Down
24 changes: 17 additions & 7 deletions lib/aruba/platforms/windows_environment_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ module Platforms
# env["PATH"]
# # => nil
class WindowsEnvironmentVariables < UnixEnvironmentVariables
def initialize(env = ENV.to_hash)
@actions = []

@env = env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v }
def initialize(env = ENV)
super(upcase_env env)
end

def update(other_env, &block)
other_env = other_env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v }

super(other_env, &block)
super(upcase_env(other_env), &block)
end

def fetch(name, default = UnixEnvironmentVariables::UNDEFINED)
Expand Down Expand Up @@ -67,6 +63,20 @@ def prepend(name, value)
def delete(name)
super(name.upcase)
end

def self.hash_from_env
upcase_env(ENV)
end

def self.upcase_env(env)
env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v }
end

private

def upcase_env(env)
self.class.upcase_env(env)
end
end
end
end
8 changes: 5 additions & 3 deletions lib/aruba/processes/basic_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class BasicProcess
attr_reader :exit_status, :environment, :working_directory, :main_class,
:io_wait_timeout, :exit_timeout, :startup_wait_time, :stop_signal

def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
def initialize(cmd, exit_timeout, io_wait_timeout, working_directory,
environment = Aruba.platform.environment_variables.hash_from_env,
main_class = nil, stop_signal = nil, startup_wait_time = 0)
@cmd = cmd
@working_directory = working_directory
@environment = environment
Expand Down Expand Up @@ -120,8 +122,6 @@ def inspect

alias to_s inspect

private

def command
Shellwords.split(commandline).first
end
Expand All @@ -132,6 +132,8 @@ def arguments
[]
end

private

def truncate(string, max_length)
return string if string.length <= max_length

Expand Down
4 changes: 3 additions & 1 deletion lib/aruba/processes/in_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def exit(exitstatus)
# @private
attr_reader :main_class

def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
def initialize(cmd, exit_timeout, io_wait_timeout, working_directory,
environment = Aruba.platform.environment_variables.hash_from_env,
main_class = nil, stop_signal = nil, startup_wait_time = 0)
@cmd = cmd
@argv = arguments
@stdin = StringIO.new
Expand Down
19 changes: 11 additions & 8 deletions lib/aruba/processes/spawn_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def self.match?(_mode)
#
# @param [Numeric] startup_wait_time
# The amount of seconds to wait after Aruba has started a command.
def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
def initialize(cmd, exit_timeout, io_wait_timeout, working_directory,
environment = Aruba.platform.environment_variables.hash_from_env,
main_class = nil, stop_signal = nil, startup_wait_time = 0)
super

@process = nil
Expand All @@ -70,7 +72,7 @@ def start

@started = true

@process = ChildProcess.build(*command_string.to_a, *arguments)
@process = ChildProcess.build(*command_string.to_a)
@stdout_file = Tempfile.new('aruba-stdout-')
@stderr_file = Tempfile.new('aruba-stderr-')

Expand Down Expand Up @@ -238,7 +240,7 @@ def send_signal(signal)
# @return [Aruba::Platforms::FilesystemStatus]
# This returns a File::Stat-object
def filesystem_status
Aruba.platform.filesystem_status.new(command_string.to_s)
Aruba.platform.filesystem_status.new(command_path)
end

# Content of command
Expand All @@ -247,7 +249,7 @@ def filesystem_status
# The content of the script/command. This might be binary output as
# string if your command is a binary executable.
def content
File.read command_string.to_s
File.read command_path
end

def interactive?
Expand All @@ -257,12 +259,13 @@ def interactive?
private

def command_string
# gather fully qualified path
cmd = Aruba.platform.which(command, environment['PATH'])
fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) if command_path.nil?

fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) if cmd.nil?
Aruba.platform.command_string.new(command_path, *arguments)
end

Aruba.platform.command_string.new(cmd)
def command_path
@command_path ||= Aruba.platform.which(command, environment['PATH'])
end

def wait_for_io(time_to_wait)
Expand Down
3 changes: 2 additions & 1 deletion lib/aruba/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
setup_aruba

# Modify PATH to include project/bin
prepend_environment_variable 'PATH', aruba.config.command_search_paths.join(':') + ':'
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
Expand Down
Loading

0 comments on commit 816e6c1

Please sign in to comment.