aruba 1.0.0.pre.alpha.5 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +153 -28
  3. data/CONTRIBUTING.md +0 -9
  4. data/LICENSE +1 -1
  5. data/README.md +37 -30
  6. data/lib/aruba/api.rb +0 -1
  7. data/lib/aruba/api/bundler.rb +17 -2
  8. data/lib/aruba/api/commands.rb +15 -16
  9. data/lib/aruba/api/core.rb +64 -50
  10. data/lib/aruba/api/environment.rb +12 -4
  11. data/lib/aruba/api/filesystem.rb +32 -46
  12. data/lib/aruba/api/text.rb +15 -3
  13. data/lib/aruba/aruba_path.rb +23 -95
  14. data/lib/aruba/basic_configuration.rb +46 -65
  15. data/lib/aruba/basic_configuration/option.rb +2 -2
  16. data/lib/aruba/cli.rb +4 -1
  17. data/lib/aruba/config/jruby.rb +1 -1
  18. data/lib/aruba/config_wrapper.rb +17 -4
  19. data/lib/aruba/configuration.rb +29 -22
  20. data/lib/aruba/console.rb +0 -2
  21. data/lib/aruba/console/help.rb +8 -5
  22. data/lib/aruba/contracts/absolute_path.rb +3 -3
  23. data/lib/aruba/contracts/is_power_of_two.rb +2 -2
  24. data/lib/aruba/contracts/relative_path.rb +3 -3
  25. data/lib/aruba/cucumber/command.rb +93 -82
  26. data/lib/aruba/cucumber/file.rb +43 -23
  27. data/lib/aruba/cucumber/hooks.rb +4 -1
  28. data/lib/aruba/cucumber/testing_frameworks.rb +14 -12
  29. data/lib/aruba/event_bus.rb +4 -2
  30. data/lib/aruba/event_bus/name_resolver.rb +9 -8
  31. data/lib/aruba/events.rb +2 -1
  32. data/lib/aruba/hooks.rb +2 -4
  33. data/lib/aruba/in_config_wrapper.rb +8 -5
  34. data/lib/aruba/initializer.rb +9 -3
  35. data/lib/aruba/matchers/base/base_matcher.rb +2 -11
  36. data/lib/aruba/matchers/base/message_indenter.rb +1 -1
  37. data/lib/aruba/matchers/base/object_formatter.rb +0 -5
  38. data/lib/aruba/matchers/collection/include_an_object.rb +4 -4
  39. data/lib/aruba/matchers/command/be_successfully_executed.rb +3 -1
  40. data/lib/aruba/matchers/command/have_exit_status.rb +3 -1
  41. data/lib/aruba/matchers/command/have_finished_in_time.rb +3 -1
  42. data/lib/aruba/matchers/command/have_output.rb +3 -1
  43. data/lib/aruba/matchers/command/have_output_on_stderr.rb +3 -1
  44. data/lib/aruba/matchers/command/have_output_on_stdout.rb +3 -1
  45. data/lib/aruba/matchers/directory/have_sub_directory.rb +8 -3
  46. data/lib/aruba/matchers/file/have_file_size.rb +4 -2
  47. data/lib/aruba/matchers/path/have_permissions.rb +7 -4
  48. data/lib/aruba/platforms/announcer.rb +25 -11
  49. data/lib/aruba/platforms/aruba_file_creator.rb +3 -1
  50. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +7 -2
  51. data/lib/aruba/platforms/aruba_logger.rb +10 -9
  52. data/lib/aruba/platforms/command_monitor.rb +4 -6
  53. data/lib/aruba/platforms/determine_disk_usage.rb +55 -20
  54. data/lib/aruba/platforms/filesystem_status.rb +19 -13
  55. data/lib/aruba/platforms/simple_table.rb +2 -2
  56. data/lib/aruba/platforms/unix_environment_variables.rb +9 -4
  57. data/lib/aruba/platforms/unix_platform.rb +10 -10
  58. data/lib/aruba/platforms/unix_which.rb +1 -1
  59. data/lib/aruba/platforms/windows_command_string.rb +1 -1
  60. data/lib/aruba/platforms/windows_environment_variables.rb +2 -1
  61. data/lib/aruba/platforms/windows_platform.rb +3 -3
  62. data/lib/aruba/platforms/windows_which.rb +6 -2
  63. data/lib/aruba/processes/basic_process.rb +4 -6
  64. data/lib/aruba/processes/debug_process.rb +4 -2
  65. data/lib/aruba/processes/in_process.rb +5 -3
  66. data/lib/aruba/processes/spawn_process.rb +27 -16
  67. data/lib/aruba/rspec.rb +25 -15
  68. data/lib/aruba/runtime.rb +11 -4
  69. data/lib/aruba/setup.rb +23 -10
  70. data/lib/aruba/tasks/docker_helpers.rb +3 -1
  71. data/lib/aruba/version.rb +1 -1
  72. metadata +96 -109
  73. data/.cucumberproignore +0 -3
  74. data/.document +0 -5
  75. data/.github/ISSUE_TEMPLATE.md +0 -48
  76. data/.github/PULL_REQUEST_TEMPLATE.md +0 -41
  77. data/.gitignore +0 -38
  78. data/.rspec +0 -3
  79. data/.rubocop.yml +0 -31
  80. data/.rubocop_todo.yml +0 -258
  81. data/.simplecov +0 -34
  82. data/.travis.yml +0 -73
  83. data/.yardopts +0 -11
  84. data/Dockerfile +0 -67
  85. data/Gemfile +0 -15
  86. data/Rakefile +0 -92
  87. data/TODO.md +0 -13
  88. data/appveyor.yml +0 -30
  89. data/aruba.gemspec +0 -46
  90. data/bin/console +0 -7
  91. data/bin/test +0 -9
  92. data/config/.gitignore +0 -1
  93. data/cucumber.yml +0 -6
  94. data/docker-compose.yml +0 -26
  95. data/fixtures/cli-app/.gitignore +0 -9
  96. data/fixtures/cli-app/.rspec +0 -2
  97. data/fixtures/cli-app/README.md +0 -39
  98. data/fixtures/cli-app/Rakefile +0 -1
  99. data/fixtures/cli-app/bin/aruba-test-cli +0 -6
  100. data/fixtures/cli-app/cli-app.gemspec +0 -25
  101. data/fixtures/cli-app/features/support/aruba.rb +0 -1
  102. data/fixtures/cli-app/features/support/env.rb +0 -1
  103. data/fixtures/cli-app/lib/cli/app.rb +0 -9
  104. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +0 -15
  105. data/fixtures/cli-app/lib/cli/app/version.rb +0 -5
  106. data/fixtures/cli-app/script/console +0 -14
  107. data/fixtures/cli-app/spec/spec_helper.rb +0 -7
  108. data/fixtures/cli-app/spec/support/aruba.rb +0 -1
  109. data/fixtures/copy/file.txt +0 -1
  110. data/fixtures/empty-app/.gitignore +0 -9
  111. data/fixtures/empty-app/.rspec +0 -2
  112. data/fixtures/empty-app/README.md +0 -24
  113. data/fixtures/empty-app/Rakefile +0 -1
  114. data/fixtures/empty-app/cli-app.gemspec +0 -25
  115. data/fixtures/empty-app/lib/cli/app.rb +0 -7
  116. data/fixtures/empty-app/lib/cli/app/version.rb +0 -5
  117. data/fixtures/getting-started-app/.gitignore +0 -4
  118. data/fixtures/getting-started-app/Gemfile +0 -4
  119. data/fixtures/getting-started-app/README.md +0 -3
  120. data/fixtures/getting-started-app/features/support/env.rb +0 -1
  121. data/lib/aruba/extensions/string/strip.rb +0 -25
  122. data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
@@ -14,7 +14,14 @@ module Aruba
14
14
  # @param [#to_s] text
15
15
  # Input
16
16
  def unescape_text(text)
17
- text.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e").gsub('\033', "\e").gsub('\016', "\016").gsub('\017', "\017").gsub('\t', "\t")
17
+ text
18
+ .gsub('\n', "\n")
19
+ .gsub('\"', '"')
20
+ .gsub('\e', "\e")
21
+ .gsub('\033', "\e")
22
+ .gsub('\016', "\016")
23
+ .gsub('\017', "\017")
24
+ .gsub('\t', "\t")
18
25
  end
19
26
 
20
27
  # Remove ansi characters from text
@@ -22,7 +29,10 @@ module Aruba
22
29
  # @param [#to_s] text
23
30
  # Input
24
31
  def extract_text(text)
25
- text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '').gsub(/\\\[|\\\]/, '').gsub(/\007|\016|\017/, '')
32
+ text
33
+ .gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '')
34
+ .gsub(/\\\[|\\\]/, '')
35
+ .gsub(/\007|\016|\017/, '')
26
36
  end
27
37
 
28
38
  # Unescape special characters and remove ANSI characters
@@ -41,7 +51,9 @@ module Aruba
41
51
  # @param [#to_s] text
42
52
  # The text to parse
43
53
  def replace_variables(text)
44
- text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s) if text.include? '<pid-last-command-started>'
54
+ if text.include? '<pid-last-command-started>'
55
+ text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s)
56
+ end
45
57
 
46
58
  text
47
59
  end
@@ -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 < Delegator
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
- # Get path
21
- def __getobj__
22
- ::Pathname.new(::File.join(*@delegate_sd_obj))
13
+ def to_str
14
+ to_pathname.to_s
23
15
  end
24
16
 
25
- # Set path
26
- def __setobj__(obj)
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
- @delegate_sd_obj << p
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/dir.d'
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
- @delegate_sd_obj.pop
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,19 @@ module Aruba
89
52
  to_s[index]
90
53
  end
91
54
 
92
- # TODO: Aruba.config.physical_block_size could be allowed to be nil
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
- typical_fs_unit = 4096
133
- typical_dev_bsize = 512 # google dev_bsize for more info
134
-
135
- block_multiplier = typical_fs_unit / typical_dev_bsize
136
- fs_unit_size = dev_bsize * block_multiplier
137
- fs_units = (stat.size + fs_unit_size - 1) / fs_unit_size
138
- fs_units = 1 if fs_units.zero?
139
- fs_units * fs_unit_size
57
+ # Get path
58
+ def to_pathname
59
+ current_path = @obj.inject do |path, element|
60
+ if element.start_with?('~') ||
61
+ Aruba.platform.absolute_path?(element)
62
+ element
63
+ else
64
+ File.join(path, element)
65
+ end
66
+ end
67
+ ::Pathname.new(current_path)
140
68
  end
141
69
  end
142
70
  end
@@ -20,27 +20,18 @@ module Aruba
20
20
  # @param [Symbol] name
21
21
  # The name of the reader
22
22
  #
23
- # @param [Hash] opts
24
- # Options
25
- #
26
- # @option [Class, Module] contract
27
- # The contract for the option
23
+ # @option [Class, Module] type
24
+ # The type contract for the option
28
25
  #
29
26
  # @option [Object] default
30
27
  # The default value
31
- def option_reader(name, opts = {})
32
- contract = opts[:contract]
33
- default = opts[:default]
34
-
35
- fail ArgumentError, 'Either use block or default value' if block_given? && default
36
- fail ArgumentError, 'contract-options is required' if contract.nil?
28
+ def option_reader(name, type:, default: nil)
29
+ raise ArgumentError, 'Either use block or default value' if block_given? && default
37
30
 
38
- Contract contract
39
31
  add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
40
32
 
33
+ Contract None => type
41
34
  define_method(name) { find_option(name).value }
42
-
43
- self
44
35
  end
45
36
 
46
37
  # Define an option reader and writer
@@ -48,31 +39,23 @@ module Aruba
48
39
  # @param [Symbol] name
49
40
  # The name of the reader
50
41
  #
51
- # @param [Hash] opts
52
- # Options
53
- #
54
- # @option [Class, Module] contract
55
- # The contract for the option
42
+ # @option [Class, Module] type
43
+ # The type contract for the option
56
44
  #
57
45
  # @option [Object] default
58
46
  # The default value
59
47
  #
60
- def option_accessor(name, opts = {})
61
- contract = opts[:contract]
62
- default = opts[:default]
63
-
64
- fail ArgumentError, 'Either use block or default value' if block_given? && default
65
- # fail ArgumentError, 'Either use block or default value' if !block_given? && default.nil? && default.to_s.empty?
66
- fail ArgumentError, 'contract-options is required' if contract.nil?
48
+ def option_accessor(name, type:, default: nil)
49
+ raise ArgumentError, 'Either use block or default value' if block_given? && default
67
50
 
68
51
  # Add writer
69
52
  add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
70
53
 
71
- Contract contract
54
+ Contract type => type
72
55
  define_method("#{name}=") { |v| find_option(name).value = v }
73
56
 
74
57
  # Add reader
75
- option_reader name, contract: { None => contract.values.first }
58
+ option_reader name, type: type
76
59
  end
77
60
 
78
61
  private
@@ -91,8 +74,6 @@ module Aruba
91
74
  attr_accessor :local_options
92
75
  attr_writer :hooks
93
76
 
94
- # attr_reader :hooks
95
-
96
77
  public
97
78
 
98
79
  # Create configuration
@@ -121,68 +102,68 @@ module Aruba
121
102
  obj
122
103
  end
123
104
 
124
- # Define or run before-hook
105
+ # Define before-hook
125
106
  #
126
107
  # @param [Symbol, String] name
127
108
  # The name of the hook
128
109
  #
129
- # @param [Proc] context
130
- # The context a hook should run in. This is a runtime only option.
131
- #
132
- # @param [Array] args
133
- # Arguments for the run of hook. This is a runtime only option.
134
- #
135
110
  # @yield
136
111
  # The code block which should be run. This is a configure time only option
137
- def before(name, context = proc {}, *args, &block)
112
+ def before(name, &block)
138
113
  name = format('%s_%s', 'before_', name.to_s).to_sym
114
+ raise ArgumentError, 'A block is required' unless block
139
115
 
140
- if block_given?
141
- @hooks.append(name, block)
116
+ @hooks.append(name, block)
142
117
 
143
- self
144
- else
145
- @hooks.execute(name, context, *args)
146
- end
118
+ self
147
119
  end
148
120
 
149
- # Define or run after-hook
121
+ # Run before-hook
150
122
  #
151
123
  # @param [Symbol, String] name
152
124
  # The name of the hook
153
125
  #
154
126
  # @param [Proc] context
155
- # The context a hook should run in. This is a runtime only option.
127
+ # The context a hook should run in
156
128
  #
157
129
  # @param [Array] args
158
- # Arguments for the run of hook. This is a runtime only option.
130
+ # Arguments for the run of hook
131
+ def run_before_hook(name, context, *args)
132
+ name = format('%s_%s', 'before_', name.to_s).to_sym
133
+
134
+ @hooks.execute(name, context, *args)
135
+ end
136
+
137
+ # Define after-hook
138
+ #
139
+ # @param [Symbol, String] name
140
+ # The name of the hook
159
141
  #
160
142
  # @yield
161
143
  # The code block which should be run. This is a configure time only option
162
- def after(name, context = proc {}, *args, &block)
144
+ def after(name, &block)
163
145
  name = format('%s_%s', 'after_', name.to_s).to_sym
146
+ raise ArgumentError, 'A block is required' unless block
164
147
 
165
- if block_given?
166
- @hooks.append(name, block)
167
-
168
- self
169
- else
170
- @hooks.execute(name, context, *args)
171
- end
172
- end
173
-
174
- # Check if before-hook <name> is defined
175
- def before?(name)
176
- name = format('%s_%s', 'before_', name.to_s).to_sym
148
+ @hooks.append(name, block)
177
149
 
178
- @hooks.exist? name
150
+ self
179
151
  end
180
152
 
181
- # Check if after-hook <name> is defined
182
- def after?(name)
153
+ # Run after-hook
154
+ #
155
+ # @param [Symbol, String] name
156
+ # The name of the hook
157
+ #
158
+ # @param [Proc] context
159
+ # The context a hook should run in
160
+ #
161
+ # @param [Array] args
162
+ # Arguments for the run of hook
163
+ def run_after_hook(name, context, *args)
183
164
  name = format('%s_%s', 'after_', name.to_s).to_sym
184
165
 
185
- @hooks.exist? name
166
+ @hooks.execute(name, context, *args)
186
167
  end
187
168
 
188
169
  # Check if <name> is option
@@ -210,7 +191,7 @@ module Aruba
210
191
  end
211
192
 
212
193
  def find_option(name)
213
- fail NotImplementedError, %(Unknown option "#{name}") unless option? name
194
+ raise NotImplementedError, %(Unknown option "#{name}") unless option? name
214
195
 
215
196
  local_options[name]
216
197
  end
@@ -15,8 +15,8 @@ module Aruba
15
15
  name = opts[:name]
16
16
  value = opts[:value]
17
17
 
18
- fail ArgumentError, '"name" is required' unless opts.key? :name
19
- fail ArgumentError, '"value" is required' unless opts.key? :value
18
+ raise ArgumentError, '"name" is required' unless opts.key? :name
19
+ raise ArgumentError, '"value" is required' unless opts.key? :value
20
20
 
21
21
  @name = name
22
22
  @value = value
@@ -18,7 +18,10 @@ module Aruba
18
18
  end
19
19
 
20
20
  desc 'init', 'Initialize aruba'
21
- option :test_framework, default: 'cucumber', enum: %w(cucumber rspec minitest), desc: 'Choose which test framework to use'
21
+ option :test_framework,
22
+ default: 'cucumber',
23
+ enum: %w(cucumber rspec minitest),
24
+ desc: 'Choose which test framework to use'
22
25
  def init
23
26
  Aruba::Initializer.new.call(options[:test_framework])
24
27
  end
@@ -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'] =~ /solaris|sunos/i
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
@@ -30,11 +30,11 @@ 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
+ notify(name, args) if name.to_s.end_with?('=')
36
34
 
37
- config.send(name, *args, &block)
35
+ return config.send(name, *args, &block) if config.respond_to? name
36
+
37
+ super
38
38
  end
39
39
 
40
40
  # Pass on respond_to?-calls
@@ -56,5 +56,18 @@ module Aruba
56
56
  def respond_to?(m)
57
57
  config.respond_to? m
58
58
  end
59
+
60
+ private
61
+
62
+ def notify(name, args)
63
+ event_bus.notify(
64
+ Events::ChangedConfiguration.new(
65
+ changed: {
66
+ name: name.to_s.gsub(/=$/, ''),
67
+ value: args.first
68
+ }
69
+ )
70
+ )
71
+ end
59
72
  end
60
73
  end