aruba 0.8.1 → 0.9.0.pre

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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.travis.yml +3 -1
  4. data/Gemfile +13 -10
  5. data/History.md +25 -7
  6. data/README.md +6 -1
  7. data/Rakefile +16 -3
  8. data/aruba.gemspec +10 -2
  9. data/bin/aruba +7 -0
  10. data/cucumber.yml +11 -2
  11. data/features/api/command/extract_text.feature +97 -0
  12. data/features/api/command/unescape_text.feature +119 -0
  13. data/features/api/core/expand_path.feature +16 -0
  14. data/features/api/{cd.feature → filesystem/cd.feature} +2 -1
  15. data/features/api/filesystem/create_directory.feature +57 -0
  16. data/features/api/filesystem/disk_usage.feature +151 -0
  17. data/features/api/filesystem/does_exist.feature +62 -0
  18. data/features/api/filesystem/is_absolute.feature +48 -0
  19. data/features/api/filesystem/is_directory.feature +53 -0
  20. data/features/api/filesystem/is_file.feature +54 -0
  21. data/features/api/filesystem/is_relative.feature +48 -0
  22. data/features/cli/console.feature +52 -0
  23. data/features/configuration/console_history_file.feature +38 -0
  24. data/features/configuration/exit_timeout.feature +2 -1
  25. data/features/configuration/fixtures_path_prefix.feature +0 -1
  26. data/features/configuration/home_directory.feature +0 -1
  27. data/features/configuration/io_timeout.feature +0 -1
  28. data/features/configuration/keep_ansi.feature +1 -2
  29. data/features/configuration/log_level.feature +38 -0
  30. data/features/configuration/physical_block_size.feature +53 -0
  31. data/features/configuration/remove_ansi_escape_sequences.feature +38 -0
  32. data/features/configuration/root_directory.feature +0 -1
  33. data/features/configuration/working_directory.feature +2 -1
  34. data/features/fixtures/cli-app/README.md +5 -0
  35. data/features/fixtures/cli-app/lib/cli/app.rb +1 -1
  36. data/features/fixtures/cli-app/spec/spec_helper.rb +1 -2
  37. data/features/fixtures/cli-app/spec/support/aruba.rb +1 -0
  38. data/features/fixtures/empty-app/lib/cli/app.rb +1 -1
  39. data/features/fixtures/empty-app/spec/spec_helper.rb +1 -1
  40. data/features/step_definitions/aruba_dev_steps.rb +12 -1
  41. data/features/support/env.rb +1 -1
  42. data/lib/aruba/announcer.rb +1 -14
  43. data/lib/aruba/api.rb +6 -6
  44. data/lib/aruba/api/command.rb +74 -12
  45. data/lib/aruba/api/core.rb +18 -11
  46. data/lib/aruba/api/deprecated.rb +60 -72
  47. data/lib/aruba/api/filesystem.rb +41 -16
  48. data/lib/aruba/aruba_logger.rb +77 -0
  49. data/lib/aruba/aruba_path.rb +33 -0
  50. data/lib/aruba/basic_configuration.rb +2 -2
  51. data/lib/aruba/cli.rb +11 -0
  52. data/lib/aruba/config.rb +13 -3
  53. data/lib/aruba/config/jruby.rb +5 -2
  54. data/lib/aruba/console.rb +66 -0
  55. data/lib/aruba/console/help.rb +33 -0
  56. data/lib/aruba/contracts/is_power_of_two.rb +15 -0
  57. data/lib/aruba/cucumber.rb +27 -10
  58. data/lib/aruba/cucumber/hooks.rb +15 -8
  59. data/lib/aruba/disk_usage_calculator.rb +7 -0
  60. data/lib/aruba/file_size.rb +52 -0
  61. data/lib/aruba/in_process.rb +1 -1
  62. data/lib/aruba/jruby.rb +1 -1
  63. data/lib/aruba/matchers/command.rb +1 -1
  64. data/lib/aruba/matchers/directory.rb +1 -1
  65. data/lib/aruba/matchers/environment.rb +1 -1
  66. data/lib/aruba/matchers/file.rb +1 -1
  67. data/lib/aruba/matchers/path.rb +1 -1
  68. data/lib/aruba/matchers/path/match_path_pattern.rb +1 -1
  69. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +1 -1
  70. data/lib/aruba/platform.rb +14 -242
  71. data/lib/aruba/{creators → platforms}/aruba_file_creator.rb +3 -3
  72. data/lib/aruba/{creators → platforms}/aruba_fixed_size_file_creator.rb +2 -2
  73. data/lib/aruba/platforms/simple_table.rb +36 -0
  74. data/lib/aruba/platforms/unix_command_string.rb +24 -0
  75. data/lib/aruba/platforms/unix_environment_variables.rb +130 -0
  76. data/lib/aruba/platforms/unix_platform.rb +226 -0
  77. data/lib/aruba/platforms/unix_which.rb +83 -0
  78. data/lib/aruba/platforms/windows_command_string.rb +23 -0
  79. data/lib/aruba/platforms/windows_environment_variables.rb +83 -0
  80. data/lib/aruba/platforms/windows_platform.rb +39 -0
  81. data/lib/aruba/platforms/windows_which.rb +104 -0
  82. data/lib/aruba/process_monitor.rb +3 -3
  83. data/lib/aruba/processes/basic_process.rb +23 -3
  84. data/lib/aruba/processes/debug_process.rb +2 -2
  85. data/lib/aruba/processes/in_process.rb +1 -1
  86. data/lib/aruba/processes/spawn_process.rb +10 -4
  87. data/lib/aruba/reporting.rb +1 -1
  88. data/lib/aruba/rspec.rb +8 -6
  89. data/lib/aruba/runtime.rb +8 -5
  90. data/lib/aruba/version.rb +1 -1
  91. data/spec/aruba/api_spec.rb +25 -23
  92. data/spec/aruba/aruba_path_spec.rb +37 -0
  93. data/spec/aruba/jruby_spec.rb +1 -1
  94. data/spec/aruba/matchers/file_spec.rb +2 -2
  95. data/spec/aruba/matchers/path_spec.rb +3 -3
  96. data/spec/aruba/platform/simple_table_spec.rb +23 -0
  97. data/spec/aruba/platform/windows_environment_variables_spec.rb +500 -0
  98. data/spec/aruba/spawn_process_spec.rb +3 -1
  99. metadata +90 -12
  100. data/lib/aruba/contracts/is_a.rb +0 -21
  101. data/lib/aruba/environment.rb +0 -121
@@ -15,11 +15,11 @@ module Aruba
15
15
  # @param [TrueClass, FalseClass] check_presence (false)
16
16
  # Check if file exist
17
17
  def write(path, content, check_presence = false)
18
- fail "Expected #{path} to be present" if check_presence && !Aruba::Platform.file?(path)
18
+ fail "Expected #{path} to be present" if check_presence && !Aruba.platform.file?(path)
19
19
 
20
- Aruba::Platform.mkdir(File.dirname(path))
20
+ Aruba.platform.mkdir(File.dirname(path))
21
21
 
22
- if RUBY_VERSION < '1.9'
22
+ if RUBY_VERSION < '1.9.3'
23
23
  File.open(path, 'w') { |f| f << content }
24
24
  else
25
25
  File.write(path, content)
@@ -19,9 +19,9 @@ module Aruba
19
19
  # @param [TrueClass, FalseClass] check_presence (false)
20
20
  # Check if file exist
21
21
  def write(path, size, check_presence)
22
- fail "Expected #{path} to be present" if check_presence && !Aruba::Platform.file?(path)
22
+ fail "Expected #{path} to be present" if check_presence && !Aruba.platform.file?(path)
23
23
 
24
- Aruba::Platform.mkdir(File.dirname(path))
24
+ Aruba.platform.mkdir(File.dirname(path))
25
25
 
26
26
  File.open(path, "wb"){ |f| f.seek(size - 1); f.write("\0") }
27
27
 
@@ -0,0 +1,36 @@
1
+ module Aruba
2
+ module Platforms
3
+ class SimpleTable
4
+ private
5
+
6
+ attr_reader :hash
7
+
8
+ public
9
+
10
+ def initialize(hash)
11
+ @hash = hash
12
+ end
13
+
14
+ def to_s
15
+ longest_key = hash.keys.map(&:to_s).max_by(&:length)
16
+ return [] if longest_key.nil?
17
+
18
+ name_size = longest_key.length
19
+
20
+ if RUBY_VERSION < '2'
21
+ rows = []
22
+
23
+ hash.each do |k,v|
24
+ rows << format("# %-#{name_size}s => %s", k, v)
25
+ end
26
+
27
+ rows.sort
28
+ else
29
+ hash.each_with_object([]) do |(k,v), a|
30
+ a << format("# %-#{name_size}s => %s", k, v)
31
+ end.sort
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,24 @@
1
+ require 'delegate'
2
+ require 'shellwords'
3
+
4
+ module Aruba
5
+ module Platforms
6
+ # This is a command which should be run
7
+ class UnixCommandString < SimpleDelegator
8
+ def initialize(cmd)
9
+ __setobj__ cmd
10
+ end
11
+
12
+ def to_a
13
+ Shellwords.split __getobj__
14
+ end
15
+
16
+ if RUBY_VERSION < '1.9'
17
+ def to_s
18
+ __getobj__.to_s
19
+ end
20
+ alias_method :inspect, :to_s
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,130 @@
1
+ module Aruba
2
+ module Platforms
3
+ class UnixEnvironmentVariables
4
+ # We need to use this, because `nil` is a valid value as default
5
+ UNDEFINED = Object.new
6
+
7
+ private
8
+
9
+ attr_reader :env
10
+
11
+ public
12
+
13
+ def initialize(env = ENV.to_hash)
14
+ @env = Marshal.load(Marshal.dump(env))
15
+ end
16
+
17
+ # Update environment with other en
18
+ #
19
+ # @param [#to_hash, #to_h] other_env
20
+ # Another environment object or hash
21
+ #
22
+ # @yield
23
+ # Pass block to env
24
+ def update(other_env, &block)
25
+ if RUBY_VERSION <= '1.9.3'
26
+ # rubocop:disable Style/EachWithObject
27
+ other_env = other_env.to_hash.inject({}) { |a, (k, v)| a[k] = v.to_s; a }
28
+ # rubocop:enable Style/EachWithObject
29
+ else
30
+ other_env = other_env.to_h.each_with_object({}) { |(k, v), a| a[k] = v.to_s }
31
+ end
32
+
33
+ env.update(other_env, &block)
34
+
35
+ self
36
+ end
37
+
38
+ # Fetch variable from environment
39
+ #
40
+ # @param [#to_s] name
41
+ # The name of the variable
42
+ #
43
+ # @param [Object] default
44
+ # The default value used, if the variable is not defined
45
+ def fetch(name, default = UNDEFINED)
46
+ if default == UNDEFINED
47
+ env.fetch name.to_s
48
+ else
49
+ env.fetch name.to_s, default
50
+ end
51
+ end
52
+
53
+ # Check if variable exist
54
+ #
55
+ # @param [#to_s] name
56
+ # The name of the variable
57
+ def key?(name)
58
+ env.key? name.to_s
59
+ end
60
+
61
+ # Get value of variable
62
+ #
63
+ # @param [#to_s] name
64
+ # The name of the variable
65
+ def [](name)
66
+ env[name.to_s]
67
+ end
68
+
69
+ # Set value of variable
70
+ #
71
+ # @param [#to_s] name
72
+ # The name of the variable
73
+ #
74
+ # @param [#to_s] value
75
+ # The value of the variable
76
+ def []=(name, value)
77
+ env[name.to_s] = value.to_s
78
+
79
+ self
80
+ end
81
+
82
+ # Append value to variable
83
+ #
84
+ # @param [#to_s] name
85
+ # The name of the variable
86
+ #
87
+ # @param [#to_s] value
88
+ # The value of the variable
89
+ def append(name, value)
90
+ name = name.to_s
91
+ env[name] = env[name].to_s + value.to_s
92
+
93
+ self
94
+ end
95
+
96
+ # Prepend value to variable
97
+ #
98
+ # @param [#to_s] name
99
+ # The name of the variable
100
+ #
101
+ # @param [#to_s] value
102
+ # The value of the variable
103
+ def prepend(name, value)
104
+ name = name.to_s
105
+ env[name] = value.to_s + env[name].to_s
106
+
107
+ self
108
+ end
109
+
110
+ # Convert to hash
111
+ #
112
+ # @return [Hash]
113
+ # A new hash from environment
114
+ def to_h
115
+ if RUBY_VERSION < '2.0'
116
+ Marshal.load(Marshal.dump(env.to_hash))
117
+ else
118
+ Marshal.load(Marshal.dump(env.to_h))
119
+ end
120
+ end
121
+
122
+ # Reset environment
123
+ def clear
124
+ env.clear
125
+
126
+ self
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,226 @@
1
+ require 'rbconfig'
2
+ require 'pathname'
3
+
4
+ require 'aruba/platforms/simple_table'
5
+ require 'aruba/platforms/unix_command_string'
6
+ require 'aruba/platforms/unix_which'
7
+
8
+ module Aruba
9
+ # This abstracts OS-specific things
10
+ module Platforms
11
+ # WARNING:
12
+ # All methods found here are not considered part of the public API of aruba.
13
+ #
14
+ # Those methods can be changed at any time in the feature or removed without
15
+ # any further notice.
16
+ #
17
+ # This includes all methods for the UNIX platform
18
+ class UnixPlatform
19
+ def self.match?
20
+ !FFI::Platform.windows?
21
+ end
22
+
23
+ def environment_variables
24
+ UnixEnvironmentVariables.new
25
+ end
26
+
27
+ def command_string
28
+ UnixCommandString
29
+ end
30
+
31
+ def detect_ruby(cmd)
32
+ if cmd =~ /^ruby\s/
33
+ cmd.gsub(/^ruby\s/, "#{current_ruby} ")
34
+ else
35
+ cmd
36
+ end
37
+ end
38
+
39
+ def deprecated(msg)
40
+ warn(format('%s. Called by %s', msg, caller[1]))
41
+ end
42
+
43
+ def current_ruby
44
+ ::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
45
+ end
46
+
47
+ # @deprecated
48
+ # Add newline at the end
49
+ def ensure_newline(str)
50
+ deprecated('The use of "#ensure_newline" is deprecated. It will be removed soon')
51
+
52
+ str.chomp << "\n"
53
+ end
54
+
55
+ def require_matching_files(pattern, base)
56
+ if RUBY_VERSION < '1.9.3'
57
+ ::Dir.glob(::File.expand_path(pattern, base)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
58
+ else
59
+ ::Dir.glob(::File.expand_path(pattern, base)).each { |f| require_relative f }
60
+ end
61
+ end
62
+
63
+ # Create directory and subdirectories
64
+ def mkdir(dir_name)
65
+ dir_name = ::File.expand_path(dir_name)
66
+
67
+ ::FileUtils.mkdir_p(dir_name) unless ::File.directory?(dir_name)
68
+ end
69
+
70
+ # Remove file, directory + sub-directories
71
+ def rm(paths, options = {})
72
+ paths = Array(paths).map { |p| ::File.expand_path(p) }
73
+
74
+ FileUtils.rm_r(paths, options)
75
+ end
76
+
77
+ # Get current working directory
78
+ def getwd
79
+ Dir.getwd
80
+ end
81
+
82
+ # Change to directory
83
+ def chdir(dir_name, &block)
84
+ dir_name = ::File.expand_path(dir_name.to_s)
85
+
86
+ begin
87
+ if RUBY_VERSION <= '1.9.3'
88
+ old_env = ENV.to_hash.dup
89
+ else
90
+ old_env = ENV.to_h.dup
91
+ end
92
+
93
+ ENV['OLDPWD'] = getwd
94
+ ENV['PWD'] = dir_name
95
+ ::Dir.chdir(dir_name, &block)
96
+ ensure
97
+ ENV.clear
98
+ ENV.update old_env
99
+ end
100
+ end
101
+
102
+ # Touch file, directory
103
+ def touch(args, options)
104
+ FileUtils.touch(args, options)
105
+ end
106
+
107
+ # Copy file/directory
108
+ def cp(args, options)
109
+ FileUtils.cp_r(args, options)
110
+ end
111
+
112
+ # Change mode of file/directory
113
+ def chmod(mode, args, options)
114
+ FileUtils.chmod_R(mode, args, options)
115
+ end
116
+
117
+ # Exists and is file
118
+ def file?(f)
119
+ File.file? f
120
+ end
121
+
122
+ # Exists and is directory
123
+ def directory?(f)
124
+ File.directory? f
125
+ end
126
+
127
+ # Path Exists
128
+ def exist?(f)
129
+ File.exist? f
130
+ end
131
+
132
+ # Path is executable
133
+ def executable_file?(f)
134
+ File.file?(f) && File.executable?(f)
135
+ end
136
+
137
+ # Expand path
138
+ def expand_path(path, base)
139
+ File.expand_path(path, base)
140
+ end
141
+
142
+ # Is absolute path
143
+ def absolute_path?(path)
144
+ Pathname.new(path).absolute?
145
+ end
146
+
147
+ # Is relative path
148
+ def relative_path?(path)
149
+ Pathname.new(path).relative?
150
+ end
151
+
152
+ # Check if command is relative
153
+ #
154
+ # @return [TrueClass, FalseClass]
155
+ # true
156
+ # * bin/command.sh
157
+ #
158
+ # false
159
+ # * /bin/command.sh
160
+ # * command.sh
161
+ def relative_command?(path)
162
+ p = Pathname.new(path)
163
+ p.relative? && p.basename != p
164
+ end
165
+
166
+ # Check if command is relative
167
+ #
168
+ # @return [TrueClass, FalseClass]
169
+ # true
170
+ # * command.sh
171
+ #
172
+ # false
173
+ # * /bin/command.sh
174
+ # * bin/command.sh
175
+ def command?(path)
176
+ p = Pathname.new(path)
177
+ p.relative? && p.basename == p
178
+ end
179
+
180
+ # Write to file
181
+ def write_file(path, content)
182
+ if RUBY_VERSION < '1.9.3'
183
+ File.open(path, 'wb') do |f|
184
+ f.print content
185
+ end
186
+ else
187
+ File.write(path, content)
188
+ end
189
+ end
190
+
191
+ # Unescape string
192
+ #
193
+ # @param [String] string
194
+ # The string which should be unescaped, e.g. the output of a command
195
+ #
196
+ # @return
197
+ # The string stripped from escape sequences
198
+ def unescape(string, keep_ansi = true)
199
+ deprecated('The use of "Aruba.platform.unescape" is deprecated. Please use "#unescape_text" and "#extract_text" instead')
200
+
201
+ string = string.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e")
202
+ string = string.gsub(/\e\[\d+(?>(;\d+)*)m/, '') unless keep_ansi
203
+ string
204
+ end
205
+
206
+ # Transform hash to a string table which can be output on stderr/stdout
207
+ def simple_table(hash)
208
+ SimpleTable.new(hash).to_s
209
+ end
210
+
211
+ # Resolve path for command using the PATH-environment variable
212
+ #
213
+ # Mostly taken from here: https://github.com/djberg96/ptools
214
+ #
215
+ # @param [#to_s] program
216
+ # The name of the program which should be resolved
217
+ #
218
+ # @param [String] path
219
+ # The PATH, a string concatenated with ":", e.g. /usr/bin/:/bin on a
220
+ # UNIX-system
221
+ def which(program, path = ENV['PATH'])
222
+ UnixWhich.new.call(program, path)
223
+ end
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,83 @@
1
+ require 'aruba/platform'
2
+
3
+ module Aruba
4
+ module Platforms
5
+ # Implement `which(command)` for UNIX/Linux
6
+ class UnixWhich
7
+ # Bail out because this should never be reached
8
+ class DefaultWhich
9
+ def self.match?(*)
10
+ true
11
+ end
12
+
13
+ def call(program, path)
14
+ fail %(Invalid input program "#{program}" and/or path "#{path}".)
15
+ end
16
+ end
17
+
18
+ # Find path for absolute or relative command
19
+ class AbsoluteOrRelativePathWhich
20
+ def self.match?(program)
21
+ Aruba.platform.absolute_path?(program) || Aruba.platform.relative_command?(program)
22
+ end
23
+
24
+ def call(program, path)
25
+ return File.expand_path(program) if Aruba.platform.executable_file?(program)
26
+
27
+ nil
28
+ end
29
+ end
30
+
31
+ # Find path for command
32
+ class ProgramWhich
33
+ def self.match?(program)
34
+ Aruba.platform.command?(program)
35
+ end
36
+
37
+ # rubocop:disable Metrics/CyclomaticComplexity
38
+ # rubocop:disable Metrics/MethodLength
39
+ def call(program, path)
40
+ # Iterate over each path glob the dir + program.
41
+ path.split(File::PATH_SEPARATOR).each do |dir|
42
+ dir = Aruba.platform.expand_path(dir, Dir.getwd)
43
+ next unless Aruba.platform.exist?(dir) # In case of bogus second argument
44
+
45
+ found = Dir[File.join(dir, program)].first
46
+ return found if found && Aruba.platform.executable_file?(found)
47
+ end
48
+
49
+ nil
50
+ end
51
+ # rubocop:enable Metrics/CyclomaticComplexity
52
+ # rubocop:enable Metrics/MethodLength
53
+ end
54
+
55
+ private
56
+
57
+ attr_reader :whiches
58
+
59
+ public
60
+
61
+ def initialize
62
+ @whiches = []
63
+ @whiches << AbsoluteOrRelativePathWhich
64
+ @whiches << ProgramWhich
65
+ @whiches << DefaultWhich
66
+ end
67
+
68
+ # Find fully quallified path for program
69
+ #
70
+ # @param [String] program
71
+ # Name of program
72
+ #
73
+ # @param [String] path
74
+ # ENV['PATH']
75
+ def call(program, path = ENV['PATH'])
76
+ raise ArgumentError, "ENV['PATH'] cannot be empty" if path.nil? || path.empty?
77
+ program = program.to_s
78
+
79
+ whiches.find { |w| w.match? program }.new.call(program, path)
80
+ end
81
+ end
82
+ end
83
+ end