aruba 0.9.0.pre → 0.9.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -3
  3. data/History.md +61 -19
  4. data/README.md +10 -6
  5. data/TODO.md +6 -1
  6. data/cucumber.yml +10 -6
  7. data/features/.nav +72 -0
  8. data/features/announce.feature +203 -0
  9. data/features/api/command/extract_text.feature +10 -0
  10. data/features/api/command/run.feature +6 -6
  11. data/features/api/command/stop_all_commands.feature +53 -0
  12. data/features/api/command/terminate_all_commands.feature +53 -0
  13. data/features/api/command/unescape_text.feature +12 -0
  14. data/features/api/command/which.feature +3 -3
  15. data/features/api/core/expand_path.feature +4 -4
  16. data/features/api/environment/append_environment_variable.feature +18 -8
  17. data/features/api/environment/prepend_environment_variable.feature +18 -8
  18. data/features/api/environment/set_environment_variable.feature +33 -16
  19. data/features/api/filesystem/cd.feature +23 -13
  20. data/features/api/filesystem/create_directory.feature +2 -2
  21. data/features/api/filesystem/disk_usage.feature +7 -6
  22. data/features/api/filesystem/does_exist.feature +2 -2
  23. data/features/api/filesystem/is_absolute.feature +2 -2
  24. data/features/api/filesystem/is_directory.feature +2 -2
  25. data/features/api/filesystem/is_file.feature +2 -2
  26. data/features/api/filesystem/is_relative.feature +2 -2
  27. data/features/api/filesystem/move.feature +119 -0
  28. data/features/cli/console.feature +3 -3
  29. data/features/commands/debug_command.feature +93 -0
  30. data/features/commands/environment_variables.feature +64 -0
  31. data/features/commands/flushing.feature +74 -0
  32. data/features/commands/interactive.feature +90 -0
  33. data/features/commands/output/all_output.feature +445 -0
  34. data/features/commands/output/stdout.feature +66 -0
  35. data/features/configuration/exit_timeout.feature +5 -5
  36. data/features/configuration/fixtures_directories.feature +3 -3
  37. data/features/configuration/fixtures_path_prefix.feature +1 -1
  38. data/features/configuration/home_directory.feature +4 -4
  39. data/features/configuration/io_timeout.feature +2 -2
  40. data/features/configuration/keep_ansi.feature +2 -2
  41. data/features/configuration/log_level.feature +3 -3
  42. data/features/configuration/physical_block_size.feature +3 -3
  43. data/features/configuration/usage.feature +159 -0
  44. data/features/core/cleanup_aruba_directory.feature +52 -0
  45. data/features/development/build.feature +16 -0
  46. data/features/development/test.feature +24 -0
  47. data/features/file_system_commands.feature +12 -12
  48. data/features/getting_started/supported_programming_languages.feature +89 -0
  49. data/features/hooks/after/command.feature +1 -1
  50. data/features/hooks/before/command.feature +2 -2
  51. data/features/matchers/collection/include_an_object.feature +72 -0
  52. data/features/matchers/timeouts.feature +2 -2
  53. data/features/output.feature +60 -181
  54. data/features/step_definitions/aruba_dev_steps.rb +17 -10
  55. data/features/step_definitions/hooks.rb +11 -0
  56. data/features/steps/commands/exit_statuses.feature +3 -3
  57. data/features/steps/commands/run.feature +0 -15
  58. data/features/steps/filesystem/copy.feature +45 -0
  59. data/features/steps/filesystem/create_directory.feature +47 -0
  60. data/features/steps/filesystem/create_file.feature +53 -0
  61. data/features/steps/filesystem/file_content.feature +1 -1
  62. data/features/steps/filesystem/move.feature +45 -0
  63. data/features/steps/filesystem/overwrite_file.feature +72 -0
  64. data/features/steps/filesystem/use_fixture.feature +77 -0
  65. data/features/usage/install.feature +8 -0
  66. data/{features/fixtures → fixtures}/cli-app/.gitignore +0 -0
  67. data/{features/fixtures → fixtures}/cli-app/.rspec +0 -0
  68. data/{features/fixtures → fixtures}/cli-app/README.md +0 -0
  69. data/{features/fixtures → fixtures}/cli-app/Rakefile +0 -0
  70. data/{features/fixtures → fixtures}/cli-app/bin/cli +0 -0
  71. data/{features/fixtures → fixtures}/cli-app/cli-app.gemspec +0 -0
  72. data/{features/fixtures → fixtures}/cli-app/features/support/env.rb +0 -0
  73. data/{features/fixtures → fixtures}/cli-app/lib/cli/app.rb +0 -0
  74. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +15 -0
  75. data/{features/fixtures → fixtures}/cli-app/lib/cli/app/version.rb +0 -0
  76. data/{features/fixtures/empty-app → fixtures/cli-app}/script/console +3 -3
  77. data/{features/fixtures → fixtures}/cli-app/spec/spec_helper.rb +0 -0
  78. data/{features/fixtures → fixtures}/cli-app/spec/support/aruba.rb +0 -0
  79. data/{features/fixtures → fixtures}/copy/file.txt +0 -0
  80. data/{features/fixtures → fixtures}/empty-app/.gitignore +0 -0
  81. data/{features/fixtures → fixtures}/empty-app/.rspec +0 -0
  82. data/{features/fixtures → fixtures}/empty-app/README.md +0 -0
  83. data/{features/fixtures → fixtures}/empty-app/Rakefile +0 -0
  84. data/{features/fixtures → fixtures}/empty-app/bin/cli +0 -0
  85. data/{features/fixtures → fixtures}/empty-app/cli-app.gemspec +0 -0
  86. data/{features/fixtures → fixtures}/empty-app/lib/cli/app.rb +0 -0
  87. data/{features/fixtures → fixtures}/empty-app/lib/cli/app/version.rb +0 -0
  88. data/{features/fixtures/cli-app → fixtures/empty-app}/script/console +3 -3
  89. data/{features/fixtures → fixtures}/empty-app/spec/spec_helper.rb +0 -0
  90. data/{features/fixtures → fixtures}/fixtures-app/test.txt +0 -0
  91. data/fixtures/getting-started-app/.gitignore +4 -0
  92. data/fixtures/getting-started-app/Gemfile +4 -0
  93. data/fixtures/getting-started-app/README.md +3 -0
  94. data/fixtures/getting-started-app/features/support/env.rb +1 -0
  95. data/{features/fixtures → fixtures}/spawn_process/stderr.sh +0 -0
  96. data/lib/aruba/announcer.rb +6 -2
  97. data/lib/aruba/api.rb +0 -16
  98. data/lib/aruba/api/command.rb +64 -266
  99. data/lib/aruba/api/core.rb +24 -26
  100. data/lib/aruba/api/deprecated.rb +370 -12
  101. data/lib/aruba/api/filesystem.rb +64 -15
  102. data/lib/aruba/aruba_path.rb +4 -0
  103. data/lib/aruba/config.rb +1 -1
  104. data/lib/aruba/cucumber.rb +5 -449
  105. data/lib/aruba/cucumber/command.rb +378 -0
  106. data/lib/aruba/cucumber/core.rb +29 -0
  107. data/lib/aruba/cucumber/environment.rb +30 -0
  108. data/lib/aruba/cucumber/file.rb +210 -0
  109. data/lib/aruba/cucumber/hooks.rb +11 -14
  110. data/lib/aruba/cucumber/rvm.rb +3 -0
  111. data/lib/aruba/matchers/base/base_matcher.rb +94 -0
  112. data/lib/aruba/matchers/collection.rb +1 -0
  113. data/lib/aruba/matchers/collection/all_objects.rb +2 -0
  114. data/lib/aruba/matchers/collection/include_an_object.rb +120 -0
  115. data/lib/aruba/matchers/command/be_successfully_executed.rb +3 -3
  116. data/lib/aruba/matchers/command/have_exit_status.rb +2 -11
  117. data/lib/aruba/matchers/command/have_finished_in_time.rb +5 -5
  118. data/lib/aruba/matchers/command/have_output.rb +46 -0
  119. data/lib/aruba/matchers/command/have_output_on_stderr.rb +42 -0
  120. data/lib/aruba/matchers/command/have_output_on_stdout.rb +42 -0
  121. data/lib/aruba/matchers/command/have_output_size.rb +28 -0
  122. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +1 -1
  123. data/lib/aruba/matchers/file/be_an_existing_file.rb +1 -1
  124. data/lib/aruba/matchers/file/have_file_content.rb +1 -1
  125. data/lib/aruba/matchers/file/have_file_size.rb +2 -2
  126. data/lib/aruba/matchers/file/have_same_file_content.rb +1 -1
  127. data/lib/aruba/matchers/path/have_permissions.rb +1 -1
  128. data/lib/aruba/platforms/aruba_file_creator.rb +2 -3
  129. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +2 -3
  130. data/lib/aruba/platforms/determine_disk_usage.rb +23 -0
  131. data/lib/aruba/platforms/determine_file_size.rb +13 -0
  132. data/lib/aruba/platforms/disk_usage_calculator.rb +11 -0
  133. data/lib/aruba/platforms/local_environment.rb +15 -0
  134. data/lib/aruba/platforms/unix_environment_variables.rb +1 -1
  135. data/lib/aruba/platforms/unix_platform.rb +35 -14
  136. data/lib/aruba/process_monitor.rb +53 -7
  137. data/lib/aruba/processes/basic_process.rb +25 -5
  138. data/lib/aruba/processes/debug_process.rb +27 -25
  139. data/lib/aruba/processes/in_process.rb +7 -22
  140. data/lib/aruba/processes/spawn_process.rb +74 -31
  141. data/lib/aruba/rspec.rb +1 -6
  142. data/lib/aruba/version.rb +1 -1
  143. data/script/console +0 -1
  144. data/spec/aruba/api/environment/restore_env_spec.rb +65 -0
  145. data/spec/aruba/api/environment/set_env_spec.rb +42 -0
  146. data/spec/aruba/api/filesystem/file_size_spec.rb +28 -0
  147. data/spec/aruba/api_spec.rb +10 -7
  148. data/spec/aruba/matchers/command/have_output_size_spec.rb +25 -0
  149. data/spec/aruba/matchers/command_spec.rb +135 -4
  150. data/spec/aruba/spawn_process_spec.rb +1 -1
  151. metadata +107 -65
  152. data/.nav +0 -12
  153. data/features/debug.feature +0 -15
  154. data/features/fixtures/cli-app/spec/cli/app_spec.rb +0 -7
  155. data/features/flushing.feature +0 -26
  156. data/features/interactive.feature +0 -66
  157. data/features/no_clobber.feature +0 -25
  158. data/lib/aruba/disk_usage_calculator.rb +0 -7
@@ -11,50 +11,52 @@ module Aruba
11
11
 
12
12
  # rubocop:disable Metrics/MethodLength
13
13
  # rubocop:disable Metrics/CyclomaticComplexity
14
- def run!
15
- # rubocop:disable Metrics/LineLength
16
- fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) unless which(command)
17
- # rubocop:enable Metrics/LineLength
18
-
19
- if RUBY_VERSION < '1.9'
20
- begin
21
- old_env = ENV.to_hash.dup
22
- ENV.update environment
23
-
24
- Dir.chdir @working_directory do
25
- @exit_status = system(@cmd) ? 0 : 1
26
- end
27
- ensure
28
- ENV.clear
29
- ENV.update old_env
14
+ def start
15
+ Dir.chdir @working_directory do
16
+ Aruba.platform.with_environment(environment) do
17
+ @exit_status = system(command, *arguments) ? 0 : 1
30
18
  end
31
- elsif RUBY_VERSION < '2'
32
- Dir.chdir @working_directory do
33
- @exit_status = system(environment, @cmd) ? 0 : 1
34
- end
35
- else
36
- @exit_status = system(environment, @cmd, :chdir => @working_directory) ? 0 : 1
37
19
  end
38
20
  end
39
21
  # rubocop:enable Metrics/CyclomaticComplexity
40
22
  # rubocop:enable Metrics/MethodLength
41
23
 
24
+ # Return stdin
25
+ #
26
+ # @return [NilClass]
27
+ # Nothing
42
28
  def stdin(*); end
43
29
 
30
+ # Return stdout
31
+ #
32
+ # @return [String]
33
+ # A predefined string to make users aware they are using the DebugProcess
44
34
  def stdout(*)
45
- ''
35
+ 'This is the debug launcher on STDOUT. If this output is unexpected, please check your setup.'
46
36
  end
47
37
 
38
+ # Return stderr
39
+ #
40
+ # @return [String]
41
+ # A predefined string to make users aware they are using the DebugProcess
48
42
  def stderr(*)
49
- ''
43
+ 'This is the debug launcher on STDERR. If this output is unexpected, please check your setup.'
50
44
  end
51
45
 
52
- def stop(_reader)
46
+ # Write to nothing
47
+ def write(*); end
48
+
49
+ # Close nothing
50
+ def close_io(*); end
51
+
52
+ # Stop process
53
+ def stop(*)
53
54
  @stopped = true
54
55
 
55
56
  @exit_status
56
57
  end
57
58
 
59
+ # Terminate process
58
60
  def terminate(*)
59
61
  stop
60
62
  end
@@ -1,6 +1,7 @@
1
1
  require 'shellwords'
2
2
  require 'stringio'
3
3
  require 'aruba/processes/basic_process'
4
+ require 'aruba/platform'
4
5
 
5
6
  module Aruba
6
7
  module Processes
@@ -29,6 +30,7 @@ module Aruba
29
30
  attr_accessor :main_class
30
31
  end
31
32
 
33
+ # @private
32
34
  attr_reader :main_class
33
35
 
34
36
  def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil)
@@ -42,13 +44,13 @@ module Aruba
42
44
  super
43
45
  end
44
46
 
45
- def run!
47
+ def start
46
48
  fail "You need to call aruba.config.main_class = YourMainClass" unless main_class
47
49
 
48
50
  Dir.chdir @working_directory do
49
51
  before_run
50
52
 
51
- in_environment 'PWD' => @working_directory do
53
+ Aruba.platform.with_environment environment.merge('PWD' => @working_directory) do
52
54
  main_class.new(@argv, @stdin, @stdout, @stderr, @kernel).execute!
53
55
  end
54
56
 
@@ -58,7 +60,7 @@ module Aruba
58
60
  end
59
61
  end
60
62
 
61
- def stop(reader)
63
+ def stop(*)
62
64
  @stopped = true
63
65
  @exit_status = @kernel.exitstatus
64
66
  end
@@ -67,11 +69,11 @@ module Aruba
67
69
  @stdin.string
68
70
  end
69
71
 
70
- def stdout
72
+ def stdout(*)
71
73
  @stdout.string
72
74
  end
73
75
 
74
- def stderr
76
+ def stderr(*)
75
77
  @stderr.string
76
78
  end
77
79
 
@@ -88,23 +90,6 @@ module Aruba
88
90
  def terminate
89
91
  stop
90
92
  end
91
-
92
- private
93
-
94
- def in_environment(env = {}, &block)
95
- if RUBY_VERSION <= '1.9.3'
96
- old_env = ENV.to_hash
97
- else
98
- old_env = ENV.to_h
99
- end
100
-
101
- ENV.update(environment).update(env)
102
-
103
- block.call if block_given?
104
- ensure
105
- ENV.clear
106
- ENV.update old_env
107
- end
108
93
  end
109
94
  end
110
95
  end
@@ -30,11 +30,9 @@ module Aruba
30
30
  def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil)
31
31
  super
32
32
 
33
- @exit_timeout = exit_timeout
34
- @io_wait = io_wait
35
33
  @process = nil
36
- @output_cache = nil
37
- @error_cache = nil
34
+ @stdout_cache = nil
35
+ @stderr_cache = nil
38
36
  end
39
37
 
40
38
  # Run the command
@@ -44,9 +42,10 @@ module Aruba
44
42
  #
45
43
  # rubocop:disable Metrics/MethodLength
46
44
  # rubocop:disable Metrics/CyclomaticComplexity
47
- def run!
45
+ def start
48
46
  # gather fully qualified path
49
- cmd = which(command)
47
+ cmd = Aruba.platform.which(command, environment['PATH'])
48
+
50
49
  # rubocop:disable Metrics/LineLength
51
50
  fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) if cmd.nil?
52
51
  # rubocop:enable Metrics/LineLength
@@ -54,22 +53,25 @@ module Aruba
54
53
  cmd = Aruba.platform.command_string.new(cmd)
55
54
 
56
55
  @process = ChildProcess.build(*[cmd.to_a, arguments].flatten)
57
- @out = Tempfile.new("aruba-out")
58
- @err = Tempfile.new("aruba-err")
56
+ @stdout_file = Tempfile.new("aruba-stdout")
57
+ @stderr_file = Tempfile.new("aruba-stderr")
59
58
  @exit_status = nil
60
- @duplex = true
59
+ @duplex = true
61
60
 
62
61
  before_run
63
62
 
64
- @process.io.stdout = @out
65
- @process.io.stderr = @err
63
+ @process.leader = true
64
+ @process.io.stdout = @stdout_file
65
+ @process.io.stderr = @stderr_file
66
66
  @process.duplex = @duplex
67
67
  @process.cwd = @working_directory
68
68
 
69
69
  @process.environment.update(environment)
70
70
 
71
71
  begin
72
- @process.start
72
+ Aruba.platform.with_environment(environment) do
73
+ @process.start
74
+ end
73
75
  rescue ChildProcess::LaunchError => e
74
76
  raise LaunchError, "It tried to start #{cmd}. " + e.message
75
77
  end
@@ -81,35 +83,75 @@ module Aruba
81
83
  # rubocop:enable Metrics/MethodLength
82
84
  # rubocop:enable Metrics/CyclomaticComplexity
83
85
 
86
+ # Access to stdout of process
84
87
  def stdin
88
+ return if @process.nil?
89
+
85
90
  @process.io.stdin
86
91
  end
87
92
 
88
- def stdout
89
- wait_for_io do
93
+ # Access to stdout of process
94
+ #
95
+ # @param [Hash] opts
96
+ # Options
97
+ #
98
+ # @option [Integer] wait_for_io
99
+ # Wait for IO to be finished
100
+ #
101
+ # @return [String]
102
+ # The content of stdout
103
+ def stdout(opts = {})
104
+ return @stdout_cache if @process.nil?
105
+
106
+ wait_for_io = opts.fetch(:wait_for_io, @io_wait)
107
+
108
+ wait_for_io wait_for_io do
90
109
  @process.io.stdout.flush
91
- read(@out)
92
- end || @output_cache
110
+ open(@stdout_file.path).read
111
+ end
93
112
  end
94
113
 
95
- def stderr
96
- wait_for_io do
114
+ # Access to stderr of process
115
+ #
116
+ # @param [Hash] opts
117
+ # Options
118
+ #
119
+ # @option [Integer] wait_for_io
120
+ # Wait for IO to be finished
121
+ #
122
+ # @return [String]
123
+ # The content of stderr
124
+ def stderr(opts = {})
125
+ return @stderr_cache if @process.nil?
126
+
127
+ wait_for_io = opts.fetch(:wait_for_io, @io_wait)
128
+
129
+ wait_for_io wait_for_io do
97
130
  @process.io.stderr.flush
98
- read(@err)
99
- end || @error_cache
131
+ open(@stderr_file.path).read
132
+ end
100
133
  end
101
134
 
102
135
  def read_stdout
103
- warn('The use of "#read_stdout" is deprecated. Use "#stdout" instead.')
104
- stdout
136
+ # rubocop:disable Metrics/LineLength
137
+ Aruba.platform.deprecated('The use of "#read_stdout" is deprecated. Use "#stdout" instead. To reduce the time to wait for io, pass `:wait_for_io => 0` or some suitable for your use case')
138
+ # rubocop:enable Metrics/LineLength
139
+
140
+ stdout(:wait_for_io => 0)
105
141
  end
106
142
 
107
143
  def write(input)
144
+ return if @process.nil?
145
+
108
146
  @process.io.stdin.write(input)
109
147
  @process.io.stdin.flush
148
+
149
+ self
110
150
  end
111
151
 
112
152
  def close_io(name)
153
+ return if @process.nil?
154
+
113
155
  if RUBY_VERSION < '1.9'
114
156
  @process.io.send(name.to_sym).close
115
157
  else
@@ -152,10 +194,11 @@ module Aruba
152
194
 
153
195
  private
154
196
 
155
- def wait_for_io(&block)
156
- return unless @process
197
+ def wait_for_io(time_to_wait, &block)
198
+ return if @process.nil?
199
+
200
+ sleep time_to_wait
157
201
 
158
- sleep @io_wait
159
202
  yield
160
203
  end
161
204
 
@@ -165,15 +208,15 @@ module Aruba
165
208
  end
166
209
 
167
210
  def close_and_cache_out
168
- @output_cache = read @out
169
- @out.close
170
- @out = nil
211
+ @stdout_cache = read @stdout_file
212
+ @stdout_file.close
213
+ @stdout_file = nil
171
214
  end
172
215
 
173
216
  def close_and_cache_err
174
- @error_cache = read @err
175
- @err.close
176
- @err = nil
217
+ @stderr_cache = read @stderr_file
218
+ @stderr_file.close
219
+ @stderr_file = nil
177
220
  end
178
221
  end
179
222
  end
@@ -25,17 +25,12 @@ RSpec.configure do |config|
25
25
 
26
26
  if Aruba::VERSION >= '1.0.0'
27
27
  config.around :each do |example|
28
- begin
29
- old_env = ENV.to_hash.dup
28
+ Aruba.platform.with_environment do
30
29
  example.run
31
- ensure
32
- ENV.clear
33
- ENV.update old_env
34
30
  end
35
31
  end
36
32
  end
37
33
 
38
- # Use rspec metadata as option for aruba
39
34
  config.before :each do |example|
40
35
  next unless self.class.include? Aruba::Api
41
36
 
@@ -1,3 +1,3 @@
1
1
  module Aruba
2
- VERSION = '0.9.0.pre'
2
+ VERSION = '0.9.0.pre2'
3
3
  end
@@ -5,7 +5,6 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
5
  require 'pry'
6
6
 
7
7
  require 'aruba/api'
8
- require 'aruba/reporting'
9
8
 
10
9
  module Aruba
11
10
  class MyConsole
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Command Environment' do
4
+ include_context 'uses aruba API'
5
+
6
+ around do |example|
7
+ Aruba.platform.with_environment do
8
+ example.run
9
+ end
10
+ end
11
+
12
+ describe '#restore_env' do
13
+ context 'when non-existing variable' do
14
+ before :each do
15
+ ENV.delete 'LONG_LONG_ENV_VARIABLE'
16
+ end
17
+
18
+ context 'when set single' do
19
+ before :each do
20
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
21
+ @aruba.restore_env
22
+ end
23
+
24
+ it { expect(ENV).not_to be_key 'LONG_LONG_ENV_VARIABLE' }
25
+ end
26
+
27
+ context 'when set multiple times' do
28
+ before :each do
29
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
30
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2'
31
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '3'
32
+ @aruba.restore_env
33
+ end
34
+
35
+ it { expect(ENV).not_to be_key 'LONG_LONG_ENV_VARIABLE' }
36
+ end
37
+ end
38
+
39
+ context 'when existing variable from outer context' do
40
+ before :each do
41
+ ENV['LONG_LONG_ENV_VARIABLE'] = '0'
42
+ end
43
+
44
+ context 'when set single time' do
45
+ before :each do
46
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
47
+ @aruba.restore_env
48
+ end
49
+
50
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '0' }
51
+ end
52
+
53
+ context 'when set multiple times' do
54
+ before :each do
55
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
56
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2'
57
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '3'
58
+ @aruba.restore_env
59
+ end
60
+
61
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '0' }
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Command Environment' do
4
+ include_context 'uses aruba API'
5
+
6
+ around do |example|
7
+ Aruba.platform.with_environment do
8
+ example.run
9
+ end
10
+ end
11
+
12
+ describe '#set_env' do
13
+ context 'when non-existing variable' do
14
+ before :each do
15
+ ENV.delete('LONG_LONG_ENV_VARIABLE')
16
+ end
17
+
18
+ context 'when string' do
19
+ before :each do
20
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
21
+ end
22
+
23
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '1' }
24
+ end
25
+ end
26
+
27
+ context 'when existing variable set by aruba' do
28
+ before :each do
29
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
30
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2'
31
+ end
32
+
33
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '2' }
34
+ end
35
+
36
+ context 'when existing variable by outer context' do
37
+ before :each do
38
+ ENV['LONG_LONG_ENV_VARIABLE'] = '1'
39
+ end
40
+ end
41
+ end
42
+ end