aruba 1.0.0.pre.alpha.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/.rubocop_todo.yml +29 -25
- data/.simplecov +7 -5
- data/.travis.yml +23 -34
- data/CHANGELOG.md +94 -28
- data/CONTRIBUTING.md +0 -1
- data/Gemfile +3 -6
- data/LICENSE +1 -1
- data/README.md +37 -30
- data/Rakefile +2 -14
- data/appveyor.yml +1 -2
- data/aruba.gemspec +22 -14
- data/cucumber.yml +3 -3
- data/lib/aruba/api/commands.rb +3 -1
- data/lib/aruba/api/core.rb +27 -30
- data/lib/aruba/api/filesystem.rb +12 -29
- data/lib/aruba/aruba_path.rb +24 -95
- data/lib/aruba/config/jruby.rb +1 -1
- data/lib/aruba/config_wrapper.rb +1 -3
- data/lib/aruba/configuration.rb +6 -4
- data/lib/aruba/contracts/absolute_path.rb +2 -2
- data/lib/aruba/contracts/relative_path.rb +2 -2
- data/lib/aruba/event_bus/name_resolver.rb +2 -2
- data/lib/aruba/initializer.rb +5 -1
- data/lib/aruba/matchers/base/message_indenter.rb +1 -1
- data/lib/aruba/matchers/base/object_formatter.rb +0 -2
- data/lib/aruba/platforms/announcer.rb +5 -3
- data/lib/aruba/platforms/determine_disk_usage.rb +56 -19
- data/lib/aruba/platforms/unix_environment_variables.rb +7 -0
- data/lib/aruba/platforms/unix_platform.rb +9 -9
- data/lib/aruba/platforms/windows_command_string.rb +1 -1
- data/lib/aruba/platforms/windows_platform.rb +1 -1
- data/lib/aruba/processes/basic_process.rb +2 -4
- data/lib/aruba/processes/spawn_process.rb +11 -8
- data/lib/aruba/version.rb +1 -1
- metadata +38 -41
- data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
data/lib/aruba/aruba_path.rb
CHANGED
@@ -1,30 +1,21 @@
|
|
1
1
|
require 'pathname'
|
2
|
-
require 'delegate'
|
3
|
-
|
4
|
-
require 'aruba/file_size'
|
5
2
|
|
6
3
|
# Aruba
|
7
4
|
module Aruba
|
8
5
|
# Pathname for aruba files and directories
|
9
6
|
#
|
10
7
|
# @private
|
11
|
-
class ArubaPath
|
8
|
+
class ArubaPath
|
12
9
|
def initialize(path)
|
13
|
-
obj = [path.to_s].flatten
|
14
|
-
|
15
|
-
super obj
|
16
|
-
|
17
|
-
@delegate_sd_obj = obj
|
10
|
+
@obj = [path.to_s].flatten
|
18
11
|
end
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
::Pathname.new(::File.join(*@delegate_sd_obj))
|
13
|
+
def to_str
|
14
|
+
to_pathname.to_s
|
23
15
|
end
|
24
16
|
|
25
|
-
|
26
|
-
|
27
|
-
@delegate_sd_obj = [obj.to_s].flatten
|
17
|
+
def to_s
|
18
|
+
to_str
|
28
19
|
end
|
29
20
|
|
30
21
|
# Add directory/file to path
|
@@ -39,47 +30,19 @@ module Aruba
|
|
39
30
|
# puts path
|
40
31
|
# # => path/to/dir.d/subdir.d
|
41
32
|
def push(p)
|
42
|
-
@
|
33
|
+
@obj << p
|
43
34
|
end
|
44
35
|
alias << push
|
45
36
|
|
46
|
-
# Remove last component of path
|
37
|
+
# Remove last pushed component of path
|
47
38
|
#
|
48
39
|
# @example
|
49
|
-
# path = ArubaPath.new 'path/to
|
40
|
+
# path = ArubaPath.new 'path/to'
|
41
|
+
# path.push 'dir'
|
50
42
|
# path.pop
|
51
43
|
# puts path # => path/to
|
52
44
|
def pop
|
53
|
-
@
|
54
|
-
end
|
55
|
-
|
56
|
-
# How many parts has the file name
|
57
|
-
#
|
58
|
-
# @return [Integer]
|
59
|
-
# The count of file name parts
|
60
|
-
#
|
61
|
-
# @example
|
62
|
-
# path = ArubaPath.new('path/to/file.txt')
|
63
|
-
# path.depth # => 3
|
64
|
-
#
|
65
|
-
def depth
|
66
|
-
__getobj__.each_filename.to_a.size
|
67
|
-
end
|
68
|
-
|
69
|
-
# Path ends with string
|
70
|
-
#
|
71
|
-
# @param [String] string
|
72
|
-
# The string to check
|
73
|
-
def end_with?(string)
|
74
|
-
to_s.end_with? string
|
75
|
-
end
|
76
|
-
|
77
|
-
# Path starts with string
|
78
|
-
#
|
79
|
-
# @param [String] string
|
80
|
-
# The string to check
|
81
|
-
def start_with?(string)
|
82
|
-
to_s.start_with? string
|
45
|
+
@obj.pop
|
83
46
|
end
|
84
47
|
|
85
48
|
# Return string at index
|
@@ -89,54 +52,20 @@ module Aruba
|
|
89
52
|
to_s[index]
|
90
53
|
end
|
91
54
|
|
92
|
-
|
93
|
-
# (So the unit size can be autodetected)
|
94
|
-
|
95
|
-
# Report minimum disk space used
|
96
|
-
#
|
97
|
-
# This estimates the minimum bytes allocated by the path.
|
98
|
-
#
|
99
|
-
# E.g. a 1-byte text file on a typical EXT-3 filesystem takes up 4096 bytes
|
100
|
-
# (could be more if it was truncated or less for sparse files).
|
101
|
-
#
|
102
|
-
# Both `File::Stat` and the `stat()` system call will report 8 `blocks`
|
103
|
-
# (each "usually" represents 512 bytes). So 8 * 512 is exactly 4096 bytes.
|
104
|
-
#
|
105
|
-
# (The "magic" 512 bye implied makes the value of "blocks" so confusing).
|
106
|
-
#
|
107
|
-
# Currently Aruba allows you to set what's called the `physical_block_size`,
|
108
|
-
# which is a bit misleading - it's the "512" value. So if you somehow have a
|
109
|
-
# "filesystem unit size" of 8192 (instead of a typical 4KB), set the
|
110
|
-
# `physical_block_size` to 1024 (yes, divide by 8: 8192/8 = 1024).
|
111
|
-
#
|
112
|
-
# Ideally, Aruba should provide e.g. `Aruba.config.fs_allocation_unit`
|
113
|
-
# (with 4096 as the default), so you wouldn't have to "divide by 8".
|
114
|
-
#
|
115
|
-
# (typical_fs_unit / typical_dev_bsize = 4096 / 512 = 8)
|
116
|
-
#
|
117
|
-
#
|
118
|
-
# @return [Integer]
|
119
|
-
# Total bytes allocate
|
120
|
-
#
|
121
|
-
# TODO: this is recommended over the above "blocks"
|
122
|
-
def minimum_disk_space_used
|
123
|
-
# TODO: replace Aruba.config.physical_block_size
|
124
|
-
# with something like Aruba.config.fs_allocation_unit
|
125
|
-
dev_bsize = Aruba.config.physical_block_size
|
126
|
-
|
127
|
-
stat = File::Stat.new(to_s)
|
128
|
-
|
129
|
-
blocks = stat.blocks
|
130
|
-
return (blocks * dev_bsize) if blocks
|
55
|
+
private
|
131
56
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
57
|
+
# Get path
|
58
|
+
def to_pathname
|
59
|
+
current_path = @obj.inject do |path, element|
|
60
|
+
if element.start_with? '~'
|
61
|
+
element
|
62
|
+
elsif Aruba.platform.absolute_path? element
|
63
|
+
element
|
64
|
+
else
|
65
|
+
File.join(path, element)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
::Pathname.new(current_path)
|
140
69
|
end
|
141
70
|
end
|
142
71
|
end
|
data/lib/aruba/config/jruby.rb
CHANGED
@@ -17,7 +17,7 @@ Aruba.configure do |config|
|
|
17
17
|
|
18
18
|
env['JRUBY_OPTS'] = jruby_opts
|
19
19
|
|
20
|
-
if RbConfig::CONFIG['host_os']
|
20
|
+
if /solaris|sunos/i.match?(RbConfig::CONFIG['host_os'])
|
21
21
|
java_opts = env['JAVA_OPTS'] || ''
|
22
22
|
|
23
23
|
# force jRuby to use client JVM for faster startup times
|
data/lib/aruba/config_wrapper.rb
CHANGED
@@ -30,9 +30,7 @@ module Aruba
|
|
30
30
|
# If one method ends with "=", e.g. ":option1=", then notify the event
|
31
31
|
# queue, that the user changes the value of "option1"
|
32
32
|
def method_missing(name, *args, &block)
|
33
|
-
if name.to_s.end_with? '='
|
34
|
-
event_bus.notify Events::ChangedConfiguration.new(changed: { name: name.to_s.gsub(/=$/, ''), value: args.first })
|
35
|
-
end
|
33
|
+
event_bus.notify Events::ChangedConfiguration.new(changed: { name: name.to_s.gsub(/=$/, ''), value: args.first }) if name.to_s.end_with? '='
|
36
34
|
|
37
35
|
config.send(name, *args, &block)
|
38
36
|
end
|
data/lib/aruba/configuration.rb
CHANGED
@@ -45,12 +45,14 @@ module Aruba
|
|
45
45
|
option_accessor :main_class, contract: { Class => Maybe[Class] }, default: nil
|
46
46
|
|
47
47
|
option_accessor :home_directory,
|
48
|
-
contract: { Or[Aruba::Contracts::AbsolutePath, Aruba::Contracts::RelativePath] =>
|
49
|
-
|
50
|
-
|
48
|
+
contract: { Or[Aruba::Contracts::AbsolutePath, Aruba::Contracts::RelativePath] =>
|
49
|
+
Or[Aruba::Contracts::AbsolutePath, Aruba::Contracts::RelativePath] } do |config|
|
50
|
+
File.join(config.root_directory.value, config.working_directory.value)
|
51
|
+
end
|
51
52
|
|
52
53
|
option_accessor :log_level,
|
53
|
-
contract: { Aruba::Contracts::Enum[:fatal, :warn, :debug, :info, :error, :unknown, :silent] =>
|
54
|
+
contract: { Aruba::Contracts::Enum[:fatal, :warn, :debug, :info, :error, :unknown, :silent] =>
|
55
|
+
Aruba::Contracts::Enum[:fatal, :warn, :debug, :info, :error, :unknown, :silent] },
|
54
56
|
default: :info
|
55
57
|
|
56
58
|
# TODO: deprecate this value and replace with "filesystem allocation unit"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'aruba/
|
1
|
+
require 'aruba/platform'
|
2
2
|
|
3
3
|
# Aruba
|
4
4
|
module Aruba
|
@@ -11,7 +11,7 @@ module Aruba
|
|
11
11
|
# @param [Object] value
|
12
12
|
# The value to be checked
|
13
13
|
def self.valid?(value)
|
14
|
-
|
14
|
+
Aruba.platform.absolute_path? value
|
15
15
|
rescue
|
16
16
|
false
|
17
17
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'aruba/
|
1
|
+
require 'aruba/platform'
|
2
2
|
|
3
3
|
# Aruba
|
4
4
|
module Aruba
|
@@ -11,7 +11,7 @@ module Aruba
|
|
11
11
|
# @param [String] value
|
12
12
|
# The path to be checked
|
13
13
|
def self.valid?(value)
|
14
|
-
|
14
|
+
Aruba.platform.relative_path? value
|
15
15
|
rescue
|
16
16
|
false
|
17
17
|
end
|
@@ -148,9 +148,9 @@ module Aruba
|
|
148
148
|
def transform(event_id)
|
149
149
|
resolvers.find { |r| r.match? event_id }.new.transform(default_namespace, event_id)
|
150
150
|
rescue => e
|
151
|
-
# rubocop:disable
|
151
|
+
# rubocop:disable Layout/LineLength
|
152
152
|
raise EventNameResolveError, %(Transforming "#{event_id}" into an event class failed. Supported types are: #{@resolvers.map(&:supports).flatten.join(', ')}. #{e.message}.\n\n#{e.backtrace.join("\n")})
|
153
|
-
# rubocop:enable
|
153
|
+
# rubocop:enable Layout/LineLength
|
154
154
|
end
|
155
155
|
end
|
156
156
|
end
|
data/lib/aruba/initializer.rb
CHANGED
@@ -23,7 +23,11 @@ module Aruba
|
|
23
23
|
end
|
24
24
|
|
25
25
|
content = if File.exist? file
|
26
|
-
|
26
|
+
file_ends_with_carriage_return = File.open(file, 'r').readlines.last.match(/.*\n$/)
|
27
|
+
|
28
|
+
prefix = file_ends_with_carriage_return ? '' : "\n"
|
29
|
+
|
30
|
+
%(#{prefix}gem 'aruba', '~> #{Aruba::VERSION}')
|
27
31
|
else
|
28
32
|
%(source 'https://rubygems.org'\ngem 'aruba', '~> #{Aruba::VERSION}'\n)
|
29
33
|
end
|
@@ -12,7 +12,6 @@ module Aruba
|
|
12
12
|
prepare_for_inspection(object).inspect
|
13
13
|
end
|
14
14
|
|
15
|
-
# rubocop:disable MethodLength
|
16
15
|
# rubocop:disable Metrics/CyclomaticComplexity
|
17
16
|
|
18
17
|
# @private
|
@@ -48,7 +47,6 @@ module Aruba
|
|
48
47
|
InspectableItem.new(inspection)
|
49
48
|
end
|
50
49
|
# rubocop:enable Metrics/CyclomaticComplexity
|
51
|
-
# rubocop:enable MethodLength
|
52
50
|
|
53
51
|
# @private
|
54
52
|
def self.prepare_hash(input)
|
@@ -92,9 +92,11 @@ module Aruba
|
|
92
92
|
output_format :stop_signal, proc { |p, s| format('Command will be stopped with `kill -%s %s`', s, p) }
|
93
93
|
output_format :timeout, '# %s-timeout: %s seconds'
|
94
94
|
output_format :wait_time, '# %s: %s seconds'
|
95
|
-
output_format :command_filesystem_status,
|
96
|
-
|
97
|
-
|
95
|
+
output_format :command_filesystem_status,
|
96
|
+
proc { |status|
|
97
|
+
format("<<-COMMAND FILESYSTEM STATUS\n%s\nCOMMAND FILESYSTEM STATUS",
|
98
|
+
Aruba.platform.simple_table(status.to_h, sort: false))
|
99
|
+
}
|
98
100
|
end
|
99
101
|
|
100
102
|
def output_format(channel, string = '%s', &block)
|
@@ -1,33 +1,70 @@
|
|
1
|
-
require 'aruba/
|
1
|
+
require 'aruba/file_size'
|
2
2
|
|
3
|
-
# Aruba
|
4
3
|
module Aruba
|
5
|
-
# Platforms
|
6
4
|
module Platforms
|
7
5
|
# Determinate disk usage
|
8
6
|
#
|
9
7
|
# @private
|
10
8
|
class DetermineDiskUsage
|
11
|
-
def call(
|
12
|
-
|
13
|
-
|
14
|
-
deprecated_block_size = args.pop
|
15
|
-
paths = args
|
16
|
-
|
17
|
-
size = paths.flatten.map do |p|
|
18
|
-
# TODO: replace the `call` methods signature so that you can use just
|
19
|
-
# p.minimum_disk_space_used
|
20
|
-
#
|
21
|
-
# (Same result, since the values are multiplied, so
|
22
|
-
# deprecated_block_size is canceled out
|
23
|
-
DiskUsageCalculator.new.call(
|
24
|
-
(p.minimum_disk_space_used / deprecated_block_size),
|
25
|
-
deprecated_block_size
|
26
|
-
)
|
9
|
+
def call(paths)
|
10
|
+
size = paths.flatten.map do |path|
|
11
|
+
minimum_disk_space_used path
|
27
12
|
end.inject(0, &:+)
|
28
13
|
|
29
14
|
FileSize.new(size)
|
30
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# TODO: Aruba.config.physical_block_size could be allowed to be nil
|
20
|
+
# (So the unit size can be autodetected)
|
21
|
+
|
22
|
+
# Report minimum disk space used
|
23
|
+
#
|
24
|
+
# This estimates the minimum bytes allocated by the path.
|
25
|
+
#
|
26
|
+
# E.g. a 1-byte text file on a typical EXT-3 filesystem takes up 4096 bytes
|
27
|
+
# (could be more if it was truncated or less for sparse files).
|
28
|
+
#
|
29
|
+
# Both `File::Stat` and the `stat()` system call will report 8 `blocks`
|
30
|
+
# (each "usually" represents 512 bytes). So 8 * 512 is exactly 4096 bytes.
|
31
|
+
#
|
32
|
+
# (The "magic" 512 bye implied makes the value of "blocks" so confusing).
|
33
|
+
#
|
34
|
+
# Currently Aruba allows you to set what's called the `physical_block_size`,
|
35
|
+
# which is a bit misleading - it's the "512" value. So if you somehow have a
|
36
|
+
# "filesystem unit size" of 8192 (instead of a typical 4KB), set the
|
37
|
+
# `physical_block_size` to 1024 (yes, divide by 8: 8192/8 = 1024).
|
38
|
+
#
|
39
|
+
# Ideally, Aruba should provide e.g. `Aruba.config.fs_allocation_unit`
|
40
|
+
# (with 4096 as the default), so you wouldn't have to "divide by 8".
|
41
|
+
#
|
42
|
+
# (typical_fs_unit / typical_dev_bsize = 4096 / 512 = 8)
|
43
|
+
#
|
44
|
+
#
|
45
|
+
# @return [Integer]
|
46
|
+
# Total bytes allocate
|
47
|
+
#
|
48
|
+
# TODO: this is recommended over the above "blocks"
|
49
|
+
def minimum_disk_space_used(path)
|
50
|
+
# TODO: replace Aruba.config.physical_block_size
|
51
|
+
# with something like Aruba.config.fs_allocation_unit
|
52
|
+
dev_bsize = Aruba.config.physical_block_size
|
53
|
+
|
54
|
+
stat = File::Stat.new(path.to_s)
|
55
|
+
|
56
|
+
blocks = stat.blocks
|
57
|
+
return (blocks * dev_bsize) if blocks
|
58
|
+
|
59
|
+
typical_fs_unit = 4096
|
60
|
+
typical_dev_bsize = 512 # google dev_bsize for more info
|
61
|
+
|
62
|
+
block_multiplier = typical_fs_unit / typical_dev_bsize
|
63
|
+
fs_unit_size = dev_bsize * block_multiplier
|
64
|
+
fs_units = (stat.size + fs_unit_size - 1) / fs_unit_size
|
65
|
+
fs_units = 1 if fs_units.zero?
|
66
|
+
fs_units * fs_unit_size
|
67
|
+
end
|
31
68
|
end
|
32
69
|
end
|
33
70
|
end
|
@@ -62,8 +62,8 @@ module Aruba
|
|
62
62
|
DetermineFileSize.new.call(*args)
|
63
63
|
end
|
64
64
|
|
65
|
-
def determine_disk_usage(
|
66
|
-
DetermineDiskUsage.new.call(
|
65
|
+
def determine_disk_usage(paths)
|
66
|
+
DetermineDiskUsage.new.call(paths)
|
67
67
|
end
|
68
68
|
|
69
69
|
def create_file(*args)
|
@@ -83,7 +83,7 @@ module Aruba
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def detect_ruby(cmd)
|
86
|
-
if
|
86
|
+
if /^ruby\s/.match?(cmd)
|
87
87
|
cmd.gsub(/^ruby\s/, "#{current_ruby} ")
|
88
88
|
else
|
89
89
|
cmd
|
@@ -136,13 +136,13 @@ module Aruba
|
|
136
136
|
end
|
137
137
|
|
138
138
|
# Copy file/directory
|
139
|
-
def cp(
|
140
|
-
FileUtils.cp_r(
|
139
|
+
def cp(src, dest)
|
140
|
+
FileUtils.cp_r(src, dest)
|
141
141
|
end
|
142
142
|
|
143
143
|
# Move file/directory
|
144
|
-
def mv(
|
145
|
-
FileUtils.mv(
|
144
|
+
def mv(src, dest)
|
145
|
+
FileUtils.mv(src, dest)
|
146
146
|
end
|
147
147
|
|
148
148
|
# Change mode of file/directory
|
@@ -195,8 +195,8 @@ module Aruba
|
|
195
195
|
# * /bin/command.sh
|
196
196
|
# * command.sh
|
197
197
|
def relative_command?(path)
|
198
|
-
p =
|
199
|
-
p.relative? && p.
|
198
|
+
p = Pathname.new(path)
|
199
|
+
p.relative? && p.basename != p
|
200
200
|
end
|
201
201
|
|
202
202
|
# Check if command is relative
|