aruba 0.11.2 → 0.12.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 640c6d6d67827e65e671ee40fea3fd3bd8b40138
4
- data.tar.gz: a726ab79cf1c258322423cccbcb8ab325a5af0d6
3
+ metadata.gz: a03bef8bda8e7603e1f838f59617c33ed241a6c5
4
+ data.tar.gz: 2400a8a46277213356de308fc2be9bff799de045
5
5
  SHA512:
6
- metadata.gz: 6c061409af3d9b559ba62ad74c7dba3af505dfd87224b246a0ec4d7f11a1d82631e827ae0755eb93bbec0e0c6c12099ff634d3a90938edabf1029f4a0a572ec4
7
- data.tar.gz: e05cb84b2085d874698c2aaf34b6d91f94005d421e5d22cefddfd3b65b9ee366d8ffde4f8315f0fa7232db7d89fba51d31923954776a5ef37ccee0d3afcf9163
6
+ metadata.gz: dee2acfaddc2865642aacb0d4dd464aa8e9656e9485511e16a78568b7305a60a8fb79c0529c86c493dab163e8f12d9549eda3f2638c589201c04630e6ea11462
7
+ data.tar.gz: 07adf9438e735fd1d9bc85149b95ae4f51795d193676f793f0e516f9dbff80f99d75380e081cde6bd9eea78c821a4d796016b1e54db693b8d7eb5584fad47cf0
data/.travis.yml CHANGED
@@ -7,27 +7,28 @@ rvm:
7
7
  - 1.9.2
8
8
  - 1.9.3
9
9
  - 2.0.0
10
- - 2.1.7
11
- - 2.2.3
10
+ - 2.1.8
11
+ - 2.2.4
12
+ - 2.3.0
12
13
  - jruby
13
14
  - jruby-20mode
14
15
  - jruby-21mode
15
16
  - rbx
16
17
  matrix:
17
18
  include:
18
- - rvm: jruby-9.0.0.0
19
+ - rvm: jruby-9.0.1.0
19
20
  env: JRUBY_OPTS='--dev'
20
- - rvm: jruby-9.0.0.0-20mode
21
+ - rvm: jruby-9.0.1.0-20mode
21
22
  env: JRUBY_OPTS='--dev'
22
- - rvm: jruby-9.0.0.0-21mode
23
+ - rvm: jruby-9.0.1.0-21mode
23
24
  env: JRUBY_OPTS='--dev'
24
25
  allow_failures:
25
26
  - rvm: rbx
26
- - rvm: jruby-9.0.0.0
27
+ - rvm: jruby-9.0.1.0
27
28
  env: JRUBY_OPTS='--dev'
28
- - rvm: jruby-9.0.0.0-20mode
29
+ - rvm: jruby-9.0.1.0-20mode
29
30
  env: JRUBY_OPTS='--dev'
30
- - rvm: jruby-9.0.0.0-21mode
31
+ - rvm: jruby-9.0.1.0-21mode
31
32
  env: JRUBY_OPTS='--dev'
32
33
  notifications:
33
34
  email:
data/History.md CHANGED
@@ -1,10 +1,17 @@
1
1
  # Latest Release
2
2
 
3
+ ## [v0.12.0](https://github.com/cucumber/aruba/compare/v0.11.2...v0.12.0)
4
+
5
+ * Add matcher to check if a command can be found in PATH (PR #336)
6
+ * Fixed issue with environment variables set by external libraries (fix #321,
7
+ issue #320)
8
+
9
+ # Old releases
10
+
3
11
  ## [v0.11.2](https://github.com/cucumber/aruba/compare/v0.11.1...v0.11.2)
4
12
 
5
13
  * Fixed problem with positional arguments in `#run_simple()` (issue #322)
6
14
 
7
- # Old releases
8
15
 
9
16
  ## [v0.11.1](https://github.com/cucumber/aruba/compare/v0.11.0...v0.11.1)
10
17
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2015 Aslak Hellesøy, David Chelimsky, Mike Sassak, Jarl Friis, Matt Wynne, Dennis Günnewig
1
+ Copyright (c) 2010-2016 Aslak Hellesøy, David Chelimsky, Mike Sassak, Jarl Friis, Matt Wynne, Dennis Günnewig
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
@@ -219,8 +219,8 @@ A full documentation of the API can be found
219
219
 
220
220
  ## Contributing
221
221
 
222
- Please see the `CONTRIBUTING.md`.
222
+ Please see the [CONTRIBUTING](CONTRIBUTING.md) file.
223
223
 
224
224
  ## Copyright
225
225
 
226
- Copyright (c) 2010-2015 Aslak Hellesøy et al. See LICENSE for details.
226
+ Copyright (c) 2010-2016 Aslak Hellesøy et al. See [MIT License](LICENSE) for details.
data/aruba.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_runtime_dependency 'thor', '~> 0.19'
22
22
  s.add_runtime_dependency 'event-bus', '~> 0.2'
23
23
 
24
- s.add_development_dependency 'bundler', '~> 1.10.2'
24
+ s.add_development_dependency 'bundler', '~> 1.11'
25
25
 
26
26
  s.rubygems_version = ">= 1.6.1"
27
27
 
@@ -35,7 +35,7 @@ Use on ruby 1.8.7
35
35
  * Make sure you add something like that to your `Gemfile`. Otherwise you will
36
36
  get cucumber > 2 and this will fail on ruby 1.8.7
37
37
 
38
- gem 'cucumber', ~> '1.3.20'
38
+ gem 'cucumber', '~> 1.3.20'
39
39
 
40
40
  With aruba >= 1.0 there will be breaking changes. Make sure to read https://github.com/cucumber/aruba/blob/master/History.md for 1.0.0
41
41
  EOS
@@ -1,4 +1,4 @@
1
- Feature: Remove existing environment variable via API-method
1
+ Feature: Delete existing environment variable via API-method
2
2
 
3
3
  It is quite handy to modify the environment of a process. To make this
4
4
  possible, `aruba` provides several methods. One of these is
@@ -69,6 +69,46 @@ Feature: Set environment variable via API-method
69
69
  When I run `rspec`
70
70
  Then the specs should all pass
71
71
 
72
+ Scenario: Set variable via ENV
73
+
74
+ Given a file named "spec/environment_spec.rb" with:
75
+ """ruby
76
+ require 'spec_helper'
77
+
78
+ RSpec.describe 'Environment command', :type => :aruba do
79
+ before(:each) { ENV['REALLY_LONG_LONG_VARIABLE'] = '2' }
80
+
81
+ before(:each) { run('env') }
82
+ before(:each) { stop_all_commands }
83
+
84
+ it { expect(last_command_started.output).to include 'REALLY_LONG_LONG_VARIABLE=2' }
85
+ end
86
+ """
87
+ When I run `rspec`
88
+ Then the specs should all pass
89
+
90
+ Scenario: Existing variable set in before block in RSpec
91
+
92
+ Setting environment variables with `#set_environment_variable('VAR', 'value')` takes
93
+ precedence before setting variables with `ENV['VAR'] = 'value'`.
94
+
95
+ Given a file named "spec/environment_spec.rb" with:
96
+ """ruby
97
+ require 'spec_helper'
98
+
99
+ RSpec.describe 'Environment command', :type => :aruba do
100
+ before(:each) { set_environment_variable 'REALLY_LONG_LONG_VARIABLE', '1' }
101
+ before(:each) { ENV['REALLY_LONG_LONG_VARIABLE'] = '2' }
102
+
103
+ before(:each) { run('env') }
104
+ before(:each) { stop_all_commands }
105
+
106
+ it { expect(last_command_started.output).to include 'REALLY_LONG_LONG_VARIABLE=1' }
107
+ end
108
+ """
109
+ When I run `rspec`
110
+ Then the specs should all pass
111
+
72
112
  Scenario: Run some ruby code in code with previously set environment
73
113
 
74
114
  The `#with_environment`-block makes the change environment temporary
@@ -304,3 +344,33 @@ Feature: Set environment variable via API-method
304
344
  """
305
345
  When I run `rspec`
306
346
  Then the specs should all pass
347
+
348
+ Scenario: External ruby file / ruby gem modifying ENV
349
+
350
+ There are some Rubygems around which need to modify ENV['NODE_PATH'] like
351
+ [`ruby-stylus`](https://github.com/forgecrafted/ruby-stylus/blob/e7293362dc8cbf550f7c317d721ba6b9087e8833/lib/stylus.rb#L168).
352
+ This is supported by aruba as well.
353
+
354
+ Given a file named "spec/environment_spec.rb" with:
355
+ """ruby
356
+ require 'spec_helper'
357
+
358
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
359
+
360
+ RSpec.describe 'Environment command', :type => :aruba do
361
+ before(:each) do
362
+ require 'my_library'
363
+ end
364
+
365
+ before(:each) { run('env') }
366
+ before(:each) { stop_all_commands }
367
+
368
+ it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=1' }
369
+ end
370
+ """
371
+ And a file named "lib/my_library.rb" with:
372
+ """
373
+ ENV['LONG_LONG_VARIABLE'] = '1'
374
+ """
375
+ When I run `rspec`
376
+ Then the specs should all pass
@@ -0,0 +1,129 @@
1
+ Feature: Define default process environment
2
+ Say you want to have a default set of environment variables, then use this
3
+ code.
4
+
5
+ ~~~ruby
6
+ Aruba.configure do |config|
7
+ config.command_runtime_environment = { 'MY_VARIABLE' => 'x' }
8
+ end
9
+ ~~~
10
+
11
+ This can be changed via `#set_environment_variable`,
12
+ `#append_environment_variable`, `#delete_environment_variable` or
13
+ `#prepend_environment_variable`.
14
+
15
+ Background:
16
+ Given I use the fixture "cli-app"
17
+
18
+ Scenario: Overwrite existing variable with new default value
19
+ Given a file named "spec/environment_spec.rb" with:
20
+ """ruby
21
+ require 'spec_helper'
22
+
23
+ ENV['LONG_LONG_VARIABLE'] = 'y'
24
+
25
+ Aruba.configure do |config|
26
+ config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
27
+ end
28
+
29
+ RSpec.describe 'Environment command', :type => :aruba do
30
+ before(:each) { run('env') }
31
+ before(:each) { stop_all_commands }
32
+
33
+ it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=x' }
34
+ end
35
+ """
36
+ When I run `rspec`
37
+ Then the specs should all pass
38
+
39
+ Scenario: Overwrite default value for variable
40
+ Given a file named "spec/environment_spec.rb" with:
41
+ """ruby
42
+ require 'spec_helper'
43
+
44
+ ENV['LONG_LONG_VARIABLE'] = 'y'
45
+
46
+ Aruba.configure do |config|
47
+ config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
48
+ end
49
+
50
+ RSpec.describe 'Environment command', :type => :aruba do
51
+ before(:each) { set_environment_variable 'LONG_LONG_VARIABLE', 'z' }
52
+
53
+ before(:each) { run('env') }
54
+ before(:each) { stop_all_commands }
55
+
56
+ it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=z' }
57
+ end
58
+ """
59
+ When I run `rspec`
60
+ Then the specs should all pass
61
+
62
+ Scenario: Append value to default value
63
+ Given a file named "spec/environment_spec.rb" with:
64
+ """ruby
65
+ require 'spec_helper'
66
+
67
+ ENV['LONG_LONG_VARIABLE'] = 'y'
68
+
69
+ Aruba.configure do |config|
70
+ config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
71
+ end
72
+
73
+ RSpec.describe 'Environment command', :type => :aruba do
74
+ before(:each) { append_environment_variable 'LONG_LONG_VARIABLE', 'z' }
75
+
76
+ before(:each) { run('env') }
77
+ before(:each) { stop_all_commands }
78
+
79
+ it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=xz' }
80
+ end
81
+ """
82
+ When I run `rspec`
83
+ Then the specs should all pass
84
+
85
+ Scenario: Prepend value
86
+ Given a file named "spec/environment_spec.rb" with:
87
+ """ruby
88
+ require 'spec_helper'
89
+
90
+ ENV['LONG_LONG_VARIABLE'] = 'y'
91
+
92
+ Aruba.configure do |config|
93
+ config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
94
+ end
95
+
96
+ RSpec.describe 'Environment command', :type => :aruba do
97
+ before(:each) { prepend_environment_variable 'LONG_LONG_VARIABLE', 'z' }
98
+
99
+ before(:each) { run('env') }
100
+ before(:each) { stop_all_commands }
101
+
102
+ it { expect(last_command_started.output).to include 'LONG_LONG_VARIABLE=zx' }
103
+ end
104
+ """
105
+ When I run `rspec`
106
+ Then the specs should all pass
107
+
108
+ Scenario: Remove variable from default set of variables
109
+ Given a file named "spec/environment_spec.rb" with:
110
+ """ruby
111
+ require 'spec_helper'
112
+
113
+ ENV['LONG_LONG_VARIABLE'] = 'y'
114
+
115
+ Aruba.configure do |config|
116
+ config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
117
+ end
118
+
119
+ RSpec.describe 'Environment command', :type => :aruba do
120
+ before(:each) { delete_environment_variable 'LONG_LONG_VARIABLE' }
121
+
122
+ before(:each) { run('env') }
123
+ before(:each) { stop_all_commands }
124
+
125
+ it { expect(last_command_started.output).not_to include 'LONG_LONG_VARIABLE' }
126
+ end
127
+ """
128
+ When I run `rspec`
129
+ Then the specs should all pass
@@ -0,0 +1,115 @@
1
+ Feature: Check if command can be found in PATH
2
+
3
+ If you need to check if a given command can be found in path, you can use the
4
+ `be_an_existing_executable`-matcher.
5
+
6
+ ```ruby
7
+ require 'spec_helper'
8
+
9
+ RSpec.describe 'Check if command can be found in PATH', :type => :aruba do
10
+ let(:file) { 'file.sh' }
11
+ before(:each) { touch(file) }
12
+ before(:each) { chmod(0755, file) }
13
+ before(:each) { prepend_environment_variable('PATH', format('%s:', expand_path('.')) }
14
+
15
+ it { expect(file).to be_an_existing_executable }
16
+ end
17
+ ```
18
+
19
+ Background:
20
+ Given I use a fixture named "cli-app"
21
+
22
+ Scenario: Expect single existing executable file
23
+ Given a file named "spec/existing_executable_spec.rb" with:
24
+ """
25
+ require 'spec_helper'
26
+
27
+ RSpec.describe 'Check if command can be found in PATH', :type => :aruba do
28
+ let(:file) { 'file.sh' }
29
+
30
+ before(:each) { touch(file) }
31
+ before(:each) { chmod(0755, file) }
32
+ before(:each) { prepend_environment_variable('PATH', format('%s:', expand_path('.'))) }
33
+
34
+ it { expect(file).to be_a_command_found_in_path }
35
+ end
36
+ """
37
+ When I run `rspec`
38
+ Then the specs should all pass
39
+
40
+ Scenario: Expect single non-existing executable file
41
+ Given a file named "spec/existing_executable_spec.rb" with:
42
+ """
43
+ require 'spec_helper'
44
+
45
+ RSpec.describe 'Check if command can be found in PATH', :type => :aruba do
46
+ let(:file) { 'file.sh' }
47
+
48
+ before(:each) { prepend_environment_variable('PATH', format('%s:', expand_path('.'))) }
49
+
50
+ it { expect(file).not_to be_a_command_found_in_path }
51
+ end
52
+ """
53
+ When I run `rspec`
54
+ Then the specs should all pass
55
+
56
+ Scenario: Expect single non-executable file
57
+ Given a file named "spec/existing_executable_spec.rb" with:
58
+ """
59
+ require 'spec_helper'
60
+
61
+ RSpec.describe 'Check if command can be found in PATH', :type => :aruba do
62
+ let(:file) { 'file.sh' }
63
+
64
+ before(:each) { touch(file) }
65
+ before(:each) { prepend_environment_variable('PATH', format('%s:', expand_path('.'))) }
66
+
67
+ it { expect(file).not_to be_a_command_found_in_path }
68
+ end
69
+ """
70
+ When I run `rspec`
71
+ Then the specs should all pass
72
+
73
+ Scenario: Expect multiple existing executable files
74
+ Given a file named "spec/existing_executable_spec.rb" with:
75
+ """
76
+ require 'spec_helper'
77
+
78
+ RSpec.describe 'Check if file exists and is an executable file', :type => :aruba do
79
+ let(:files) { %w(file1.sh file2.sh) }
80
+
81
+ before :each do
82
+ files.each do |f|
83
+ touch(f)
84
+ chmod(0755, f)
85
+ end
86
+ end
87
+
88
+ before(:each) { prepend_environment_variable('PATH', format('%s:', expand_path('.'))) }
89
+
90
+ it { expect(files).to all be_a_command_found_in_path }
91
+ end
92
+ """
93
+ When I run `rspec`
94
+ Then the specs should all pass
95
+
96
+ Scenario: Expect a least one existing executable file
97
+ Given a file named "spec/existing_executable_spec.rb" with:
98
+ """
99
+ require 'spec_helper'
100
+
101
+ RSpec.describe 'Check if file exists and is an executable file', :type => :aruba do
102
+ let(:files) { %w(file1.sh file2.sh) }
103
+
104
+ before :each do
105
+ touch(files.first)
106
+ chmod(0755, files.first)
107
+ end
108
+
109
+ before(:each) { prepend_environment_variable('PATH', format('%s:', expand_path('.'))) }
110
+
111
+ it { expect(files).to include a_command_found_in_path }
112
+ end
113
+ """
114
+ When I run `rspec`
115
+ Then the specs should all pass
@@ -9,6 +9,7 @@ Feature: Check if path exists and is an executable file
9
9
  RSpec.describe 'Check if file exists and is an executable file', :type => :aruba do
10
10
  let(:file) { 'file.txt' }
11
11
  before(:each) { touch(file) }
12
+ before(:each) { chmod(0755, file) }
12
13
 
13
14
  it { expect(file).to be_an_existing_executable }
14
15
  end
@@ -164,7 +164,7 @@ module Aruba
164
164
  @commands ||= []
165
165
  @commands << cmd
166
166
 
167
- environment = aruba.environment.to_h
167
+ environment = aruba.environment
168
168
  working_directory = expand_path('.')
169
169
  event_bus = aruba.event_bus
170
170
 
@@ -202,7 +202,7 @@ module Aruba
202
202
  :exit_timeout => exit_timeout,
203
203
  :io_wait_timeout => io_wait_timeout,
204
204
  :working_directory => working_directory,
205
- :environment => environment,
205
+ :environment => environment.to_hash,
206
206
  :main_class => main_class,
207
207
  :stop_signal => stop_signal,
208
208
  :startup_wait_time => startup_wait_time,
@@ -217,6 +217,7 @@ module Aruba
217
217
  end
218
218
 
219
219
  aruba.config.before(:command, self, command)
220
+
220
221
  command.start
221
222
 
222
223
  aruba.announcer.announce(:stop_signal, command.pid, stop_signal) if stop_signal
@@ -179,8 +179,10 @@ module Aruba
179
179
  def with_environment(env = {}, &block)
180
180
  old_aruba_env = aruba.environment.to_h
181
181
 
182
+ # make sure the old environment is really restored in "ENV"
182
183
  Aruba.platform.with_environment aruba.environment.update(env).to_h, &block
183
184
  ensure
185
+ # make sure the old environment is really restored in "aruba.environment"
184
186
  aruba.environment.clear
185
187
  aruba.environment.update old_aruba_env
186
188
  end
data/lib/aruba/config.rb CHANGED
@@ -36,7 +36,7 @@ module Aruba
36
36
  option_accessor :io_wait_timeout, :contract => { Num => Num }, :default => 0.1
37
37
  option_accessor :startup_wait_time, :contract => { Num => Num }, :default => 0
38
38
  option_accessor :fixtures_directories, :contract => { Array => ArrayOf[String] }, :default => %w(features/fixtures spec/fixtures test/fixtures fixtures)
39
- option_accessor :command_runtime_environment, :contract => { Hash => Hash }, :default => ENV.to_hash.dup
39
+ option_accessor :command_runtime_environment, :contract => { Hash => Hash }, :default => ENV.to_hash
40
40
  # rubocop:disable Metrics/LineLength
41
41
  option_accessor(:command_search_paths, :contract => { ArrayOf[String] => ArrayOf[String] }) { |config| [File.join(config.root_directory.value, 'bin')] }
42
42
  # rubocop:enable Metrics/LineLength
@@ -10,9 +10,6 @@ if Aruba::VERSION >= '1.0.0'
10
10
  end
11
11
 
12
12
  Before do
13
- # this is ENV by default ...
14
- aruba.environment.update aruba.config.command_runtime_environment
15
-
16
13
  # ... so every change needs to be done later
17
14
  prepend_environment_variable 'PATH', aruba.config.command_search_paths.join(':') + ':'
18
15
  set_environment_variable 'HOME', aruba.config.home_directory
@@ -0,0 +1,36 @@
1
+ require 'rspec/expectations/version'
2
+
3
+ # @!method be_a_command_found_in_path
4
+ # This matchers checks if <command> can be found in path
5
+ #
6
+ # @return [TrueClass, FalseClass] The result
7
+ #
8
+ # false:
9
+ # * if command was not found in PATH
10
+ # true:
11
+ # * if command can be found in PATH
12
+ #
13
+ # @example Use matcher
14
+ #
15
+ # RSpec.describe do
16
+ # it { expect(cmd).to be_a_command_found_in_path }
17
+ # end
18
+ RSpec::Matchers.define :be_a_command_found_in_path do
19
+ match do |actual|
20
+ @actual = Shellwords.split(actual.commandline).first if actual.respond_to? :commandline
21
+
22
+ !which(@actual).nil?
23
+ end
24
+
25
+ failure_message do |actual|
26
+ format(%(expected that command "%s" can be found in PATH "#{ENV['PATH']}".), actual)
27
+ end
28
+
29
+ failure_message_when_negated do |actual|
30
+ format(%(expected that command "%s" cannot be found in PATH "#{ENV['PATH']}".), actual)
31
+ end
32
+ end
33
+
34
+ if RSpec::Expectations::Version::STRING >= '3.0'
35
+ RSpec::Matchers.alias_matcher :a_command_found_in_path, :be_a_command_found_in_path
36
+ end
@@ -4,17 +4,69 @@ module Aruba
4
4
  module Platforms
5
5
  # Abstract environment variables
6
6
  class UnixEnvironmentVariables
7
+ # Update environment
8
+ class UpdateAction
9
+ attr_reader :other_env, :block
10
+
11
+ def initialize(other_env, &block)
12
+ @other_env = other_env
13
+
14
+ if RUBY_VERSION <= '1.9.3'
15
+ # rubocop:disable Style/EachWithObject
16
+ @other_env = @other_env.to_hash.inject({}) { |a, (k, v)| a[k] = v.to_s; a }
17
+ # rubocop:enable Style/EachWithObject
18
+ else
19
+ @other_env = @other_env.to_h.each_with_object({}) { |(k, v), a| a[k] = v.to_s }
20
+ end
21
+
22
+ if block_given?
23
+ @block = block
24
+ else
25
+ @block = nil
26
+ end
27
+ end
28
+
29
+ def call(env)
30
+ if block
31
+ env.update(other_env, &block)
32
+ else
33
+ env.update(other_env)
34
+ end
35
+ end
36
+ end
37
+
38
+ # Remove variables from environment
39
+ class RemoveAction
40
+ attr_reader :variables
41
+
42
+ def initialize(variables)
43
+ @variables = Array(variables)
44
+ end
45
+
46
+ def call(env)
47
+ variables.each { |v| env.delete v }
48
+
49
+ env
50
+ end
51
+ end
52
+
7
53
  # We need to use this, because `nil` is a valid value as default
8
54
  UNDEFINED = Object.new.freeze
9
55
 
10
56
  private
11
57
 
12
- attr_reader :env
58
+ attr_reader :actions, :env
13
59
 
14
60
  public
15
61
 
16
- def initialize(env = ENV.to_hash)
17
- @env = Marshal.load(Marshal.dump(env))
62
+ def initialize(env = ENV)
63
+ @actions = []
64
+
65
+ if RUBY_VERSION < '2.0'
66
+ @env = env.to_hash
67
+ else
68
+ @env = env.to_h
69
+ end
18
70
  end
19
71
 
20
72
  # Update environment with other en
@@ -24,18 +76,10 @@ module Aruba
24
76
  #
25
77
  # @yield
26
78
  # Pass block to env
27
- def update(other_env, &block)
28
- if RUBY_VERSION <= '1.9.3'
29
- # rubocop:disable Style/EachWithObject
30
- other_env = other_env.to_hash.inject({}) { |a, (k, v)| a[k] = v.to_s; a }
31
- # rubocop:enable Style/EachWithObject
32
- else
33
- other_env = other_env.to_h.each_with_object({}) { |(k, v), a| a[k] = v.to_s }
34
- end
79
+ def update(other_env)
80
+ actions << UpdateAction.new(other_env)
35
81
 
36
- env.update(other_env, &block)
37
-
38
- self
82
+ UnixEnvironmentVariables.new(to_h)
39
83
  end
40
84
 
41
85
  # Fetch variable from environment
@@ -47,9 +91,9 @@ module Aruba
47
91
  # The default value used, if the variable is not defined
48
92
  def fetch(name, default = UNDEFINED)
49
93
  if default == UNDEFINED
50
- env.fetch name.to_s
94
+ to_h.fetch name.to_s
51
95
  else
52
- env.fetch name.to_s, default
96
+ to_h.fetch name.to_s, default
53
97
  end
54
98
  end
55
99
 
@@ -58,7 +102,7 @@ module Aruba
58
102
  # @param [#to_s] name
59
103
  # The name of the variable
60
104
  def key?(name)
61
- env.key? name.to_s
105
+ to_h.key? name.to_s
62
106
  end
63
107
 
64
108
  # Get value of variable
@@ -66,7 +110,7 @@ module Aruba
66
110
  # @param [#to_s] name
67
111
  # The name of the variable
68
112
  def [](name)
69
- env[name.to_s]
113
+ to_h[name.to_s]
70
114
  end
71
115
 
72
116
  # Set value of variable
@@ -77,9 +121,11 @@ module Aruba
77
121
  # @param [#to_s] value
78
122
  # The value of the variable
79
123
  def []=(name, value)
80
- env[name.to_s] = value.to_s
124
+ value = value.to_s
125
+
126
+ actions << UpdateAction.new(name.to_s => value)
81
127
 
82
- self
128
+ value
83
129
  end
84
130
 
85
131
  # Append value to variable
@@ -90,10 +136,12 @@ module Aruba
90
136
  # @param [#to_s] value
91
137
  # The value of the variable
92
138
  def append(name, value)
93
- name = name.to_s
94
- env[name] = env[name].to_s + value.to_s
139
+ name = name.to_s
140
+ value = self[name].to_s + value.to_s
141
+
142
+ actions << UpdateAction.new(name => value )
95
143
 
96
- self
144
+ value
97
145
  end
98
146
 
99
147
  # Prepend value to variable
@@ -104,10 +152,12 @@ module Aruba
104
152
  # @param [#to_s] value
105
153
  # The value of the variable
106
154
  def prepend(name, value)
107
- name = name.to_s
108
- env[name] = value.to_s + env[name].to_s
155
+ name = name.to_s
156
+ value = value.to_s + self[name].to_s
109
157
 
110
- self
158
+ actions << UpdateAction.new(name => value)
159
+
160
+ value
111
161
  end
112
162
 
113
163
  # Delete variable
@@ -115,9 +165,24 @@ module Aruba
115
165
  # @param [#to_s] name
116
166
  # The name of the variable
117
167
  def delete(name)
118
- env.delete name.to_s
168
+ # Rescue value, before it is deleted
169
+ value = to_h[name.to_s]
170
+
171
+ actions << RemoveAction.new(name.to_s)
172
+
173
+ value
174
+ end
175
+
176
+ # Pass on checks
177
+ def method_missing(name, *args, &block)
178
+ super unless to_h.respond_to? name
179
+
180
+ to_h.send name, *args, &block
181
+ end
119
182
 
120
- self
183
+ # Check for respond_to
184
+ def respond_to_missing?(name, _private)
185
+ to_h.respond_to? name
121
186
  end
122
187
 
123
188
  # Convert to hash
@@ -126,17 +191,31 @@ module Aruba
126
191
  # A new hash from environment
127
192
  def to_h
128
193
  if RUBY_VERSION < '2.0'
129
- Marshal.load(Marshal.dump(env.to_hash))
194
+ Marshal.load(Marshal.dump(prepared_environment.to_hash))
130
195
  else
131
- Marshal.load(Marshal.dump(env.to_h))
196
+ Marshal.load(Marshal.dump(prepared_environment.to_h))
132
197
  end
133
198
  end
134
199
 
135
200
  # Reset environment
136
201
  def clear
137
- env.clear
202
+ value = to_h
138
203
 
139
- self
204
+ actions.clear
205
+
206
+ value
207
+ end
208
+
209
+ private
210
+
211
+ def prepared_environment
212
+ if RUBY_VERSION <= '1.9.3'
213
+ # rubocop:disable Style/EachWithObject
214
+ actions.inject(ENV.to_hash.merge(env)) { |a, e| e.call(a) }
215
+ # rubocop:enable Style/EachWithObject
216
+ else
217
+ actions.each_with_object(ENV.to_hash.merge(env)) { |e, a| a = e.call(a) }
218
+ end
140
219
  end
141
220
  end
142
221
  end
@@ -34,7 +34,7 @@ module Aruba
34
34
  end
35
35
 
36
36
  def environment_variables
37
- UnixEnvironmentVariables.new
37
+ UnixEnvironmentVariables
38
38
  end
39
39
 
40
40
  def command_string
@@ -34,14 +34,14 @@ module Aruba
34
34
  # will always work.
35
35
  class WindowsEnvironmentVariables < UnixEnvironmentVariables
36
36
  def initialize(env = ENV.to_hash)
37
- @env = Marshal.load(Marshal.dump(env))
37
+ @actions = []
38
38
 
39
39
  if RUBY_VERSION <= '1.9.3'
40
40
  # rubocop:disable Style/EachWithObject
41
- @env = @env.inject({}) { |a, (k,v)| a[k.to_s.upcase] = v; a }
41
+ @env = env.inject({}) { |a, (k,v)| a[k.to_s.upcase] = v; a }
42
42
  # rubocop:enable Style/EachWithObject
43
43
  else
44
- @env = @env.each_with_object({}) { |(k,v), a| a[k.to_s.upcase] = v }
44
+ @env = env.each_with_object({}) { |(k,v), a| a[k.to_s.upcase] = v }
45
45
  end
46
46
  end
47
47
 
@@ -30,7 +30,7 @@ module Aruba
30
30
 
31
31
  # @see UnixPlatform#environment_variables
32
32
  def environment_variables
33
- WindowsEnvironmentVariables.new
33
+ WindowsEnvironmentVariables
34
34
  end
35
35
 
36
36
  # @see UnixPlatform#which
data/lib/aruba/rspec.rb CHANGED
@@ -91,14 +91,13 @@ RSpec.configure do |config|
91
91
  config.before :each do
92
92
  next unless self.class.include? Aruba::Api
93
93
 
94
- aruba.environment.update aruba.config.command_runtime_environment
95
- aruba.environment.prepend 'PATH', aruba.config.command_search_paths.join(':') + ':'
94
+ prepend_environment_variable 'PATH', aruba.config.command_search_paths.join(':') + ':'
96
95
  end
97
96
 
98
97
  # Use configured home directory as HOME
99
98
  config.before :each do |example|
100
99
  next unless self.class.include? Aruba::Api
101
100
 
102
- aruba.environment['HOME'] = aruba.config.home_directory
101
+ set_environment_variable 'HOME', aruba.config.home_directory
103
102
  end
104
103
  end
data/lib/aruba/runtime.rb CHANGED
@@ -40,14 +40,15 @@ module Aruba
40
40
  attr_accessor :config, :environment, :logger, :command_monitor, :announcer, :event_bus
41
41
 
42
42
  def initialize(opts = {})
43
- @environment = opts.fetch(:environment, Aruba.platform.environment_variables)
44
- @event_bus = ::Event::Bus.new(::Event::NameResolver.new(Aruba::Events))
43
+ @event_bus = ::Event::Bus.new(::Event::NameResolver.new(Aruba::Events))
45
44
  @announcer = opts.fetch(:announcer, Aruba.platform.announcer.new)
46
-
47
- @config = opts.fetch(:config, ConfigWrapper.new(Aruba.config.make_copy, @event_bus))
45
+ @config = opts.fetch(:config, ConfigWrapper.new(Aruba.config.make_copy, @event_bus))
46
+ @environment = opts.fetch(:environment, Aruba.platform.environment_variables.new)
48
47
  @current_directory = ArubaPath.new(@config.working_directory)
49
48
  @root_directory = ArubaPath.new(@config.root_directory)
50
49
 
50
+ @environment.update(@config.command_runtime_environment)
51
+
51
52
  if Aruba::VERSION < '1'
52
53
  @command_monitor = opts.fetch(:command_monitor, Aruba.platform.command_monitor.new(:announcer => @announcer))
53
54
  else
data/lib/aruba/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Aruba
2
- VERSION = '0.11.2'
2
+ VERSION = '0.12.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aruba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aslak Hellesøy
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2015-12-09 00:00:00.000000000 Z
16
+ date: 2016-01-03 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: cucumber
@@ -119,14 +119,14 @@ dependencies:
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: 1.10.2
122
+ version: '1.11'
123
123
  type: :development
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: 1.10.2
129
+ version: '1.11'
130
130
  description: Extension for popular TDD and BDD frameworks like "Cucumber", "RSpec"
131
131
  and "Minitest" to make testing commandline applications meaningful, easy and fun.
132
132
  email: cukes@googlegroups.com
@@ -168,8 +168,8 @@ files:
168
168
  - features/api/command/which.feature
169
169
  - features/api/core/expand_path.feature
170
170
  - features/api/environment/append_environment_variable.feature
171
+ - features/api/environment/delete_environment_variable.feature
171
172
  - features/api/environment/prepend_environment_variable.feature
172
- - features/api/environment/remove_environment_variable.feature
173
173
  - features/api/environment/set_environment_variable.feature
174
174
  - features/api/filesystem/cd.feature
175
175
  - features/api/filesystem/create_directory.feature
@@ -187,6 +187,7 @@ files:
187
187
  - features/api/text/unescape_text.feature
188
188
  - features/cli/console.feature
189
189
  - features/cli/init.feature
190
+ - features/configuration/command_runtime_environment.feature
190
191
  - features/configuration/console_history_file.feature
191
192
  - features/configuration/exit_timeout.feature
192
193
  - features/configuration/fixtures_directories.feature
@@ -212,6 +213,7 @@ files:
212
213
  - features/hooks/before/command.feature
213
214
  - features/matchers/collection/include_an_object.feature
214
215
  - features/matchers/directory/have_sub_directory.feature
216
+ - features/matchers/file/be_a_command_found_in_path.feature
215
217
  - features/matchers/file/be_existing_executable.feature
216
218
  - features/matchers/file/be_existing_file.feature
217
219
  - features/matchers/file/have_file_content.feature
@@ -345,6 +347,7 @@ files:
345
347
  - lib/aruba/matchers/directory/have_sub_directory.rb
346
348
  - lib/aruba/matchers/environment.rb
347
349
  - lib/aruba/matchers/file.rb
350
+ - lib/aruba/matchers/file/be_a_command_found_in_path.rb
348
351
  - lib/aruba/matchers/file/be_an_existing_executable.rb
349
352
  - lib/aruba/matchers/file/be_an_existing_file.rb
350
353
  - lib/aruba/matchers/file/have_file_content.rb
@@ -450,7 +453,7 @@ post_install_message: |
450
453
  * Make sure you add something like that to your `Gemfile`. Otherwise you will
451
454
  get cucumber > 2 and this will fail on ruby 1.8.7
452
455
 
453
- gem 'cucumber', ~> '1.3.20'
456
+ gem 'cucumber', '~> 1.3.20'
454
457
 
455
458
  With aruba >= 1.0 there will be breaking changes. Make sure to read https://github.com/cucumber/aruba/blob/master/History.md for 1.0.0
456
459
  rdoc_options:
@@ -469,10 +472,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
469
472
  version: '0'
470
473
  requirements: []
471
474
  rubyforge_project:
472
- rubygems_version: 2.4.5.1
475
+ rubygems_version: 2.5.1
473
476
  signing_key:
474
477
  specification_version: 4
475
- summary: aruba-0.11.2
478
+ summary: aruba-0.12.0
476
479
  test_files:
477
480
  - features/api/command/find_command.feature
478
481
  - features/api/command/last_command_started.feature
@@ -486,8 +489,8 @@ test_files:
486
489
  - features/api/command/which.feature
487
490
  - features/api/core/expand_path.feature
488
491
  - features/api/environment/append_environment_variable.feature
492
+ - features/api/environment/delete_environment_variable.feature
489
493
  - features/api/environment/prepend_environment_variable.feature
490
- - features/api/environment/remove_environment_variable.feature
491
494
  - features/api/environment/set_environment_variable.feature
492
495
  - features/api/filesystem/cd.feature
493
496
  - features/api/filesystem/create_directory.feature
@@ -505,6 +508,7 @@ test_files:
505
508
  - features/api/text/unescape_text.feature
506
509
  - features/cli/console.feature
507
510
  - features/cli/init.feature
511
+ - features/configuration/command_runtime_environment.feature
508
512
  - features/configuration/console_history_file.feature
509
513
  - features/configuration/exit_timeout.feature
510
514
  - features/configuration/fixtures_directories.feature
@@ -530,6 +534,7 @@ test_files:
530
534
  - features/hooks/before/command.feature
531
535
  - features/matchers/collection/include_an_object.feature
532
536
  - features/matchers/directory/have_sub_directory.feature
537
+ - features/matchers/file/be_a_command_found_in_path.feature
533
538
  - features/matchers/file/be_existing_executable.feature
534
539
  - features/matchers/file/be_existing_file.feature
535
540
  - features/matchers/file/have_file_content.feature