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.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.nav +12 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +12 -0
  6. data/.simplecov +2 -0
  7. data/.travis.yml +5 -6
  8. data/Gemfile +53 -26
  9. data/History.md +17 -0
  10. data/LICENSE +1 -1
  11. data/README.md +45 -19
  12. data/Rakefile +12 -2
  13. data/TODO.md +3 -0
  14. data/aruba.gemspec +19 -8
  15. data/cucumber.yml +1 -1
  16. data/features/api/cd.feature +119 -0
  17. data/features/api/command/run.feature +37 -0
  18. data/features/api/command/which.feature +37 -0
  19. data/features/api/environment/append_environment_variable.feature +118 -0
  20. data/features/api/environment/prepend_environment_variable.feature +118 -0
  21. data/features/api/environment/set_environment_variable.feature +252 -0
  22. data/features/configuration/exit_timeout.feature +51 -0
  23. data/features/configuration/fixtures_directories.feature +31 -0
  24. data/features/configuration/fixtures_path_prefix.feature +24 -0
  25. data/features/configuration/io_timeout.feature +31 -0
  26. data/features/configuration/keep_ansi.feature +31 -0
  27. data/features/configuration/root_directory.feature +31 -0
  28. data/features/configuration/working_directory.feature +32 -0
  29. data/features/fixtures/cli-app/.gitignore +9 -0
  30. data/features/fixtures/cli-app/.rspec +2 -0
  31. data/features/fixtures/cli-app/README.md +34 -0
  32. data/features/fixtures/cli-app/Rakefile +1 -0
  33. data/features/fixtures/cli-app/bin/cli +6 -0
  34. data/features/fixtures/cli-app/cli-app.gemspec +26 -0
  35. data/features/fixtures/cli-app/features/support/env.rb +1 -0
  36. data/features/fixtures/cli-app/lib/cli/app.rb +13 -0
  37. data/features/fixtures/cli-app/lib/cli/app/version.rb +5 -0
  38. data/features/fixtures/cli-app/script/console +14 -0
  39. data/features/fixtures/cli-app/spec/cli/app_spec.rb +7 -0
  40. data/features/fixtures/cli-app/spec/spec_helper.rb +10 -0
  41. data/features/fixtures/copy/file.txt +1 -1
  42. data/features/hooks/after/command.feature +34 -0
  43. data/features/hooks/before/command.feature +61 -0
  44. data/features/matchers/directory/have_sub_directory.feature +110 -0
  45. data/features/matchers/file/be_existing_file.feature +82 -0
  46. data/features/matchers/file/have_file_content.feature +123 -0
  47. data/features/matchers/file/have_file_size.feature +107 -0
  48. data/features/matchers/path/be_an_absolute_path.feature +74 -0
  49. data/features/matchers/path/be_an_existing_path.feature +97 -0
  50. data/features/matchers/path/have_permissions.feature +118 -0
  51. data/features/matchers/timeouts.feature +48 -0
  52. data/features/step_definitions/aruba_dev_steps.rb +69 -1
  53. data/features/steps/commands/exit_statuses.feature +136 -0
  54. data/features/steps/commands/in_process.feature +129 -0
  55. data/features/steps/commands/run.feature +36 -0
  56. data/features/steps/environment/home_variable.feature +49 -0
  57. data/features/steps/environment/set_environment_variable.feature +34 -0
  58. data/features/support/aruba.rb +5 -0
  59. data/features/support/env.rb +8 -4
  60. data/lib/aruba.rb +20 -8
  61. data/lib/aruba/announcer.rb +1 -0
  62. data/lib/aruba/api.rb +18 -1179
  63. data/lib/aruba/api/command.rb +351 -0
  64. data/lib/aruba/api/core.rb +141 -0
  65. data/lib/aruba/api/deprecated.rb +549 -0
  66. data/lib/aruba/api/environment.rb +61 -0
  67. data/lib/aruba/api/filesystem.rb +305 -0
  68. data/lib/aruba/api/rvm.rb +39 -0
  69. data/lib/aruba/aruba_path.rb +75 -0
  70. data/lib/aruba/basic_configuration.rb +208 -0
  71. data/lib/aruba/basic_configuration/option.rb +25 -0
  72. data/lib/aruba/config.rb +43 -30
  73. data/lib/aruba/config/jruby.rb +14 -0
  74. data/lib/aruba/config_wrapper.rb +17 -0
  75. data/lib/aruba/contracts/relative_path.rb +13 -0
  76. data/lib/aruba/creators/aruba_file_creator.rb +32 -0
  77. data/lib/aruba/creators/aruba_fixed_size_file_creator.rb +32 -0
  78. data/lib/aruba/cucumber.rb +87 -53
  79. data/lib/aruba/cucumber/hooks.rb +65 -10
  80. data/lib/aruba/environment.rb +121 -0
  81. data/lib/aruba/errors.rb +3 -0
  82. data/lib/aruba/extensions/string/strip.rb +24 -0
  83. data/lib/aruba/hooks.rb +54 -0
  84. data/lib/aruba/jruby.rb +4 -9
  85. data/lib/aruba/matchers/command.rb +1 -79
  86. data/lib/aruba/matchers/command/be_successfully_executed.rb +30 -0
  87. data/lib/aruba/matchers/command/have_exit_status.rb +47 -0
  88. data/lib/aruba/matchers/command/have_finished_in_time.rb +42 -0
  89. data/lib/aruba/matchers/directory.rb +1 -59
  90. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +34 -0
  91. data/lib/aruba/matchers/directory/have_sub_directory.rb +49 -0
  92. data/lib/aruba/matchers/file.rb +1 -177
  93. data/lib/aruba/matchers/file/be_an_existing_file.rb +34 -0
  94. data/lib/aruba/matchers/file/have_file_content.rb +58 -0
  95. data/lib/aruba/matchers/file/have_file_size.rb +43 -0
  96. data/lib/aruba/matchers/file/have_same_file_content.rb +44 -0
  97. data/lib/aruba/matchers/path.rb +1 -99
  98. data/lib/aruba/matchers/path/a_path_matching_pattern.rb +21 -0
  99. data/lib/aruba/matchers/path/be_an_absolute_path.rb +32 -0
  100. data/lib/aruba/matchers/path/be_an_existing_path.rb +33 -0
  101. data/lib/aruba/matchers/path/have_permissions.rb +60 -0
  102. data/lib/aruba/matchers/path/match_path_pattern.rb +41 -0
  103. data/lib/aruba/matchers/rspec.rb +0 -0
  104. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +1 -1
  105. data/lib/aruba/platform.rb +230 -0
  106. data/lib/aruba/process_monitor.rb +23 -5
  107. data/lib/aruba/processes/basic_process.rb +35 -1
  108. data/lib/aruba/processes/debug_process.rb +26 -15
  109. data/lib/aruba/processes/in_process.rb +21 -9
  110. data/lib/aruba/processes/spawn_process.rb +29 -19
  111. data/lib/aruba/reporting.rb +2 -0
  112. data/lib/aruba/rspec.rb +61 -13
  113. data/lib/aruba/runtime.rb +33 -0
  114. data/script/bootstrap +4 -6
  115. data/spec/aruba/api/runtime_spec.rb +28 -0
  116. data/spec/aruba/api_spec.rb +129 -126
  117. data/spec/aruba/aruba_path_spec.rb +65 -0
  118. data/spec/aruba/basic_configuration_spec.rb +5 -0
  119. data/spec/aruba/config_wrapper_spec.rb +25 -0
  120. data/spec/aruba/configuration_spec.rb +5 -0
  121. data/spec/aruba/jruby_spec.rb +34 -18
  122. data/spec/aruba/matchers/directory_spec.rb +6 -7
  123. data/spec/aruba/matchers/file_spec.rb +16 -20
  124. data/spec/aruba/matchers/path_spec.rb +14 -11
  125. data/spec/aruba/rspec_spec.rb +15 -0
  126. data/spec/aruba/runtime_spec.rb +29 -0
  127. data/spec/aruba/spawn_process_spec.rb +2 -2
  128. data/spec/spec_helper.rb +10 -2
  129. data/spec/support/configs/rspec.rb +1 -1
  130. data/spec/support/matchers/option.rb +35 -0
  131. data/spec/support/shared_contexts/aruba.rb +10 -8
  132. data/spec/support/shared_examples/configuration.rb +116 -0
  133. metadata +182 -33
  134. data/.rvmrc +0 -1
  135. data/features/before_cmd_hooks.feature +0 -61
  136. data/features/command_environment_variables.feature +0 -31
  137. data/features/custom_ruby_process.feature +0 -12
  138. data/features/exit_statuses.feature +0 -30
  139. data/features/support/custom_main.rb +0 -28
  140. data/lib/aruba/matchers/mode.rb +0 -52
  141. data/lib/aruba/utils.rb +0 -21
@@ -0,0 +1,129 @@
1
+ @announce
2
+ Feature: Run commands in ruby process
3
+
4
+ Running a lot of scenarios where each scenario uses Aruba
5
+ to spawn a new ruby process can be time consuming.
6
+
7
+ Aruba lets you plug in your own process class that can
8
+ run a command in the same ruby process as Cucumber/Aruba.
9
+
10
+ Background:
11
+ Given I use a fixture named "cli-app"
12
+
13
+ Scenario: Run custom code
14
+ Given a file named "lib/cli/app/runner.rb" with:
15
+ """
16
+ module Cli
17
+ module App
18
+ class Runner
19
+ def initialize(argv, stdin, stdout, stderr, kernel)
20
+ @argv = argv
21
+ @stdin = stdin
22
+ @stdout = stdout
23
+ @stderr = stderr
24
+ @kernel = kernel
25
+ end
26
+
27
+ def execute!
28
+ @stdout.puts(@argv.map(&:reverse).join(' '))
29
+ end
30
+ end
31
+ end
32
+ end
33
+ """
34
+ And a file named "features/support/cli_app.rb" with:
35
+ """
36
+ require 'cli/app/runner'
37
+ """
38
+ And a file named "features/support/in_proccess.rb" with:
39
+ """
40
+ require 'aruba/cucumber'
41
+ require 'aruba/processes/in_process'
42
+
43
+ Before('@in-process') do
44
+ Aruba.process = Aruba::Processes::InProcess
45
+ Aruba.process.main_class = Cli::App::Runner
46
+ end
47
+
48
+ After('@in-process') do
49
+ Aruba.process = Aruba::Processes::SpawnProcess
50
+ end
51
+ """
52
+ And a file named "features/in_process.feature" with:
53
+ """
54
+ Feature: Exit status
55
+ @in-process
56
+ Scenario: Run command
57
+ When I run `reverse.rb Hello World`
58
+ Then the output should contain:
59
+ \"\"\"
60
+ olleH dlroW
61
+ \"\"\"
62
+ """
63
+ When I run `cucumber`
64
+ Then the features should all pass
65
+
66
+ Scenario: Mixing custom code and normal cli
67
+ Given an executable named "bin/cli" with:
68
+ """
69
+ #!/bin/bash
70
+ echo $*
71
+ """
72
+ And a file named "lib/cli/app/runner.rb" with:
73
+ """
74
+ module Cli
75
+ module App
76
+ class Runner
77
+ def initialize(argv, stdin, stdout, stderr, kernel)
78
+ @argv = argv
79
+ @stdin = stdin
80
+ @stdout = stdout
81
+ @stderr = stderr
82
+ @kernel = kernel
83
+ end
84
+
85
+ def execute!
86
+ @stdout.puts(@argv.map(&:reverse).join(' '))
87
+ end
88
+ end
89
+ end
90
+ end
91
+ """
92
+ And a file named "features/support/cli_app.rb" with:
93
+ """
94
+ require 'cli/app/runner'
95
+ """
96
+ And a file named "features/support/in_proccess.rb" with:
97
+ """
98
+ require 'aruba/cucumber'
99
+ require 'aruba/processes/in_process'
100
+
101
+ Before('@in-process') do
102
+ Aruba.process = Aruba::Processes::InProcess
103
+ Aruba.process.main_class = Cli::App::Runner
104
+ end
105
+
106
+ After('@in-process') do
107
+ Aruba.process = Aruba::Processes::SpawnProcess
108
+ end
109
+ """
110
+ And a file named "features/in_process.feature" with:
111
+ """
112
+ Feature: Exit status
113
+ @in-process
114
+ Scenario: Run command in process
115
+ When I run `reverse.rb Hello World`
116
+ Then the output should contain:
117
+ \"\"\"
118
+ olleH dlroW
119
+ \"\"\"
120
+
121
+ Scenario: Run command
122
+ When I run `cli Hello World`
123
+ Then the output should contain:
124
+ \"\"\"
125
+ Hello World
126
+ \"\"\"
127
+ """
128
+ When I run `cucumber`
129
+ Then the features should all pass
@@ -0,0 +1,36 @@
1
+ Feature: Run commands
2
+
3
+ There are several steps to run commands with `aruba`.
4
+
5
+ Background:
6
+ Given I use a fixture named "cli-app"
7
+
8
+ Scenario: Run command found in path
9
+ Given an executable named "bin/cli" with:
10
+ """
11
+ #!/bin/bash
12
+ exit 0
13
+ """
14
+ And a file named "features/run.feature" with:
15
+ """
16
+ Feature: Run it
17
+ Scenario: Run command
18
+ When I run `cli`
19
+ """
20
+ When I run `cucumber`
21
+ Then the features should all pass
22
+
23
+ Scenario: Relative command
24
+ Given an executable named "bin/cli" with:
25
+ """
26
+ #!/bin/bash
27
+ exit 0
28
+ """
29
+ And a file named "features/run.feature" with:
30
+ """
31
+ Feature: Run it
32
+ Scenario: Run command
33
+ When I run `bin/cli`
34
+ """
35
+ When I run `cucumber`
36
+ Then the features should all pass
@@ -0,0 +1,49 @@
1
+ Feature: Mock the HOME variable
2
+
3
+ If you develop commandline applications, you might want to give your users
4
+ the possibility to configure your program. Normally this is done via
5
+ `.your-app-rc` or via `.config/your-app` an systems which comply to the
6
+ freedesktop-specifications.
7
+
8
+ To prevent to litter the developers HOME-directory `aruba` comes with a step
9
+ which mocks the `HOME`-variable. It is set to the
10
+ `aruba`-`working-directory`.
11
+
12
+ Background:
13
+ Given I use the fixture "cli-app"
14
+ And an executable named "bin/cli" with:
15
+ """
16
+ #!/bin/bash
17
+
18
+ echo "HOME: $HOME"
19
+ """
20
+
21
+ Scenario: Mocked home directory by using a step
22
+ Given a file named "features/home_variable.feature" with:
23
+ """
24
+ Feature: Home Variable
25
+ Scenario: Run command
26
+ Given a mocked home directory
27
+ When I run `cli`
28
+ Then the output should contain:
29
+ \"\"\"
30
+ tmp/aruba
31
+ \"\"\"
32
+ """
33
+ When I run `cucumber`
34
+ Then the features should all pass
35
+
36
+ Scenario: Mocked home directory by using a tag
37
+ Given a file named "features/home_variable.feature" with:
38
+ """
39
+ Feature: Home Variable
40
+ @mocked-home-directory
41
+ Scenario: Run command
42
+ When I run `cli`
43
+ Then the output should contain:
44
+ \"\"\"
45
+ tmp/aruba
46
+ \"\"\"
47
+ """
48
+ When I run `cucumber`
49
+ Then the features should all pass
@@ -0,0 +1,34 @@
1
+ Feature: Set environment variable via "cucumber"-step
2
+
3
+ It is quite handy to modify the environment of a process. To make this
4
+ possible, `aruba` provides several steps. One of these is
5
+ `I set the environment variables to:`-step. Using this step sets the values of a
6
+ non-existing variables and overwrites an existing values. Each variable name
7
+ and each value is converted to a string. Otherwise `ruby` would complain
8
+ about an invalid argument.
9
+
10
+ Background:
11
+ Given I use the fixture "cli-app"
12
+
13
+ Scenario: Set environment variable by using a step
14
+ Given an executable named "bin/cli" with:
15
+ """
16
+ #!/bin/bash
17
+
18
+ echo $LONG_LONG_VARIABLE
19
+ """
20
+ And a file named "features/home_variable.feature" with:
21
+ """
22
+ Feature: Environment Variable
23
+ Scenario: Run command
24
+ Given I set the environment variables to:
25
+ | variable | value |
26
+ | LONG_LONG_VARIABLE | long_value |
27
+ When I run `cli`
28
+ Then the output should contain:
29
+ \"\"\"
30
+ long_value
31
+ \"\"\"
32
+ """
33
+ When I run `cucumber`
34
+ Then the features should all pass
@@ -0,0 +1,5 @@
1
+ require 'aruba/cucumber'
2
+
3
+ Aruba.configure do |config|
4
+ config.exit_timeout = 5
5
+ end
@@ -12,8 +12,7 @@ require 'aruba/cucumber'
12
12
  require 'rspec/expectations'
13
13
 
14
14
  Before do |scenario|
15
- command_name = case scenario
16
- when Cucumber::RunningTestCase::Scenario
15
+ command_name = if scenario.respond_to?(:feature) && scenario.respond_to?(:name)
17
16
  "#{scenario.feature.title} #{scenario.name}"
18
17
  else
19
18
  raise TypeError.new("Don't know how to extract command name from #{scenario.class}")
@@ -21,9 +20,14 @@ Before do |scenario|
21
20
 
22
21
  # Used in simplecov_setup so that each scenario has a different name and their coverage results are merged instead
23
22
  # of overwriting each other as 'Cucumber Features'
24
- set_env('SIMPLECOV_COMMAND_NAME', command_name)
23
+ ENV['SIMPLECOV_COMMAND_NAME'] = command_name.to_s
25
24
 
26
25
  simplecov_setup_pathname = Pathname.new(__FILE__).expand_path.parent.join('simplecov_setup')
26
+
27
27
  # set environment variable so child processes will merge their coverage data with parent process's coverage data.
28
- set_env('RUBYOPT', "-r#{simplecov_setup_pathname} #{ENV['RUBYOPT']}")
28
+ if RUBY_VERSION < '1.9'
29
+ ENV['RUBYOPT'] = "-r rubygems -r#{simplecov_setup_pathname} #{ENV['RUBYOPT']}"
30
+ else
31
+ ENV['RUBYOPT'] = "-r#{simplecov_setup_pathname} #{ENV['RUBYOPT']}"
32
+ end
29
33
  end
@@ -1,8 +1,20 @@
1
- require 'aruba/processes/spawn_process'
2
-
3
- module Aruba
4
- class << self
5
- attr_accessor :process
6
- end
7
- self.process = Aruba::Processes::SpawnProcess
8
- end
1
+ # require 'contracts'
2
+
3
+ # require 'fileutils'
4
+ # require 'rbconfig'
5
+ # require 'ostruct'
6
+ # require 'pathname'
7
+
8
+ # require 'aruba/hooks'
9
+ # require 'aruba/basic_configuration'
10
+ # require 'aruba/config_wrapper'
11
+ # require 'aruba/config'
12
+
13
+ # require 'aruba/announcer'
14
+ # require 'aruba/process_monitor'
15
+ # require 'aruba/runtime'
16
+
17
+ # require 'aruba/platform'
18
+ # require 'aruba/spawn_process'
19
+
20
+ require 'aruba/api'
@@ -77,6 +77,7 @@ module Aruba
77
77
  format_string :directory, '$ cd %s'
78
78
  format_string :command, '$ %s'
79
79
  format_string :environment, '$ export %s=%s"'
80
+ format_string :timeout, '# %s-timeout: %s seconds'
80
81
 
81
82
  # rubocop:disable Metrics/LineLength
82
83
  if @options[:stdout]
@@ -1,1171 +1,26 @@
1
- require 'fileutils'
2
- require 'rbconfig'
3
1
  require 'rspec/expectations'
4
- require 'aruba'
5
- require 'aruba/config'
6
- require 'aruba/errors'
7
- require 'aruba/process_monitor'
8
- require 'aruba/utils'
9
- require 'aruba/announcer'
10
- require 'ostruct'
11
- require 'pathname'
2
+ require 'shellwords'
12
3
 
13
- Dir.glob( File.join( File.expand_path( '../matchers' , __FILE__ ) , '*.rb' ) ).each { |rb| require rb }
4
+ require 'aruba/extensions/string/strip'
14
5
 
15
- module Aruba
16
- module Api
17
- include RSpec::Matchers
18
- include Aruba::Utils
19
-
20
- # Expand file name
21
- #
22
- # @param [String] file_name
23
- # Name of file
24
- #
25
- # @param [String] dir_string
26
- # Name of directory to use as starting point, otherwise current directory is used.
27
- #
28
- # @return [String]
29
- # The full path
30
- #
31
- # @example Single file name
32
- #
33
- # # => <path>/tmp/aruba/file
34
- # expand_path('file')
35
- #
36
- # @example Single Dot
37
- #
38
- # # => <path>/tmp/aruba
39
- # expand_path('.')
40
- #
41
- # @example using home directory
42
- #
43
- # # => <path>/home/<name>/file
44
- # expand_path('~/file')
45
- #
46
- # @example using fixtures directory
47
- #
48
- # # => <path>/test/fixtures/file
49
- # expand_path('%/file')
50
- #
51
- def expand_path(file_name, dir_string = nil)
52
- message = "Filename cannot be nil or empty. Please use `expand_path('.')` if you want the current directory to be expanded."
53
- # rubocop:disable Style/RaiseArgs
54
- fail ArgumentError, message if file_name.nil? || file_name.empty?
55
- # rubocop:enable Style/RaiseArgs
56
-
57
- if FIXTURES_PATH_PREFIX == file_name[0]
58
- File.join fixtures_directory, file_name[1..-1]
59
- else
60
- in_current_directory { File.expand_path file_name, dir_string }
61
- end
62
- end
63
-
64
- # @private
65
- # @deprecated
66
- def absolute_path(*args)
67
- warn('The use of "absolute_path" is deprecated. Use "expand_path" instead. But be aware that "expand_path" uses a different implementation.')
68
-
69
- in_current_directory { File.expand_path File.join(*args) }
70
- end
71
-
72
- # Execute block in current directory
73
- #
74
- # @yield
75
- # The block which should be run in current directory
76
- def in_current_directory(&block)
77
- _mkdir(current_directory)
78
- Dir.chdir(current_directory, &block)
79
- end
80
-
81
- # Check if file or directory exist
82
- #
83
- # @param [String] file_or_directory
84
- # The file/directory which should exist
85
- def exist?(file_or_directory)
86
- File.exist? expand_path(file_or_directory)
87
- end
88
-
89
- # Check if file exist and is file
90
- #
91
- # @param [String] file
92
- # The file/directory which should exist
93
- def file?(file)
94
- File.file? expand_path(file)
95
- end
96
-
97
- # Check if directory exist and is directory
98
- #
99
- # @param [String] file
100
- # The file/directory which should exist
101
- def directory?(file)
102
- File.directory? expand_path(file)
103
- end
104
-
105
- # Check if path is absolute
106
- #
107
- # @return [TrueClass, FalseClass]
108
- # Result of check
109
- def absolute?(path)
110
- Pathname.new(path).absolute?
111
- end
112
-
113
- # Check if path is relative
114
- #
115
- # @return [TrueClass, FalseClass]
116
- # Result of check
117
- def relative?(path)
118
- Pathname.new(path).relative?
119
- end
120
-
121
- # Return all existing paths (directories, files) in current dir
122
- #
123
- # @return [Array]
124
- # List of files and directories
125
- def all_paths
126
- list('.').map { |p| expand_path(p) }
127
- end
128
-
129
- # Return all existing files in current directory
130
- #
131
- # @return [Array]
132
- # List of files
133
- def all_files
134
- list('.').select { |p| file? p }.map { |p| expand_path(p) }
135
- end
136
-
137
- # Return all existing directories in current directory
138
- #
139
- # @return [Array]
140
- # List of files
141
- def all_directories
142
- list('.').select { |p| directory? p }.map { |p| expand_path(p) }
143
- end
144
-
145
- # Create directory object
146
- #
147
- # @return [Dir]
148
- # The directory object
149
- def directory(path)
150
- fail ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
151
-
152
- Dir.new(expand_path(path))
153
- end
154
-
155
- # @deprecated
156
- # @private
157
- def in_current_dir(*args, &block)
158
- warn('The use of "in_current_dir" is deprecated. Use "in_current_directory" instead')
159
- in_current_directory(*args, &block)
160
- end
161
-
162
- # Clean the current directory
163
- def clean_current_directory
164
- _rm_rf(current_directory)
165
- _mkdir(current_directory)
166
- end
167
-
168
- # @deprecated
169
- # @private
170
- def clean_current_dir(*args, &block)
171
- warn('The use of "clean_current_dir" is deprecated. Use "clean_current_directory" instead')
172
- clean_current_directory(*args, &block)
173
- end
174
-
175
- # Return content of directory
176
- #
177
- # @return [Array]
178
- # The content of directory
179
- def list(name)
180
- fail ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
181
- fail ArgumentError, %(Only directories are supported. Path "#{name}" is not a directory.) unless directory? name
182
-
183
- existing_files = Dir.glob(expand_path(File.join(name, '**', '*')))
184
- current_working_directory = Pathname.new(expand_path('.'))
185
-
186
- existing_files.map { |d| Pathname.new(d).relative_path_from(current_working_directory).to_s }
187
- end
188
-
189
- # Return content of file
190
- #
191
- # @return [Array]
192
- # The content of file
193
- def read(name)
194
- fail ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
195
- fail ArgumentError, %(Only files are supported. Path "#{name}" is not a file.) unless file? name
196
-
197
- File.readlines(expand_path(name))
198
- end
199
-
200
- # Get access to current dir
201
- #
202
- # @return
203
- # Current directory
204
- def current_directory
205
- File.join(*dirs)
206
- end
207
-
208
- # @deprecated
209
- # @private
210
- def current_dir(*args, &block)
211
- warn('The use of "current_dir" is deprecated. Use "current_directory" instead')
212
- current_directory(*args, &block)
213
- end
214
-
215
- # Switch to directory
216
- #
217
- # @param [String] dir
218
- # The directory
219
- def cd(dir)
220
- dirs << dir
221
- raise "#{current_directory} is not a directory." unless File.directory?(current_directory)
222
- end
223
-
224
- # The path to the directory which should contain all your test data
225
- # You might want to overwrite this method to place your data else where.
226
- #
227
- # @return [Array]
228
- # The directory path: Each subdirectory is a member of an array
229
- def dirs
230
- @dirs ||= %w(tmp aruba)
231
- end
232
-
233
- # Create a file with given content
234
- #
235
- # The method does not check if file already exists. If the file name is a
236
- # path the method will create all neccessary directories.
237
- #
238
- # @param [String] file_name
239
- # The name of the file
240
- #
241
- # @param [String] file_content
242
- # The content which should be written to the file
243
- def write_file(file_name, file_content)
244
- _create_file(file_name, file_content, false)
245
- end
246
-
247
- # @private
248
- # @deprecated
249
- # Create an empty file
250
- #
251
- # @param [String] file_name
252
- # The name of the file
253
- def touch_file(*args)
254
- warn('The use of "touch_file" is deprecated. Use "touch" instead')
255
-
256
- touch(*args)
257
- end
258
-
259
- # Create an empty file
260
- #
261
- # @param [String] file_name
262
- # The name of the file
263
- def touch(*args)
264
- args = args.flatten
265
-
266
- options = if args.last.kind_of? Hash
267
- args.pop
268
- else
269
- {}
270
- end
271
-
272
- args = args.map { |p| expand_path(p) }
273
- args.each { |p| _mkdir(File.dirname(p)) }
274
-
275
- FileUtils.touch(args, options)
276
-
277
- self
278
- end
279
-
280
- # Copy a file and/or directory
281
- #
282
- # @param [String, Array] source
283
- # A single file or directory, multiple files or directories or multiple
284
- # files and directories. If multiple sources are given the destination
285
- # needs to be a directory
286
- #
287
- # @param [String] destination
288
- # A file or directory name. If multiple sources are given the destination
289
- # needs to be a directory
290
- #
291
- # rubocop:disable Metrics/CyclomaticComplexity
292
- # rubocop:disable Metrics/PerceivedComplexity
293
- def copy(*source, destination)
294
- source = source.flatten
295
-
296
- source.each do |s|
297
- raise ArgumentError, %(The following source "#{s}" does not exist.) unless exist? s
298
- end
299
-
300
- raise ArgumentError, "Using a fixture as destination (#{destination}) is not supported" if destination.start_with? FIXTURES_PATH_PREFIX
301
- raise ArgumentError, "Multiples sources can only be copied to a directory" if source.count > 1 && exist?(destination) && !directory?(destination)
302
-
303
- source_paths = source.map { |f| expand_path(f) }
304
- destination_path = expand_path(destination)
305
-
306
- if source_paths.count > 1
307
- _mkdir(destination_path)
308
- else
309
- _mkdir(File.dirname(destination_path))
310
- source_paths = source_paths.first
311
- end
312
-
313
- FileUtils.cp_r source_paths, destination_path
314
-
315
- self
316
- end
317
- # rubocop:enable Metrics/PerceivedComplexity
318
- # rubocop:enable Metrics/CyclomaticComplexity
319
-
320
- # Create a file with the given size
321
- #
322
- # The method does not check if file already exists. If the file name is a
323
- # path the method will create all neccessary directories.
324
- #
325
- # @param [String] file_name
326
- # The name of the file
327
- #
328
- # @param [Integer] file_size
329
- # The size of the file
330
- def write_fixed_size_file(file_name, file_size)
331
- _create_fixed_size_file(file_name, file_size, false)
332
- end
6
+ require 'aruba/platform'
7
+ require 'aruba/api/core'
8
+ require 'aruba/api/command'
9
+ require 'aruba/api/deprecated'
10
+ require 'aruba/api/environment'
11
+ require 'aruba/api/filesystem'
12
+ require 'aruba/api/rvm'
333
13
 
334
- # Create a file with given content
335
- #
336
- # The method does check if file already exists and fails if the file is
337
- # missing. If the file name is a path the method will create all neccessary
338
- # directories.
339
- def overwrite_file(file_name, file_content)
340
- _create_file(file_name, file_content, true)
341
- end
342
-
343
- # @private
344
- def _create_file(file_name, file_content, check_presence)
345
- file_name = expand_path(file_name)
346
-
347
- raise "expected #{file_name} to be present" if check_presence && !File.file?(file_name)
348
-
349
- _mkdir(File.dirname(file_name))
350
- File.open(file_name, 'w') { |f| f << file_content }
351
-
352
- self
353
- end
354
-
355
- # Change file system permissions of file
356
- #
357
- # @param [Octal] mode
358
- # File system mode, eg. 0755
359
- #
360
- # @param [String] file_name
361
- # Name of file to be modified. This file needs to be present to succeed
362
- def filesystem_permissions(*args)
363
- args = args.flatten
364
-
365
- options = if args.last.kind_of? Hash
366
- args.pop
367
- else
368
- {}
369
- end
370
-
371
- mode = args.shift
372
- mode = if mode.kind_of? String
373
- mode.to_i(8)
374
- else
375
- mode
376
- end
377
-
378
- args = args.map { |p| expand_path(p) }
379
- args.each { |p| raise "Expected #{p} to be present" unless FileTest.exists?(p) }
380
-
381
- FileUtils.chmod(mode, args, options)
382
-
383
- self
384
- end
385
-
386
- # @private
387
- # @deprecated
388
- def chmod(*args, &block)
389
- warn('The use of "chmod" is deprecated. Use "filesystem_permissions" instead')
390
-
391
- filesystem_permissions(*args, &block)
392
- end
393
-
394
- # Check file system permissions of file
395
- #
396
- # @param [Octal] expected_permissions
397
- # Expected file system permissions, e.g. 0755
398
- # @param [String] file_names
399
- # The file name(s)
400
- # @param [Boolean] expected_result
401
- # Are the permissions expected to be mode or are they expected not to be mode?
402
- def check_filesystem_permissions(*args)
403
- args = args.flatten
404
-
405
- expected_permissions = args.shift
406
- expected_result = args.pop
407
-
408
- args = args.map { |p| expand_path(p) }
409
-
410
- args.each do |p|
411
- raise "Expected #{p} to be present" unless FileTest.exists?(p)
412
-
413
- if expected_result
414
- expect(p).to have_permissions expected_permissions
415
- else
416
- expect(p).not_to have_permissions expected_permissions
417
- end
418
- end
419
- end
420
-
421
- # @private
422
- # @deprecated
423
- def mod?(*args, &block)
424
- warn('The use of "mod?" is deprecated. Use "check_filesystem_permissions" instead')
425
-
426
- check_filesystem_permissions(*args, &block)
427
- end
428
-
429
- # @private
430
- def _create_fixed_size_file(file_name, file_size, check_presence)
431
- file_name = expand_path(file_name)
432
-
433
- raise "expected #{file_name} to be present" if check_presence && !File.file?(file_name)
434
- _mkdir(File.dirname(file_name))
435
- File.open(file_name, "wb"){ |f| f.seek(file_size - 1); f.write("\0") }
436
- end
437
-
438
- # @private
439
- # @deprecated
440
- # Remove file
441
- #
442
- # @param [String] file_name
443
- # The file which should be deleted in current directory
444
- def remove_file(*args)
445
- warn('The use of "remove_file" is deprecated. Use "remove" instead')
446
-
447
- remove(*args)
448
- end
449
-
450
- # Append data to file
451
- #
452
- # @param [String] file_name
453
- # The name of the file to be used
454
- #
455
- # @param [String] file_content
456
- # The content which should be appended to file
457
- def append_to_file(file_name, file_content)
458
- file_name = expand_path(file_name)
459
-
460
- _mkdir(File.dirname(file_name))
461
- File.open(file_name, 'a') { |f| f << file_content }
462
- end
463
-
464
- # Create a directory in current directory
465
- #
466
- # @param [String] directory_name
467
- # The name of the directory which should be created
468
- def create_directory(directory_name)
469
- FileUtils.mkdir_p expand_path(directory_name)
470
-
471
- self
472
- end
473
-
474
- # @private
475
- # @deprecated
476
- def create_dir(*args)
477
- warn('The use of "create_dir" is deprecated. Use "create_directory" instead')
478
- create_directory(*args)
479
- end
480
-
481
- # Remove file or directory
482
- #
483
- # @param [Array, String] name
484
- # The name of the file / directory which should be removed
485
- def remove(*args)
486
- args = args.flatten
487
-
488
- options = if args.last.kind_of? Hash
489
- args.pop
490
- else
491
- {}
492
- end
493
-
494
- args = args.map { |p| expand_path(p) }
495
-
496
- FileUtils.rm_r(args, options)
497
- end
498
-
499
- # @private
500
- # @deprecated
501
- # Remove directory
502
- #
503
- # @param [String] directory_name
504
- # The name of the directory which should be removed
505
- def remove_directory(*args)
506
- warn('The use of "remove_directory" is deprecated. Use "remove" instead')
507
- remove(*args)
508
- end
509
-
510
- # @private
511
- # @deprecated
512
- def remove_dir(*args)
513
- warn('The use of "remove_dir" is deprecated. Use "remove" instead')
514
- remove(*args)
515
- end
516
-
517
- # @deprecated
518
- #
519
- # Check if paths are present
520
- #
521
- # @param [#each] paths
522
- # The paths which should be checked
523
- #
524
- # @param [true,false] expect_presence
525
- # Should the given paths be present (true) or absent (false)
526
- def check_file_presence(paths, expect_presence = true)
527
- warn('The use of "check_file_presence" is deprecated. Use "expect().to be_existing_file or expect(all_paths).to match_path_pattern() instead" ')
528
-
529
- stop_processes!
530
-
531
- Array(paths).each do |path|
532
- if path.kind_of? Regexp
533
- if expect_presence
534
- expect(all_paths).to match_path_pattern(path)
535
- else
536
- expect(all_paths).not_to match_path_pattern(path)
537
- end
538
- else
539
- if expect_presence
540
- expect(path).to be_existing_file
541
- else
542
- expect(path).not_to be_existing_file
543
- end
544
- end
545
- end
546
- end
547
-
548
- # Pipe data in file
549
- #
550
- # @param [String] file_name
551
- # The file which should be used to pipe in data
552
- def pipe_in_file(file_name)
553
- file_name = expand_path(file_name)
554
-
555
- File.open(file_name, 'r').each_line do |line|
556
- last_command.write(line)
557
- end
558
- end
559
-
560
- # Check the file size of paths
561
- #
562
- # @params [Hash] paths_and_sizes
563
- # A hash containing the path (key) and the expected size (value)
564
- #
565
- # @example
566
- #
567
- # paths_and_sizes = {
568
- # 'file' => 10
569
- # }
570
- #
571
- # check_file_size(paths_and_sizes)
572
- #
573
- def check_file_size(paths_and_sizes)
574
- stop_processes!
575
-
576
- paths_and_sizes.each do |path, size|
577
- path = expand_path(path)
578
-
579
- expect(File.size(path)).to eq size
580
- end
581
- end
582
-
583
- # Read content of file and yield the content to block
584
- #
585
- # @param [String) file
586
- # The name of file which should be read from
587
- #
588
- # @yield
589
- # Pass the content of the given file to this block
590
- def with_file_content(file, &block)
591
- stop_processes!
592
-
593
- file = expand_path(file)
594
- content = IO.read(file)
595
-
596
- yield(content)
597
- end
598
-
599
- # Check the content of file
600
- #
601
- # It supports partial content as well. And it is up to you to decided if
602
- # the content must be there or not.
603
- #
604
- # @param [String] file
605
- # The file to be checked
606
- #
607
- # @param [String, Regexp] content
608
- # The content which must/must not be in the file. If content is
609
- # a String exact match is done, if content is a Regexp then file
610
- # is matched using regular expression
611
- #
612
- # @param [true, false] expect_match
613
- # Must the content be in the file or not
614
- def check_file_content(file, content, expect_match = true)
615
- stop_processes!
616
-
617
- match_content =
618
- if(Regexp === content)
619
- match(content)
620
- else
621
- eq(content)
622
- end
623
-
624
- content = IO.read(expand_path(file))
625
-
626
- if expect_match
627
- expect(content).to match_content
628
- else
629
- expect(content).not_to match_content
630
- end
631
- end
632
-
633
- # @private
634
- # @deprecated
635
- def check_exact_file_content(file, exact_content, expect_match = true)
636
- warn('The use of "check_exact_file_content" is deprecated. Use "#check_file_content" with a string instead.')
637
-
638
- check_file_content(file, exact_content, expect_match)
639
- end
14
+ Aruba::Platform.require_matching_files('../matchers/**/*.rb', __FILE__)
640
15
 
641
- # Check if the content of file against the content of a reference file
642
- #
643
- # @param [String] file
644
- # The file to be checked
645
- #
646
- # @param [String] reference_file
647
- # The reference file
648
- #
649
- # @param [true, false] expect_match
650
- # Must the content be in the file or not
651
- def check_binary_file_content(file, reference_file, expect_match = true)
652
- if expect_match
653
- expect(file).to have_same_file_content_like reference_file
654
- else
655
- expect(file).not_to have_same_file_content_like reference_file
656
- end
657
- end
658
-
659
- # Check presence of a directory
660
- #
661
- # @param [Array] paths
662
- # The paths to be checked
663
- #
664
- # @param [true, false] expect_presence
665
- # Should the directory be there or should the directory not be there
666
- def check_directory_presence(paths, expect_presence)
667
- stop_processes!
668
-
669
- paths.each do |path|
670
- path = expand_path(path)
671
-
672
- if expect_presence
673
- expect(File).to be_directory(path)
674
- else
675
- expect(File).not_to be_directory(path)
676
- end
677
- end
678
- end
679
-
680
- # @private
681
- def prep_for_fs_check(&block)
682
- warn('The use of "prep_for_fs_check" is deprecated. It will be removed soon.')
683
-
684
- process_monitor.stop_processes!
685
- in_current_directory{ block.call }
686
- end
687
-
688
- # @private
689
- def _mkdir(dir_name)
690
- dir_name = File.expand_path(dir_name)
691
-
692
- FileUtils.mkdir_p(dir_name) unless File.directory?(dir_name)
693
- end
694
-
695
- # @private
696
- def _rm_rf(dir_name)
697
- dir_name = File.expand_path(dir_name)
698
-
699
- FileUtils.rm_rf(dir_name)
700
- end
701
-
702
- # Unescape string
703
- #
704
- # @param [String] string
705
- # The string which should be unescaped, e.g. the output of a command
706
- #
707
- # @return
708
- # The string stripped from escape sequences
709
- def unescape(string)
710
- string = string.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e")
711
- string = string.gsub(/\e\[\d+(?>(;\d+)*)m/, '') unless @aruba_keep_ansi
712
- string
713
- end
714
-
715
- # Fetch output (stdout, stderr) from command
716
- #
717
- # @param [String] cmd
718
- # The command
719
- def output_from(cmd)
720
- process_monitor.output_from(cmd)
721
- end
722
-
723
- # Fetch stdout from command
724
- #
725
- # @param [String] cmd
726
- # The command
727
- def stdout_from(cmd)
728
- process_monitor.stdout_from(cmd)
729
- end
730
-
731
- # Fetch stderr from command
732
- #
733
- # @param [String] cmd
734
- # The command
735
- def stderr_from(cmd)
736
- process_monitor.stderr_from(cmd)
737
- end
738
-
739
- # Get stdout of all processes
740
- #
741
- # @return [String]
742
- # The stdout of all process which have run before
743
- def all_stdout
744
- process_monitor.all_stdout
745
- end
746
-
747
- # Get stderr of all processes
748
- #
749
- # @return [String]
750
- # The stderr of all process which have run before
751
- def all_stderr
752
- process_monitor.all_stderr
753
- end
754
-
755
- # Get stderr and stdout of all processes
756
- #
757
- # @return [String]
758
- # The stderr and stdout of all process which have run before
759
- def all_output
760
- process_monitor.all_output
761
- end
762
-
763
- # Full compare arg1 and arg2
764
- #
765
- # @return [TrueClass, FalseClass]
766
- # If arg1 is exactly the same as arg2 return true, otherwise false
767
- def assert_exact_output(expected, actual)
768
- actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
769
- expect(unescape(actual)).to eq unescape(expected)
770
- end
771
-
772
- # Partial compare arg1 and arg2
773
- #
774
- # @return [TrueClass, FalseClass]
775
- # If arg2 contains arg1 return true, otherwise false
776
- def assert_partial_output(expected, actual)
777
- actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
778
- expect(unescape(actual)).to include(unescape(expected))
779
- end
780
-
781
- # Regex Compare arg1 and arg2
782
- #
783
- # @return [TrueClass, FalseClass]
784
- # If arg2 matches arg1 return true, otherwise false
785
- def assert_matching_output(expected, actual)
786
- actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
787
- expect(unescape(actual)).to match(/#{unescape(expected)}/m)
788
- end
789
-
790
- # Negative regex compare arg1 and arg2
791
- #
792
- # @return [TrueClass, FalseClass]
793
- # If arg2 does not match arg1 return true, otherwise false
794
- def assert_not_matching_output(expected, actual)
795
- actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
796
- expect(unescape(actual)).not_to match(/#{unescape(expected)}/m)
797
- end
798
-
799
- # Negative partial compare arg1 and arg2
800
- #
801
- # @return [TrueClass, FalseClass]
802
- # If arg2 does not match/include arg1 return true, otherwise false
803
- def assert_no_partial_output(unexpected, actual)
804
- actual.force_encoding(unexpected.encoding) if RUBY_VERSION >= "1.9"
805
- if Regexp === unexpected
806
- expect(unescape(actual)).not_to match unexpected
807
- else
808
- expect(unescape(actual)).not_to include(unexpected)
809
- end
810
- end
811
-
812
- # Partial compare output of interactive command and arg1
813
- #
814
- # @return [TrueClass, FalseClass]
815
- # If output of interactive command includes arg1 return true, otherwise false
816
- def assert_partial_output_interactive(expected)
817
- unescape(last_command.stdout).include?(unescape(expected)) ? true : false
818
- end
819
-
820
- # Check if command succeeded and if arg1 is included in output
821
- #
822
- # @return [TrueClass, FalseClass]
823
- # If exit status is 0 and arg1 is included in output return true, otherwise false
824
- def assert_passing_with(expected)
825
- assert_success(true)
826
- assert_partial_output(expected, all_output)
827
- end
828
-
829
- # Check if command failed and if arg1 is included in output
830
- #
831
- # @return [TrueClass, FalseClass]
832
- # If exit status is not equal 0 and arg1 is included in output return true, otherwise false
833
- def assert_failing_with(expected)
834
- assert_success(false)
835
- assert_partial_output(expected, all_output)
836
- end
837
-
838
- # @private
839
- # @deprecated
840
- def assert_exit_status_and_partial_output(expect_to_pass, expected)
841
- warn('The use of "assert_exit_status_and_partial_output" is deprecated. Use "#assert_access" and "#assert_partial_output" instead.')
842
-
843
- assert_success(expect_to_pass)
844
- assert_partial_output(expected, all_output)
845
- end
846
-
847
- # TODO: Remove this. Call more methods elsewhere instead. Reveals more intent.
848
- # @private
849
- # @deprecated
850
- def assert_exit_status_and_output(expect_to_pass, expected_output, expect_exact_output)
851
- assert_success(expect_to_pass)
852
- if expect_exact_output
853
- assert_exact_output(expected_output, all_output)
854
- else
855
- assert_partial_output(expected_output, all_output)
856
- end
857
- end
858
-
859
- # Check exit status of process
860
- #
861
- # @return [TrueClass, FalseClass]
862
- # If arg1 is true, return true if command was successful
863
- # If arg1 is false, return true if command failed
864
- def assert_success(success)
865
- if success
866
- expect(last_command).to be_successfully_executed
867
- else
868
- expect(last_command).not_to be_successfully_executed
869
- end
870
- end
871
-
872
- # @private
873
- def assert_exit_status(status)
874
- expect(last_command).to have_exit_status(status)
875
- end
876
-
877
- # @private
878
- def assert_not_exit_status(status)
879
- expect(last_exit_status).not_to eq(status),
880
- append_output_to("Exit status was #{last_exit_status} which was not expected.")
881
- end
882
-
883
- # @private
884
- def append_output_to(message)
885
- "#{message} Output:\n\n#{all_output}\n"
886
- end
887
-
888
- def process_monitor
889
- @process_monitor ||= ProcessMonitor.new(announcer)
890
- end
891
-
892
- # @private
893
- def processes
894
- process_monitor.send(:processes)
895
- end
896
-
897
- # @private
898
- def stop_processes!
899
- process_monitor.stop_processes!
900
- end
901
-
902
- # Terminate all running processes
903
- def terminate_processes!
904
- process_monitor.terminate_processes!
905
- end
906
-
907
- # @private
908
- def last_command
909
- processes.last[1]
910
- end
911
-
912
- # @private
913
- def register_process(*args)
914
- process_monitor.register_process(*args)
915
- end
916
-
917
- # @private
918
- def get_process(wanted)
919
- process_monitor.get_process(wanted)
920
- end
921
-
922
- # @private
923
- def only_processes
924
- process_monitor.only_processes
925
- end
926
-
927
- # Run given command and stop it if timeout is reached
928
- #
929
- # @param [String] cmd
930
- # The command which should be executed
931
- #
932
- # @param [Integer] timeout
933
- # If the timeout is reached the command will be killed
934
- #
935
- # @yield [SpawnProcess]
936
- # Run block with process
937
- def run(cmd, timeout = nil)
938
- timeout ||= exit_timeout
939
- @commands ||= []
940
- @commands << cmd
941
-
942
- cmd = detect_ruby(cmd)
943
-
944
- Aruba.config.hooks.execute(:before_cmd, self, cmd)
945
-
946
- announcer.announce(:directory, Dir.pwd)
947
- announcer.announce(:command, cmd)
948
-
949
- process = Aruba.process.new(cmd, timeout, io_wait, expand_path('.'))
950
- process_monitor.register_process(cmd, process)
951
- process.run!
952
-
953
- block_given? ? yield(process) : process
954
- end
955
-
956
- DEFAULT_TIMEOUT_SECONDS = 3
957
-
958
- # Default exit timeout for running commands with aruba
959
- #
960
- # Overwrite this method if you want a different timeout or set
961
- # `@aruba_timeout_seconds`.
962
- def exit_timeout
963
- @aruba_timeout_seconds || DEFAULT_TIMEOUT_SECONDS
964
- end
965
-
966
- DEFAULT_IO_WAIT_SECONDS = 0.1
967
-
968
- # Default io wait timeout
969
- #
970
- # Overwrite this method if you want a different timeout or set
971
- # `@aruba_io_wait_seconds
972
- def io_wait
973
- @aruba_io_wait_seconds || DEFAULT_IO_WAIT_SECONDS
974
- end
975
-
976
- DEFAULT_ROOT_DIRECTORY = Dir.getwd
977
-
978
- # The root directory of aruba
979
- def root_directory
980
- @aruba_root_directory || DEFAULT_ROOT_DIRECTORY
981
- end
982
-
983
- # Path prefix for fixtures
984
- FIXTURES_PATH_PREFIX = ?%
985
-
986
- DEFAULT_FIXTURES_DIRECTORIES = %w(
987
- features/fixtures
988
- spec/fixtures
989
- test/fixtures
990
- )
991
-
992
- # The path to the directory which contains fixtures
993
- # You might want to overwrite this method to place your data else where.
994
- #
995
- # @return [String]
996
- # The directory to where your fixtures are stored
997
- def fixtures_directory
998
- unless @fixtures_directory
999
- candidates = DEFAULT_FIXTURES_DIRECTORIES.map { |dir| File.join(root_directory, dir) }
1000
- @fixtures_directory = candidates.find { |dir| File.directory? dir }
1001
- raise "No fixtures directories are found" unless @fixtures_directory
1002
- end
1003
- raise "#{@fixtures_directory} is not a directory" unless File.directory?(@fixtures_directory)
1004
- @fixtures_directory
1005
- end
1006
-
1007
- # Run a command with aruba
1008
- #
1009
- # Checks for error during command execution and checks the output to detect
1010
- # an timeout error.
1011
- #
1012
- # @param [String] cmd
1013
- # The command to be executed
1014
- #
1015
- # @param [TrueClass,FalseClass] fail_on_error
1016
- # Should aruba fail on error?
1017
- #
1018
- # @param [Integer] timeout
1019
- # Timeout for execution
1020
- def run_simple(cmd, fail_on_error = true, timeout = nil)
1021
- command = run(cmd, timeout) do |process|
1022
- process_monitor.stop_process(process)
1023
-
1024
- process
1025
- end
1026
-
1027
- @timed_out = command.exit_status.nil?
1028
-
1029
- expect(command).to be_successfully_executed if fail_on_error
1030
- end
1031
-
1032
- # Run a command interactively
1033
- #
1034
- # @param [String] cmd
1035
- # The command to by run
1036
- #
1037
- # @see #cmd
1038
- # @deprectated
1039
- # @private
1040
- def run_interactive(cmd)
1041
- warn('The use of "run_interactive" is deprecated. You can simply use "run" instead.')
1042
-
1043
- run(cmd)
1044
- end
1045
-
1046
- # Provide data to command via stdin
1047
- #
1048
- # @param [String] input
1049
- # The input for the command
1050
- def type(input)
1051
- return close_input if "" == input
1052
- last_command.write(_ensure_newline(input))
1053
- end
1054
-
1055
- # Close stdin
1056
- def close_input
1057
- last_command.close_io(:stdin)
1058
- end
1059
-
1060
- # @deprecated
1061
- # @private
1062
- def eot
1063
- warn(%{\e[35m The \"#eot\"-method is deprecated. It will be deleted with the next major version. Please use \"#close_input\"-method instead.\e[0m})
1064
- close_input
1065
- end
1066
-
1067
- # @private
1068
- def _write_interactive(input)
1069
- warn('The use of "_write_interactive" is deprecated. It will be removed soon.')
1070
-
1071
- last_command.write(input)
1072
- end
1073
-
1074
- # @private
1075
- def _read_interactive
1076
- warn('The use of "_read_interactive" is deprecated. It will be removed soon.')
1077
-
1078
- last_command.stdout
1079
- end
1080
-
1081
- # @private
1082
- def _ensure_newline(str)
1083
- Utils.ensure_newline(str)
1084
- end
1085
-
1086
- # @private
1087
- def announce_or_puts(msg)
1088
- if(@puts)
1089
- Kernel.puts(msg)
1090
- else
1091
- puts(msg)
1092
- end
1093
- end
1094
-
1095
- # Use a clean rvm gemset
1096
- #
1097
- # Please make sure that you've got [rvm](http://rvm.io/) installed.
1098
- #
1099
- # @param [String] gemset
1100
- # The name of the gemset to be used
1101
- def use_clean_gemset(gemset)
1102
- run_simple(%{rvm gemset create "#{gemset}"}, true)
1103
- if all_stdout =~ /'#{gemset}' gemset created \((.*)\)\./
1104
- gem_home = Regexp.last_match[1]
1105
- set_env('GEM_HOME', gem_home)
1106
- set_env('GEM_PATH', gem_home)
1107
- set_env('BUNDLE_PATH', gem_home)
1108
-
1109
- paths = (ENV['PATH'] || "").split(File::PATH_SEPARATOR)
1110
- paths.unshift(File.join(gem_home, 'bin'))
1111
- set_env('PATH', paths.uniq.join(File::PATH_SEPARATOR))
1112
-
1113
- run_simple("gem install bundler", true)
1114
- else
1115
- raise "I didn't understand rvm's output: #{all_stdout}"
1116
- end
1117
- end
1118
-
1119
- # Unset variables used by bundler
1120
- def unset_bundler_env_vars
1121
- %w[RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE].each do |key|
1122
- set_env(key, nil)
1123
- end
1124
- end
1125
-
1126
- # Set environment variable
1127
- #
1128
- # @param [String] key
1129
- # The name of the environment variable as string, e.g. 'HOME'
1130
- #
1131
- # @param [String] value
1132
- # The value of the environment variable. Needs to be a string.
1133
- def set_env(key, value)
1134
- announcer.announce(:environment, key, value)
1135
- original_env[key] = ENV.delete(key) unless original_env.key? key
1136
- ENV[key] = value
1137
- end
1138
-
1139
- # Restore original process environment
1140
- def restore_env
1141
- original_env.each do |key, value|
1142
- if value
1143
- ENV[key] = value
1144
- else
1145
- ENV.delete key
1146
- end
1147
- end
1148
- end
1149
-
1150
- # @private
1151
- def original_env
1152
- @original_env ||= {}
1153
- end
1154
-
1155
- # Run block with environment
1156
- #
1157
- # @param [Hash] env
1158
- # The variables to be used for block.
1159
- #
1160
- # @yield
1161
- # The block of code which should be run with the modified environment variables
1162
- def with_env(env = {}, &block)
1163
- env.each do |k,v|
1164
- set_env k, v
1165
- end
1166
- block.call
1167
- restore_env
1168
- end
16
+ module Aruba
17
+ module Api
18
+ include Aruba::Api::Core
19
+ include Aruba::Api::Commands
20
+ include Aruba::Api::Environment
21
+ include Aruba::Api::Filesystem
22
+ include Aruba::Api::Rvm
23
+ include Aruba::Api::Deprecated
1169
24
 
1170
25
  # Access to announcer
1171
26
  def announcer
@@ -1182,21 +37,5 @@ module Aruba
1182
37
  end
1183
38
 
1184
39
  module_function :announcer
1185
-
1186
- # TODO: move some more methods under here!
1187
-
1188
- private
1189
-
1190
- def last_exit_status
1191
- process_monitor.last_exit_status
1192
- end
1193
-
1194
- def stop_process(process)
1195
- process_monitor.stop_process(process)
1196
- end
1197
-
1198
- def terminate_process(process)
1199
- process_monitor.terminate_process(process)
1200
- end
1201
40
  end
1202
41
  end