aruba 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +167 -3
- data/.simplecov +32 -0
- data/.travis.yml +5 -2
- data/.yardopts +8 -0
- data/CONTRIBUTING.md +18 -8
- data/Gemfile +25 -0
- data/History.md +8 -0
- data/README.md +80 -18
- data/Rakefile +1 -1
- data/aruba.gemspec +6 -8
- data/cucumber.yml +5 -6
- data/features/debug.feature +15 -0
- data/features/file_system_commands.feature +14 -2
- data/features/fixtures/copy/file.txt +1 -0
- data/features/fixtures/fixtures-app/test.txt +1 -0
- data/features/fixtures/spawn_process/stderr.sh +3 -0
- data/features/interactive.feature +2 -2
- data/features/step_definitions/aruba_dev_steps.rb +1 -1
- data/features/support/custom_main.rb +10 -6
- data/features/support/env.rb +27 -2
- data/features/support/simplecov_setup.rb +8 -0
- data/lib/aruba.rb +2 -2
- data/lib/aruba/announcer.rb +161 -0
- data/lib/aruba/api.rb +490 -251
- data/lib/aruba/config.rb +0 -1
- data/lib/aruba/cucumber.rb +71 -59
- data/lib/aruba/cucumber/hooks.rb +18 -13
- data/lib/aruba/errors.rb +6 -0
- data/lib/aruba/in_process.rb +5 -45
- data/lib/aruba/matchers/command.rb +79 -0
- data/lib/aruba/matchers/directory.rb +59 -0
- data/lib/aruba/matchers/file.rb +177 -0
- data/lib/aruba/matchers/mode.rb +52 -0
- data/lib/aruba/matchers/path.rb +99 -0
- data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +21 -1
- data/lib/aruba/process_monitor.rb +113 -0
- data/lib/aruba/processes/basic_process.rb +25 -0
- data/lib/aruba/processes/debug_process.rb +59 -0
- data/lib/aruba/processes/in_process.rb +86 -0
- data/lib/aruba/processes/spawn_process.rb +159 -0
- data/lib/aruba/reporting.rb +2 -2
- data/lib/aruba/rspec.rb +26 -0
- data/lib/aruba/spawn_process.rb +5 -104
- data/lib/aruba/utils.rb +21 -0
- data/script/bootstrap +22 -0
- data/script/console +17 -0
- data/script/test +3 -0
- data/spec/aruba/api_spec.rb +813 -147
- data/spec/aruba/hooks_spec.rb +0 -1
- data/spec/aruba/matchers/command_spec.rb +43 -0
- data/spec/aruba/matchers/directory_spec.rb +58 -0
- data/spec/aruba/matchers/file_spec.rb +131 -0
- data/spec/aruba/matchers/path_spec.rb +85 -0
- data/spec/aruba/spawn_process_spec.rb +46 -28
- data/spec/spec_helper.rb +18 -13
- data/{config/rubocop/include.yml → spec/support/configs/.keep} +0 -0
- data/spec/support/configs/rspec.rb +15 -0
- data/spec/support/helpers/.keep +0 -0
- data/spec/support/helpers/reporting.rb +44 -0
- data/spec/support/matchers/.keep +0 -0
- data/spec/support/shared_contexts/.keep +0 -0
- data/spec/support/shared_contexts/aruba.rb +45 -0
- data/spec/support/shared_examples/.keep +0 -0
- data/spec/support/shared_examples/directory.rb +7 -0
- data/spec/support/shared_examples/file.rb +7 -0
- data/templates/js/jquery-1.11.3.min.js +5 -0
- data/templates/main.erb +1 -1
- metadata +87 -96
- data/config/rubocop/exclude.yml +0 -160
- data/templates/js/jquery-1.6.1.min.js +0 -18
data/lib/aruba/utils.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Aruba
|
2
|
+
module Utils
|
3
|
+
def detect_ruby(cmd)
|
4
|
+
if cmd =~ /^ruby\s/
|
5
|
+
cmd.gsub(/^ruby\s/, "#{current_ruby} ")
|
6
|
+
else
|
7
|
+
cmd
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def current_ruby
|
12
|
+
File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
|
13
|
+
end
|
14
|
+
|
15
|
+
def ensure_newline(str)
|
16
|
+
str.chomp << "\n"
|
17
|
+
end
|
18
|
+
|
19
|
+
module_function :detect_ruby, :current_ruby, :ensure_newline
|
20
|
+
end
|
21
|
+
end
|
data/script/bootstrap
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
info_msg="\e[0;32m[INFO]\e[0;30m"
|
6
|
+
error_msg="\e[0;31mFAILED\e[0;30m"
|
7
|
+
|
8
|
+
function output_error_log {
|
9
|
+
[[ -f error.log ]] && ( cat error.log >&2; rm error.log)
|
10
|
+
}
|
11
|
+
|
12
|
+
echo -ne "$info_msg Checking if ruby installed? "
|
13
|
+
which 'ruby' >/dev/null 2>error.log || ( echo -e "$error_msg\n\nCould not find \`ruby\`. Please install ruby or add it to PATH"; output_error_log; exit 1 )
|
14
|
+
echo OK
|
15
|
+
|
16
|
+
echo -en "$info_msg rubygem \"bundler\" "
|
17
|
+
gem install bundler >/dev/null 2>error.log || ( echo -e "$error_msg\n\nAn error occurred during installation of bundler. Run \`gem install bundler\` yourself."; output_error_log; exit 1 )
|
18
|
+
echo OK
|
19
|
+
|
20
|
+
echo -en "$info_msg \"bundle install\" "
|
21
|
+
bundle install $* >/dev/null 2>error.log || ( echo -e "$error_msg\n\nAn error occurred during bundle install. Run \`bundle install\` yourself."; output_error_log; exit 1 )
|
22
|
+
echo OK
|
data/script/console
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
require 'aruba/api'
|
8
|
+
require 'aruba/reporting'
|
9
|
+
|
10
|
+
module Aruba
|
11
|
+
class MyConsole
|
12
|
+
include Aruba::Api
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
include Aruba
|
17
|
+
Pry.start MyConsole.new
|
data/script/test
ADDED
data/spec/aruba/api_spec.rb
CHANGED
@@ -2,136 +2,714 @@ require 'spec_helper'
|
|
2
2
|
require 'securerandom'
|
3
3
|
|
4
4
|
describe Aruba::Api do
|
5
|
+
include_context 'uses aruba API'
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
describe 'current_directory' do
|
8
|
+
it "should return the current dir as 'tmp/aruba'" do
|
9
|
+
expect(@aruba.current_directory).to match(/^tmp\/aruba$/)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can be cleared" do
|
13
|
+
write_file('test', 'test test test')
|
14
|
+
|
15
|
+
in_current_directory do
|
16
|
+
expect(File.exist?('test')).to be_truthy
|
17
|
+
end
|
18
|
+
|
19
|
+
clean_current_directory
|
20
|
+
|
21
|
+
in_current_directory do
|
22
|
+
expect(File.exist?('test')).to be_falsey
|
23
|
+
end
|
24
|
+
end
|
8
25
|
end
|
9
26
|
|
10
|
-
|
11
|
-
|
12
|
-
|
27
|
+
describe '#all_paths' do
|
28
|
+
let(:name) { @file_name }
|
29
|
+
let(:path) { @file_path }
|
13
30
|
|
14
|
-
|
15
|
-
|
31
|
+
context 'when file exist' do
|
32
|
+
before :each do
|
33
|
+
File.write(path, '')
|
16
34
|
end
|
17
35
|
|
18
|
-
|
19
|
-
|
36
|
+
it { expect(all_paths).to include expand_path(name) }
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when directory exist' do
|
40
|
+
let(:name) { 'test_dir' }
|
41
|
+
let(:path) { File.join(@aruba.current_directory, name) }
|
42
|
+
|
43
|
+
before :each do
|
44
|
+
FileUtils.mkdir_p path
|
20
45
|
end
|
21
|
-
}
|
22
|
-
@aruba = klass.new
|
23
46
|
|
24
|
-
|
25
|
-
|
26
|
-
@file_path = File.join(@aruba.current_dir, @file_name)
|
47
|
+
it { expect(all_paths).to include expand_path(name) }
|
48
|
+
end
|
27
49
|
|
28
|
-
|
29
|
-
|
30
|
-
Dir.mkdir(dir) unless File.exist?(dir)
|
50
|
+
context 'when nothing exist' do
|
51
|
+
it { expect(all_paths).to eq [] }
|
31
52
|
end
|
32
|
-
raise "We must work with relative paths, everything else is dangerous" if ?/ == @aruba.current_dir[0]
|
33
|
-
FileUtils.rm_rf(@aruba.current_dir)
|
34
|
-
Dir.mkdir(@aruba.current_dir)
|
35
53
|
end
|
36
54
|
|
37
|
-
describe '
|
38
|
-
|
39
|
-
|
55
|
+
describe '#all_files' do
|
56
|
+
let(:name) { @file_name }
|
57
|
+
let(:path) { @file_path }
|
58
|
+
|
59
|
+
context 'when file exist' do
|
60
|
+
before :each do
|
61
|
+
File.write(path, '')
|
62
|
+
end
|
63
|
+
|
64
|
+
it { expect(all_files).to include expand_path(name) }
|
40
65
|
end
|
41
66
|
|
42
|
-
|
43
|
-
|
67
|
+
context 'when directory exist' do
|
68
|
+
let(:name) { 'test_dir' }
|
69
|
+
let(:path) { File.join(@aruba.current_directory, name) }
|
44
70
|
|
45
|
-
|
46
|
-
|
71
|
+
before :each do
|
72
|
+
FileUtils.mkdir_p path
|
47
73
|
end
|
48
74
|
|
49
|
-
|
75
|
+
it { expect(all_files).to eq [] }
|
76
|
+
end
|
50
77
|
|
51
|
-
|
52
|
-
|
78
|
+
context 'when nothing exist' do
|
79
|
+
it { expect(all_files).to eq [] }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#all_directories' do
|
84
|
+
let(:name) { @file_name }
|
85
|
+
let(:path) { @file_path }
|
86
|
+
|
87
|
+
context 'when file exist' do
|
88
|
+
before :each do
|
89
|
+
File.write(path, '')
|
53
90
|
end
|
54
91
|
|
92
|
+
it { expect(all_directories).to eq [] }
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when directory exist' do
|
96
|
+
let(:name) { 'test_dir' }
|
97
|
+
let(:path) { File.join(@aruba.current_directory, name) }
|
98
|
+
|
99
|
+
before :each do
|
100
|
+
FileUtils.mkdir_p path
|
101
|
+
end
|
102
|
+
|
103
|
+
it { expect(all_directories).to include expand_path(name) }
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'when nothing exist' do
|
107
|
+
it { expect(all_directories).to eq [] }
|
55
108
|
end
|
56
109
|
end
|
57
110
|
|
58
111
|
describe 'directories' do
|
59
112
|
before(:each) do
|
60
113
|
@directory_name = 'test_dir'
|
61
|
-
@directory_path = File.join(@aruba.
|
114
|
+
@directory_path = File.join(@aruba.current_directory, @directory_name)
|
62
115
|
end
|
63
116
|
|
64
|
-
context '#
|
117
|
+
context '#create_directory' do
|
65
118
|
it 'creates a directory' do
|
66
|
-
@aruba.
|
119
|
+
@aruba.create_directory @directory_name
|
67
120
|
expect(File.exist?(File.expand_path(@directory_path))).to be_truthy
|
68
121
|
end
|
69
122
|
end
|
123
|
+
end
|
70
124
|
|
71
|
-
|
72
|
-
|
73
|
-
|
125
|
+
describe '#read' do
|
126
|
+
let(:name) { 'test.txt'}
|
127
|
+
let(:path) { File.join(@aruba.current_directory, name) }
|
128
|
+
let(:content) { 'asdf' }
|
129
|
+
|
130
|
+
before :each do
|
131
|
+
set_env 'HOME', File.expand_path(@aruba.current_directory)
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'when does not exist' do
|
135
|
+
it { expect { @aruba.read(name) }.to raise_error ArgumentError }
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'when exists' do
|
139
|
+
context 'when file' do
|
140
|
+
before :each do
|
141
|
+
File.open(File.expand_path(path), 'w') { |f| f << content }
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when normal file' do
|
145
|
+
it { expect(@aruba.read(name)).to eq [content] }
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when binary file' do
|
149
|
+
let(:content) { "\u0000" }
|
150
|
+
it { expect(@aruba.read(name)).to eq [content] }
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when is empty file' do
|
154
|
+
let(:content) { '' }
|
155
|
+
it { expect(@aruba.read(name)).to eq [] }
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'when path contains ~' do
|
159
|
+
let(:string) { random_string }
|
160
|
+
let(:name) { File.join('~', string) }
|
161
|
+
let(:path) { File.join(@aruba.current_directory, string) }
|
162
|
+
|
163
|
+
it { expect(@aruba.read(name)).to eq [content] }
|
164
|
+
end
|
74
165
|
end
|
75
166
|
|
76
|
-
|
77
|
-
|
78
|
-
|
167
|
+
context 'when directory' do
|
168
|
+
let(:name) { 'test.d' }
|
169
|
+
|
170
|
+
before :each do
|
171
|
+
Array(path).each { |p| Dir.mkdir p }
|
172
|
+
end
|
173
|
+
|
174
|
+
it { expect { @aruba.read(name) }.to raise_error ArgumentError }
|
79
175
|
end
|
176
|
+
end
|
177
|
+
end
|
80
178
|
|
81
|
-
|
82
|
-
|
179
|
+
describe '#list' do
|
180
|
+
let(:name) { 'test.d' }
|
181
|
+
let(:content) { %w(subdir.1.d subdir.2.d) }
|
182
|
+
let(:path) { File.join(@aruba.current_directory, name) }
|
183
|
+
|
184
|
+
before :each do
|
185
|
+
set_env 'HOME', File.expand_path(@aruba.current_directory)
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'when does not exist' do
|
189
|
+
it { expect { @aruba.list(name) }.to raise_error ArgumentError }
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when exists' do
|
193
|
+
context 'when file' do
|
194
|
+
let(:name) { 'test.txt' }
|
195
|
+
|
196
|
+
before :each do
|
197
|
+
File.open(File.expand_path(path), 'w') { |f| f << content }
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'when normal file' do
|
201
|
+
it { expect{ @aruba.list(name) }.to raise_error ArgumentError }
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'when directory' do
|
206
|
+
before :each do
|
207
|
+
Array(path).each { |p| Dir.mkdir p }
|
208
|
+
end
|
83
209
|
|
84
|
-
|
85
|
-
Dir.mkdir
|
86
|
-
|
210
|
+
before :each do
|
211
|
+
Array(content).each { |p| Dir.mkdir File.join(path, p) }
|
212
|
+
end
|
213
|
+
|
214
|
+
context 'when has subdirectories' do
|
215
|
+
context 'when is simple path' do
|
216
|
+
let(:existing_files) { @aruba.list(name) }
|
217
|
+
let(:expected_files) { content.map { |c| File.join(name, c) }.sort }
|
218
|
+
|
219
|
+
it { expect(expected_files - existing_files).to be_empty}
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'when path contains ~' do
|
223
|
+
let(:string) { random_string }
|
224
|
+
let(:name) { File.join('~', string) }
|
225
|
+
let(:path) { File.join(@aruba.current_directory, string) }
|
226
|
+
|
227
|
+
let(:existing_files) { @aruba.list(name) }
|
228
|
+
let(:expected_files) { content.map { |c| File.join(string, c) } }
|
87
229
|
|
88
|
-
|
230
|
+
it { expect(expected_files - existing_files).to be_empty}
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'when has no subdirectories' do
|
235
|
+
let(:content) { [] }
|
236
|
+
it { expect(@aruba.list(name)).to eq [] }
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe '#remove' do
|
243
|
+
let(:name) { 'test.txt'}
|
244
|
+
let(:path) { File.join(@aruba.current_directory, name) }
|
245
|
+
let(:options) { {} }
|
246
|
+
|
247
|
+
before :each do
|
248
|
+
set_env 'HOME', File.expand_path(@aruba.current_directory)
|
249
|
+
end
|
250
|
+
|
251
|
+
context 'when file' do
|
252
|
+
context 'when exists' do
|
253
|
+
before :each do
|
254
|
+
Array(path).each { |p| File.open(File.expand_path(p), 'w') { |f| f << "" } }
|
255
|
+
end
|
256
|
+
|
257
|
+
before :each do
|
258
|
+
@aruba.remove(name, options)
|
259
|
+
end
|
260
|
+
|
261
|
+
context 'when is a single file' do
|
262
|
+
it_behaves_like 'a non-existing file'
|
263
|
+
end
|
264
|
+
|
265
|
+
context 'when are multiple files' do
|
266
|
+
let(:file_name) { %w(file1 file2 file3) }
|
267
|
+
let(:file_path) { %w(file1 file2 file3).map { |p| File.join(@aruba.current_directory, p) } }
|
268
|
+
|
269
|
+
it_behaves_like 'a non-existing file'
|
270
|
+
end
|
271
|
+
|
272
|
+
context 'when path contains ~' do
|
273
|
+
let(:string) { random_string }
|
274
|
+
let(:file_name) { File.join('~', string) }
|
275
|
+
let(:file_path) { File.join(@aruba.current_directory, string) }
|
276
|
+
|
277
|
+
it_behaves_like 'a non-existing file'
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context 'when does not exist' do
|
282
|
+
before :each do
|
283
|
+
@aruba.remove(name, options)
|
284
|
+
end
|
285
|
+
|
286
|
+
context 'when is forced to delete file' do
|
287
|
+
let(:options) { { force: true } }
|
288
|
+
|
289
|
+
it_behaves_like 'a non-existing file'
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
context 'when is directory' do
|
295
|
+
let(:name) { 'test.d' }
|
296
|
+
|
297
|
+
context 'when exists' do
|
298
|
+
before :each do
|
299
|
+
Array(path).each { |p| Dir.mkdir p }
|
300
|
+
end
|
301
|
+
|
302
|
+
before :each do
|
303
|
+
@aruba.remove(name, options)
|
304
|
+
end
|
305
|
+
|
306
|
+
context 'when is a single directory' do
|
307
|
+
it_behaves_like 'a non-existing directory'
|
308
|
+
end
|
309
|
+
|
310
|
+
context 'when are multiple directorys' do
|
311
|
+
let(:directory_name) { %w(directory1 directory2 directory3) }
|
312
|
+
let(:directory_path) { %w(directory1 directory2 directory3).map { |p| File.join(@aruba.current_directory, p) } }
|
313
|
+
|
314
|
+
it_behaves_like 'a non-existing directory'
|
315
|
+
end
|
316
|
+
|
317
|
+
context 'when path contains ~' do
|
318
|
+
let(:string) { random_string }
|
319
|
+
let(:directory_name) { File.join('~', string) }
|
320
|
+
let(:directory_path) { File.join(@aruba.current_directory, string) }
|
321
|
+
|
322
|
+
it_behaves_like 'a non-existing directory'
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
context 'when does not exist' do
|
327
|
+
before :each do
|
328
|
+
@aruba.remove(name, options)
|
329
|
+
end
|
330
|
+
|
331
|
+
context 'when is forced to delete directory' do
|
332
|
+
let(:options) { { force: true } }
|
333
|
+
|
334
|
+
it_behaves_like 'a non-existing directory'
|
89
335
|
end
|
90
336
|
end
|
91
337
|
end
|
92
338
|
end
|
93
339
|
|
94
340
|
describe 'files' do
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
341
|
+
describe '#touch' do
|
342
|
+
let(:name) { @file_name }
|
343
|
+
let(:path) { @file_path }
|
344
|
+
let(:options) { {} }
|
345
|
+
|
346
|
+
before :each do
|
347
|
+
set_env 'HOME', File.expand_path(@aruba.current_directory)
|
100
348
|
end
|
101
349
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
350
|
+
context 'when file' do
|
351
|
+
before :each do
|
352
|
+
@aruba.touch(name, options)
|
353
|
+
end
|
354
|
+
|
355
|
+
context 'when does not exist' do
|
356
|
+
context 'and should be created in existing directory' do
|
357
|
+
it { expect(File.size(path)).to eq 0 }
|
358
|
+
it_behaves_like 'an existing file'
|
359
|
+
end
|
360
|
+
|
361
|
+
context 'and should be created in non-existing directory' do
|
362
|
+
let(:name) { 'directory/test' }
|
363
|
+
let(:path) { File.join(@aruba.current_directory, 'directory/test') }
|
364
|
+
|
365
|
+
it_behaves_like 'an existing file'
|
366
|
+
end
|
367
|
+
|
368
|
+
context 'and path includes ~' do
|
369
|
+
let(:string) { random_string }
|
370
|
+
let(:name) { File.join('~', string) }
|
371
|
+
let(:path) { File.join(@aruba.current_directory, string) }
|
372
|
+
|
373
|
+
it_behaves_like 'an existing file'
|
374
|
+
end
|
375
|
+
|
376
|
+
context 'and the mtime should be set statically' do
|
377
|
+
let(:time) { Time.parse('2014-01-01 10:00:00') }
|
378
|
+
let(:options) { { mtime: Time.parse('2014-01-01 10:00:00') } }
|
379
|
+
|
380
|
+
it_behaves_like 'an existing file'
|
381
|
+
it { expect(File.mtime(path)).to eq time }
|
382
|
+
end
|
106
383
|
|
107
|
-
|
384
|
+
context 'and multiple file names are given' do
|
385
|
+
let(:name) { %w(file1 file2 file3) }
|
386
|
+
let(:path) { %w(file1 file2 file3).map { |p| File.join(@aruba.current_directory, p) } }
|
387
|
+
it_behaves_like 'an existing file'
|
388
|
+
end
|
389
|
+
end
|
108
390
|
end
|
109
391
|
|
110
|
-
|
111
|
-
|
392
|
+
context 'when directory' do
|
393
|
+
let(:name) { %w(directory1) }
|
394
|
+
let(:path) { Array(name).map { |p| File.join(@aruba.current_directory, p) } }
|
112
395
|
|
113
|
-
|
114
|
-
|
115
|
-
|
396
|
+
context 'when exist' do
|
397
|
+
before(:each) { Array(path).each { |p| FileUtils.mkdir_p p } }
|
398
|
+
|
399
|
+
before :each do
|
400
|
+
@aruba.touch(name, options)
|
401
|
+
end
|
402
|
+
|
403
|
+
context 'and the mtime should be set statically' do
|
404
|
+
let(:time) { Time.parse('2014-01-01 10:00:00') }
|
405
|
+
let(:options) { { mtime: Time.parse('2014-01-01 10:00:00') } }
|
406
|
+
|
407
|
+
it_behaves_like 'an existing directory'
|
408
|
+
it { Array(path).each { |p| expect(File.mtime(p)).to eq time } }
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
describe '#absolute?' do
|
415
|
+
let(:name) { @file_name }
|
416
|
+
let(:path) { File.expand_path(File.join(@aruba.current_directory, name)) }
|
417
|
+
|
418
|
+
context 'when is absolute path' do
|
419
|
+
it { expect(@aruba).to be_absolute(path) }
|
420
|
+
end
|
421
|
+
|
422
|
+
context 'when is relative path' do
|
423
|
+
it { expect(@aruba).not_to be_absolute(name) }
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
describe '#relative?' do
|
428
|
+
let(:name) { @file_name }
|
429
|
+
let(:path) { File.expand_path(File.join(@aruba.current_directory, name)) }
|
430
|
+
|
431
|
+
context 'when is absolute path' do
|
432
|
+
it { expect(@aruba).not_to be_relative(path) }
|
433
|
+
end
|
434
|
+
|
435
|
+
context 'when is relative path' do
|
436
|
+
it { expect(@aruba).to be_relative(name) }
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
describe '#exist?' do
|
441
|
+
context 'when is file' do
|
442
|
+
let(:name) { @file_name }
|
443
|
+
let(:path) { @file_path }
|
444
|
+
|
445
|
+
context 'when exists' do
|
446
|
+
before :each do
|
447
|
+
File.write(path, '')
|
448
|
+
end
|
449
|
+
|
450
|
+
it { expect(@aruba).to be_exist(name) }
|
451
|
+
end
|
452
|
+
|
453
|
+
context 'when does not exist' do
|
454
|
+
it { expect(@aruba).not_to be_exist(name) }
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
context 'when is directory' do
|
459
|
+
let(:name) { 'test.d' }
|
460
|
+
let(:path) { File.join(@aruba.current_directory, name) }
|
461
|
+
|
462
|
+
context 'when exists' do
|
463
|
+
before :each do
|
464
|
+
FileUtils.mkdir_p path
|
465
|
+
end
|
466
|
+
|
467
|
+
it { expect(@aruba).to be_exist(name) }
|
468
|
+
end
|
469
|
+
|
470
|
+
context 'when does not exist' do
|
471
|
+
it { expect(@aruba).not_to be_exist(name) }
|
472
|
+
end
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
describe '#file?' do
|
477
|
+
context 'when is file' do
|
478
|
+
let(:name) { @file_name }
|
479
|
+
let(:path) { @file_path }
|
480
|
+
|
481
|
+
context 'when exists' do
|
482
|
+
before :each do
|
483
|
+
File.write(path, '')
|
484
|
+
end
|
485
|
+
|
486
|
+
it { expect(@aruba).to be_file(name) }
|
487
|
+
end
|
488
|
+
|
489
|
+
context 'when does not exist' do
|
490
|
+
it { expect(@aruba).not_to be_file(name) }
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
context 'when is directory' do
|
495
|
+
let(:name) { 'test.d' }
|
496
|
+
let(:path) { File.join(@aruba.current_directory, name) }
|
497
|
+
|
498
|
+
context 'when exists' do
|
499
|
+
before :each do
|
500
|
+
FileUtils.mkdir_p path
|
501
|
+
end
|
502
|
+
|
503
|
+
it { expect(@aruba).not_to be_file(name) }
|
504
|
+
end
|
505
|
+
|
506
|
+
context 'when does not exist' do
|
507
|
+
it { expect(@aruba).not_to be_file(name) }
|
508
|
+
end
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
describe '#directory?' do
|
513
|
+
context 'when is file' do
|
514
|
+
let(:name) { @file_name }
|
515
|
+
let(:path) { @file_path }
|
516
|
+
|
517
|
+
context 'when exists' do
|
518
|
+
before :each do
|
519
|
+
File.write(path, '')
|
520
|
+
end
|
521
|
+
|
522
|
+
it { expect(@aruba).not_to be_directory(name) }
|
523
|
+
end
|
524
|
+
|
525
|
+
context 'when does not exist' do
|
526
|
+
it { expect(@aruba).not_to be_directory(name) }
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
context 'when is directory' do
|
531
|
+
let(:name) { 'test.d' }
|
532
|
+
let(:path) { File.join(@aruba.current_directory, name) }
|
533
|
+
|
534
|
+
context 'when exists' do
|
535
|
+
before :each do
|
536
|
+
FileUtils.mkdir_p path
|
537
|
+
end
|
538
|
+
|
539
|
+
it { expect(@aruba).to be_directory(name) }
|
540
|
+
end
|
541
|
+
|
542
|
+
context 'when does not exist' do
|
543
|
+
it { expect(@aruba).not_to be_directory(name) }
|
544
|
+
end
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
describe '#copy' do
|
549
|
+
let(:source) { 'file.txt' }
|
550
|
+
let(:destination) { 'file1.txt' }
|
551
|
+
|
552
|
+
context 'when source is existing' do
|
553
|
+
context 'when destination is non-existing' do
|
554
|
+
context 'when source is file' do
|
555
|
+
before(:each) { create_test_files(source) }
|
556
|
+
|
557
|
+
before :each do
|
558
|
+
@aruba.copy source, destination
|
559
|
+
end
|
560
|
+
|
561
|
+
context 'when source is plain file' do
|
562
|
+
it { expect(destination).to be_existing_file }
|
563
|
+
end
|
564
|
+
|
565
|
+
context 'when source is contains "~" in path' do
|
566
|
+
let(:source) { '~/file.txt' }
|
567
|
+
it { expect(destination).to be_existing_file }
|
568
|
+
end
|
569
|
+
|
570
|
+
context 'when source is fixture' do
|
571
|
+
let(:source) { '%/copy/file.txt' }
|
572
|
+
let(:destination) { 'file.txt' }
|
573
|
+
it { expect(destination).to be_existing_file }
|
574
|
+
end
|
575
|
+
|
576
|
+
context 'when source is list of files' do
|
577
|
+
let(:source) { %w(file1.txt file2.txt file3.txt) }
|
578
|
+
let(:destination) { 'file.d' }
|
579
|
+
let(:destination_files) { source.map { |s| File.join(destination, s) } }
|
580
|
+
|
581
|
+
it { expect(destination_files).to be_existing_files }
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
585
|
+
context 'when source is directory' do
|
586
|
+
let(:source) { 'src.d' }
|
587
|
+
let(:destination) { 'dst.d' }
|
588
|
+
|
589
|
+
before :each do
|
590
|
+
FileUtils.mkdir_p File.join(@aruba.current_directory, source)
|
591
|
+
end
|
592
|
+
|
593
|
+
before :each do
|
594
|
+
@aruba.copy source, destination
|
595
|
+
end
|
596
|
+
|
597
|
+
context 'when source is single directory' do
|
598
|
+
it { expect(destination).to be_existing_directory }
|
599
|
+
end
|
600
|
+
|
601
|
+
context 'when source is nested directory' do
|
602
|
+
let(:source) { 'src.d/subdir.d' }
|
603
|
+
let(:destination) { 'dst.d/' }
|
604
|
+
|
605
|
+
it { expect(destination).to be_existing_directory }
|
606
|
+
end
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
context 'when destination is existing' do
|
611
|
+
context 'when source is list of files' do
|
612
|
+
before(:each) { create_test_files(source) }
|
613
|
+
|
614
|
+
context 'when destination is directory' do
|
615
|
+
let(:source) { %w(file1.txt file2.txt file3.txt) }
|
616
|
+
let(:destination) { 'file.d' }
|
617
|
+
let(:destination_files) { source.map { |s| File.join(destination, s) } }
|
618
|
+
|
619
|
+
before :each do
|
620
|
+
FileUtils.mkdir_p File.join(@aruba.current_directory, destination)
|
621
|
+
end
|
622
|
+
|
623
|
+
before :each do
|
624
|
+
@aruba.copy source, destination
|
625
|
+
end
|
626
|
+
|
627
|
+
it { source.each { |s| expect(destination_files).to be_existing_files } }
|
628
|
+
end
|
629
|
+
|
630
|
+
context 'when destination is not a directory' do
|
631
|
+
let(:source) { %w(file1.txt file2.txt file3.txt) }
|
632
|
+
let(:destination) { 'file.txt' }
|
633
|
+
|
634
|
+
before(:each) { create_test_files(destination) }
|
635
|
+
|
636
|
+
it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, "Multiples sources can only be copied to a directory" }
|
637
|
+
end
|
638
|
+
|
639
|
+
context 'when a source is the same like destination' do
|
640
|
+
let(:source) { 'file1.txt' }
|
641
|
+
let(:destination) { 'file1.txt' }
|
642
|
+
|
643
|
+
before(:each) { create_test_files(source) }
|
644
|
+
|
645
|
+
# rubocop:disable Metrics/LineLength
|
646
|
+
it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, %(same file: #{File.expand_path(File.join(@aruba.current_directory, source))} and #{File.expand_path(File.join(@aruba.current_directory, destination))}) }
|
647
|
+
# rubocop:enable Metrics/LineLength
|
648
|
+
end
|
649
|
+
|
650
|
+
context 'when a fixture is destination' do
|
651
|
+
let(:source) { '%/copy/file.txt' }
|
652
|
+
let(:destination) { '%/copy/file.txt' }
|
653
|
+
|
654
|
+
it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, "Using a fixture as destination (#{destination}) is not supported" }
|
655
|
+
end
|
656
|
+
end
|
657
|
+
end
|
658
|
+
|
659
|
+
context 'when source is non-existing' do
|
660
|
+
it { expect { @aruba.copy source, destination }.to raise_error ArgumentError}
|
116
661
|
end
|
117
662
|
end
|
118
663
|
end
|
119
664
|
|
120
665
|
context '#absolute_path' do
|
121
|
-
|
122
|
-
expect(@aruba.absolute_path(@file_name)).to eq File.expand_path(@
|
666
|
+
context 'when file_name is array of path names' do
|
667
|
+
it { silence(:stderr) { expect(@aruba.absolute_path(['path', @file_name])).to eq File.expand_path(File.join(current_directory, 'path', @file_name)) } }
|
668
|
+
end
|
669
|
+
end
|
670
|
+
|
671
|
+
context '#expand_path' do
|
672
|
+
context 'when file_name is given' do
|
673
|
+
it { expect(@aruba.expand_path(@file_name)).to eq File.expand_path(@file_path) }
|
674
|
+
end
|
675
|
+
|
676
|
+
context 'when path contains "."' do
|
677
|
+
it { expect(@aruba.expand_path('.')).to eq File.expand_path(current_directory) }
|
678
|
+
end
|
679
|
+
|
680
|
+
context 'when path contains ".."' do
|
681
|
+
it { expect(@aruba.expand_path('path/..')).to eq File.expand_path(File.join(current_directory)) }
|
682
|
+
end
|
683
|
+
|
684
|
+
context 'when path is nil' do
|
685
|
+
it { expect { @aruba.expand_path(nil) }.to raise_error ArgumentError }
|
123
686
|
end
|
124
687
|
|
125
|
-
|
126
|
-
expect
|
688
|
+
context 'when path is empty' do
|
689
|
+
it { expect { @aruba.expand_path('') }.to raise_error ArgumentError }
|
127
690
|
end
|
128
691
|
|
129
|
-
|
130
|
-
expect(@aruba.
|
692
|
+
context 'when dir_path is given similar to File.expand_path ' do
|
693
|
+
it { expect(@aruba.expand_path(@file_name, 'path')).to eq File.expand_path(File.join(current_directory, 'path', @file_name)) }
|
131
694
|
end
|
132
695
|
|
133
|
-
|
134
|
-
|
696
|
+
context 'when file_name contains fixtures "%" string' do
|
697
|
+
let(:klass) do
|
698
|
+
Class.new do
|
699
|
+
include Aruba::Api
|
700
|
+
|
701
|
+
def root_directory
|
702
|
+
File.expand_path(current_directory)
|
703
|
+
end
|
704
|
+
end
|
705
|
+
end
|
706
|
+
|
707
|
+
before :each do
|
708
|
+
@aruba = klass.new
|
709
|
+
@aruba.touch_file 'spec/fixtures/file1'
|
710
|
+
end
|
711
|
+
|
712
|
+
it { expect(@aruba.expand_path('%/file1')).to eq File.expand_path(File.join(current_directory, 'spec', 'fixtures', 'file1')) }
|
135
713
|
end
|
136
714
|
end
|
137
715
|
|
@@ -153,7 +731,7 @@ describe Aruba::Api do
|
|
153
731
|
it "works with ~ in path name" do
|
154
732
|
file_path = File.join('~', random_string)
|
155
733
|
|
156
|
-
with_env 'HOME' => File.expand_path(
|
734
|
+
with_env 'HOME' => File.expand_path(current_directory) do
|
157
735
|
@aruba.write_fixed_size_file(file_path, @file_size)
|
158
736
|
|
159
737
|
expect(File.exist?(File.expand_path(file_path))).to eq true
|
@@ -176,7 +754,7 @@ describe Aruba::Api do
|
|
176
754
|
it "works with ~ in path name" do
|
177
755
|
file_path = File.join('~', random_string)
|
178
756
|
|
179
|
-
with_env 'HOME' => File.expand_path(
|
757
|
+
with_env 'HOME' => File.expand_path(current_directory) do
|
180
758
|
@aruba.write_fixed_size_file(file_path, @file_size)
|
181
759
|
@aruba.check_file_size([[file_path, @file_size]])
|
182
760
|
end
|
@@ -188,78 +766,100 @@ describe Aruba::Api do
|
|
188
766
|
end
|
189
767
|
end
|
190
768
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
@aruba.filesystem_permissions(0644, @file_name)
|
196
|
-
result = sprintf( "%o" , File::Stat.new(@file_path).mode )[-4,4]
|
197
|
-
expect(result).to eq('0644')
|
769
|
+
describe '#filesystem_permissions' do
|
770
|
+
def actuctual_permissions
|
771
|
+
format( "%o" , File::Stat.new(file_path).mode )[-4,4]
|
772
|
+
end
|
198
773
|
|
199
|
-
|
200
|
-
|
201
|
-
|
774
|
+
let(:file_name) { @file_name }
|
775
|
+
let(:file_path) { @file_path }
|
776
|
+
let(:permissions) { '0655' }
|
202
777
|
|
203
|
-
|
204
|
-
|
205
|
-
expect(result).to eq('0655')
|
778
|
+
before(:each) do
|
779
|
+
File.open(file_path, 'w') { |f| f << "" }
|
206
780
|
end
|
207
781
|
|
208
|
-
|
209
|
-
@aruba.filesystem_permissions(
|
210
|
-
@aruba.check_filesystem_permissions('0666', @file_name, true)
|
782
|
+
before(:each) do
|
783
|
+
@aruba.filesystem_permissions(permissions, file_name)
|
211
784
|
end
|
212
785
|
|
213
|
-
|
214
|
-
|
215
|
-
|
786
|
+
context 'when file exists' do
|
787
|
+
context 'and permissions are given as string' do
|
788
|
+
it { expect(actuctual_permissions).to eq('0655') }
|
789
|
+
end
|
790
|
+
|
791
|
+
context 'and permissions are given as octal number' do
|
792
|
+
let(:permissions) { 0655 }
|
793
|
+
it { expect(actuctual_permissions).to eq('0655') }
|
794
|
+
end
|
795
|
+
|
796
|
+
context 'and path has ~ in it' do
|
797
|
+
let(:string) { random_string }
|
798
|
+
let(:file_name) { File.join('~', string) }
|
799
|
+
let(:file_path) { File.join(@aruba.current_directory, string) }
|
800
|
+
|
801
|
+
it { expect(actuctual_permissions).to eq('0655') }
|
802
|
+
end
|
216
803
|
end
|
804
|
+
end
|
805
|
+
|
806
|
+
describe '#check_filesystem_permissions' do
|
807
|
+
let(:file_name) { @file_name }
|
808
|
+
let(:file_path) { @file_path }
|
217
809
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
}.to raise_error
|
810
|
+
let(:permissions) { '0655' }
|
811
|
+
|
812
|
+
before :each do
|
813
|
+
set_env 'HOME', File.expand_path(@aruba.current_directory)
|
223
814
|
end
|
224
815
|
|
225
|
-
|
226
|
-
|
227
|
-
expect {
|
228
|
-
@aruba.check_filesystem_permissions(0755, @file_name, true)
|
229
|
-
}.to raise_error
|
816
|
+
before(:each) do
|
817
|
+
File.open(file_path, 'w') { |f| f << "" }
|
230
818
|
end
|
231
819
|
|
232
|
-
|
233
|
-
@aruba.filesystem_permissions(
|
234
|
-
@aruba.check_filesystem_permissions(0666, @file_name, true)
|
820
|
+
before(:each) do
|
821
|
+
@aruba.filesystem_permissions(permissions, file_name)
|
235
822
|
end
|
236
823
|
|
237
|
-
|
238
|
-
|
824
|
+
context 'when file exists' do
|
825
|
+
context 'and should have permissions' do
|
826
|
+
context 'and permissions are given as string' do
|
827
|
+
it { @aruba.check_filesystem_permissions(permissions, file_name, true) }
|
828
|
+
end
|
829
|
+
|
830
|
+
context 'and permissions are given as octal number' do
|
831
|
+
let(:permissions) { 0666 }
|
832
|
+
|
833
|
+
it { @aruba.check_filesystem_permissions(permissions, file_name, true) }
|
834
|
+
end
|
239
835
|
|
240
|
-
|
241
|
-
|
836
|
+
context 'and path includes ~' do
|
837
|
+
let(:string) { random_string }
|
838
|
+
let(:file_name) { File.join('~', string) }
|
839
|
+
let(:file_path) { File.join(@aruba.current_directory, string) }
|
242
840
|
|
243
|
-
|
244
|
-
|
841
|
+
it { @aruba.check_filesystem_permissions(permissions, file_name, true) }
|
842
|
+
end
|
843
|
+
|
844
|
+
context 'but fails because the permissions are different' do
|
845
|
+
let(:expected_permissions) { 0666 }
|
846
|
+
|
847
|
+
it { expect { @aruba.check_filesystem_permissions(expected_permissions, file_name, true) }.to raise_error }
|
848
|
+
end
|
245
849
|
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
context '#remove_file' do
|
249
|
-
before(:each) { File.open(@file_path, 'w') { |f| f << "" } }
|
250
850
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
end
|
851
|
+
context 'and should not have permissions' do
|
852
|
+
context 'and succeeds when the difference is expected and permissions are different' do
|
853
|
+
let(:different_permissions) { 0666 }
|
255
854
|
|
256
|
-
|
257
|
-
|
855
|
+
it { @aruba.check_filesystem_permissions(different_permissions, file_name, false) }
|
856
|
+
end
|
258
857
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
858
|
+
context 'and fails because the permissions are the same although they should be different' do
|
859
|
+
let(:different_permissions) { 0655 }
|
860
|
+
|
861
|
+
it { expect { @aruba.check_filesystem_permissions(different_permissions, file_name, false) }.to raise_error }
|
862
|
+
end
|
263
863
|
end
|
264
864
|
end
|
265
865
|
end
|
@@ -269,7 +869,7 @@ describe Aruba::Api do
|
|
269
869
|
|
270
870
|
it "should check existence using plain match" do
|
271
871
|
file_name = 'nested/dir/hello_world.txt'
|
272
|
-
file_path = File.join(@aruba.
|
872
|
+
file_path = File.join(@aruba.current_directory, file_name)
|
273
873
|
|
274
874
|
FileUtils.mkdir_p File.dirname( file_path )
|
275
875
|
File.open(file_path, 'w') { |f| f << "" }
|
@@ -282,7 +882,7 @@ describe Aruba::Api do
|
|
282
882
|
|
283
883
|
it "should check existence using regex" do
|
284
884
|
file_name = 'nested/dir/hello_world.txt'
|
285
|
-
file_path = File.join(@aruba.
|
885
|
+
file_path = File.join(@aruba.current_directory, file_name)
|
286
886
|
|
287
887
|
FileUtils.mkdir_p File.dirname( file_path )
|
288
888
|
File.open(file_path, 'w') { |f| f << "" }
|
@@ -295,7 +895,7 @@ describe Aruba::Api do
|
|
295
895
|
|
296
896
|
it "is no problem to mix both" do
|
297
897
|
file_name = 'nested/dir/hello_world.txt'
|
298
|
-
file_path = File.join(@aruba.
|
898
|
+
file_path = File.join(@aruba.current_directory, file_name)
|
299
899
|
|
300
900
|
FileUtils.mkdir_p File.dirname( file_path )
|
301
901
|
File.open(file_path, 'w') { |f| f << "" }
|
@@ -307,7 +907,7 @@ describe Aruba::Api do
|
|
307
907
|
it "works with ~ in path name" do
|
308
908
|
file_path = File.join('~', random_string)
|
309
909
|
|
310
|
-
with_env 'HOME' => File.expand_path(
|
910
|
+
with_env 'HOME' => File.expand_path(current_directory) do
|
311
911
|
FileUtils.mkdir_p File.dirname(File.expand_path(file_path))
|
312
912
|
File.open(File.expand_path(file_path), 'w') { |f| f << "" }
|
313
913
|
|
@@ -321,20 +921,38 @@ describe Aruba::Api do
|
|
321
921
|
@aruba.write_file(@file_name, "foo bar baz")
|
322
922
|
end
|
323
923
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
924
|
+
describe "#check_binary_file_content" do
|
925
|
+
let(:file_name) { @file_name }
|
926
|
+
let(:file_path) { @file_path }
|
927
|
+
|
928
|
+
let(:reference_file) { 'fixture' }
|
929
|
+
let(:reference_file_content) { 'foo bar baz' }
|
930
|
+
|
931
|
+
before :each do
|
932
|
+
@aruba.write_file(reference_file, reference_file_content)
|
329
933
|
end
|
330
934
|
|
331
|
-
|
332
|
-
|
333
|
-
|
935
|
+
context 'when files are the same' do
|
936
|
+
context 'and this is expected' do
|
937
|
+
it { @aruba.check_binary_file_content(file_name, reference_file) }
|
938
|
+
it { @aruba.check_binary_file_content(file_name, reference_file, true) }
|
939
|
+
end
|
940
|
+
|
941
|
+
context 'and this is not expected' do
|
942
|
+
it { expect { @aruba.check_binary_file_content(file_name, reference_file, false) }.to raise_error }
|
943
|
+
end
|
334
944
|
end
|
335
945
|
|
336
|
-
|
337
|
-
|
946
|
+
context 'when files are not the same' do
|
947
|
+
let(:reference_file_content) { 'bar' }
|
948
|
+
|
949
|
+
context 'and this is expected' do
|
950
|
+
it { @aruba.check_binary_file_content(file_name, reference_file, false) }
|
951
|
+
end
|
952
|
+
|
953
|
+
context 'and this is not expected' do
|
954
|
+
it { expect { @aruba.check_binary_file_content(file_name, reference_file, true) }.to raise_error }
|
955
|
+
end
|
338
956
|
end
|
339
957
|
end
|
340
958
|
|
@@ -354,7 +972,7 @@ describe Aruba::Api do
|
|
354
972
|
it "works with ~ in path name" do
|
355
973
|
file_path = File.join('~', random_string)
|
356
974
|
|
357
|
-
with_env 'HOME' => File.expand_path(
|
975
|
+
with_env 'HOME' => File.expand_path(current_directory) do
|
358
976
|
@aruba.write_file(file_path, "foo bar baz")
|
359
977
|
@aruba.check_file_content(file_path, non_matching_content, false)
|
360
978
|
end
|
@@ -375,7 +993,7 @@ describe Aruba::Api do
|
|
375
993
|
it "works with ~ in path name" do
|
376
994
|
file_path = File.join('~', random_string)
|
377
995
|
|
378
|
-
with_env 'HOME' => File.expand_path(
|
996
|
+
with_env 'HOME' => File.expand_path(current_directory) do
|
379
997
|
@aruba.write_file(file_path, "foo bar baz")
|
380
998
|
@aruba.check_file_content(file_path, non_matching_content, false)
|
381
999
|
end
|
@@ -398,7 +1016,7 @@ describe Aruba::Api do
|
|
398
1016
|
it "works with ~ in path name" do
|
399
1017
|
file_path = File.join('~', random_string)
|
400
1018
|
|
401
|
-
with_env 'HOME' => File.expand_path(
|
1019
|
+
with_env 'HOME' => File.expand_path(current_directory) do
|
402
1020
|
@aruba.write_file(file_path, "foo bar baz")
|
403
1021
|
|
404
1022
|
@aruba.with_file_content file_path do |full_content|
|
@@ -448,20 +1066,28 @@ describe Aruba::Api do
|
|
448
1066
|
describe '@announce_stdout' do
|
449
1067
|
after(:each){@aruba.stop_processes!}
|
450
1068
|
context 'enabled' do
|
1069
|
+
before :each do
|
1070
|
+
@aruba.send(:announcer).activate(:stdout)
|
1071
|
+
end
|
1072
|
+
|
451
1073
|
it "should announce to stdout exactly once" do
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
1074
|
+
result = capture(:stdout) do
|
1075
|
+
@aruba.run_simple('echo "hello world"', false)
|
1076
|
+
end
|
1077
|
+
|
1078
|
+
expect(result).to include('hello world')
|
1079
|
+
expect(@aruba.all_output).to include('hello world')
|
456
1080
|
end
|
457
1081
|
end
|
458
1082
|
|
459
1083
|
context 'disabled' do
|
460
1084
|
it "should not announce to stdout" do
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
1085
|
+
result = capture(:stdout) do
|
1086
|
+
@aruba.run_simple('echo "hello world"', false)
|
1087
|
+
end
|
1088
|
+
|
1089
|
+
expect(result).not_to include('hello world')
|
1090
|
+
expect(@aruba.all_output).to include('hello world')
|
465
1091
|
end
|
466
1092
|
end
|
467
1093
|
end
|
@@ -520,6 +1146,46 @@ describe Aruba::Api do
|
|
520
1146
|
end
|
521
1147
|
end
|
522
1148
|
|
1149
|
+
describe 'fixtures' do
|
1150
|
+
let(:aruba) do
|
1151
|
+
klass = Class.new do
|
1152
|
+
include Aruba::Api
|
1153
|
+
|
1154
|
+
def root_directory
|
1155
|
+
expand_path('.')
|
1156
|
+
end
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
klass.new
|
1160
|
+
end
|
1161
|
+
|
1162
|
+
describe '#fixtures_directory' do
|
1163
|
+
context 'when no fixtures directories exist' do
|
1164
|
+
it "should raise exception" do
|
1165
|
+
expect { aruba.fixtures_directory }.to raise_error
|
1166
|
+
end
|
1167
|
+
end
|
1168
|
+
|
1169
|
+
context 'when "/features/fixtures"-directory exist' do
|
1170
|
+
before(:each) { aruba.create_directory('features/fixtures') }
|
1171
|
+
|
1172
|
+
it { expect(aruba.fixtures_directory).to eq expand_path('features/fixtures') }
|
1173
|
+
end
|
1174
|
+
|
1175
|
+
context 'when "/spec/fixtures"-directory exist' do
|
1176
|
+
before(:each) { aruba.create_directory('spec/fixtures') }
|
1177
|
+
|
1178
|
+
it { expect(aruba.fixtures_directory).to eq expand_path('spec/fixtures') }
|
1179
|
+
end
|
1180
|
+
|
1181
|
+
context 'when "/test/fixtures"-directory exist' do
|
1182
|
+
before(:each) { aruba.create_directory('test/fixtures') }
|
1183
|
+
|
1184
|
+
it { expect(aruba.fixtures_directory).to eq expand_path('test/fixtures') }
|
1185
|
+
end
|
1186
|
+
end
|
1187
|
+
end
|
1188
|
+
|
523
1189
|
describe "#set_env" do
|
524
1190
|
after(:each) do
|
525
1191
|
@aruba.stop_processes!
|