aruba 0.11.0.pre → 0.11.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/History.md +21 -1
  4. data/aruba.gemspec +1 -0
  5. data/features/api/command/find_command.feature +83 -0
  6. data/features/api/command/last_command_started.feature +50 -0
  7. data/features/api/command/last_command_stopped.feature +89 -0
  8. data/features/api/command/run.feature +259 -0
  9. data/features/api/command/stop.feature +53 -1
  10. data/features/api/text/replace_variables.feature +1 -1
  11. data/features/getting_started/run_commands.feature +177 -0
  12. data/features/matchers/file/be_existing_executable.feature +87 -0
  13. data/features/{integration/rspec/getting_started.feature → rspec/integration.feature} +31 -0
  14. data/fixtures/getting-started-app/Gemfile +1 -1
  15. data/lib/aruba.rb +0 -19
  16. data/lib/aruba/api.rb +2 -0
  17. data/lib/aruba/api/command.rb +103 -44
  18. data/lib/aruba/api/core.rb +13 -8
  19. data/lib/aruba/api/deprecated.rb +26 -4
  20. data/lib/aruba/api/environment.rb +21 -13
  21. data/lib/aruba/api/filesystem.rb +13 -0
  22. data/lib/aruba/api/rvm.rb +5 -0
  23. data/lib/aruba/api/text.rb +7 -1
  24. data/lib/aruba/aruba_path.rb +6 -0
  25. data/lib/aruba/basic_configuration.rb +35 -3
  26. data/lib/aruba/basic_configuration/option.rb +7 -0
  27. data/lib/aruba/cli.rb +4 -0
  28. data/lib/aruba/command.rb +47 -1
  29. data/lib/aruba/config.rb +15 -2
  30. data/lib/aruba/config_wrapper.rb +49 -8
  31. data/lib/aruba/console.rb +4 -1
  32. data/lib/aruba/console/help.rb +2 -0
  33. data/lib/aruba/contracts/absolute_path.rb +7 -0
  34. data/lib/aruba/contracts/enum.rb +5 -0
  35. data/lib/aruba/contracts/is_power_of_two.rb +9 -2
  36. data/lib/aruba/contracts/relative_path.rb +7 -0
  37. data/lib/aruba/cucumber/command.rb +6 -9
  38. data/lib/aruba/cucumber/file.rb +1 -1
  39. data/lib/aruba/cucumber/hooks.rb +36 -29
  40. data/lib/aruba/errors.rb +16 -1
  41. data/lib/aruba/events.rb +39 -0
  42. data/lib/aruba/extensions/string/strip.rb +1 -0
  43. data/lib/aruba/file_size.rb +11 -0
  44. data/lib/aruba/hooks.rb +2 -0
  45. data/lib/aruba/in_config_wrapper.rb +24 -0
  46. data/lib/aruba/in_process.rb +2 -0
  47. data/lib/aruba/initializer.rb +37 -0
  48. data/lib/aruba/matchers/base/base_matcher.rb +2 -0
  49. data/lib/aruba/matchers/base/object_formatter.rb +4 -0
  50. data/lib/aruba/matchers/collection/all.rb +2 -0
  51. data/lib/aruba/matchers/collection/include_an_object.rb +2 -0
  52. data/lib/aruba/matchers/command/have_exit_status.rb +1 -1
  53. data/lib/aruba/matchers/command/have_finished_in_time.rb +1 -10
  54. data/lib/aruba/matchers/command/have_output.rb +1 -10
  55. data/lib/aruba/matchers/command/have_output_on_stderr.rb +1 -10
  56. data/lib/aruba/matchers/command/have_output_on_stdout.rb +1 -10
  57. data/lib/aruba/matchers/file/be_an_existing_executable.rb +37 -0
  58. data/lib/aruba/platform.rb +4 -0
  59. data/lib/aruba/platforms/announcer.rb +225 -0
  60. data/lib/aruba/platforms/aruba_file_creator.rb +4 -0
  61. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +4 -0
  62. data/lib/aruba/{aruba_logger.rb → platforms/aruba_logger.rb} +4 -0
  63. data/lib/aruba/platforms/command_monitor.rb +229 -0
  64. data/lib/aruba/platforms/determine_disk_usage.rb +5 -0
  65. data/lib/aruba/platforms/determine_file_size.rb +9 -0
  66. data/lib/aruba/platforms/disk_usage_calculator.rb +9 -0
  67. data/lib/aruba/platforms/local_environment.rb +12 -0
  68. data/lib/aruba/platforms/simple_table.rb +11 -0
  69. data/lib/aruba/platforms/unix_command_string.rb +3 -0
  70. data/lib/aruba/platforms/unix_environment_variables.rb +3 -0
  71. data/lib/aruba/platforms/unix_platform.rb +20 -2
  72. data/lib/aruba/platforms/unix_which.rb +6 -2
  73. data/lib/aruba/platforms/windows_command_string.rb +7 -0
  74. data/lib/aruba/platforms/windows_environment_variables.rb +2 -0
  75. data/lib/aruba/platforms/windows_platform.rb +3 -0
  76. data/lib/aruba/platforms/windows_which.rb +6 -2
  77. data/lib/aruba/processes/basic_process.rb +20 -5
  78. data/lib/aruba/processes/debug_process.rb +3 -1
  79. data/lib/aruba/processes/in_process.rb +18 -2
  80. data/lib/aruba/processes/spawn_process.rb +14 -13
  81. data/lib/aruba/rspec.rb +34 -23
  82. data/lib/aruba/runtime.rb +65 -6
  83. data/lib/aruba/setup.rb +87 -0
  84. data/lib/aruba/version.rb +1 -1
  85. data/spec/aruba/api_spec.rb +13 -36
  86. data/spec/aruba/{config_wrapper_spec.rb → in_config_wrapper_spec.rb} +1 -1
  87. data/spec/aruba/spawn_process_spec.rb +9 -14
  88. data/spec/support/configs/pry.rb +3 -0
  89. data/spec/support/shared_contexts/aruba.rb +1 -0
  90. metadata +40 -14
  91. data/features/getting_started/supported_programming_languages.feature +0 -89
  92. data/lib/aruba/announcer.rb +0 -219
  93. data/lib/aruba/matchers/rspec.rb +0 -0
  94. data/lib/aruba/process_monitor.rb +0 -201
  95. data/lib/aruba/processes/null_process.rb +0 -26
@@ -1,12 +1,13 @@
1
1
  require 'rspec/expectations'
2
- require 'aruba/announcer'
3
2
  require 'aruba/runtime'
4
3
  require 'aruba/errors'
4
+ require 'aruba/setup'
5
5
 
6
6
  require 'aruba/config/jruby'
7
- require 'aruba/aruba_logger'
8
7
 
8
+ # Aruba
9
9
  module Aruba
10
+ # Api
10
11
  module Api
11
12
  # Core methods of aruba
12
13
  #
@@ -25,9 +26,7 @@ module Aruba
25
26
  # artifacts of your tests. This does NOT clean up the current working
26
27
  # directory.
27
28
  def setup_aruba
28
- Aruba.platform.rm File.join(Aruba.config.root_directory, Aruba.config.working_directory), :force => true
29
- Aruba.platform.mkdir File.join(Aruba.config.root_directory, Aruba.config.working_directory)
30
- Aruba.platform.chdir Aruba.config.root_directory
29
+ Aruba::Setup.new(aruba).call
31
30
 
32
31
  self
33
32
  end
@@ -52,8 +51,11 @@ module Aruba
52
51
  begin
53
52
  fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory? expand_path(dir)
54
53
 
54
+ old_directory = expand_path('.')
55
55
  aruba.current_directory << dir
56
- announcer.announce :directory, expand_path(dir)
56
+ new_directory = expand_path('.')
57
+
58
+ aruba.event_bus.notify Events::ChangedWorkingDirectory.new(:old => old_directory, :new => new_directory)
57
59
 
58
60
  old_dir = Aruba.platform.getwd
59
61
 
@@ -74,8 +76,11 @@ module Aruba
74
76
 
75
77
  fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory? expand_path(dir)
76
78
 
79
+ old_directory = expand_path('.')
77
80
  aruba.current_directory << dir
78
- announcer.announce :directory, expand_path(dir)
81
+ new_directory = expand_path('.')
82
+
83
+ aruba.event_bus.notify Events::ChangedWorkingDirectory.new(:old => old_directory, :new => new_directory)
79
84
 
80
85
  self
81
86
  end
@@ -170,7 +175,7 @@ module Aruba
170
175
  # The variables to be used for block.
171
176
  #
172
177
  # @yield
173
- # The block of code which should be run with the modified environment variables
178
+ # The block of code which should be run with the changed environment variables
174
179
  def with_environment(env = {}, &block)
175
180
  old_aruba_env = aruba.environment.to_h
176
181
 
@@ -1,5 +1,10 @@
1
+ require 'aruba/platforms/announcer'
2
+
3
+ # Aruba
1
4
  module Aruba
5
+ # Api
2
6
  module Api
7
+ # Deprecated
3
8
  module Deprecated
4
9
  # @deprecated
5
10
  # The path to the directory which should contain all your test data
@@ -376,7 +381,7 @@ module Aruba
376
381
  # The variables to be used for block.
377
382
  #
378
383
  # @yield
379
- # The block of code which should be run with the modified environment variables
384
+ # The block of code which should be run with the changed environment variables
380
385
  def with_env(env = {}, &block)
381
386
  Aruba.platform.deprecated('The use of "#with_env" is deprecated. Use "#with_environment {}" instead. But be careful this uses a different implementation')
382
387
 
@@ -415,8 +420,9 @@ module Aruba
415
420
  def set_env(key, value)
416
421
  Aruba.platform.deprecated('The use of "#set_env" is deprecated. Please use "set_environment_variable" instead. But be careful, this method uses a different kind of implementation')
417
422
 
418
- announcer.announce(:environment, key, value)
423
+ aruba.announcer.announce(:environment, key, value)
419
424
  set_environment_variable key, value
425
+
420
426
  original_env[key] = ENV.delete(key) unless original_env.key? key
421
427
  ENV[key] = value
422
428
  end
@@ -879,9 +885,9 @@ module Aruba
879
885
  #
880
886
  # Access to announcer
881
887
  def announcer
882
- # Aruba.platform.deprecated('The use of "#announcer" is deprecated. Use "aruba.announcer" instead')
888
+ Aruba.platform.deprecated('The use of "#announcer" is deprecated. Use "aruba.announcer" instead')
883
889
 
884
- @announcer ||= Announcer.new(
890
+ @announcer ||= Platforms::Announcer.new(
885
891
  self,
886
892
  :stdout => defined?(@announce_stdout),
887
893
  :stderr => defined?(@announce_stderr),
@@ -892,6 +898,22 @@ module Aruba
892
898
 
893
899
  @announcer
894
900
  end
901
+
902
+ # @private
903
+ # @deprecated
904
+ def process_monitor
905
+ Aruba.platform.deprecated('The use of "#process_monitor" is deprecated.')
906
+
907
+ aruba.command_monitor
908
+ end
909
+
910
+ # @private
911
+ # @deprecated
912
+ def processes
913
+ Aruba.platform.deprecated('The use of "#process_monitor" is deprecated. Please use "#all_commands" instead.')
914
+
915
+ aruba.command_monitor.send(:processes)
916
+ end
895
917
  end
896
918
  end
897
919
  end
@@ -1,12 +1,14 @@
1
1
  require 'aruba/platform'
2
2
 
3
+ # Aruba
3
4
  module Aruba
5
+ # Api
4
6
  module Api
5
7
  # Environment methods of aruba
6
8
  module Environment
7
9
  # Set environment variable
8
10
  #
9
- # @param [String] key
11
+ # @param [String] name
10
12
  # The name of the environment variable as string, e.g. 'HOME'
11
13
  #
12
14
  # @param [String] value
@@ -15,17 +17,18 @@ module Aruba
15
17
  name = name.to_s
16
18
  value = value.to_s
17
19
 
18
- announcer.announce(:environment, name, value)
19
- announcer.announce(:modified_environment, name, value)
20
-
20
+ old_environment = aruba.environment.to_h
21
21
  aruba.environment[name] = value
22
+ new_environment = aruba.environment.to_h
23
+
24
+ aruba.event_bus.notify Events::AddedEnvironmentVariable.new(:old => old_environment, :new => new_environment, :changed => { :name => name, :value => value })
22
25
 
23
26
  self
24
27
  end
25
28
 
26
29
  # Append environment variable
27
30
  #
28
- # @param [String] key
31
+ # @param [String] name
29
32
  # The name of the environment variable as string, e.g. 'HOME'
30
33
  #
31
34
  # @param [String] value
@@ -34,16 +37,18 @@ module Aruba
34
37
  name = name.to_s
35
38
  value = value.to_s
36
39
 
40
+ old_environment = aruba.environment.to_h
37
41
  aruba.environment.append name, value
38
- announcer.announce(:environment, name, aruba.environment[name])
39
- announcer.announce(:modified_environment, name, aruba.environment[name])
42
+ new_environment = aruba.environment.to_h
43
+
44
+ aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(:old => old_environment, :new => new_environment, :changed => { :name => name, :value => value })
40
45
 
41
46
  self
42
47
  end
43
48
 
44
49
  # Prepend environment variable
45
50
  #
46
- # @param [String] key
51
+ # @param [String] name
47
52
  # The name of the environment variable as string, e.g. 'HOME'
48
53
  #
49
54
  # @param [String] value
@@ -52,9 +57,11 @@ module Aruba
52
57
  name = name.to_s
53
58
  value = value.to_s
54
59
 
60
+ old_environment = aruba.environment.to_h
55
61
  aruba.environment.prepend name, value
56
- announcer.announce(:environment, name, aruba.environment[name])
57
- announcer.announce(:modified_environment, name, aruba.environment[name])
62
+ new_environment = aruba.environment.to_h
63
+
64
+ aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(:old => old_environment, :new => new_environment, :changed => { :name => name, :value => value })
58
65
 
59
66
  self
60
67
  end
@@ -69,10 +76,11 @@ module Aruba
69
76
  def delete_environment_variable(name)
70
77
  name = name.to_s
71
78
 
72
- announcer.announce(:environment, name, '')
73
- announcer.announce(:modified_environment, name, '')
74
-
79
+ old_environment = aruba.environment.to_h
75
80
  aruba.environment.delete name
81
+ new_environment = aruba.environment.to_h
82
+
83
+ aruba.event_bus.notify Events::DeletedEnvironmentVariable.new(:old => old_environment, :new => new_environment, :changed => { :name => name, :value => '' })
76
84
 
77
85
  self
78
86
  end
@@ -8,8 +8,11 @@ Aruba.platform.require_matching_files('../matchers/file/*.rb', __FILE__)
8
8
  Aruba.platform.require_matching_files('../matchers/directory/*.rb', __FILE__)
9
9
  Aruba.platform.require_matching_files('../matchers/path/*.rb', __FILE__)
10
10
 
11
+ # Aruba
11
12
  module Aruba
13
+ # Api
12
14
  module Api
15
+ # Filesystem methods
13
16
  module Filesystem
14
17
  # Check if file or directory exist
15
18
  #
@@ -35,6 +38,16 @@ module Aruba
35
38
  Aruba.platform.directory? expand_path(file)
36
39
  end
37
40
 
41
+ # Check if file exist and is executable
42
+ #
43
+ # @param [String] file
44
+ # The file which should exist
45
+ def executable?(path)
46
+ path = expand_path(path)
47
+
48
+ Aruba.platform.file?(path) && Aruba.platform.executable?(path)
49
+ end
50
+
38
51
  # Check if path is absolute
39
52
  #
40
53
  # @return [TrueClass, FalseClass]
data/lib/aruba/api/rvm.rb CHANGED
@@ -1,8 +1,13 @@
1
1
  require 'aruba/api/environment'
2
2
  require 'aruba/api/command'
3
3
 
4
+ # Aruba
4
5
  module Aruba
6
+ # Api
5
7
  module Api
8
+ # RVM
9
+ #
10
+ # @deprecated
6
11
  module Rvm
7
12
  # Use a clean rvm gemset
8
13
  #
@@ -1,5 +1,8 @@
1
+ # Aruba
1
2
  module Aruba
3
+ # Api
2
4
  module Api
5
+ # Text manipulation
3
6
  module Text
4
7
  # Unescape text
5
8
  #
@@ -40,8 +43,11 @@ module Aruba
40
43
  # @experimental
41
44
  #
42
45
  # Replace variables in command string
46
+ #
47
+ # @param [#to_s] text
48
+ # The text to parse
43
49
  def replace_variables(text)
44
- text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s)
50
+ text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s) if text.include? '<pid-last-command-started>'
45
51
 
46
52
  text
47
53
  end
@@ -3,7 +3,11 @@ require 'delegate'
3
3
 
4
4
  require 'aruba/file_size'
5
5
 
6
+ # Aruba
6
7
  module Aruba
8
+ # Pathname for aruba files and directories
9
+ #
10
+ # @private
7
11
  class ArubaPath < Delegator
8
12
  def initialize(path)
9
13
  obj = [path.to_s].flatten
@@ -13,10 +17,12 @@ module Aruba
13
17
  @delegate_sd_obj = obj
14
18
  end
15
19
 
20
+ # Get path
16
21
  def __getobj__
17
22
  ::Pathname.new(::File.join(*@delegate_sd_obj))
18
23
  end
19
24
 
25
+ # Set path
20
26
  def __setobj__(obj)
21
27
  @delegate_sd_obj = [obj.to_s].flatten
22
28
  end
@@ -1,8 +1,12 @@
1
1
  require 'contracts'
2
2
  require 'aruba/basic_configuration/option'
3
+ require 'aruba/in_config_wrapper'
3
4
 
5
+ # Aruba
4
6
  module Aruba
5
- # Basic configuration for ProxyPacRb
7
+ # Basic configuration for Aruba
8
+ #
9
+ # @private
6
10
  class BasicConfiguration
7
11
  include Contracts
8
12
 
@@ -11,6 +15,19 @@ module Aruba
11
15
  @known_options ||= {}
12
16
  end
13
17
 
18
+ # Define an option reader
19
+ #
20
+ # @param [Symbol] name
21
+ # The name of the reader
22
+ #
23
+ # @param [Hash] opts
24
+ # Options
25
+ #
26
+ # @option [Class, Module] contract
27
+ # The contract for the option
28
+ #
29
+ # @option [Object] default
30
+ # The default value
14
31
  def option_reader(name, opts = {})
15
32
  contract = opts[:contract]
16
33
  default = opts[:default]
@@ -19,13 +36,27 @@ module Aruba
19
36
  fail ArgumentError, 'contract-options is required' if contract.nil?
20
37
 
21
38
  Contract contract
22
- add_option(name, block_given? ? yield(ConfigWrapper.new(known_options)) : default)
39
+ add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
23
40
 
24
41
  define_method(name) { find_option(name).value }
25
42
 
26
43
  self
27
44
  end
28
45
 
46
+ # Define an option reader and writer
47
+ #
48
+ # @param [Symbol] name
49
+ # The name of the reader
50
+ #
51
+ # @param [Hash] opts
52
+ # Options
53
+ #
54
+ # @option [Class, Module] contract
55
+ # The contract for the option
56
+ #
57
+ # @option [Object] default
58
+ # The default value
59
+ #
29
60
  # rubocop:disable Metrics/CyclomaticComplexity
30
61
  def option_accessor(name, opts = {})
31
62
  contract = opts[:contract]
@@ -36,7 +67,7 @@ module Aruba
36
67
  fail ArgumentError, 'contract-options is required' if contract.nil?
37
68
 
38
69
  # Add writer
39
- add_option(name, block_given? ? yield(ConfigWrapper.new(known_options)) : default)
70
+ add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
40
71
 
41
72
  Contract contract
42
73
  define_method("#{name}=") { |v| find_option(name).value = v }
@@ -66,6 +97,7 @@ module Aruba
66
97
 
67
98
  public
68
99
 
100
+ # Create configuration
69
101
  def initialize
70
102
  initialize_configuration
71
103
  end
@@ -1,10 +1,16 @@
1
+ # Aruba
1
2
  module Aruba
3
+ # Basic Configuration
4
+ #
2
5
  class BasicConfiguration
3
6
  # A configuration option
7
+ #
8
+ # @private
4
9
  class Option
5
10
  attr_accessor :name, :value
6
11
  attr_reader :default_value
7
12
 
13
+ # Create option
8
14
  def initialize(opts = {})
9
15
  name = opts[:name]
10
16
  value = opts[:value]
@@ -17,6 +23,7 @@ module Aruba
17
23
  @default_value = value
18
24
  end
19
25
 
26
+ # Compare option
20
27
  def ==(other)
21
28
  name == other.name && value == other.value
22
29
  end
data/lib/aruba/cli.rb CHANGED
@@ -2,7 +2,11 @@ require 'thor'
2
2
  require 'aruba/console'
3
3
  require 'aruba/initializer'
4
4
 
5
+ # Aruba
5
6
  module Aruba
7
+ # Command line Interface
8
+ #
9
+ # @private
6
10
  class Cli < Thor
7
11
  def self.exit_on_failure?
8
12
  true
data/lib/aruba/command.rb CHANGED
@@ -1,14 +1,32 @@
1
+ require 'delegate'
1
2
  require 'aruba/processes/spawn_process'
2
3
  require 'aruba/processes/in_process'
3
4
  require 'aruba/processes/debug_process'
4
5
 
6
+ # Aruba
5
7
  module Aruba
8
+ # Command
9
+ #
10
+ # This class is not meant for direct use - Command.new, though it's API is
11
+ # public. As it is just a wrapper class, have a look at `BasicProcess` and
12
+ # the like for the public API.
13
+ #
14
+ # @see BasicProcess
15
+ # @see SpawnProcess
16
+ #
17
+ # @private
6
18
  class Command < SimpleDelegator
19
+ private
20
+
21
+ attr_reader :event_bus
22
+
23
+ public
24
+
25
+ # rubocop:disable Metrics/MethodLength
7
26
  def initialize(command, opts = {})
8
27
  launchers = []
9
28
  launchers << Processes::DebugProcess
10
29
  launchers << Processes::InProcess
11
- launchers << Processes::NullProcess
12
30
  launchers << Processes::SpawnProcess
13
31
 
14
32
  launcher = launchers.find { |l| l.match? opts[:mode] }
@@ -23,8 +41,36 @@ module Aruba
23
41
  opts.fetch(:stop_signal),
24
42
  opts.fetch(:startup_wait_time)
25
43
  )
44
+
45
+ @event_bus = opts.fetch(:event_bus)
26
46
  rescue KeyError => e
27
47
  raise ArgumentError, e.message
28
48
  end
49
+ # rubocop:enable Metrics/MethodLength
50
+
51
+ # Stop command
52
+ def stop(*)
53
+ __getobj__.stop
54
+ event_bus.notify Events::CommandStopped.new(self)
55
+
56
+ self
57
+ end
58
+
59
+ # Terminate command
60
+ def terminate(*)
61
+ __getobj__.terminate
62
+ event_bus.notify Events::CommandStopped.new(self)
63
+
64
+ self
65
+ end
66
+
67
+ # Start command
68
+ def start
69
+ __getobj__.start
70
+ event_bus.notify Events::CommandStarted.new(self)
71
+
72
+ self
73
+ end
74
+ alias_method :run!, :start
29
75
  end
30
76
  end