aruba 1.0.0.pre.alpha.4 → 1.0.3

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 (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +249 -46
  3. data/CONTRIBUTING.md +7 -16
  4. data/LICENSE +1 -1
  5. data/README.md +37 -30
  6. data/exe/aruba +1 -1
  7. data/lib/aruba/api.rb +6 -6
  8. data/lib/aruba/api/bundler.rb +1 -1
  9. data/lib/aruba/api/commands.rb +36 -13
  10. data/lib/aruba/api/core.rb +74 -47
  11. data/lib/aruba/api/environment.rb +16 -4
  12. data/lib/aruba/api/filesystem.rb +48 -48
  13. data/lib/aruba/api/text.rb +15 -3
  14. data/lib/aruba/aruba_path.rb +24 -95
  15. data/lib/aruba/basic_configuration.rb +5 -6
  16. data/lib/aruba/basic_configuration/option.rb +2 -2
  17. data/lib/aruba/cli.rb +4 -1
  18. data/lib/aruba/colorizer.rb +10 -99
  19. data/lib/aruba/config/jruby.rb +15 -5
  20. data/lib/aruba/config_wrapper.rb +17 -2
  21. data/lib/aruba/configuration.rb +43 -14
  22. data/lib/aruba/console.rb +0 -2
  23. data/lib/aruba/console/help.rb +8 -5
  24. data/lib/aruba/contracts/absolute_path.rb +3 -3
  25. data/lib/aruba/contracts/is_power_of_two.rb +2 -2
  26. data/lib/aruba/contracts/relative_path.rb +3 -3
  27. data/lib/aruba/cucumber.rb +0 -2
  28. data/lib/aruba/cucumber/command.rb +199 -110
  29. data/lib/aruba/cucumber/file.rb +53 -35
  30. data/lib/aruba/cucumber/hooks.rb +4 -1
  31. data/lib/aruba/cucumber/testing_frameworks.rb +76 -50
  32. data/lib/aruba/event_bus.rb +4 -2
  33. data/lib/aruba/event_bus/name_resolver.rb +9 -8
  34. data/lib/aruba/events.rb +2 -1
  35. data/lib/aruba/hooks.rb +2 -4
  36. data/lib/aruba/in_config_wrapper.rb +10 -3
  37. data/lib/aruba/initializer.rb +37 -31
  38. data/lib/aruba/matchers/base/base_matcher.rb +2 -11
  39. data/lib/aruba/matchers/base/message_indenter.rb +1 -1
  40. data/lib/aruba/matchers/base/object_formatter.rb +0 -5
  41. data/lib/aruba/matchers/collection/include_an_object.rb +4 -4
  42. data/lib/aruba/matchers/command/be_successfully_executed.rb +6 -0
  43. data/lib/aruba/matchers/command/have_exit_status.rb +15 -3
  44. data/lib/aruba/matchers/command/have_finished_in_time.rb +3 -1
  45. data/lib/aruba/matchers/command/have_output.rb +3 -1
  46. data/lib/aruba/matchers/command/have_output_on_stderr.rb +3 -1
  47. data/lib/aruba/matchers/command/have_output_on_stdout.rb +3 -1
  48. data/lib/aruba/matchers/command/have_output_size.rb +1 -1
  49. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +1 -1
  50. data/lib/aruba/matchers/directory/have_sub_directory.rb +8 -3
  51. data/lib/aruba/matchers/file/be_an_existing_file.rb +1 -1
  52. data/lib/aruba/matchers/file/have_file_size.rb +4 -2
  53. data/lib/aruba/matchers/path/have_permissions.rb +7 -4
  54. data/lib/aruba/platform.rb +0 -7
  55. data/lib/aruba/platforms/announcer.rb +36 -17
  56. data/lib/aruba/platforms/aruba_file_creator.rb +3 -1
  57. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +7 -2
  58. data/lib/aruba/platforms/command_monitor.rb +40 -6
  59. data/lib/aruba/platforms/determine_disk_usage.rb +56 -19
  60. data/lib/aruba/platforms/simple_table.rb +2 -10
  61. data/lib/aruba/platforms/unix_environment_variables.rb +10 -13
  62. data/lib/aruba/platforms/unix_platform.rb +16 -12
  63. data/lib/aruba/platforms/unix_which.rb +1 -1
  64. data/lib/aruba/platforms/windows_command_string.rb +2 -2
  65. data/lib/aruba/platforms/windows_environment_variables.rb +9 -2
  66. data/lib/aruba/platforms/windows_platform.rb +4 -0
  67. data/lib/aruba/platforms/windows_which.rb +6 -2
  68. data/lib/aruba/processes/basic_process.rb +14 -16
  69. data/lib/aruba/processes/debug_process.rb +11 -5
  70. data/lib/aruba/processes/in_process.rb +4 -2
  71. data/lib/aruba/processes/spawn_process.rb +32 -16
  72. data/lib/aruba/rspec.rb +24 -14
  73. data/lib/aruba/runtime.rb +11 -4
  74. data/lib/aruba/setup.rb +27 -14
  75. data/lib/aruba/tasks/docker_helpers.rb +3 -1
  76. data/lib/aruba/version.rb +1 -1
  77. metadata +214 -79
  78. data/.cucumberproignore +0 -3
  79. data/.document +0 -5
  80. data/.github/ISSUE_TEMPLATE.md +0 -48
  81. data/.github/PULL_REQUEST_TEMPLATE.md +0 -41
  82. data/.gitignore +0 -38
  83. data/.rspec +0 -4
  84. data/.rubocop.yml +0 -13
  85. data/.rubocop_todo.yml +0 -364
  86. data/.simplecov +0 -34
  87. data/.travis.yml +0 -75
  88. data/.yardopts +0 -11
  89. data/Dockerfile +0 -67
  90. data/Gemfile +0 -63
  91. data/Rakefile +0 -109
  92. data/TODO.md +0 -13
  93. data/appveyor.yml +0 -32
  94. data/aruba.gemspec +0 -36
  95. data/bin/build +0 -3
  96. data/bin/console +0 -7
  97. data/bin/release +0 -3
  98. data/bin/test +0 -9
  99. data/config/.gitignore +0 -1
  100. data/cucumber.yml +0 -17
  101. data/docker-compose.yml +0 -26
  102. data/fixtures/cli-app/.gitignore +0 -9
  103. data/fixtures/cli-app/.rspec +0 -2
  104. data/fixtures/cli-app/README.md +0 -39
  105. data/fixtures/cli-app/Rakefile +0 -1
  106. data/fixtures/cli-app/bin/aruba-test-cli +0 -6
  107. data/fixtures/cli-app/cli-app.gemspec +0 -27
  108. data/fixtures/cli-app/features/support/aruba.rb +0 -1
  109. data/fixtures/cli-app/features/support/env.rb +0 -1
  110. data/fixtures/cli-app/lib/cli/app.rb +0 -9
  111. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +0 -15
  112. data/fixtures/cli-app/lib/cli/app/version.rb +0 -5
  113. data/fixtures/cli-app/script/console +0 -14
  114. data/fixtures/cli-app/spec/spec_helper.rb +0 -7
  115. data/fixtures/cli-app/spec/support/aruba.rb +0 -1
  116. data/fixtures/copy/file.txt +0 -1
  117. data/fixtures/empty-app/.gitignore +0 -9
  118. data/fixtures/empty-app/.rspec +0 -2
  119. data/fixtures/empty-app/README.md +0 -24
  120. data/fixtures/empty-app/Rakefile +0 -1
  121. data/fixtures/empty-app/cli-app.gemspec +0 -27
  122. data/fixtures/empty-app/lib/cli/app.rb +0 -9
  123. data/fixtures/empty-app/lib/cli/app/version.rb +0 -5
  124. data/fixtures/getting-started-app/.gitignore +0 -4
  125. data/fixtures/getting-started-app/Gemfile +0 -4
  126. data/fixtures/getting-started-app/README.md +0 -3
  127. data/fixtures/getting-started-app/features/support/env.rb +0 -1
  128. data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
@@ -129,11 +129,11 @@ Or use these Rake tasks:
129
129
  # Run the whole test suite
130
130
  rake test
131
131
  # Run RSpec tests
132
- rake test:rspec
132
+ rake spec
133
133
  # Run Cucumber features
134
- rake test:cucumber
134
+ rake cucumber
135
135
  # Run Cucumber features which are "WORK IN PROGRESS" and are allowed to fail
136
- rake test:cucumber_wip
136
+ rake cucumber:wip
137
137
  ```
138
138
 
139
139
  If you have problems because our assumptions about your local setup are wrong,
@@ -186,7 +186,6 @@ Aruba's Rakefile provides the following linting tasks
186
186
  bundle exec rake lint # Run all linters
187
187
  bundle exec rake lint:coding_guidelines # Lint our code with "rubocop"
188
188
  bundle exec rake lint:licenses # Check for relevant licenses in project
189
- bundle exec rake lint:travis # Lint our .travis.yml
190
189
  ```
191
190
 
192
191
  ### Building and installing your local Aruba version
@@ -195,11 +194,11 @@ You can use the following Rake tasks to build and install your work-in-progress
195
194
 
196
195
  ```bash
197
196
  # Build your copy
198
- bundle exec rake rubygem:build
197
+ bundle exec rake build
199
198
  # Build and install your copy
200
- bundle exec rake rubygem:install
199
+ bundle exec rake install
201
200
  # Build and install your copy without network access
202
- bundle exec rake rubygem:install:local
201
+ bundle exec rake install:local
203
202
  ```
204
203
 
205
204
  ## Getting started as a "Maintainer"
@@ -211,8 +210,6 @@ bundle exec rake rubygem:install:local
211
210
  entries for all fixes.
212
211
  * No need to add a [`CHANGELOG.md`] header at this point - this should be done
213
212
  later, when a new change is made.
214
- * If a major version is released, update the `still` branch, which points to
215
- the "old" major version.
216
213
 
217
214
  Now release it:
218
215
 
@@ -225,13 +222,7 @@ bin/test
225
222
 
226
223
  # Release gem
227
224
  git commit -m "Version bump"
228
- bin/release
229
-
230
- # If it's a major relase:
231
- # Merge changes back to have correct documentation
232
- git checkout still
233
- git merge master
234
- git push
225
+ bundle exec rake release
235
226
  ```
236
227
 
237
228
  Now send a PR to [cucumber/website] adding an article
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2016 Aslak Hellesøy, David Chelimsky, Mike Sassak, Jarl Friis, Matt Wynne, Dennis Günnewig
1
+ Copyright (c) 2010-2020 Aslak Hellesøy, David Chelimsky, Mike Sassak, Jarl Friis, Matt Wynne, Dennis Günnewig and Matijs van Zuijlen
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,66 +1,70 @@
1
- [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/cucumber/aruba/master/LICENSE)
1
+ [![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/cucumber/aruba/master/LICENSE)
2
2
  [![Docs](https://img.shields.io/badge/cucumber.pro-aruba-3d10af.svg)](https://app.cucumber.pro/projects/aruba)
3
3
  [![Gem Version](https://badge.fury.io/rb/aruba.svg)](http://badge.fury.io/rb/aruba)
4
4
  [![Code Climate](https://codeclimate.com/github/cucumber/aruba.svg)](https://codeclimate.com/github/cucumber/aruba)
5
5
  [![Support](https://img.shields.io/badge/cucumber-support-orange.svg)](https://cucumber.io/support)
6
6
 
7
- [![Build Status for "master" on Linux/Mac OS](https://travis-ci.org/cucumber/aruba.svg?branch=master)](https://travis-ci.org/cucumber/aruba)
8
- [![Build status for "master" on Windows](https://ci.appveyor.com/api/projects/status/jfo2tkqhnrqqcivl/branch/master?svg=true&passingText=master%20windows%20passing&failingText=master%20windows%20failing&pendingText=master%20windows%20pending)](https://ci.appveyor.com/project/cucumberbdd/aruba/branch/master)
9
-
10
- **This is the [latest](https://github.com/cucumber/aruba/blob/master/README.md) version of our README.md (Branch: "[master](https://github.com/cucumber/aruba/tree/master)"). There is also [the README of the latest released version of "aruba"](https://github.com/cucumber/aruba/blob/still/README.md) (Branch: "[still](https://github.com/cucumber/aruba/tree/still)").**
7
+ [![Travis CI build status](https://travis-ci.org/cucumber/aruba.svg)](https://travis-ci.org/cucumber/aruba)
8
+ [![Appveyor build status](https://ci.appveyor.com/api/projects/status/jfo2tkqhnrqqcivl?svg=true)](https://ci.appveyor.com/project/cucumberbdd/aruba)
11
9
 
12
10
  ## Install
13
11
 
14
12
  Add this line to your application's `Gemfile`:
15
13
 
16
- ~~~ruby
14
+ ```ruby
17
15
  gem 'aruba'
18
- ~~~
16
+ ```
19
17
 
20
18
  And then execute:
21
19
 
22
- ~~~bash
20
+ ```bash
23
21
  bundle
24
- ~~~
22
+ ```
25
23
 
26
24
  Or install it yourself as:
27
25
 
28
- ~~~bash
26
+ ```bash
29
27
  gem install aruba
30
- ~~~
28
+ ```
31
29
 
32
30
  ## Usage
33
31
 
34
- ### As a user getting started with "aruba"
32
+ ### As a user getting started with Aruba
35
33
 
36
- Our most current documentation to get started with `aruba` as a user can be found on [![See our documentation on Cucumber Pro](https://github.com/cucumber-ltd/brand/raw/master/images/png/notm/cucumber-pro-black/cucumber-pro-black-32.png)](https://app.cucumber.pro/projects/aruba). It is generated from our feature files describing the use of `aruba`.
34
+ Our most current documentation to get started with Aruba as a user can be
35
+ found on [Cucumber Jam](https://app.cucumber.pro/projects/aruba).
36
+ It is generated from our feature files describing the use of Aruba.
37
37
 
38
38
  ### As a user getting started with a ruby testing framework
39
39
 
40
40
  * **Cucumber**:
41
41
 
42
- If you're new to the "Cucumber" ecosystem, it's worth to visit
42
+ If you're new to the Cucumber ecosystem, it's worth to visit
43
43
  [the project's documentation site](https://cucumber.io/docs). This also includes
44
- information about how to write feature files in "Gherkin".
44
+ information about how to write feature files in Gherkin.
45
45
 
46
46
  * **RSpec**:
47
47
 
48
- If you want to use "aruba" with "RSpec" and you need some information about how to use "RSpec", please visit [their website](http://rspec.info/documentation/).
48
+ If you want to use Aruba with RSpec and you need some information about how to use RSpec, please visit [their website](http://rspec.info/documentation/).
49
49
 
50
50
  * **minitest**:
51
51
 
52
- The documentation for "minitest" can be found [here](http://docs.seattlerb.org/minitest/).
52
+ The documentation for minitest can be found [here](http://docs.seattlerb.org/minitest/).
53
53
 
54
- ### As a developer getting started with "aruba"
54
+ ### As a developer getting started with Aruba
55
55
 
56
56
  A full documentation of the API for developers can be found on
57
- [RubyDoc](http://www.rubydoc.info/github/cucumber/aruba/master/frames).
57
+ [RubyDoc](http://www.rubydoc.info/gems/aruba).
58
58
 
59
59
  ## Support
60
60
 
61
61
  ### Channels
62
62
 
63
- For support, please have a look at the ["support website"](https://cucumber.io/support) of "Cucumber". You have different options to reach out for help: Recommended for `aruba` are using the "Slack" channels - e.g. "aruba-devs" or "general" ([Register account](https://cucumberbdd-slack-invite.herokuapp.com/)) and the "Issues" page on [GitHub](https://github.com/cucumber/aruba/issues). Addressing one of the maintainers directly would be helpful.
63
+ For support, please have a look at the [support website](https://cucumber.io/support)
64
+ of Cucumber. You have different options to reach out for help: Recommended for
65
+ Aruba are using the Slack channels — e.g. `committers-aruba` or `help-cucumber-ruby`
66
+ — ([register account](https://cucumberbdd-slack-invite.herokuapp.com/)), and the
67
+ [Issues page on GitHub](https://github.com/cucumber/aruba/issues).
64
68
 
65
69
  ### Maintainers
66
70
 
@@ -74,7 +78,13 @@ We try to comply with [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.
74
78
 
75
79
  ## Supported Ruby versions
76
80
 
77
- For an up-to-date list of all supported Ruby versions, please see our [`.travis.yml`](https://github.com/cucumber/aruba/blob/master/.travis.yml). We only test against the latest version of a version branch - most times.
81
+ Aruba is supported on Ruby 2.4 and up, and tested against CRuby 2.4, 2.5, 2.6
82
+ and 2.7, and JRuby 9.2.
83
+
84
+ ## Supported operating systems
85
+
86
+ Aruba is fully tested in CI on Linux and MacOS. On Windows, only RSpec tests
87
+ are run, so YMMV. Full Windows support is a work in progress.
78
88
 
79
89
  ## Contributing
80
90
 
@@ -82,14 +92,11 @@ Please see the [CONTRIBUTING](CONTRIBUTING.md) file.
82
92
 
83
93
  ## Code branches
84
94
 
85
- We use two branches for development: "master" and "still". The "master" branch
86
- contains the code of the current major version. The "still" branch is used for the
87
- old major version. New features are only added to "master". The "still" branch is
88
- still maintained, but only get fixes for major bugs. The "still" branch should be considered as experimental, as we need to find out how much work it is to maintain two branches of code.
95
+ Development takes place in the `master` branch and currently targets the 1.x
96
+ releases. If necessary, maintenance of the old 0.14.x releases takes place in
97
+ the `0-14-stable` branch. Stable branches will not be created until absolutely
98
+ necessary.
89
99
 
90
- ## Build Status
100
+ ## License
91
101
 
92
- |Version|Linux / OS X|Windows|
93
- | ------ | ------ | ------ |
94
- | master | [![Build Status](https://travis-ci.org/cucumber/aruba.svg?branch=master)](https://travis-ci.org/cucumber/aruba) | [![Build status](https://ci.appveyor.com/api/projects/status/jfo2tkqhnrqqcivl/branch/master?svg=true&passingText=master%20windows%20passing&failingText=master%20windows%20failing&pendingText==master%20windows%20pending)](https://ci.appveyor.com/project/cucumberbdd/aruba/branch/master)|
95
- | still | [![Build Status](https://travis-ci.org/cucumber/aruba.svg?branch=still)](https://travis-ci.org/cucumber/aruba) | [![Build status](https://ci.appveyor.com/api/projects/status/jfo2tkqhnrqqcivl/branch/still?svg=true&passingText=still%20windows%20passing&failingText=still%20windows%20failing&pendingText=master%20windows%20pending)](https://ci.appveyor.com/project/cucumberbdd/aruba/branch/still)
102
+ See the file [LICENSE](LICENSE).
data/exe/aruba CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH << File.expand_path('../lib', __dir__)
4
4
 
5
5
  require 'aruba/cli'
6
6
 
@@ -19,11 +19,11 @@ Aruba.platform.require_matching_files('../matchers/**/*.rb', __FILE__)
19
19
  module Aruba
20
20
  # Api
21
21
  module Api
22
- include Aruba::Api::Core
23
- include Aruba::Api::Commands
24
- include Aruba::Api::Environment
25
- include Aruba::Api::Filesystem
26
- include Aruba::Api::Text
27
- include Aruba::Api::Bundler
22
+ include Core
23
+ include Commands
24
+ include Environment
25
+ include Filesystem
26
+ include Text
27
+ include Bundler
28
28
  end
29
29
  end
@@ -7,7 +7,7 @@ module Aruba
7
7
 
8
8
  # Unset variables used by bundler
9
9
  def unset_bundler_env_vars
10
- %w[RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE].each do |key|
10
+ %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).each do |key|
11
11
  delete_environment_variable(key)
12
12
  end
13
13
  end
@@ -92,6 +92,30 @@ module Aruba
92
92
  self
93
93
  end
94
94
 
95
+ # Get stdout of all processes
96
+ #
97
+ # @return [String]
98
+ # The stdout of all processes which have run before
99
+ def all_stdout
100
+ aruba.command_monitor.all_stdout
101
+ end
102
+
103
+ # Get stderr of all processes
104
+ #
105
+ # @return [String]
106
+ # The stderr of all processes which have run before
107
+ def all_stderr
108
+ aruba.command_monitor.all_stderr
109
+ end
110
+
111
+ # Get stderr and stdout of all processes
112
+ #
113
+ # @return [String]
114
+ # The stderr and stdout of all processes which have run before
115
+ def all_output
116
+ aruba.command_monitor.all_output
117
+ end
118
+
95
119
  # Find a started command
96
120
  #
97
121
  # @param [String, Command] commandline
@@ -128,7 +152,7 @@ module Aruba
128
152
 
129
153
  unless command.interactive?
130
154
  raise NotImplementedError,
131
- 'Running interactively is not supported with this process launcher.'
155
+ 'Running interactively is not supported with this process launcher.'
132
156
  end
133
157
 
134
158
  start_command(command)
@@ -144,16 +168,16 @@ module Aruba
144
168
  # @param [String] cmd
145
169
  # The command to be executed
146
170
  #
147
- # @param [Hash] options
171
+ # @param [Hash] opts
148
172
  # Options for aruba
149
173
  #
150
- # @option options [Boolean] fail_on_error
174
+ # @option opts [Boolean] :fail_on_error
151
175
  # Should aruba fail on error?
152
176
  #
153
- # @option options [Numeric] exit_timeout
177
+ # @option opts [Numeric] :exit_timeout
154
178
  # Timeout for execution
155
179
  #
156
- # @option options [Numeric] io_wait_timeout
180
+ # @option opts [Numeric] :io_wait_timeout
157
181
  # Timeout for IO - STDERR, STDOUT
158
182
  #
159
183
  def run_command_and_stop(cmd, opts = {})
@@ -196,12 +220,11 @@ module Aruba
196
220
 
197
221
  private
198
222
 
199
- # rubocop:disable Metrics/MethodLength
200
223
  def prepare_command(cmd, opts)
201
- exit_timeout = opts[:exit_timeout].nil? ? aruba.config.exit_timeout : opts[:exit_timeout]
202
- io_wait_timeout = opts[:io_wait_timeout].nil? ? aruba.config.io_wait_timeout : opts[:io_wait_timeout]
203
- stop_signal = opts[:stop_signal].nil? ? aruba.config.stop_signal : opts[:stop_signal]
204
- startup_wait_time = opts[:startup_wait_time].nil? ? aruba.config.startup_wait_time : opts[:startup_wait_time]
224
+ exit_timeout = opts[:exit_timeout] || aruba.config.exit_timeout
225
+ io_wait_timeout = opts[:io_wait_timeout] || aruba.config.io_wait_timeout
226
+ stop_signal = opts[:stop_signal] || aruba.config.stop_signal
227
+ startup_wait_time = opts[:startup_wait_time] || aruba.config.startup_wait_time
205
228
 
206
229
  cmd = replace_variables(cmd)
207
230
 
@@ -232,12 +255,12 @@ module Aruba
232
255
  )
233
256
  end
234
257
 
235
- # rubocop:enable Metrics/MethodLength
236
-
237
258
  def start_command(command)
238
259
  aruba.config.before(:command, self, command)
239
260
 
240
- command.start
261
+ in_current_directory do
262
+ command.start
263
+ end
241
264
 
242
265
  stop_signal = command.stop_signal
243
266
  aruba.announcer.announce(:stop_signal, command.pid, stop_signal) if stop_signal
@@ -3,8 +3,6 @@ require 'aruba/runtime'
3
3
  require 'aruba/errors'
4
4
  require 'aruba/setup'
5
5
 
6
- require 'aruba/config/jruby'
7
-
8
6
  # Aruba
9
7
  module Aruba
10
8
  # Api
@@ -17,6 +15,10 @@ module Aruba
17
15
 
18
16
  # Aruba Runtime
19
17
  def aruba
18
+ # TODO: Check this variable being accessed inconsistently. Should only
19
+ # be using the memo!
20
+ # Renaming this to `aruba` causes 100's of rspec failures. Needs a
21
+ # deeper dive, approach with caution!
20
22
  @_aruba_runtime ||= Runtime.new
21
23
  end
22
24
 
@@ -31,6 +33,15 @@ module Aruba
31
33
  self
32
34
  end
33
35
 
36
+ # Execute block in Aruba's current directory
37
+ #
38
+ # @yield
39
+ # The block which should be run in current directory
40
+ def in_current_directory(&block)
41
+ create_directory '.' unless directory?('.')
42
+ cd('.', &block)
43
+ end
44
+
34
45
  # Switch to directory
35
46
  #
36
47
  # @param [String] dir
@@ -45,25 +56,30 @@ module Aruba
45
56
  # @example Run code in directory
46
57
  # result = cd('some-dir') { Dir.getwd }
47
58
  #
48
- # rubocop:disable Metrics/MethodLength
49
59
  def cd(dir, &block)
50
60
  if block_given?
51
61
  begin
52
- fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory? expand_path(dir)
62
+ unless Aruba.platform.directory?(expand_path(dir))
63
+ raise ArgumentError,
64
+ "#{expand_path(dir)} is not a directory or does not exist."
65
+ end
53
66
 
54
67
  old_directory = expand_path('.')
55
68
  aruba.current_directory << dir
56
69
  new_directory = expand_path('.')
57
70
 
58
- aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, new: new_directory)
71
+ aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory,
72
+ new: new_directory)
59
73
 
60
74
  old_dir = Aruba.platform.getwd
61
75
 
62
- Aruba.platform.chdir File.join(aruba.root_directory, aruba.current_directory)
76
+ real_new_directory = File.expand_path(aruba.current_directory,
77
+ aruba.root_directory)
78
+ Aruba.platform.chdir real_new_directory
63
79
 
64
80
  result = with_environment(
65
81
  'OLDPWD' => old_dir,
66
- 'PWD' => File.expand_path(File.join(aruba.root_directory, aruba.current_directory)),
82
+ 'PWD' => real_new_directory,
67
83
  &block
68
84
  )
69
85
  ensure
@@ -74,17 +90,19 @@ module Aruba
74
90
  return result
75
91
  end
76
92
 
77
- fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory? expand_path(dir)
93
+ unless Aruba.platform.directory?(expand_path(dir))
94
+ raise ArgumentError, "#{expand_path(dir)} is not a directory or does not exist."
95
+ end
78
96
 
79
97
  old_directory = expand_path('.')
80
98
  aruba.current_directory << dir
81
99
  new_directory = expand_path('.')
82
100
 
83
- aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, new: new_directory)
101
+ aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory,
102
+ new: new_directory)
84
103
 
85
104
  self
86
105
  end
87
- # rubocop:enable Metrics/MethodLength
88
106
 
89
107
  # Expand file name
90
108
  #
@@ -122,57 +140,70 @@ module Aruba
122
140
  # # => /foo/bar
123
141
  # expand_path('/foo/bar')
124
142
  #
125
- # rubocop:disable Metrics/MethodLength
126
- # rubocop:disable Metrics/CyclomaticComplexity
127
- # rubocop:disable Metrics/PerceivedComplexity
128
143
  def expand_path(file_name, dir_string = nil)
129
- # rubocop:disable Metrics/LineLength
130
- message = %(Filename "#{file_name}" needs to be a string. It cannot be nil or empty either. Please use `expand_path('.')` if you want the current directory to be expanded.)
131
- # rubocop:enable Metrics/LineLength
144
+ unless file_name.is_a?(String) && !file_name.empty?
145
+ message = "Filename #{file_name} needs to be a string." \
146
+ ' It cannot be nil or empty either. '\
147
+ "Please use `expand_path('.')` if you want the current directory to be expanded."
132
148
 
133
- fail ArgumentError, message unless file_name.is_a?(String) && !file_name.empty?
134
-
135
- # rubocop:disable Metrics/LineLength
136
- fail %(Aruba's working directory does not exist. Maybe you forgot to run `setup_aruba` before using its API.) unless Aruba.platform.directory? File.join(aruba.config.root_directory, aruba.config.working_directory)
149
+ raise ArgumentError, message
150
+ end
137
151
 
138
- # rubocop:enable Metrics/LineLength
152
+ unless Aruba.platform.directory? File.join(aruba.config.root_directory,
153
+ aruba.config.working_directory)
154
+ raise "Aruba's working directory does not exist." \
155
+ ' Maybe you forgot to run `setup_aruba` before using its API.'
156
+ end
139
157
 
140
158
  prefix = file_name[0]
141
- rest = file_name[2..-1]
142
159
 
143
160
  if aruba.config.fixtures_path_prefix == prefix
161
+ rest = file_name[2..-1]
144
162
  path = File.join(*[aruba.fixtures_directory, rest].compact)
145
-
146
- # rubocop:disable Metrics/LineLength
147
- fail ArgumentError, %(Fixture "#{rest}" does not exist in fixtures directory "#{aruba.fixtures_directory}". This was the one we found first on your system from all possible candidates: #{aruba.config.fixtures_directories.map { |p| format('"%s"', p) }.join(', ')}.) unless Aruba.platform.exist? path
148
-
149
- # rubocop:enable Metrics/LineLength
163
+ unless Aruba.platform.exist? path
164
+ aruba_fixture_candidates = aruba.config.fixtures_directories
165
+ .map { |p| format('"%s"', p) }.join(', ')
166
+
167
+ raise ArgumentError,
168
+ "Fixture \"#{rest}\" does not exist" \
169
+ " in fixtures directory \"#{aruba.fixtures_directory}\"." \
170
+ ' This was the one we found first on your system from all possible' \
171
+ " candidates: #{aruba_fixture_candidates}."
172
+ end
150
173
 
151
174
  path
152
175
  elsif prefix == '~'
153
176
  path = with_environment do
154
- ArubaPath.new(File.expand_path(file_name))
177
+ File.expand_path(file_name)
155
178
  end
156
179
 
157
- fail ArgumentError, 'Expanding "~/" to "/" is not allowed' if path.to_s == '/'
158
- fail ArgumentError, %(Expanding "~/" to a relative path "#{path}" is not allowed) unless path.absolute?
180
+ raise ArgumentError, 'Expanding "~/" to "/" is not allowed' if path == '/'
181
+
182
+ unless Aruba.platform.absolute_path? path
183
+ raise ArgumentError,
184
+ "Expanding \"~\" to a relative path \"#{path}\" is not allowed"
185
+ end
159
186
 
160
187
  path.to_s
161
- elsif absolute? file_name
188
+ elsif absolute?(file_name)
162
189
  unless aruba.config.allow_absolute_paths
163
- aruba.logger.warn 'Using absolute paths in Aruba is not recommended.' \
164
- ' Set config.allow_absolute_paths = true to silence this warning'
190
+ caller_location = caller_locations(1, 1).first
191
+ caller_file_line = "#{caller_location.path}:#{caller_location.lineno}"
192
+ aruba.logger.warn \
193
+ "Aruba's `expand_path` method was called with an absolute path" \
194
+ " at #{caller_file_line}, which is not recommended." \
195
+ ' Change the call to pass a relative path or set '\
196
+ '`config.allow_absolute_paths = true` to silence this warning'
165
197
  end
166
198
  file_name
167
199
  else
168
- directory = File.join(aruba.root_directory, aruba.current_directory)
169
- directory = File.expand_path(dir_string, directory) if dir_string
170
- File.expand_path(file_name, directory)
200
+ with_environment do
201
+ directory = File.expand_path(aruba.current_directory, aruba.root_directory)
202
+ directory = File.expand_path(dir_string, directory) if dir_string
203
+ File.expand_path(file_name, directory)
204
+ end
171
205
  end
172
206
  end
173
- # rubocop:enable Metrics/MethodLength
174
- # rubocop:enable Metrics/CyclomaticComplexity
175
- # rubocop:enable Metrics/PerceivedComplexity
176
207
 
177
208
  # Run block with environment
178
209
  #
@@ -182,14 +213,10 @@ module Aruba
182
213
  # @yield
183
214
  # The block of code which should be run with the changed environment variables
184
215
  def with_environment(env = {}, &block)
185
- old_aruba_env = aruba.environment.to_h
186
-
187
- # make sure the old environment is really restored in "ENV"
188
- Aruba.platform.with_environment aruba.environment.update(env).to_h, &block
189
- ensure
190
- # make sure the old environment is really restored in "aruba.environment"
191
- aruba.environment.clear
192
- aruba.environment.update old_aruba_env
216
+ aruba.environment.nest do |nested_env|
217
+ nested_env.update(env)
218
+ Aruba.platform.with_environment nested_env.to_h, &block
219
+ end
193
220
  end
194
221
  end
195
222
  end