aruba 0.14.9 → 0.14.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.travis.yml +17 -37
  4. data/CHANGELOG.md +30 -0
  5. data/Gemfile +11 -1
  6. data/features/{getting_started/cleanup.feature → 01_getting_started_with_aruba/cleanup_working_directory.feature} +4 -5
  7. data/features/{getting_started → 01_getting_started_with_aruba}/run_commands.feature +45 -15
  8. data/features/{getting_started → 01_getting_started_with_aruba}/supported_testing_frameworks.feature +5 -21
  9. data/features/{configuration → 02_configure_aruba}/activate_announcer_on_command_failure.feature +2 -2
  10. data/features/{configuration/usage.feature → 02_configure_aruba/basics.feature} +21 -29
  11. data/features/{configuration → 02_configure_aruba}/command_runtime_environment.feature +0 -0
  12. data/features/{configuration → 02_configure_aruba}/console_history_file.feature +2 -2
  13. data/features/{configuration → 02_configure_aruba}/exit_timeout.feature +25 -17
  14. data/features/{configuration → 02_configure_aruba}/fixtures_directories.feature +2 -2
  15. data/features/{configuration → 02_configure_aruba}/fixtures_path_prefix.feature +1 -1
  16. data/features/{configuration → 02_configure_aruba}/home_directory.feature +6 -6
  17. data/features/{configuration → 02_configure_aruba}/io_timeout.feature +2 -2
  18. data/features/{configuration → 02_configure_aruba}/keep_ansi.feature +0 -0
  19. data/features/{configuration → 02_configure_aruba}/log_level.feature +2 -2
  20. data/features/{configuration → 02_configure_aruba}/physical_block_size.feature +3 -3
  21. data/features/{configuration → 02_configure_aruba}/remove_ansi_escape_sequences.feature +2 -2
  22. data/features/{configuration → 02_configure_aruba}/root_directory.feature +1 -1
  23. data/features/{configuration → 02_configure_aruba}/startup_wait_time.feature +2 -2
  24. data/features/{configuration → 02_configure_aruba}/working_directory.feature +9 -4
  25. data/features/{steps/core/announce.feature → 03_testing_frameworks/cucumber/announce_information_for_troubleshooting.feature} +20 -40
  26. data/features/{steps/environment → 03_testing_frameworks/cucumber}/disable_bunder.feature +0 -0
  27. data/features/{steps/command/exit_statuses.feature → 03_testing_frameworks/cucumber/steps/command/check_for_exit_statuses.feature} +20 -20
  28. data/features/{steps/command/output.feature → 03_testing_frameworks/cucumber/steps/command/check_output_of_command.feature} +58 -111
  29. data/features/{steps/command/stderr.feature → 03_testing_frameworks/cucumber/steps/command/check_stderr_of_command.feature} +1 -1
  30. data/features/{steps/command/stdout.feature → 03_testing_frameworks/cucumber/steps/command/check_stdout_of_command.feature} +6 -6
  31. data/features/{steps/command/debug.feature → 03_testing_frameworks/cucumber/steps/command/debug_your_command_in_aruba.feature} +6 -6
  32. data/features/{steps/command/run.feature → 03_testing_frameworks/cucumber/steps/command/run_a_command.feature} +4 -4
  33. data/features/{steps/command/in_process.feature → 03_testing_frameworks/cucumber/steps/command/run_command_in_process.feature} +2 -2
  34. data/features/{steps/command/interactive.feature → 03_testing_frameworks/cucumber/steps/command/run_command_interactively.feature} +2 -2
  35. data/features/03_testing_frameworks/cucumber/steps/command/run_commands_which_require_a_shell.feature +79 -0
  36. data/features/{steps/command/send_signal.feature → 03_testing_frameworks/cucumber/steps/command/send_signal_to_command.feature} +19 -40
  37. data/features/{steps/command/stop.feature → 03_testing_frameworks/cucumber/steps/command/stop_command.feature} +47 -75
  38. data/features/{steps → 03_testing_frameworks/cucumber/steps}/environment/append_environment_variable.feature +3 -3
  39. data/features/{steps/environment/home_variable.feature → 03_testing_frameworks/cucumber/steps/environment/modify_home_variable_for_testing.feature} +4 -4
  40. data/features/{steps → 03_testing_frameworks/cucumber/steps}/environment/prepend_environment_variable.feature +3 -3
  41. data/features/{steps → 03_testing_frameworks/cucumber/steps}/environment/set_environment_variable.feature +3 -3
  42. data/features/{steps → 03_testing_frameworks/cucumber/steps}/filesystem/append_to_file.feature +0 -0
  43. data/features/{steps → 03_testing_frameworks/cucumber/steps}/filesystem/cd_to_directory.feature +0 -0
  44. data/features/{steps/filesystem/existence_of_directory.feature → 03_testing_frameworks/cucumber/steps/filesystem/check_existence_of_directory.feature} +0 -0
  45. data/features/{steps/filesystem/existence_of_file.feature → 03_testing_frameworks/cucumber/steps/filesystem/check_existence_of_file.feature} +0 -0
  46. data/features/{steps/filesystem/file_content.feature → 03_testing_frameworks/cucumber/steps/filesystem/check_file_content.feature} +57 -0
  47. data/features/{steps/filesystem/non_existence_of_directory.feature → 03_testing_frameworks/cucumber/steps/filesystem/check_non_existence_of_directory.feature} +0 -0
  48. data/features/{steps/filesystem/non_existence_of_file.feature → 03_testing_frameworks/cucumber/steps/filesystem/check_non_existence_of_file.feature} +0 -0
  49. data/features/{steps → 03_testing_frameworks/cucumber/steps}/filesystem/check_permissions_of_file.feature +0 -0
  50. data/features/{steps → 03_testing_frameworks/cucumber/steps}/filesystem/compare_files.feature +0 -0
  51. data/features/{steps/filesystem/copy.feature → 03_testing_frameworks/cucumber/steps/filesystem/copy_file_or_directory.feature} +0 -0
  52. data/features/{steps → 03_testing_frameworks/cucumber/steps}/filesystem/create_directory.feature +0 -0
  53. data/features/{steps → 03_testing_frameworks/cucumber/steps}/filesystem/create_file.feature +0 -0
  54. data/features/{steps/filesystem/move.feature → 03_testing_frameworks/cucumber/steps/filesystem/move_file_or_directory.feature} +0 -1
  55. data/features/{steps → 03_testing_frameworks/cucumber/steps}/filesystem/overwrite_file.feature +0 -0
  56. data/features/{steps → 03_testing_frameworks/cucumber/steps}/filesystem/remove_directory.feature +0 -0
  57. data/features/{steps → 03_testing_frameworks/cucumber/steps}/filesystem/remove_file.feature +0 -0
  58. data/features/{steps/filesystem/use_fixture.feature → 03_testing_frameworks/cucumber/steps/filesystem/use_fixtures_for_setup_test.feature} +0 -0
  59. data/features/{hooks/after/command.feature → 03_testing_frameworks/rspec/hooks/define_after_hook_for_commands.feature} +1 -4
  60. data/features/{hooks/before/command.feature → 03_testing_frameworks/rspec/hooks/define_before_hook_for_commands.feature} +1 -5
  61. data/features/{rspec/integration.feature → 03_testing_frameworks/rspec/setup_aruba_for_rspec.feature} +17 -17
  62. data/features/{api/command/find_command.feature → 04_aruba_api/command/find_a_started_command.feature} +0 -0
  63. data/features/{api/command/which.feature → 04_aruba_api/command/find_command_in_PATH.feature} +4 -4
  64. data/features/{api/command/stderr.feature → 04_aruba_api/command/read_stderr_of_command.feature} +8 -8
  65. data/features/{api/command/stdout.feature → 04_aruba_api/command/read_stdout_of_command.feature} +7 -7
  66. data/features/{api/command/run.feature → 04_aruba_api/command/run_command.feature} +53 -44
  67. data/features/{api → 04_aruba_api}/command/run_simple.feature +46 -34
  68. data/features/{api/command/send_signal.feature → 04_aruba_api/command/send_signal_to_command.feature} +8 -8
  69. data/features/{api → 04_aruba_api}/command/stop_all_commands.feature +18 -14
  70. data/features/{api/command/stop.feature → 04_aruba_api/command/stop_single_command.feature} +19 -18
  71. data/features/{api → 04_aruba_api}/command/terminate_all_commands.feature +16 -12
  72. data/features/{api/command/last_command_started.feature → 04_aruba_api/command/use_last_command_started.feature} +0 -0
  73. data/features/{api/command/last_command_stopped.feature → 04_aruba_api/command/use_last_command_stopped.feature} +2 -2
  74. data/features/{api → 04_aruba_api}/core/expand_path.feature +0 -0
  75. data/features/{api → 04_aruba_api}/environment/append_environment_variable.feature +0 -0
  76. data/features/{api → 04_aruba_api}/environment/delete_environment_variable.feature +0 -0
  77. data/features/{api → 04_aruba_api}/environment/prepend_environment_variable.feature +0 -0
  78. data/features/{api → 04_aruba_api}/environment/set_environment_variable.feature +0 -0
  79. data/features/{api/filesystem/cd.feature → 04_aruba_api/filesystem/cd_to_directory.feature} +0 -0
  80. data/features/{api/filesystem/does_exist.feature → 04_aruba_api/filesystem/check_existence_file_or_directory.feature} +0 -0
  81. data/features/{api/filesystem/is_absolute.feature → 04_aruba_api/filesystem/check_if_path_is_absolute.feature} +0 -0
  82. data/features/{api/filesystem/is_directory.feature → 04_aruba_api/filesystem/check_if_path_is_directory.feature} +0 -0
  83. data/features/{api/filesystem/is_file.feature → 04_aruba_api/filesystem/check_if_path_is_file.feature} +0 -0
  84. data/features/{api/filesystem/is_relative.feature → 04_aruba_api/filesystem/check_if_path_is_relative.feature} +0 -0
  85. data/features/{api → 04_aruba_api}/filesystem/create_directory.feature +0 -0
  86. data/features/{api/filesystem/move.feature → 04_aruba_api/filesystem/move_file_or_directory.feature} +0 -0
  87. data/features/{api/filesystem/disk_usage.feature → 04_aruba_api/filesystem/report_disk_usage.feature} +0 -0
  88. data/features/{api/filesystem/fixtures.feature → 04_aruba_api/filesystem/use_fixtures.feature} +0 -0
  89. data/features/{api → 04_aruba_api}/text/extract_text.feature +8 -8
  90. data/features/{api → 04_aruba_api}/text/replace_variables.feature +2 -2
  91. data/features/{api → 04_aruba_api}/text/sanitize_text.feature +22 -22
  92. data/features/{api → 04_aruba_api}/text/unescape_text.feature +12 -12
  93. data/features/{matchers/timeouts.feature → 05_use_rspec_matchers/command/check_timeouts.feature} +4 -4
  94. data/features/{matchers → 05_use_rspec_matchers}/directory/have_sub_directory.feature +0 -0
  95. data/features/{matchers → 05_use_rspec_matchers}/file/be_a_command_found_in_path.feature +0 -0
  96. data/features/{matchers → 05_use_rspec_matchers}/file/be_existing_executable.feature +0 -0
  97. data/features/{matchers → 05_use_rspec_matchers}/file/be_existing_file.feature +0 -0
  98. data/features/{matchers → 05_use_rspec_matchers}/file/have_file_content.feature +0 -0
  99. data/features/{matchers → 05_use_rspec_matchers}/file/have_file_size.feature +0 -0
  100. data/features/{matchers → 05_use_rspec_matchers}/path/be_an_absolute_path.feature +0 -0
  101. data/features/{matchers → 05_use_rspec_matchers}/path/be_an_existing_path.feature +0 -0
  102. data/features/{matchers → 05_use_rspec_matchers}/path/have_permissions.feature +4 -4
  103. data/features/{cli/init.feature → 06_use_aruba_cli/initialize_project_with_aruba.feature} +0 -0
  104. data/features/{cli/console.feature → 06_use_aruba_cli/open_console.feature} +0 -0
  105. data/features/08_other/improve_performance_if_using_jruby.feature +37 -0
  106. data/features/step_definitions/hooks.rb +0 -10
  107. data/features/support/env.rb +1 -1
  108. data/features/support/simplecov_setup.rb +9 -6
  109. data/fixtures/cli-app/bin/{cli → aruba-test-cli} +0 -0
  110. data/fixtures/cli-app/spec/spec_helper.rb +1 -0
  111. data/fixtures/empty-app/lib/cli/app.rb +0 -6
  112. data/lib/aruba/api/commands.rb +24 -0
  113. data/lib/aruba/api/core.rb +9 -2
  114. data/lib/aruba/api/deprecated.rb +2 -73
  115. data/lib/aruba/api/filesystem.rb +1 -1
  116. data/lib/aruba/colorizer.rb +10 -99
  117. data/lib/aruba/config/jruby.rb +15 -5
  118. data/lib/aruba/cucumber.rb +1 -0
  119. data/lib/aruba/cucumber/command.rb +63 -93
  120. data/lib/aruba/cucumber/deprecated.rb +93 -0
  121. data/lib/aruba/cucumber/file.rb +0 -12
  122. data/lib/aruba/cucumber/hooks.rb +0 -44
  123. data/lib/aruba/in_process.rb +2 -0
  124. data/lib/aruba/matchers/string/output_string_eq.rb +1 -1
  125. data/lib/aruba/platforms/announcer.rb +1 -1
  126. data/lib/aruba/platforms/command_monitor.rb +0 -3
  127. data/lib/aruba/processes/spawn_process.rb +17 -5
  128. data/lib/aruba/spawn_process.rb +4 -1
  129. data/lib/aruba/version.rb +1 -1
  130. data/script/bootstrap +0 -4
  131. data/spec/aruba/api/core_spec.rb +142 -0
  132. data/spec/aruba/api/deprecated_spec.rb +113 -0
  133. data/spec/aruba/api/filesystem_spec.rb +746 -0
  134. data/spec/aruba/api_spec.rb +1 -885
  135. data/spec/aruba/jruby_spec.rb +46 -28
  136. data/spec/aruba/{spawn_process_spec.rb → processes/spawn_process_spec.rb} +18 -2
  137. data/spec/spec_helper.rb +5 -3
  138. metadata +108 -115
  139. data/features/development/build.feature +0 -15
  140. data/features/getting_started/writing_good_feature_tests.feature +0 -38
  141. data/features/matchers/collection/include_an_object.feature +0 -72
  142. data/features/platforms/jruby.feature +0 -14
  143. data/features/step_definitions/aruba_dev_steps.rb +0 -56
  144. data/features/steps/command/shell.feature +0 -155
  145. data/features/steps/filesystem/check_file_content.feature +0 -61
  146. data/features/steps/filesystem/fixtures.feature +0 -64
  147. data/features/steps/overview.feature +0 -25
  148. data/spec/aruba/api/environment/restore_env_spec.rb +0 -86
  149. data/spec/aruba/api/environment/set_env_spec.rb +0 -46
  150. data/spec/aruba/api/filesystem/file_size_spec.rb +0 -28
@@ -1,895 +1,11 @@
1
1
  require 'spec_helper'
2
2
  require 'aruba/api'
3
3
  require 'fileutils'
4
+ require 'time'
4
5
 
5
6
  describe Aruba::Api do
6
7
  include_context 'uses aruba API'
7
8
 
8
- describe '#all_paths' do
9
- let(:name) { @file_name }
10
- let(:path) { @file_path }
11
-
12
- context 'when file exist' do
13
- before :each do
14
- Aruba.platform.write_file(path, '')
15
- end
16
-
17
- it { expect(all_paths).to include expand_path(name) }
18
- end
19
-
20
- context 'when directory exist' do
21
- let(:name) { 'test_dir' }
22
- let(:path) { File.join(@aruba.aruba.current_directory, name) }
23
-
24
- before :each do
25
- Aruba.platform.mkdir(path)
26
- end
27
-
28
- it { expect(all_paths).to include expand_path(name) }
29
- end
30
-
31
- context 'when nothing exist' do
32
- it { expect(all_paths).to eq [] }
33
- end
34
- end
35
-
36
- describe '#all_files' do
37
- let(:name) { @file_name }
38
- let(:path) { @file_path }
39
-
40
- context 'when file exist' do
41
- before :each do
42
- Aruba.platform.write_file(path, '')
43
- end
44
-
45
- it { expect(all_files).to include expand_path(name) }
46
- end
47
-
48
- context 'when directory exist' do
49
- let(:name) { 'test_dir' }
50
- let(:path) { File.join(@aruba.aruba.current_directory, name) }
51
-
52
- before :each do
53
- Aruba.platform.mkdir(path)
54
- end
55
-
56
- it { expect(all_files).to eq [] }
57
- end
58
-
59
- context 'when nothing exist' do
60
- it { expect(all_files).to eq [] }
61
- end
62
- end
63
-
64
- describe '#all_directories' do
65
- let(:name) { @file_name }
66
- let(:path) { @file_path }
67
-
68
- context 'when file exist' do
69
- before :each do
70
- Aruba.platform.write_file(path, '')
71
- end
72
-
73
- it { expect(all_directories).to eq [] }
74
- end
75
-
76
- context 'when directory exist' do
77
- let(:name) { 'test_dir' }
78
- let(:path) { File.join(@aruba.aruba.current_directory, name) }
79
-
80
- before :each do
81
- Aruba.platform.mkdir(path)
82
- end
83
-
84
- it { expect(all_directories).to include expand_path(name) }
85
- end
86
-
87
- context 'when nothing exist' do
88
- it { expect(all_directories).to eq [] }
89
- end
90
- end
91
-
92
- describe 'directories' do
93
- before(:each) do
94
- @directory_name = 'test_dir'
95
- @directory_path = File.join(@aruba.aruba.current_directory, @directory_name)
96
- end
97
-
98
- context '#create_directory' do
99
- it 'creates a directory' do
100
- @aruba.create_directory @directory_name
101
- expect(File.exist?(File.expand_path(@directory_path))).to be_truthy
102
- end
103
- end
104
-
105
- describe '#cd' do
106
- context 'with a block given' do
107
- it 'runs the passed block in the given directory' do
108
- @aruba.create_directory @directory_name
109
- full_path = File.expand_path(@directory_path)
110
- @aruba.cd @directory_name do
111
- expect(Dir.pwd).to eq full_path
112
- end
113
- expect(Dir.pwd).not_to eq full_path
114
- end
115
-
116
- it 'sets directory environment in the passed block' do
117
- @aruba.create_directory @directory_name
118
- old_pwd = ENV['PWD']
119
- full_path = File.expand_path(@directory_path)
120
- @aruba.cd @directory_name do
121
- expect(ENV['PWD']).to eq full_path
122
- expect(ENV['OLDPWD']).to eq old_pwd
123
- end
124
- end
125
-
126
- it 'sets aruba environment in the passed block' do
127
- @aruba.create_directory @directory_name
128
- @aruba.set_environment_variable('FOO', 'bar')
129
- @aruba.cd @directory_name do
130
- expect(ENV['FOO']).to eq 'bar'
131
- end
132
- end
133
-
134
- it 'does not touch other environment variables in the passed block' do
135
- @aruba.create_directory @directory_name
136
- @aruba.cd @directory_name do
137
- expect(ENV['HOME']).not_to be_nil
138
- end
139
- end
140
- end
141
- end
142
- end
143
-
144
- describe '#read' do
145
- let(:name) { 'test.txt'}
146
- let(:path) { File.join(@aruba.aruba.current_directory, name) }
147
- let(:content) { 'asdf' }
148
-
149
- before :each do
150
- @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
151
- end
152
-
153
- context 'when does not exist' do
154
- it { expect { @aruba.read(name) }.to raise_error ArgumentError }
155
- end
156
-
157
- context 'when exists' do
158
- context 'when file' do
159
- before :each do
160
- File.open(File.expand_path(path), 'w') { |f| f << content }
161
- end
162
-
163
- context 'when normal file' do
164
- it { expect(@aruba.read(name)).to eq [content] }
165
- end
166
-
167
- context 'when binary file' do
168
- let(:content) { "\u0000" }
169
- it { expect(@aruba.read(name)).to eq [content] }
170
- end
171
-
172
- context 'when is empty file' do
173
- let(:content) { '' }
174
- it { expect(@aruba.read(name)).to eq [] }
175
- end
176
-
177
- context 'when path contains ~' do
178
- let(:string) { random_string }
179
- let(:name) { File.join('~', string) }
180
- let(:path) { File.join(@aruba.aruba.current_directory, string) }
181
-
182
- it { expect(@aruba.read(name)).to eq [content] }
183
- end
184
- end
185
-
186
- context 'when directory' do
187
- let(:name) { 'test.d' }
188
-
189
- before :each do
190
- Array(path).each { |p| Aruba.platform.mkdir p }
191
- end
192
-
193
- it { expect { @aruba.read(name) }.to raise_error ArgumentError }
194
- end
195
- end
196
- end
197
-
198
- describe '#list' do
199
- let(:name) { 'test.d' }
200
- let(:content) { %w(subdir.1.d subdir.2.d) }
201
- let(:path) { File.join(@aruba.aruba.current_directory, name) }
202
-
203
- before :each do
204
- @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
205
- end
206
-
207
- context 'when does not exist' do
208
- it { expect { @aruba.list(name) }.to raise_error ArgumentError }
209
- end
210
-
211
- context 'when exists' do
212
- context 'when file' do
213
- let(:name) { 'test.txt' }
214
-
215
- before :each do
216
- File.open(File.expand_path(path), 'w') { |f| f << content }
217
- end
218
-
219
- context 'when normal file' do
220
- it { expect{ @aruba.list(name) }.to raise_error ArgumentError }
221
- end
222
- end
223
-
224
- context 'when directory' do
225
- before :each do
226
- Array(path).each { |p| Aruba.platform.mkdir p }
227
- end
228
-
229
- before :each do
230
- Array(content).each { |p| Aruba.platform.mkdir File.join(path, p) }
231
- end
232
-
233
- context 'when has subdirectories' do
234
- context 'when is simple path' do
235
- let(:existing_files) { @aruba.list(name) }
236
- let(:expected_files) { content.map { |c| File.join(name, c) }.sort }
237
-
238
- it { expect(expected_files - existing_files).to be_empty}
239
- end
240
-
241
- context 'when path contains ~' do
242
- let(:string) { random_string }
243
- let(:name) { File.join('~', string) }
244
- let(:path) { File.join(@aruba.aruba.current_directory, string) }
245
-
246
- let(:existing_files) { @aruba.list(name) }
247
- let(:expected_files) { content.map { |c| File.join(string, c) } }
248
-
249
- it { expect(expected_files - existing_files).to be_empty}
250
- end
251
- end
252
-
253
- context 'when has no subdirectories' do
254
- let(:content) { [] }
255
- it { expect(@aruba.list(name)).to eq [] }
256
- end
257
- end
258
- end
259
- end
260
-
261
- describe '#remove' do
262
- let(:name) { 'test.txt'}
263
- let(:path) { File.join(@aruba.aruba.current_directory, name) }
264
- let(:options) { {} }
265
-
266
- before :each do
267
- @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
268
- end
269
-
270
- context 'when file' do
271
- context 'when exists' do
272
- before :each do
273
- Array(path).each { |p| File.open(File.expand_path(p), 'w') { |f| f << "" } }
274
- end
275
-
276
- before :each do
277
- @aruba.remove(name, options)
278
- end
279
-
280
- context 'when is a single file' do
281
- it_behaves_like 'a non-existing file'
282
- end
283
-
284
- context 'when are multiple files' do
285
- let(:file_name) { %w(file1 file2 file3) }
286
- let(:file_path) { %w(file1 file2 file3).map { |p| File.join(@aruba.aruba.current_directory, p) } }
287
-
288
- it_behaves_like 'a non-existing file'
289
- end
290
-
291
- context 'when path contains ~' do
292
- let(:string) { random_string }
293
- let(:file_name) { File.join('~', string) }
294
- let(:file_path) { File.join(@aruba.aruba.current_directory, string) }
295
-
296
- it_behaves_like 'a non-existing file'
297
- end
298
- end
299
-
300
- context 'when does not exist' do
301
- before :each do
302
- @aruba.remove(name, options)
303
- end
304
-
305
- context 'when is forced to delete file' do
306
- let(:options) { { :force => true } }
307
-
308
- it_behaves_like 'a non-existing file'
309
- end
310
- end
311
- end
312
-
313
- context 'when is directory' do
314
- let(:name) { 'test.d' }
315
-
316
- context 'when exists' do
317
- before :each do
318
- Array(path).each { |p| Aruba.platform.mkdir p }
319
- end
320
-
321
- before :each do
322
- @aruba.remove(name, options)
323
- end
324
-
325
- context 'when is a single directory' do
326
- it_behaves_like 'a non-existing directory'
327
- end
328
-
329
- context 'when are multiple directorys' do
330
- let(:directory_name) { %w(directory1 directory2 directory3) }
331
- let(:directory_path) { %w(directory1 directory2 directory3).map { |p| File.join(@aruba.aruba.current_directory, p) } }
332
-
333
- it_behaves_like 'a non-existing directory'
334
- end
335
-
336
- context 'when path contains ~' do
337
- let(:string) { random_string }
338
- let(:directory_name) { File.join('~', string) }
339
- let(:directory_path) { File.join(@aruba.aruba.current_directory, string) }
340
-
341
- it_behaves_like 'a non-existing directory'
342
- end
343
- end
344
-
345
- context 'when does not exist' do
346
- before :each do
347
- @aruba.remove(name, options)
348
- end
349
-
350
- context 'when is forced to delete directory' do
351
- let(:options) { { :force => true } }
352
-
353
- it_behaves_like 'a non-existing directory'
354
- end
355
- end
356
- end
357
- end
358
-
359
- describe 'files' do
360
- describe '#touch' do
361
- let(:name) { @file_name }
362
- let(:path) { @file_path }
363
- let(:options) { {} }
364
-
365
- before :each do
366
- @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
367
- end
368
-
369
- context 'when file' do
370
- before :each do
371
- @aruba.touch(name, options)
372
- end
373
-
374
- context 'when does not exist' do
375
- context 'and should be created in existing directory' do
376
- it { expect(File.size(path)).to eq 0 }
377
- it_behaves_like 'an existing file'
378
- end
379
-
380
- context 'and should be created in non-existing directory' do
381
- let(:name) { 'directory/test' }
382
- let(:path) { File.join(@aruba.aruba.current_directory, 'directory/test') }
383
-
384
- it_behaves_like 'an existing file'
385
- end
386
-
387
- context 'and path includes ~' do
388
- let(:string) { random_string }
389
- let(:name) { File.join('~', string) }
390
- let(:path) { File.join(@aruba.aruba.current_directory, string) }
391
-
392
- it_behaves_like 'an existing file'
393
- end
394
-
395
- context 'and the mtime should be set statically' do
396
- let(:time) { Time.parse('2014-01-01 10:00:00') }
397
- let(:options) { { :mtime => Time.parse('2014-01-01 10:00:00') } }
398
-
399
- it_behaves_like 'an existing file'
400
- it { expect(File.mtime(path)).to eq time }
401
- end
402
-
403
- context 'and multiple file names are given' do
404
- let(:name) { %w(file1 file2 file3) }
405
- let(:path) { %w(file1 file2 file3).map { |p| File.join(@aruba.aruba.current_directory, p) } }
406
- it_behaves_like 'an existing file'
407
- end
408
- end
409
- end
410
-
411
- context 'when directory' do
412
- let(:name) { %w(directory1) }
413
- let(:path) { Array(name).map { |p| File.join(@aruba.aruba.current_directory, p) } }
414
-
415
- context 'when exist' do
416
- before(:each) { Array(path).each { |p| Aruba.platform.mkdir p } }
417
-
418
- before :each do
419
- @aruba.touch(name, options)
420
- end
421
-
422
- context 'and the mtime should be set statically' do
423
- let(:time) { Time.parse('2014-01-01 10:00:00') }
424
- let(:options) { { :mtime => Time.parse('2014-01-01 10:00:00') } }
425
-
426
- it_behaves_like 'an existing directory'
427
- it { Array(path).each { |p| expect(File.mtime(p)).to eq time } }
428
- end
429
- end
430
- end
431
- end
432
-
433
- describe '#absolute?' do
434
- let(:name) { @file_name }
435
- let(:path) { File.expand_path(File.join(@aruba.aruba.current_directory, name)) }
436
-
437
- context 'when is absolute path' do
438
- it { expect(@aruba).to be_absolute(path) }
439
- end
440
-
441
- context 'when is relative path' do
442
- it { expect(@aruba).not_to be_absolute(name) }
443
- end
444
- end
445
-
446
- describe '#relative?' do
447
- let(:name) { @file_name }
448
- let(:path) { File.expand_path(File.join(@aruba.aruba.current_directory, name)) }
449
-
450
- context 'when is absolute path' do
451
- it { expect(@aruba).not_to be_relative(path) }
452
- end
453
-
454
- context 'when is relative path' do
455
- it { expect(@aruba).to be_relative(name) }
456
- end
457
- end
458
-
459
- describe '#exist?' do
460
- context 'when is file' do
461
- let(:name) { @file_name }
462
- let(:path) { @file_path }
463
-
464
- context 'when exists' do
465
- before :each do
466
- Aruba.platform.write_file(path, '')
467
- end
468
-
469
- it { expect(@aruba).to be_exist(name) }
470
- end
471
-
472
- context 'when does not exist' do
473
- it { expect(@aruba).not_to be_exist(name) }
474
- end
475
- end
476
-
477
- context 'when is directory' do
478
- let(:name) { 'test.d' }
479
- let(:path) { File.join(@aruba.aruba.current_directory, name) }
480
-
481
- context 'when exists' do
482
- before :each do
483
- Aruba.platform.mkdir(path)
484
- end
485
-
486
- it { expect(@aruba).to be_exist(name) }
487
- end
488
-
489
- context 'when does not exist' do
490
- it { expect(@aruba).not_to be_exist(name) }
491
- end
492
- end
493
- end
494
-
495
- describe '#file?' do
496
- context 'when is file' do
497
- let(:name) { @file_name }
498
- let(:path) { @file_path }
499
-
500
- context 'when exists' do
501
- before :each do
502
- Aruba.platform.write_file(path, '')
503
- end
504
-
505
- it { expect(@aruba).to be_file(name) }
506
- end
507
-
508
- context 'when does not exist' do
509
- it { expect(@aruba).not_to be_file(name) }
510
- end
511
- end
512
-
513
- context 'when is directory' do
514
- let(:name) { 'test.d' }
515
- let(:path) { File.join(@aruba.aruba.current_directory, name) }
516
-
517
- context 'when exists' do
518
- before :each do
519
- Aruba.platform.mkdir(path)
520
- end
521
-
522
- it { expect(@aruba).not_to be_file(name) }
523
- end
524
-
525
- context 'when does not exist' do
526
- it { expect(@aruba).not_to be_file(name) }
527
- end
528
- end
529
- end
530
-
531
- describe '#directory?' do
532
- context 'when is file' do
533
- let(:name) { @file_name }
534
- let(:path) { @file_path }
535
-
536
- context 'when exists' do
537
- before :each do
538
- Aruba.platform.write_file(path, '')
539
- end
540
-
541
- it { expect(@aruba).not_to be_directory(name) }
542
- end
543
-
544
- context 'when does not exist' do
545
- it { expect(@aruba).not_to be_directory(name) }
546
- end
547
- end
548
-
549
- context 'when is directory' do
550
- let(:name) { 'test.d' }
551
- let(:path) { File.join(@aruba.aruba.current_directory, name) }
552
-
553
- context 'when exists' do
554
- before :each do
555
- Aruba.platform.mkdir(path)
556
- end
557
-
558
- it { expect(@aruba).to be_directory(name) }
559
- end
560
-
561
- context 'when does not exist' do
562
- it { expect(@aruba).not_to be_directory(name) }
563
- end
564
- end
565
- end
566
-
567
- describe '#copy' do
568
- let(:source) { 'file.txt' }
569
- let(:destination) { 'file1.txt' }
570
-
571
- context 'when source is existing' do
572
- context 'when destination is non-existing' do
573
- context 'when source is file' do
574
- before(:each) { create_test_files(source) }
575
-
576
- before :each do
577
- @aruba.copy source, destination
578
- end
579
-
580
- context 'when source is plain file' do
581
- it { expect(destination).to be_an_existing_file }
582
- end
583
-
584
- context 'when source is contains "~" in path' do
585
- let(:source) { '~/file.txt' }
586
- it { expect(destination).to be_an_existing_file }
587
- end
588
-
589
- context 'when source is fixture' do
590
- let(:source) { '%/copy/file.txt' }
591
- let(:destination) { 'file.txt' }
592
- it { expect(destination).to be_an_existing_file }
593
- end
594
-
595
- context 'when source is list of files' do
596
- let(:source) { %w(file1.txt file2.txt file3.txt) }
597
- let(:destination) { 'file.d' }
598
- let(:destination_files) { source.map { |s| File.join(destination, s) } }
599
-
600
- it { expect(destination_files).to all be_an_existing_file }
601
- end
602
- end
603
-
604
- context 'when source is directory' do
605
- let(:source) { 'src.d' }
606
- let(:destination) { 'dst.d' }
607
-
608
- before :each do
609
- Aruba.platform.mkdir(File.join(@aruba.aruba.current_directory, source))
610
- end
611
-
612
- before :each do
613
- @aruba.copy source, destination
614
- end
615
-
616
- context 'when source is single directory' do
617
- it { expect(destination).to be_an_existing_directory }
618
- end
619
-
620
- context 'when source is nested directory' do
621
- let(:source) { 'src.d/subdir.d' }
622
- let(:destination) { 'dst.d/' }
623
-
624
- it { expect(destination).to be_an_existing_directory }
625
- end
626
- end
627
- end
628
-
629
- context 'when destination is existing' do
630
- context 'when source is list of files' do
631
- before(:each) { create_test_files(source) }
632
-
633
- context 'when destination is directory' do
634
- let(:source) { %w(file1.txt file2.txt file3.txt) }
635
- let(:destination) { 'file.d' }
636
- let(:destination_files) { source.map { |s| File.join(destination, s) } }
637
-
638
- before :each do
639
- Aruba.platform.mkdir(File.join(@aruba.aruba.current_directory, destination))
640
- end
641
-
642
- before :each do
643
- @aruba.copy source, destination
644
- end
645
-
646
- it { source.each { |s| expect(destination_files).to all be_an_existing_file } }
647
- end
648
-
649
- context 'when destination is not a directory' do
650
- let(:source) { %w(file1.txt file2.txt file3.txt) }
651
- let(:destination) { 'file.txt' }
652
-
653
- before(:each) { create_test_files(destination) }
654
-
655
- it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, "Multiples sources can only be copied to a directory" }
656
- end
657
-
658
- context 'when a source is the same like destination' do
659
- let(:source) { 'file1.txt' }
660
- let(:destination) { 'file1.txt' }
661
-
662
- before(:each) { create_test_files(source) }
663
-
664
- # rubocop:disable Metrics/LineLength
665
- it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, %(same file: #{File.expand_path(File.join(@aruba.aruba.current_directory, source))} and #{File.expand_path(File.join(@aruba.aruba.current_directory, destination))}) }
666
- # rubocop:enable Metrics/LineLength
667
- end
668
-
669
- context 'when a fixture is destination' do
670
- let(:source) { '%/copy/file.txt' }
671
- let(:destination) { '%/copy/file.txt' }
672
-
673
- it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, "Using a fixture as destination (#{destination}) is not supported" }
674
- end
675
- end
676
- end
677
-
678
- context 'when source is non-existing' do
679
- it { expect { @aruba.copy source, destination }.to raise_error ArgumentError}
680
- end
681
- end
682
- end
683
-
684
- context '#absolute_path' do
685
- context 'when file_name is array of path names' do
686
- it { silence(:stderr) { expect(@aruba.absolute_path(['path', @file_name])).to eq File.expand_path(File.join(aruba.current_directory, 'path', @file_name)) } }
687
- end
688
- end
689
-
690
- context '#expand_path' do
691
- context 'when file_name is given' do
692
- it { expect(@aruba.expand_path(@file_name)).to eq File.expand_path(@file_path) }
693
- end
694
-
695
- context 'when file_path is given' do
696
- it { expect(@aruba.expand_path(@file_path)).to eq @file_path }
697
- end
698
-
699
- context 'when path contains "."' do
700
- it { expect(@aruba.expand_path('.')).to eq File.expand_path(aruba.current_directory) }
701
- end
702
-
703
- context 'when path contains ".."' do
704
- it { expect(@aruba.expand_path('path/..')).to eq File.expand_path(File.join(aruba.current_directory)) }
705
- end
706
-
707
- context 'when path is nil' do
708
- it { expect { @aruba.expand_path(nil) }.to raise_error ArgumentError }
709
- end
710
-
711
- context 'when path is empty' do
712
- it { expect { @aruba.expand_path('') }.to raise_error ArgumentError }
713
- end
714
-
715
- context 'when dir_path is given similar to File.expand_path ' do
716
- it { expect(@aruba.expand_path(@file_name, 'path')).to eq File.expand_path(File.join(aruba.current_directory, 'path', @file_name)) }
717
- end
718
-
719
- context 'when file_name contains fixtures "%" string' do
720
- let(:runtime) { instance_double('Aruba::Runtime') }
721
- let(:config) { double('Aruba::Config') }
722
- let(:environment) { instance_double('Aruba::Environment') }
723
-
724
- let(:klass) do
725
- Class.new do
726
- include Aruba::Api
727
-
728
- attr_reader :aruba
729
-
730
- def initialize(aruba)
731
- @aruba = aruba
732
- end
733
- end
734
- end
735
-
736
- before :each do
737
- allow(config).to receive(:fixtures_path_prefix).and_return('%')
738
- allow(config).to receive(:root_directory).and_return aruba.config.root_directory
739
- allow(config).to receive(:working_directory).and_return aruba.config.working_directory
740
- end
741
-
742
- before :each do
743
- allow(environment).to receive(:clear)
744
- allow(environment).to receive(:update).and_return(environment)
745
- allow(environment).to receive(:to_h).and_return('PATH' => aruba.current_directory.to_s)
746
- end
747
-
748
- before :each do
749
- allow(runtime).to receive(:config).and_return config
750
- allow(runtime).to receive(:environment).and_return environment
751
- allow(runtime).to receive(:current_directory).and_return aruba.current_directory
752
- allow(runtime).to receive(:root_directory).and_return aruba.root_directory
753
- allow(runtime).to receive(:fixtures_directory).and_return File.join(aruba.root_directory, aruba.current_directory, 'spec', 'fixtures')
754
- end
755
-
756
- before :each do
757
- @aruba = klass.new(runtime)
758
- @aruba.touch 'spec/fixtures/file1'
759
- end
760
-
761
- it { expect(@aruba.expand_path('%/file1')).to eq File.expand_path(File.join(aruba.current_directory, 'spec', 'fixtures', 'file1')) }
762
- end
763
- end
764
-
765
- context '#write_file' do
766
- it 'writes file' do
767
- @aruba.write_file(@file_name, '')
768
-
769
- expect(File.exist?(@file_path)).to eq true
770
- end
771
- end
772
-
773
- context '#write_fixed_size_file' do
774
- it "should write a fixed sized file" do
775
- @aruba.write_fixed_size_file(@file_name, @file_size)
776
- expect(File.exist?(@file_path)).to eq true
777
- expect(File.size(@file_path)).to eq @file_size
778
- end
779
-
780
- it "works with ~ in path name" do
781
- file_path = File.join('~', random_string)
782
-
783
- @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
784
- @aruba.write_fixed_size_file(file_path, @file_size)
785
-
786
- expect(File.exist?(File.expand_path(file_path))).to eq true
787
- expect(File.size(File.expand_path(file_path))).to eq @file_size
788
- end
789
- end
790
- end
791
-
792
- describe '#chmod' do
793
- def actual_permissions
794
- format( "%o" , File::Stat.new(file_path).mode )[-4,4]
795
- end
796
-
797
- let(:file_name) { @file_name }
798
- let(:file_path) { @file_path }
799
- let(:permissions) { '0655' }
800
-
801
- before :each do
802
- @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
803
- end
804
-
805
- before(:each) do
806
- File.open(file_path, 'w') { |f| f << "" }
807
- end
808
-
809
- before(:each) do
810
- @aruba.chmod(permissions, file_name)
811
- end
812
-
813
- context 'when file exists' do
814
- context 'and permissions are given as string' do
815
- it { expect(actual_permissions).to eq('0655') }
816
- end
817
-
818
- context 'and permissions are given as octal number' do
819
- let(:permissions) { 0o655 }
820
- it { expect(actual_permissions).to eq('0655') }
821
- end
822
-
823
- context 'and path has ~ in it' do
824
- let(:path) { random_string }
825
- let(:file_name) { File.join('~', path) }
826
- let(:file_path) { File.join(@aruba.aruba.current_directory, path) }
827
-
828
- it { expect(actual_permissions).to eq('0655') }
829
- end
830
- end
831
- end
832
-
833
- context "#with_file_content" do
834
- before :each do
835
- @aruba.write_file(@file_name, "foo bar baz")
836
- end
837
-
838
- it "checks the given file's full content against the expectations in the passed block" do
839
- @aruba.with_file_content @file_name do |full_content|
840
- expect(full_content).to eq "foo bar baz"
841
- end
842
- end
843
-
844
- it "works with ~ in path name" do
845
- file_path = File.join('~', random_string)
846
-
847
- @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
848
- @aruba.write_file(file_path, "foo bar baz")
849
-
850
- @aruba.with_file_content file_path do |full_content|
851
- expect(full_content).to eq "foo bar baz"
852
- end
853
- end
854
- end
855
-
856
- context "checking the file's content against the expectations in the block" do
857
- it "is successful when the inner expectations match" do
858
- expect do
859
- @aruba.with_file_content @file_name do |full_content|
860
- expect(full_content).to match(/foo/)
861
- expect(full_content).not_to match(/zoo/)
862
- end
863
- end . not_to raise_error
864
- end
865
-
866
- it "raises RSpec::Expectations::ExpectationNotMetError when the inner expectations don't match" do
867
- expect do
868
- @aruba.with_file_content @file_name do |full_content|
869
- expect(full_content).to match(/zoo/)
870
- expect(full_content).not_to match(/foo/)
871
- end
872
- end . to raise_error RSpec::Expectations::ExpectationNotMetError
873
- end
874
- end
875
- end #with_file_content
876
- end
877
-
878
- describe 'process environment' do
879
- context '#with_environment' do
880
- it 'modifies env for block' do
881
- variable = 'THIS_IS_A_ENV_VAR'
882
- ENV[variable] = '1'
883
-
884
- @aruba.with_environment variable => '0' do
885
- expect(ENV[variable]).to eq '0'
886
- end
887
-
888
- expect(ENV[variable]).to eq '1'
889
- end
890
- end
891
- end
892
-
893
9
  describe 'tags' do
894
10
  describe '@announce_stdout' do
895
11
  after(:each) { @aruba.all_commands.each(&:stop) }