aruba 0.7.4 → 0.8.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.nav +12 -0
- data/.rspec +1 -0
- data/.rubocop.yml +12 -0
- data/.simplecov +2 -0
- data/.travis.yml +5 -6
- data/Gemfile +53 -26
- data/History.md +17 -0
- data/LICENSE +1 -1
- data/README.md +45 -19
- data/Rakefile +12 -2
- data/TODO.md +3 -0
- data/aruba.gemspec +19 -8
- data/cucumber.yml +1 -1
- data/features/api/cd.feature +119 -0
- data/features/api/command/run.feature +37 -0
- data/features/api/command/which.feature +37 -0
- data/features/api/environment/append_environment_variable.feature +118 -0
- data/features/api/environment/prepend_environment_variable.feature +118 -0
- data/features/api/environment/set_environment_variable.feature +252 -0
- data/features/configuration/exit_timeout.feature +51 -0
- data/features/configuration/fixtures_directories.feature +31 -0
- data/features/configuration/fixtures_path_prefix.feature +24 -0
- data/features/configuration/io_timeout.feature +31 -0
- data/features/configuration/keep_ansi.feature +31 -0
- data/features/configuration/root_directory.feature +31 -0
- data/features/configuration/working_directory.feature +32 -0
- data/features/fixtures/cli-app/.gitignore +9 -0
- data/features/fixtures/cli-app/.rspec +2 -0
- data/features/fixtures/cli-app/README.md +34 -0
- data/features/fixtures/cli-app/Rakefile +1 -0
- data/features/fixtures/cli-app/bin/cli +6 -0
- data/features/fixtures/cli-app/cli-app.gemspec +26 -0
- data/features/fixtures/cli-app/features/support/env.rb +1 -0
- data/features/fixtures/cli-app/lib/cli/app.rb +13 -0
- data/features/fixtures/cli-app/lib/cli/app/version.rb +5 -0
- data/features/fixtures/cli-app/script/console +14 -0
- data/features/fixtures/cli-app/spec/cli/app_spec.rb +7 -0
- data/features/fixtures/cli-app/spec/spec_helper.rb +10 -0
- data/features/fixtures/copy/file.txt +1 -1
- data/features/hooks/after/command.feature +34 -0
- data/features/hooks/before/command.feature +61 -0
- data/features/matchers/directory/have_sub_directory.feature +110 -0
- data/features/matchers/file/be_existing_file.feature +82 -0
- data/features/matchers/file/have_file_content.feature +123 -0
- data/features/matchers/file/have_file_size.feature +107 -0
- data/features/matchers/path/be_an_absolute_path.feature +74 -0
- data/features/matchers/path/be_an_existing_path.feature +97 -0
- data/features/matchers/path/have_permissions.feature +118 -0
- data/features/matchers/timeouts.feature +48 -0
- data/features/step_definitions/aruba_dev_steps.rb +69 -1
- data/features/steps/commands/exit_statuses.feature +136 -0
- data/features/steps/commands/in_process.feature +129 -0
- data/features/steps/commands/run.feature +36 -0
- data/features/steps/environment/home_variable.feature +49 -0
- data/features/steps/environment/set_environment_variable.feature +34 -0
- data/features/support/aruba.rb +5 -0
- data/features/support/env.rb +8 -4
- data/lib/aruba.rb +20 -8
- data/lib/aruba/announcer.rb +1 -0
- data/lib/aruba/api.rb +18 -1179
- data/lib/aruba/api/command.rb +351 -0
- data/lib/aruba/api/core.rb +141 -0
- data/lib/aruba/api/deprecated.rb +549 -0
- data/lib/aruba/api/environment.rb +61 -0
- data/lib/aruba/api/filesystem.rb +305 -0
- data/lib/aruba/api/rvm.rb +39 -0
- data/lib/aruba/aruba_path.rb +75 -0
- data/lib/aruba/basic_configuration.rb +208 -0
- data/lib/aruba/basic_configuration/option.rb +25 -0
- data/lib/aruba/config.rb +43 -30
- data/lib/aruba/config/jruby.rb +14 -0
- data/lib/aruba/config_wrapper.rb +17 -0
- data/lib/aruba/contracts/relative_path.rb +13 -0
- data/lib/aruba/creators/aruba_file_creator.rb +32 -0
- data/lib/aruba/creators/aruba_fixed_size_file_creator.rb +32 -0
- data/lib/aruba/cucumber.rb +87 -53
- data/lib/aruba/cucumber/hooks.rb +65 -10
- data/lib/aruba/environment.rb +121 -0
- data/lib/aruba/errors.rb +3 -0
- data/lib/aruba/extensions/string/strip.rb +24 -0
- data/lib/aruba/hooks.rb +54 -0
- data/lib/aruba/jruby.rb +4 -9
- data/lib/aruba/matchers/command.rb +1 -79
- data/lib/aruba/matchers/command/be_successfully_executed.rb +30 -0
- data/lib/aruba/matchers/command/have_exit_status.rb +47 -0
- data/lib/aruba/matchers/command/have_finished_in_time.rb +42 -0
- data/lib/aruba/matchers/directory.rb +1 -59
- data/lib/aruba/matchers/directory/be_an_existing_directory.rb +34 -0
- data/lib/aruba/matchers/directory/have_sub_directory.rb +49 -0
- data/lib/aruba/matchers/file.rb +1 -177
- data/lib/aruba/matchers/file/be_an_existing_file.rb +34 -0
- data/lib/aruba/matchers/file/have_file_content.rb +58 -0
- data/lib/aruba/matchers/file/have_file_size.rb +43 -0
- data/lib/aruba/matchers/file/have_same_file_content.rb +44 -0
- data/lib/aruba/matchers/path.rb +1 -99
- data/lib/aruba/matchers/path/a_path_matching_pattern.rb +21 -0
- data/lib/aruba/matchers/path/be_an_absolute_path.rb +32 -0
- data/lib/aruba/matchers/path/be_an_existing_path.rb +33 -0
- data/lib/aruba/matchers/path/have_permissions.rb +60 -0
- data/lib/aruba/matchers/path/match_path_pattern.rb +41 -0
- data/lib/aruba/matchers/rspec.rb +0 -0
- data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +1 -1
- data/lib/aruba/platform.rb +230 -0
- data/lib/aruba/process_monitor.rb +23 -5
- data/lib/aruba/processes/basic_process.rb +35 -1
- data/lib/aruba/processes/debug_process.rb +26 -15
- data/lib/aruba/processes/in_process.rb +21 -9
- data/lib/aruba/processes/spawn_process.rb +29 -19
- data/lib/aruba/reporting.rb +2 -0
- data/lib/aruba/rspec.rb +61 -13
- data/lib/aruba/runtime.rb +33 -0
- data/script/bootstrap +4 -6
- data/spec/aruba/api/runtime_spec.rb +28 -0
- data/spec/aruba/api_spec.rb +129 -126
- data/spec/aruba/aruba_path_spec.rb +65 -0
- data/spec/aruba/basic_configuration_spec.rb +5 -0
- data/spec/aruba/config_wrapper_spec.rb +25 -0
- data/spec/aruba/configuration_spec.rb +5 -0
- data/spec/aruba/jruby_spec.rb +34 -18
- data/spec/aruba/matchers/directory_spec.rb +6 -7
- data/spec/aruba/matchers/file_spec.rb +16 -20
- data/spec/aruba/matchers/path_spec.rb +14 -11
- data/spec/aruba/rspec_spec.rb +15 -0
- data/spec/aruba/runtime_spec.rb +29 -0
- data/spec/aruba/spawn_process_spec.rb +2 -2
- data/spec/spec_helper.rb +10 -2
- data/spec/support/configs/rspec.rb +1 -1
- data/spec/support/matchers/option.rb +35 -0
- data/spec/support/shared_contexts/aruba.rb +10 -8
- data/spec/support/shared_examples/configuration.rb +116 -0
- metadata +182 -33
- data/.rvmrc +0 -1
- data/features/before_cmd_hooks.feature +0 -61
- data/features/command_environment_variables.feature +0 -31
- data/features/custom_ruby_process.feature +0 -12
- data/features/exit_statuses.feature +0 -30
- data/features/support/custom_main.rb +0 -28
- data/lib/aruba/matchers/mode.rb +0 -52
- data/lib/aruba/utils.rb +0 -21
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require 'aruba/basic_configuration/option'
|
3
|
+
|
4
|
+
module Aruba
|
5
|
+
# Basic configuration for ProxyPacRb
|
6
|
+
class BasicConfiguration
|
7
|
+
include Contracts
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def known_options
|
11
|
+
@known_options ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def option_reader(name, opts = {})
|
15
|
+
contract = opts[:contract]
|
16
|
+
default = opts[:default]
|
17
|
+
|
18
|
+
fail ArgumentError, 'Either use block or default value' if block_given? && default
|
19
|
+
fail ArgumentError, 'contract-options is required' if contract.nil?
|
20
|
+
|
21
|
+
Contract contract
|
22
|
+
add_option(name, block_given? ? yield(ConfigWrapper.new(known_options)) : default)
|
23
|
+
|
24
|
+
define_method(name) { find_option(name).value }
|
25
|
+
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
30
|
+
def option_accessor(name, opts = {})
|
31
|
+
contract = opts[:contract]
|
32
|
+
default = opts[:default]
|
33
|
+
|
34
|
+
fail ArgumentError, 'Either use block or default value' if block_given? && default
|
35
|
+
fail ArgumentError, 'Either use block or default value' if !block_given? && default.nil? && default.empty?
|
36
|
+
fail ArgumentError, 'contract-options is required' if contract.nil?
|
37
|
+
|
38
|
+
# Add writer
|
39
|
+
add_option(name, block_given? ? yield(ConfigWrapper.new(known_options)) : default)
|
40
|
+
|
41
|
+
Contract contract
|
42
|
+
define_method("#{name}=") { |v| find_option(name).value = v }
|
43
|
+
|
44
|
+
# Add reader
|
45
|
+
option_reader name, :contract => { None => contract.values.first }
|
46
|
+
end
|
47
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def add_option(name, value = nil)
|
52
|
+
return if known_options.key?(name)
|
53
|
+
|
54
|
+
known_options[name] = Option.new(:name => name, :value => value)
|
55
|
+
|
56
|
+
self
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
|
62
|
+
attr_accessor :local_options
|
63
|
+
attr_writer :hooks
|
64
|
+
|
65
|
+
# attr_reader :hooks
|
66
|
+
|
67
|
+
public
|
68
|
+
|
69
|
+
def initialize
|
70
|
+
initialize_configuration
|
71
|
+
end
|
72
|
+
|
73
|
+
# @yield [Configuration]
|
74
|
+
#
|
75
|
+
# Yields self
|
76
|
+
def configure
|
77
|
+
yield self if block_given?
|
78
|
+
end
|
79
|
+
|
80
|
+
# Reset configuration
|
81
|
+
def reset
|
82
|
+
initialize_configuration
|
83
|
+
end
|
84
|
+
|
85
|
+
# Make deep dup copy of configuration
|
86
|
+
def make_copy
|
87
|
+
obj = self.dup
|
88
|
+
obj.local_options = Marshal.load(Marshal.dump(local_options))
|
89
|
+
obj.hooks = @hooks
|
90
|
+
|
91
|
+
obj
|
92
|
+
end
|
93
|
+
|
94
|
+
# Get access to hooks
|
95
|
+
def hooks
|
96
|
+
# rubocop:disable Metrics/LineLength
|
97
|
+
Aruba::Platform.deprecated 'The use of the "#aruba.config.hooks" is deprecated. Please use "#aruba.config.before(:name) {}" to define and "#aruba.config.before(:name, *args)" to run a hook. This method will become private in the next major version.'
|
98
|
+
# rubocop:enable Metrics/LineLength
|
99
|
+
|
100
|
+
@hooks
|
101
|
+
end
|
102
|
+
|
103
|
+
# @deprecated
|
104
|
+
def before_cmd(&block)
|
105
|
+
Aruba::Platform.deprecated 'The use of the "#before_cmd"-hook is deprecated. Please define with "#before(:command) {}" instead'
|
106
|
+
|
107
|
+
before(:command, &block)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Define or run before-hook
|
111
|
+
#
|
112
|
+
# @param [Symbol, String] name
|
113
|
+
# The name of the hook
|
114
|
+
#
|
115
|
+
# @param [Proc] context
|
116
|
+
# The context a hook should run in. This is a runtime only option.
|
117
|
+
#
|
118
|
+
# @param [Array] args
|
119
|
+
# Arguments for the run of hook. This is a runtime only option.
|
120
|
+
#
|
121
|
+
# @yield
|
122
|
+
# The code block which should be run. This is a configure time only option
|
123
|
+
def before(name, context = proc {}, *args, &block)
|
124
|
+
name = format('%s_%s', 'before_', name.to_s).to_sym
|
125
|
+
|
126
|
+
if block_given?
|
127
|
+
@hooks.append(name, block)
|
128
|
+
|
129
|
+
self
|
130
|
+
else
|
131
|
+
@hooks.execute(name, context, *args)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# Define or run after-hook
|
136
|
+
#
|
137
|
+
# @param [Symbol, String] name
|
138
|
+
# The name of the hook
|
139
|
+
#
|
140
|
+
# @param [Proc] context
|
141
|
+
# The context a hook should run in. This is a runtime only option.
|
142
|
+
#
|
143
|
+
# @param [Array] args
|
144
|
+
# Arguments for the run of hook. This is a runtime only option.
|
145
|
+
#
|
146
|
+
# @yield
|
147
|
+
# The code block which should be run. This is a configure time only option
|
148
|
+
def after(name, context = proc {}, *args, &block)
|
149
|
+
name = format('%s_%s', 'after_', name.to_s).to_sym
|
150
|
+
|
151
|
+
if block_given?
|
152
|
+
@hooks.append(name, block)
|
153
|
+
|
154
|
+
self
|
155
|
+
else
|
156
|
+
@hooks.execute(name, context, *args)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Check if before-hook <name> is defined
|
161
|
+
def before?(name)
|
162
|
+
name = format('%s_%s', 'before_', name.to_s).to_sym
|
163
|
+
|
164
|
+
@hooks.exist? name
|
165
|
+
end
|
166
|
+
|
167
|
+
# Check if after-hook <name> is defined
|
168
|
+
def after?(name)
|
169
|
+
name = format('%s_%s', 'after_', name.to_s).to_sym
|
170
|
+
|
171
|
+
@hooks.exist? name
|
172
|
+
end
|
173
|
+
|
174
|
+
# Check if <name> is option
|
175
|
+
#
|
176
|
+
# @param [String, Symbol] name
|
177
|
+
# The name of the option
|
178
|
+
def option?(name)
|
179
|
+
local_options.any? { |_, v| v.name == name.to_sym }
|
180
|
+
end
|
181
|
+
|
182
|
+
def ==(other)
|
183
|
+
local_options.values.map(&:value) == other.local_options.values.map(&:value)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Set if name is option
|
187
|
+
def set_if_option(name, *args)
|
188
|
+
if RUBY_VERSION < '1.9'
|
189
|
+
send("#{name}=".to_sym, *args) if option? name
|
190
|
+
else
|
191
|
+
public_send("#{name}=".to_sym, *args) if option? name
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
private
|
196
|
+
|
197
|
+
def initialize_configuration
|
198
|
+
@local_options = Marshal.load(Marshal.dump(self.class.known_options))
|
199
|
+
@hooks = Hooks.new
|
200
|
+
end
|
201
|
+
|
202
|
+
def find_option(name)
|
203
|
+
fail NotImplementedError, %(Unknown option "#{name}") unless option? name
|
204
|
+
|
205
|
+
local_options[name]
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Aruba
|
2
|
+
class BasicConfiguration
|
3
|
+
# A configuration option
|
4
|
+
class Option
|
5
|
+
attr_accessor :name, :value
|
6
|
+
attr_reader :default_value
|
7
|
+
|
8
|
+
def initialize(opts = {})
|
9
|
+
name = opts[:name]
|
10
|
+
value = opts[:value]
|
11
|
+
|
12
|
+
fail ArgumentError, '"name" is required' if name.nil?
|
13
|
+
fail ArgumentError, '"value" is required' if value.nil?
|
14
|
+
|
15
|
+
@name = name
|
16
|
+
@value = value
|
17
|
+
@default_value = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(other)
|
21
|
+
name == other.name && value == other.value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/aruba/config.rb
CHANGED
@@ -1,43 +1,56 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'contracts'
|
2
|
+
require 'aruba/basic_configuration'
|
3
|
+
require 'aruba/config_wrapper'
|
4
|
+
require 'aruba/hooks'
|
5
|
+
require 'aruba/contracts/relative_path'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
module Aruba
|
8
|
+
# Aruba Configuration
|
9
|
+
class Configuration < BasicConfiguration
|
10
|
+
# As of 1.0.0 root_directory is read-only
|
11
|
+
# option_reader :root_directory, :contract => { None => String }, :default => Dir.getwd
|
12
|
+
option_accessor :root_directory, :contract => { String => String }, :default => Dir.getwd
|
13
|
+
option_accessor :working_directory, :contract => { Aruba::Contracts::RelativePath => Aruba::Contracts::RelativePath }, :default => 'tmp/aruba'
|
14
|
+
|
15
|
+
if RUBY_VERSION < '1.9'
|
16
|
+
option_reader :fixtures_path_prefix, :contract => { None => String }, :default => '%'
|
17
|
+
else
|
18
|
+
option_reader :fixtures_path_prefix, :contract => { None => String }, :default => ?%
|
7
19
|
end
|
8
20
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
21
|
+
option_accessor :exit_timeout, :contract => { Num => Num }, :default => 15
|
22
|
+
option_accessor :io_wait_timeout, :contract => { Num => Num }, :default => 0.1
|
23
|
+
option_accessor :fixtures_directories, :contract => { Array => ArrayOf[String] }, :default => %w(features/fixtures spec/fixtures test/fixtures)
|
24
|
+
option_accessor :command_runtime_environment, :contract => { Hash => Hash }, :default => ENV.to_hash
|
25
|
+
option_accessor(:command_search_paths, :contract => { ArrayOf[String] => ArrayOf[String] }) { |config| [File.join(config.root_directory.value, 'bin')] }
|
26
|
+
option_accessor :keep_ansi, :contract => { Bool => Bool }, :default => false
|
13
27
|
end
|
28
|
+
end
|
14
29
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@store = Hash.new do |hash, key|
|
19
|
-
hash[key] = []
|
20
|
-
end
|
21
|
-
end
|
30
|
+
# Main Module
|
31
|
+
module Aruba
|
32
|
+
@config = Configuration.new
|
22
33
|
|
23
|
-
|
24
|
-
|
25
|
-
|
34
|
+
class << self
|
35
|
+
attr_reader :config
|
36
|
+
|
37
|
+
def configure(&block)
|
38
|
+
@config.configure(&block)
|
26
39
|
|
27
|
-
|
28
|
-
@store[label].each do |block|
|
29
|
-
context.instance_exec(*args, &block)
|
30
|
-
end
|
40
|
+
self
|
31
41
|
end
|
32
42
|
end
|
43
|
+
end
|
33
44
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
45
|
+
module Aruba
|
46
|
+
# Old Config
|
47
|
+
#
|
48
|
+
# @private
|
49
|
+
class Config < Configuration
|
50
|
+
def initialize(*args)
|
51
|
+
warn('The use of "Aruba::Config" is deprecated. Use "Aruba::Configuration" instead.')
|
52
|
+
|
53
|
+
super
|
39
54
|
end
|
40
55
|
end
|
41
|
-
|
42
|
-
self.config = Config.new
|
43
56
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
# ideas taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
|
4
|
+
Aruba.configure do |config|
|
5
|
+
config.before :command do
|
6
|
+
next unless RUBY_PLATFORM == 'java'
|
7
|
+
|
8
|
+
# disable JIT since these processes are so short lived
|
9
|
+
ENV['JRUBY_OPTS'] = "-X-C #{ENV['JRUBY_OPTS']}"
|
10
|
+
|
11
|
+
# force jRuby to use client JVM for faster startup times
|
12
|
+
ENV['JAVA_OPTS'] = "-d32 #{ENV['JAVA_OPTS']}" if RbConfig::CONFIG['host_os'] =~ /solaris|sunos/i
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Aruba
|
2
|
+
class ConfigWrapper
|
3
|
+
attr_reader :config
|
4
|
+
private :config
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
@config = config.dup
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(name, *args)
|
11
|
+
fail ArgumentError, 'Options take no argument' if args.count > 0
|
12
|
+
fail UnknownOptionError, %(Option "#{name}" is unknown. Please use only earlier defined options) unless config.key? name
|
13
|
+
|
14
|
+
config[name]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Aruba
|
2
|
+
# Create things to make aruba work
|
3
|
+
module Creators
|
4
|
+
# Normal File Creator
|
5
|
+
# This class is not meant to be used directly by users.
|
6
|
+
class ArubaFileCreator
|
7
|
+
# Write File
|
8
|
+
#
|
9
|
+
# @param [String] path
|
10
|
+
# The path to write content to
|
11
|
+
#
|
12
|
+
# @param [Object] content
|
13
|
+
# The content of the file
|
14
|
+
#
|
15
|
+
# @param [TrueClass, FalseClass] check_presence (false)
|
16
|
+
# Check if file exist
|
17
|
+
def write(path, content, check_presence = false)
|
18
|
+
fail "Expected #{path} to be present" if check_presence && !Aruba::Platform.file?(path)
|
19
|
+
|
20
|
+
Aruba::Platform.mkdir(File.dirname(path))
|
21
|
+
|
22
|
+
if RUBY_VERSION < '1.9'
|
23
|
+
File.open(path, 'w') { |f| f << content }
|
24
|
+
else
|
25
|
+
File.write(path, content)
|
26
|
+
end
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Aruba
|
2
|
+
# Create things to make aruba work
|
3
|
+
module Creators
|
4
|
+
# Create files with fixed size
|
5
|
+
#
|
6
|
+
# This class is not meant to be used directly by users.
|
7
|
+
#
|
8
|
+
# It uses a single null byte as content and really creates so called sparse
|
9
|
+
# files.
|
10
|
+
class ArubaFixedSizeFileCreator
|
11
|
+
# Write File
|
12
|
+
#
|
13
|
+
# @param [String] path
|
14
|
+
# The path to write content to
|
15
|
+
#
|
16
|
+
# @param [Numeric] size
|
17
|
+
# The size of the file
|
18
|
+
#
|
19
|
+
# @param [TrueClass, FalseClass] check_presence (false)
|
20
|
+
# Check if file exist
|
21
|
+
def write(path, size, check_presence)
|
22
|
+
fail "Expected #{path} to be present" if check_presence && !Aruba::Platform.file?(path)
|
23
|
+
|
24
|
+
Aruba::Platform.mkdir(File.dirname(path))
|
25
|
+
|
26
|
+
File.open(path, "wb"){ |f| f.seek(size - 1); f.write("\0") }
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/aruba/cucumber.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'aruba/api'
|
2
|
+
World(Aruba::Api)
|
3
|
+
|
2
4
|
require 'aruba/cucumber/hooks'
|
3
5
|
require 'aruba/reporting'
|
4
6
|
|
5
|
-
World(Aruba::Api)
|
6
|
-
|
7
7
|
Given /the default aruba timeout is (\d+) seconds/ do |seconds|
|
8
|
-
|
8
|
+
aruba.config.exit_timeout = seconds.to_i
|
9
9
|
end
|
10
10
|
|
11
11
|
Given /I use (?:a|the) fixture(?: named)? "([^"]*)"/ do |name|
|
12
|
-
copy File.join(
|
12
|
+
copy File.join(aruba.config.fixtures_path_prefix, name), name
|
13
13
|
cd name
|
14
14
|
end
|
15
15
|
|
16
16
|
Given /The default aruba timeout is (\d+) seconds/ do |seconds|
|
17
17
|
warn(%{\e[35m The /^The default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use the one with `the` and not `The` at the beginning.\e[0m})
|
18
|
-
|
18
|
+
aruba.config.exit_timeout = seconds.to_i
|
19
19
|
end
|
20
20
|
|
21
21
|
Given /^I'm using a clean gemset "([^"]*)"$/ do |gemset|
|
@@ -23,12 +23,12 @@ Given /^I'm using a clean gemset "([^"]*)"$/ do |gemset|
|
|
23
23
|
end
|
24
24
|
|
25
25
|
Given /^(?:a|the) directory(?: named)? "([^"]*)"$/ do |dir_name|
|
26
|
-
|
26
|
+
create_directory(dir_name)
|
27
27
|
end
|
28
28
|
|
29
29
|
Given /^(?:a|the) directory(?: named)? "([^"]*)" with mode "([^"]*)"$/ do |dir_name, dir_mode|
|
30
|
-
|
31
|
-
|
30
|
+
create_directory(dir_name)
|
31
|
+
chmod(dir_mode, dir_name)
|
32
32
|
end
|
33
33
|
|
34
34
|
Given /^(?:a|the) file(?: named)? "([^"]*)" with:$/ do |file_name, file_content|
|
@@ -37,7 +37,7 @@ end
|
|
37
37
|
|
38
38
|
Given /^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/ do |file_name, file_mode, file_content|
|
39
39
|
write_file(file_name, file_content)
|
40
|
-
|
40
|
+
chmod(file_mode, file_name)
|
41
41
|
end
|
42
42
|
|
43
43
|
Given /^(?:a|the) (\d+) byte file(?: named)? "([^"]*)"$/ do |file_size, file_name|
|
@@ -50,15 +50,15 @@ end
|
|
50
50
|
|
51
51
|
Given /^(?:an|the) empty file(?: named)? "([^"]*)" with mode "([^"]*)"$/ do |file_name, file_mode|
|
52
52
|
write_file(file_name, "")
|
53
|
-
|
53
|
+
chmod(file_mode, file_name)
|
54
54
|
end
|
55
55
|
|
56
56
|
Given /^a mocked home directory$/ do
|
57
|
-
|
57
|
+
set_environment_variable 'HOME', expand_path('.')
|
58
58
|
end
|
59
59
|
|
60
60
|
Given /^(?:a|the) directory(?: named)? "([^"]*)" does not exist$/ do |directory_name|
|
61
|
-
remove_directory(directory_name, force
|
61
|
+
remove_directory(directory_name, :force => true)
|
62
62
|
end
|
63
63
|
|
64
64
|
When /^I write to "([^"]*)" with:$/ do |file_name, file_content|
|
@@ -82,7 +82,7 @@ When /^I remove (?:a|the) file(?: named)? "([^"]*)"$/ do |file_name|
|
|
82
82
|
end
|
83
83
|
|
84
84
|
Given /^(?:a|the) file(?: named)? "([^"]*)" does not exist$/ do |file_name|
|
85
|
-
remove_file(file_name, force
|
85
|
+
remove_file(file_name, :force => true)
|
86
86
|
end
|
87
87
|
|
88
88
|
When(/^I remove (?:a|the) directory(?: named)? "(.*?)"$/) do |directory_name|
|
@@ -98,37 +98,37 @@ Given /^I set the environment variables to:/ do |table|
|
|
98
98
|
variable = row['variable'].to_s.upcase
|
99
99
|
value = row['value'].to_s
|
100
100
|
|
101
|
-
|
101
|
+
set_environment_variable(variable, value)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
Given /^I append the value to the environment variable:/ do |table|
|
106
106
|
table.hashes.each do |row|
|
107
107
|
variable = row['variable'].to_s.upcase
|
108
|
-
value = row['value'].to_s
|
108
|
+
value = row['value'].to_s
|
109
109
|
|
110
|
-
|
110
|
+
append_environment_variable(variable, value)
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
114
|
When /^I run "(.*)"$/ do |cmd|
|
115
115
|
warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
|
116
|
-
run_simple(unescape(cmd), false)
|
116
|
+
run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), false)
|
117
117
|
end
|
118
118
|
|
119
119
|
When /^I run `([^`]*)`$/ do |cmd|
|
120
|
-
run_simple(unescape(cmd), false)
|
120
|
+
run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), false)
|
121
121
|
end
|
122
122
|
|
123
123
|
When /^I successfully run "(.*)"$/ do |cmd|
|
124
124
|
warn(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
|
125
|
-
run_simple(unescape(cmd))
|
125
|
+
run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi))
|
126
126
|
end
|
127
127
|
|
128
128
|
## I successfully run `echo -n "Hello"`
|
129
129
|
## I successfully run `sleep 29` for up to 30 seconds
|
130
130
|
When /^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/ do |cmd, secs|
|
131
|
-
run_simple(unescape(cmd), true, secs && secs.to_i)
|
131
|
+
run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), true, secs && secs.to_i)
|
132
132
|
end
|
133
133
|
|
134
134
|
When /^I run "([^"]*)" interactively$/ do |cmd|
|
@@ -137,7 +137,7 @@ When /^I run "([^"]*)" interactively$/ do |cmd|
|
|
137
137
|
end
|
138
138
|
|
139
139
|
When /^I run `([^`]*)` interactively$/ do |cmd|
|
140
|
-
@interactive = run(unescape(cmd))
|
140
|
+
@interactive = run(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi))
|
141
141
|
end
|
142
142
|
|
143
143
|
When /^I type "([^"]*)"$/ do |input|
|
@@ -318,68 +318,102 @@ Then /^the stderr from "([^"]*)" should not contain "([^"]*)"$/ do |cmd, unexpec
|
|
318
318
|
assert_no_partial_output(unexpected, stderr_from(cmd))
|
319
319
|
end
|
320
320
|
|
321
|
-
Then /^the following files should (not )?exist:$/ do |
|
322
|
-
files.
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
321
|
+
Then /^the following files should (not )?exist:$/ do |negated, files|
|
322
|
+
files = files.rows.flatten
|
323
|
+
|
324
|
+
if negated
|
325
|
+
expect(files).not_to include an_existing_file
|
326
|
+
else
|
327
|
+
expect(files).to all be_an_existing_file
|
328
328
|
end
|
329
329
|
end
|
330
330
|
|
331
331
|
Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?exist$/ do |file, expect_match|
|
332
332
|
if expect_match
|
333
|
-
expect(file).not_to
|
333
|
+
expect(file).not_to be_an_existing_file
|
334
334
|
else
|
335
|
-
expect(file).to
|
335
|
+
expect(file).to be_an_existing_file
|
336
336
|
end
|
337
337
|
end
|
338
338
|
|
339
339
|
Then /^(?:a|the) file matching %r<(.*?)> should (not )?exist$/ do |pattern, expect_match|
|
340
340
|
if expect_match
|
341
|
-
expect(all_paths).not_to
|
341
|
+
expect(all_paths).not_to include match Regexp.new(pattern)
|
342
342
|
else
|
343
|
-
expect(all_paths).to
|
343
|
+
expect(all_paths).to include match Regexp.new(pattern)
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
347
|
-
Then /^(?:a|the) (\d+) byte file(?: named)? "([^"]*)" should exist$/ do |
|
348
|
-
|
347
|
+
Then /^(?:a|the) (\d+) byte file(?: named)? "([^"]*)" should (not )?exist$/ do |size, file, negated|
|
348
|
+
if negated
|
349
|
+
expect(file).not_to have_file_size(size)
|
350
|
+
else
|
351
|
+
expect(file).to have_file_size(size)
|
352
|
+
end
|
349
353
|
end
|
350
354
|
|
351
|
-
Then /^the following directories should (not )?exist:$/ do |
|
352
|
-
|
353
|
-
end
|
355
|
+
Then /^the following directories should (not )?exist:$/ do |negated, directories|
|
356
|
+
directories = directories.rows.flatten
|
354
357
|
|
355
|
-
|
356
|
-
|
358
|
+
if negated
|
359
|
+
expect(directories).not_to include an_existing_directory
|
360
|
+
else
|
361
|
+
expect(directories).to all be_an_existing_directory
|
362
|
+
end
|
357
363
|
end
|
358
364
|
|
359
|
-
Then /^(?:a|the)
|
360
|
-
|
365
|
+
Then /^(?:a|the) directory(?: named)? "([^"]*)" should (not )?exist$/ do |directory, negated|
|
366
|
+
if negated
|
367
|
+
expect(directory).not_to be_an_existing_directory
|
368
|
+
else
|
369
|
+
expect(directory).to be_an_existing_directory
|
370
|
+
end
|
361
371
|
end
|
362
372
|
|
363
|
-
Then /^(?:a|the) file "([^"]*)" should (not )?contain
|
364
|
-
|
373
|
+
Then /^(?:a|the) file "([^"]*)" should (not )?contain "([^"]*)"$/ do |file, negated, content|
|
374
|
+
if negated
|
375
|
+
expect(file).not_to have_file_content Regexp.new(content)
|
376
|
+
else
|
377
|
+
expect(file).to have_file_content Regexp.new(content)
|
378
|
+
end
|
365
379
|
end
|
366
380
|
|
367
|
-
Then /^(?:a|the) file "([^"]*)" should (not )?contain
|
368
|
-
|
381
|
+
Then /^(?:a|the) file "([^"]*)" should (not )?contain:$/ do |file, negated, content|
|
382
|
+
if negated
|
383
|
+
expect(file).not_to have_file_content Regexp.new(content.chomp)
|
384
|
+
else
|
385
|
+
expect(file).to have_file_content Regexp.new(content.chomp)
|
386
|
+
end
|
369
387
|
end
|
370
388
|
|
371
|
-
Then /^(?:a|the) file "([^"]*)" should (not )?
|
372
|
-
|
389
|
+
Then /^(?:a|the) file "([^"]*)" should (not )?contain exactly:$/ do |file, negated, content|
|
390
|
+
if negated
|
391
|
+
expect(file).not_to have_file_content content
|
392
|
+
else
|
393
|
+
expect(file).to have_file_content content
|
394
|
+
end
|
373
395
|
end
|
374
396
|
|
375
|
-
Then /^(?:a|the) file "([^"]*)" should (not )?
|
376
|
-
|
397
|
+
Then /^(?:a|the) file "([^"]*)" should (not )?match \/([^\/]*)\/$/ do |file, negated, content|
|
398
|
+
if negated
|
399
|
+
expect(file).not_to have_file_content Regexp.new(content)
|
400
|
+
else
|
401
|
+
expect(file).to have_file_content Regexp.new(content)
|
402
|
+
end
|
377
403
|
end
|
378
404
|
|
379
|
-
Then /^the
|
380
|
-
|
405
|
+
Then /^(?:a|the) file "([^"]*)" should (not )?be equal to file "([^"]*)"/ do |file, negated, reference_file|
|
406
|
+
if negated
|
407
|
+
expect(file).not_to have_same_file_content_like(reference_file)
|
408
|
+
else
|
409
|
+
expect(file).to have_same_file_content_like(reference_file)
|
410
|
+
end
|
381
411
|
end
|
382
412
|
|
383
|
-
|
384
|
-
|
413
|
+
Then /^the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)"$/ do |file, negated, permissions|
|
414
|
+
if negated
|
415
|
+
expect(file).not_to have_permissions(permissions)
|
416
|
+
else
|
417
|
+
expect(file).to have_permissions(permissions)
|
418
|
+
end
|
385
419
|
end
|