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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +249 -46
- data/CONTRIBUTING.md +7 -16
- data/LICENSE +1 -1
- data/README.md +37 -30
- data/exe/aruba +1 -1
- data/lib/aruba/api.rb +6 -6
- data/lib/aruba/api/bundler.rb +1 -1
- data/lib/aruba/api/commands.rb +36 -13
- data/lib/aruba/api/core.rb +74 -47
- data/lib/aruba/api/environment.rb +16 -4
- data/lib/aruba/api/filesystem.rb +48 -48
- data/lib/aruba/api/text.rb +15 -3
- data/lib/aruba/aruba_path.rb +24 -95
- data/lib/aruba/basic_configuration.rb +5 -6
- data/lib/aruba/basic_configuration/option.rb +2 -2
- data/lib/aruba/cli.rb +4 -1
- data/lib/aruba/colorizer.rb +10 -99
- data/lib/aruba/config/jruby.rb +15 -5
- data/lib/aruba/config_wrapper.rb +17 -2
- data/lib/aruba/configuration.rb +43 -14
- data/lib/aruba/console.rb +0 -2
- data/lib/aruba/console/help.rb +8 -5
- data/lib/aruba/contracts/absolute_path.rb +3 -3
- data/lib/aruba/contracts/is_power_of_two.rb +2 -2
- data/lib/aruba/contracts/relative_path.rb +3 -3
- data/lib/aruba/cucumber.rb +0 -2
- data/lib/aruba/cucumber/command.rb +199 -110
- data/lib/aruba/cucumber/file.rb +53 -35
- data/lib/aruba/cucumber/hooks.rb +4 -1
- data/lib/aruba/cucumber/testing_frameworks.rb +76 -50
- data/lib/aruba/event_bus.rb +4 -2
- data/lib/aruba/event_bus/name_resolver.rb +9 -8
- data/lib/aruba/events.rb +2 -1
- data/lib/aruba/hooks.rb +2 -4
- data/lib/aruba/in_config_wrapper.rb +10 -3
- data/lib/aruba/initializer.rb +37 -31
- data/lib/aruba/matchers/base/base_matcher.rb +2 -11
- data/lib/aruba/matchers/base/message_indenter.rb +1 -1
- data/lib/aruba/matchers/base/object_formatter.rb +0 -5
- data/lib/aruba/matchers/collection/include_an_object.rb +4 -4
- data/lib/aruba/matchers/command/be_successfully_executed.rb +6 -0
- data/lib/aruba/matchers/command/have_exit_status.rb +15 -3
- data/lib/aruba/matchers/command/have_finished_in_time.rb +3 -1
- data/lib/aruba/matchers/command/have_output.rb +3 -1
- data/lib/aruba/matchers/command/have_output_on_stderr.rb +3 -1
- data/lib/aruba/matchers/command/have_output_on_stdout.rb +3 -1
- data/lib/aruba/matchers/command/have_output_size.rb +1 -1
- data/lib/aruba/matchers/directory/be_an_existing_directory.rb +1 -1
- data/lib/aruba/matchers/directory/have_sub_directory.rb +8 -3
- data/lib/aruba/matchers/file/be_an_existing_file.rb +1 -1
- data/lib/aruba/matchers/file/have_file_size.rb +4 -2
- data/lib/aruba/matchers/path/have_permissions.rb +7 -4
- data/lib/aruba/platform.rb +0 -7
- data/lib/aruba/platforms/announcer.rb +36 -17
- data/lib/aruba/platforms/aruba_file_creator.rb +3 -1
- data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +7 -2
- data/lib/aruba/platforms/command_monitor.rb +40 -6
- data/lib/aruba/platforms/determine_disk_usage.rb +56 -19
- data/lib/aruba/platforms/simple_table.rb +2 -10
- data/lib/aruba/platforms/unix_environment_variables.rb +10 -13
- data/lib/aruba/platforms/unix_platform.rb +16 -12
- data/lib/aruba/platforms/unix_which.rb +1 -1
- data/lib/aruba/platforms/windows_command_string.rb +2 -2
- data/lib/aruba/platforms/windows_environment_variables.rb +9 -2
- data/lib/aruba/platforms/windows_platform.rb +4 -0
- data/lib/aruba/platforms/windows_which.rb +6 -2
- data/lib/aruba/processes/basic_process.rb +14 -16
- data/lib/aruba/processes/debug_process.rb +11 -5
- data/lib/aruba/processes/in_process.rb +4 -2
- data/lib/aruba/processes/spawn_process.rb +32 -16
- data/lib/aruba/rspec.rb +24 -14
- data/lib/aruba/runtime.rb +11 -4
- data/lib/aruba/setup.rb +27 -14
- data/lib/aruba/tasks/docker_helpers.rb +3 -1
- data/lib/aruba/version.rb +1 -1
- metadata +214 -79
- data/.cucumberproignore +0 -3
- data/.document +0 -5
- data/.github/ISSUE_TEMPLATE.md +0 -48
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -41
- data/.gitignore +0 -38
- data/.rspec +0 -4
- data/.rubocop.yml +0 -13
- data/.rubocop_todo.yml +0 -364
- data/.simplecov +0 -34
- data/.travis.yml +0 -75
- data/.yardopts +0 -11
- data/Dockerfile +0 -67
- data/Gemfile +0 -63
- data/Rakefile +0 -109
- data/TODO.md +0 -13
- data/appveyor.yml +0 -32
- data/aruba.gemspec +0 -36
- data/bin/build +0 -3
- data/bin/console +0 -7
- data/bin/release +0 -3
- data/bin/test +0 -9
- data/config/.gitignore +0 -1
- data/cucumber.yml +0 -17
- data/docker-compose.yml +0 -26
- data/fixtures/cli-app/.gitignore +0 -9
- data/fixtures/cli-app/.rspec +0 -2
- data/fixtures/cli-app/README.md +0 -39
- data/fixtures/cli-app/Rakefile +0 -1
- data/fixtures/cli-app/bin/aruba-test-cli +0 -6
- data/fixtures/cli-app/cli-app.gemspec +0 -27
- data/fixtures/cli-app/features/support/aruba.rb +0 -1
- data/fixtures/cli-app/features/support/env.rb +0 -1
- data/fixtures/cli-app/lib/cli/app.rb +0 -9
- data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +0 -15
- data/fixtures/cli-app/lib/cli/app/version.rb +0 -5
- data/fixtures/cli-app/script/console +0 -14
- data/fixtures/cli-app/spec/spec_helper.rb +0 -7
- data/fixtures/cli-app/spec/support/aruba.rb +0 -1
- data/fixtures/copy/file.txt +0 -1
- data/fixtures/empty-app/.gitignore +0 -9
- data/fixtures/empty-app/.rspec +0 -2
- data/fixtures/empty-app/README.md +0 -24
- data/fixtures/empty-app/Rakefile +0 -1
- data/fixtures/empty-app/cli-app.gemspec +0 -27
- data/fixtures/empty-app/lib/cli/app.rb +0 -9
- data/fixtures/empty-app/lib/cli/app/version.rb +0 -5
- data/fixtures/getting-started-app/.gitignore +0 -4
- data/fixtures/getting-started-app/Gemfile +0 -4
- data/fixtures/getting-started-app/README.md +0 -3
- data/fixtures/getting-started-app/features/support/env.rb +0 -1
- data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
data/CONTRIBUTING.md
CHANGED
|
@@ -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
|
|
132
|
+
rake spec
|
|
133
133
|
# Run Cucumber features
|
|
134
|
-
rake
|
|
134
|
+
rake cucumber
|
|
135
135
|
# Run Cucumber features which are "WORK IN PROGRESS" and are allowed to fail
|
|
136
|
-
rake
|
|
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
|
|
197
|
+
bundle exec rake build
|
|
199
198
|
# Build and install your copy
|
|
200
|
-
bundle exec rake
|
|
199
|
+
bundle exec rake install
|
|
201
200
|
# Build and install your copy without network access
|
|
202
|
-
bundle exec rake
|
|
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
|
-
|
|
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-
|
|
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
|
-
[](https://raw.githubusercontent.com/cucumber/aruba/master/LICENSE)
|
|
2
2
|
[](https://app.cucumber.pro/projects/aruba)
|
|
3
3
|
[](http://badge.fury.io/rb/aruba)
|
|
4
4
|
[](https://codeclimate.com/github/cucumber/aruba)
|
|
5
5
|
[](https://cucumber.io/support)
|
|
6
6
|
|
|
7
|
-
[ 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
|
+
[](https://travis-ci.org/cucumber/aruba)
|
|
8
|
+
[](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
|
-
|
|
14
|
+
```ruby
|
|
17
15
|
gem 'aruba'
|
|
18
|
-
|
|
16
|
+
```
|
|
19
17
|
|
|
20
18
|
And then execute:
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
```bash
|
|
23
21
|
bundle
|
|
24
|
-
|
|
22
|
+
```
|
|
25
23
|
|
|
26
24
|
Or install it yourself as:
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
```bash
|
|
29
27
|
gem install aruba
|
|
30
|
-
|
|
28
|
+
```
|
|
31
29
|
|
|
32
30
|
## Usage
|
|
33
31
|
|
|
34
|
-
### As a user getting started with
|
|
32
|
+
### As a user getting started with Aruba
|
|
35
33
|
|
|
36
|
-
Our most current documentation to get started with
|
|
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
|
|
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
|
|
44
|
+
information about how to write feature files in Gherkin.
|
|
45
45
|
|
|
46
46
|
* **RSpec**:
|
|
47
47
|
|
|
48
|
-
If you want to use
|
|
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
|
|
52
|
+
The documentation for minitest can be found [here](http://docs.seattlerb.org/minitest/).
|
|
53
53
|
|
|
54
|
-
### As a developer getting started with
|
|
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/
|
|
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 [
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
##
|
|
100
|
+
## License
|
|
91
101
|
|
|
92
|
-
|
|
93
|
-
| ------ | ------ | ------ |
|
|
94
|
-
| master | [](https://travis-ci.org/cucumber/aruba) | [](https://ci.appveyor.com/project/cucumberbdd/aruba/branch/master)|
|
|
95
|
-
| still | [](https://travis-ci.org/cucumber/aruba) | [](https://ci.appveyor.com/project/cucumberbdd/aruba/branch/still)
|
|
102
|
+
See the file [LICENSE](LICENSE).
|
data/exe/aruba
CHANGED
data/lib/aruba/api.rb
CHANGED
|
@@ -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
|
|
23
|
-
include
|
|
24
|
-
include
|
|
25
|
-
include
|
|
26
|
-
include
|
|
27
|
-
include
|
|
22
|
+
include Core
|
|
23
|
+
include Commands
|
|
24
|
+
include Environment
|
|
25
|
+
include Filesystem
|
|
26
|
+
include Text
|
|
27
|
+
include Bundler
|
|
28
28
|
end
|
|
29
29
|
end
|
data/lib/aruba/api/bundler.rb
CHANGED
|
@@ -7,7 +7,7 @@ module Aruba
|
|
|
7
7
|
|
|
8
8
|
# Unset variables used by bundler
|
|
9
9
|
def unset_bundler_env_vars
|
|
10
|
-
%w
|
|
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
|
data/lib/aruba/api/commands.rb
CHANGED
|
@@ -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
|
-
|
|
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]
|
|
171
|
+
# @param [Hash] opts
|
|
148
172
|
# Options for aruba
|
|
149
173
|
#
|
|
150
|
-
# @option
|
|
174
|
+
# @option opts [Boolean] :fail_on_error
|
|
151
175
|
# Should aruba fail on error?
|
|
152
176
|
#
|
|
153
|
-
# @option
|
|
177
|
+
# @option opts [Numeric] :exit_timeout
|
|
154
178
|
# Timeout for execution
|
|
155
179
|
#
|
|
156
|
-
# @option
|
|
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]
|
|
202
|
-
io_wait_timeout = opts[:io_wait_timeout]
|
|
203
|
-
stop_signal = opts[:stop_signal]
|
|
204
|
-
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
|
-
|
|
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
|
data/lib/aruba/api/core.rb
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
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
|
-
|
|
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' =>
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
177
|
+
File.expand_path(file_name)
|
|
155
178
|
end
|
|
156
179
|
|
|
157
|
-
|
|
158
|
-
|
|
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?
|
|
188
|
+
elsif absolute?(file_name)
|
|
162
189
|
unless aruba.config.allow_absolute_paths
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|