aruba 0.14.2 → 0.14.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,7 +30,7 @@ When(/^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/)do |cmd, secs|
30
30
  end
31
31
 
32
32
  When(/^I run the following (?:commands|script)(?: (?:with|in) `([^`]+)`)?:$/) do |shell, commands|
33
- prepend_environment_variable('PATH', expand_path('bin') + ':')
33
+ prepend_environment_variable('PATH', expand_path('bin') + File::PATH_SEPARATOR)
34
34
 
35
35
  Aruba.platform.mkdir(expand_path('bin'))
36
36
  shell ||= Aruba.platform.default_shell
@@ -153,7 +153,7 @@ When(/^I wait for (?:output|stdout) to contain "([^"]*)"$/) do |expected|
153
153
  end
154
154
 
155
155
  Then(/^the output should be (\d+) bytes long$/) do |size|
156
- expect(all_output).to have_output_size size.to_i
156
+ expect(last_command_started.output).to have_output_size size.to_i
157
157
  end
158
158
 
159
159
  Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain( exactly)? "([^"]*)"$/) do |channel, cmd, negated, exactly, expected|
@@ -418,5 +418,5 @@ When(/^I send the signal "([^"]*)" to the command (?:"([^"]*)"|(?:started last))
418
418
  end
419
419
 
420
420
  Given(/^I look for executables in "(.*)" within the current directory$/) do |directory|
421
- prepend_environment_variable 'PATH', expand_path(directory) + ':'
421
+ prepend_environment_variable 'PATH', expand_path(directory) + File::PATH_SEPARATOR
422
422
  end
@@ -11,12 +11,11 @@ end
11
11
 
12
12
  Before do
13
13
  # ... so every change needs to be done later
14
- prepend_environment_variable 'PATH', aruba.config.command_search_paths.join(':') + ':'
14
+ prepend_environment_variable 'PATH', aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR
15
15
  set_environment_variable 'HOME', aruba.config.home_directory
16
16
  end
17
17
 
18
18
  After do
19
- restore_env
20
19
  terminate_all_commands
21
20
  aruba.command_monitor.clear
22
21
  end
@@ -16,7 +16,8 @@ module Aruba
16
16
 
17
17
  # Convert to array
18
18
  def to_a
19
- Shellwords.split __getobj__
19
+ Shellwords.split( __getobj__.gsub('\\', 'ARUBA_TMP_PATHSEPARATOR') ).
20
+ map { |w| w.gsub('ARUBA_TMP_PATHSEPARATOR', '\\') }
20
21
  end
21
22
 
22
23
  if RUBY_VERSION < '1.9'
@@ -64,6 +64,9 @@ module Aruba
64
64
  @stdout_file.sync = true
65
65
  @stderr_file.sync = true
66
66
 
67
+ @stdout_file.binmode
68
+ @stderr_file.binmode
69
+
67
70
  @exit_status = nil
68
71
  @duplex = true
69
72
 
@@ -92,7 +95,7 @@ module Aruba
92
95
  end
93
96
  # rubocop:disable Metrics/MethodLength
94
97
 
95
- # Access to stdout of process
98
+ # Access to stdin of process
96
99
  def stdin
97
100
  return if @process.exited?
98
101
 
@@ -271,7 +274,11 @@ module Aruba
271
274
  data = file.read
272
275
  file.close
273
276
 
274
- data
277
+ if RUBY_VERSION >= '1.9'
278
+ data.force_encoding('UTF-8')
279
+ else
280
+ data
281
+ end
275
282
  end
276
283
  end
277
284
  end
@@ -16,7 +16,6 @@ RSpec.configure do |config|
16
16
  # Setup environment for aruba
17
17
  config.around :each do |example|
18
18
  if self.class.include? Aruba::Api
19
- restore_env
20
19
  setup_aruba
21
20
  end
22
21
 
@@ -1,3 +1,3 @@
1
1
  module Aruba
2
- VERSION = '0.14.2'.freeze
2
+ VERSION = '0.14.3'.freeze
3
3
  end
@@ -0,0 +1,308 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Deprecated API' 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
+ before do
13
+ allow(Aruba.platform).to receive(:deprecated)
14
+ end
15
+
16
+ describe "#assert_not_matching_output" do
17
+ before(:each){ @aruba.run_simple("echo foo", false) }
18
+ after(:each) { @aruba.all_commands.each(&:stop) }
19
+
20
+ it "passes when the output doesn't match a regexp" do
21
+ @aruba.assert_not_matching_output "bar", @aruba.all_output
22
+ end
23
+ it "fails when the output does match a regexp" do
24
+ expect do
25
+ @aruba.assert_not_matching_output "foo", @aruba.all_output
26
+ end . to raise_error RSpec::Expectations::ExpectationNotMetError
27
+ end
28
+ end
29
+
30
+ describe '#filesystem_permissions' do
31
+ def actual_permissions
32
+ format( "%o" , File::Stat.new(file_path).mode )[-4,4]
33
+ end
34
+
35
+ let(:file_name) { @file_name }
36
+ let(:file_path) { @file_path }
37
+ let(:permissions) { '0655' }
38
+
39
+ before :each do
40
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
41
+ end
42
+
43
+ before(:each) do
44
+ File.open(file_path, 'w') { |f| f << "" }
45
+ end
46
+
47
+ before(:each) do
48
+ @aruba.filesystem_permissions(permissions, file_name)
49
+ end
50
+
51
+ context 'when file exists' do
52
+ context 'and permissions are given as string' do
53
+ it { expect(actual_permissions).to eq('0655') }
54
+ end
55
+
56
+ context 'and permissions are given as octal number' do
57
+ let(:permissions) { 0655 }
58
+ it { expect(actual_permissions).to eq('0655') }
59
+ end
60
+
61
+ context 'and path has ~ in it' do
62
+ let(:path) { random_string }
63
+ let(:file_name) { File.join('~', path) }
64
+ let(:file_path) { File.join(@aruba.aruba.current_directory, path) }
65
+
66
+ it { expect(actual_permissions).to eq('0655') }
67
+ end
68
+ end
69
+ end
70
+
71
+ describe '#check_filesystem_permissions' do
72
+ let(:file_name) { @file_name }
73
+ let(:file_path) { @file_path }
74
+
75
+ let(:permissions) { '0655' }
76
+
77
+ before :each do
78
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
79
+ end
80
+
81
+ before(:each) do
82
+ File.open(file_path, 'w') { |f| f << "" }
83
+ end
84
+
85
+ before(:each) do
86
+ @aruba.filesystem_permissions(permissions, file_name)
87
+ end
88
+
89
+ context 'when file exists' do
90
+ context 'and should have permissions' do
91
+ context 'and permissions are given as string' do
92
+ it { @aruba.check_filesystem_permissions(permissions, file_name, true) }
93
+ end
94
+
95
+ context 'and permissions are given as octal number' do
96
+ let(:permissions) { 0666 }
97
+
98
+ it { @aruba.check_filesystem_permissions(permissions, file_name, true) }
99
+ end
100
+
101
+ context 'and path includes ~' do
102
+ let(:string) { random_string }
103
+ let(:file_name) { File.join('~', string) }
104
+ let(:file_path) { File.join(@aruba.aruba.current_directory, string) }
105
+
106
+ it { @aruba.check_filesystem_permissions(permissions, file_name, true) }
107
+ end
108
+
109
+ context 'but fails because the permissions are different' do
110
+ let(:expected_permissions) { 0666 }
111
+
112
+ it { expect { @aruba.check_filesystem_permissions(expected_permissions, file_name, true) }.to raise_error RSpec::Expectations::ExpectationNotMetError }
113
+ end
114
+ end
115
+
116
+ context 'and should not have permissions' do
117
+ context 'and succeeds when the difference is expected and permissions are different' do
118
+ let(:different_permissions) { 0666 }
119
+
120
+ it { @aruba.check_filesystem_permissions(different_permissions, file_name, false) }
121
+ end
122
+
123
+ context 'and fails because the permissions are the same although they should be different' do
124
+ let(:different_permissions) { 0655 }
125
+
126
+ it { expect { @aruba.check_filesystem_permissions(different_permissions, file_name, false) }.to raise_error RSpec::Expectations::ExpectationNotMetError }
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ context '#check_file_presence' do
133
+ before(:each) { File.open(@file_path, 'w') { |f| f << "" } }
134
+
135
+ it "should check existence using plain match" do
136
+ file_name = 'nested/dir/hello_world.txt'
137
+ file_path = File.join(@aruba.aruba.current_directory, file_name)
138
+
139
+ Aruba.platform.mkdir(File.dirname(file_path))
140
+ File.open(file_path, 'w') { |f| f << "" }
141
+
142
+ @aruba.check_file_presence(file_name)
143
+ @aruba.check_file_presence([file_name])
144
+ @aruba.check_file_presence([file_name], true)
145
+ @aruba.check_file_presence(['asdf'], false)
146
+ end
147
+
148
+ it "should check existence using regex" do
149
+ file_name = 'nested/dir/hello_world.txt'
150
+ file_path = File.join(@aruba.aruba.current_directory, file_name)
151
+
152
+ Aruba.platform.mkdir(File.dirname(file_path))
153
+ File.open(file_path, 'w') { |f| f << "" }
154
+
155
+ @aruba.check_file_presence([ /test123/ ], false )
156
+ @aruba.check_file_presence([ /hello_world.txt$/ ], true )
157
+ @aruba.check_file_presence([ /dir/ ], true )
158
+ @aruba.check_file_presence([ %r{nested/.+/} ], true )
159
+ end
160
+
161
+ it "is no problem to mix both" do
162
+ file_name = 'nested/dir/hello_world.txt'
163
+ file_path = File.join(@aruba.aruba.current_directory, file_name)
164
+
165
+ Aruba.platform.mkdir(File.dirname(file_path))
166
+ File.open(file_path, 'w') { |f| f << "" }
167
+
168
+ @aruba.check_file_presence([ file_name, /nested/ ], true )
169
+ @aruba.check_file_presence([ /test123/, 'asdf' ], false )
170
+ end
171
+
172
+ it "works with ~ in path name" do
173
+ file_path = File.join('~', random_string)
174
+
175
+ @aruba.with_environment 'HOME' => File.expand_path(@aruba.aruba.current_directory) do
176
+ Aruba.platform.mkdir(File.dirname(File.expand_path(file_path)))
177
+ File.open(File.expand_path(file_path), 'w') { |f| f << "" }
178
+
179
+ @aruba.check_file_presence( [ file_path ], true )
180
+ end
181
+ end
182
+ end
183
+
184
+ context "check file content" do
185
+ before :example do
186
+ @aruba.write_file(@file_name, "foo bar baz")
187
+ end
188
+
189
+ describe "#check_binary_file_content" do
190
+ let(:file_name) { @file_name }
191
+ let(:file_path) { @file_path }
192
+
193
+ let(:reference_file) { 'fixture' }
194
+ let(:reference_file_content) { 'foo bar baz' }
195
+
196
+ before :each do
197
+ @aruba.write_file(reference_file, reference_file_content)
198
+ end
199
+
200
+ context 'when files are the same' do
201
+ context 'and this is expected' do
202
+ it { @aruba.check_binary_file_content(file_name, reference_file) }
203
+ it { @aruba.check_binary_file_content(file_name, reference_file, true) }
204
+ end
205
+
206
+ context 'and this is not expected' do
207
+ it { expect { @aruba.check_binary_file_content(file_name, reference_file, false) }.to raise_error RSpec::Expectations::ExpectationNotMetError }
208
+ end
209
+ end
210
+
211
+ context 'when files are not the same' do
212
+ let(:reference_file_content) { 'bar' }
213
+
214
+ context 'and this is expected' do
215
+ it { @aruba.check_binary_file_content(file_name, reference_file, false) }
216
+ end
217
+
218
+ context 'and this is not expected' do
219
+ it { expect { @aruba.check_binary_file_content(file_name, reference_file, true) }.to raise_error RSpec::Expectations::ExpectationNotMetError }
220
+ end
221
+ end
222
+ end
223
+
224
+ context "#check_file_content" do
225
+ context "with regexp" do
226
+ let(:matching_content){/bar/}
227
+ let(:non_matching_content){/nothing/}
228
+ it "succeeds if file content matches" do
229
+ @aruba.check_file_content(@file_name, matching_content)
230
+ @aruba.check_file_content(@file_name, matching_content, true)
231
+ end
232
+
233
+ it "succeeds if file content does not match" do
234
+ @aruba.check_file_content(@file_name, non_matching_content, false)
235
+ end
236
+
237
+ it "works with ~ in path name" do
238
+ file_path = File.join('~', random_string)
239
+
240
+ @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
241
+ @aruba.write_file(file_path, "foo bar baz")
242
+ @aruba.check_file_content(file_path, non_matching_content, false)
243
+ end
244
+ end
245
+ end
246
+ context "with string" do
247
+ let(:matching_content){"foo bar baz"}
248
+ let(:non_matching_content){"bar"}
249
+ it "succeeds if file content matches" do
250
+ @aruba.check_file_content(@file_name, matching_content)
251
+ @aruba.check_file_content(@file_name, matching_content, true)
252
+ end
253
+
254
+ it "succeeds if file content does not match" do
255
+ @aruba.check_file_content(@file_name, non_matching_content, false)
256
+ end
257
+
258
+ it "works with ~ in path name" do
259
+ file_path = File.join('~', random_string)
260
+
261
+ @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
262
+ @aruba.write_file(file_path, "foo bar baz")
263
+ @aruba.check_file_content(file_path, non_matching_content, false)
264
+ end
265
+ end
266
+ end
267
+ end
268
+ end
269
+
270
+ context '#check_file_size' do
271
+ it "should check an existing file size" do
272
+ @aruba.write_fixed_size_file(@file_name, @file_size)
273
+ @aruba.check_file_size([[@file_name, @file_size]])
274
+ end
275
+
276
+ it "should check an existing file size and fail" do
277
+ @aruba.write_fixed_size_file(@file_name, @file_size)
278
+ expect { @aruba.check_file_size([[@file_name, @file_size + 1]]) }.to raise_error RSpec::Expectations::ExpectationNotMetError
279
+ end
280
+
281
+ it "works with ~ in path name" do
282
+ file_path = File.join('~', random_string)
283
+
284
+ @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
285
+ @aruba.write_fixed_size_file(file_path, @file_size)
286
+ @aruba.check_file_size([[file_path, @file_size]])
287
+ end
288
+ end
289
+
290
+ it "should check an existing file size and fail" do
291
+ @aruba.write_fixed_size_file(@file_name, @file_size)
292
+ expect { @aruba.check_file_size([[@file_name, @file_size + 1]]) }.to raise_error RSpec::Expectations::ExpectationNotMetError
293
+ end
294
+ end
295
+
296
+ describe "#get_process" do
297
+ before(:each){@aruba.run_simple "true"}
298
+ after(:each) { @aruba.all_commands.each(&:stop) }
299
+
300
+ it "returns a process" do
301
+ expect(@aruba.get_process("true")).not_to be(nil)
302
+ end
303
+
304
+ it "raises a descriptive exception" do
305
+ expect { @aruba.get_process("false") }.to raise_error CommandNotFoundError, "No command named 'false' has been started"
306
+ end
307
+ end
308
+ end
@@ -9,6 +9,10 @@ RSpec.describe 'Command Environment' do
9
9
  end
10
10
  end
11
11
 
12
+ before do
13
+ allow(Aruba.platform).to receive(:deprecated)
14
+ end
15
+
12
16
  describe '#restore_env' do
13
17
  context 'when non-existing variable' do
14
18
  before :each do
@@ -62,4 +66,21 @@ RSpec.describe 'Command Environment' do
62
66
  end
63
67
  end
64
68
  end
69
+
70
+ describe "#restore_env" do
71
+ after(:each) { @aruba.all_commands.each(&:stop) }
72
+ it "restores environment variable" do
73
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
74
+ @aruba.restore_env
75
+ @aruba.run "env"
76
+ expect(@aruba.all_output).not_to include("LONG_LONG_ENV_VARIABLE")
77
+ end
78
+ it "restores environment variable that has been set multiple times" do
79
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
80
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'false'
81
+ @aruba.restore_env
82
+ @aruba.run "env"
83
+ expect(@aruba.all_output).not_to include("LONG_LONG_ENV_VARIABLE")
84
+ end
85
+ end
65
86
  end
@@ -9,6 +9,10 @@ RSpec.describe 'Command Environment' do
9
9
  end
10
10
  end
11
11
 
12
+ before do
13
+ allow(Aruba.platform).to receive(:deprecated)
14
+ end
15
+
12
16
  describe '#set_env' do
13
17
  context 'when non-existing variable' do
14
18
  before :each do