aruba-win-fix 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +37 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +188 -0
  6. data/.simplecov +34 -0
  7. data/.travis.yml +47 -0
  8. data/.yardopts +8 -0
  9. data/CONTRIBUTING.md +71 -0
  10. data/Gemfile +83 -0
  11. data/History.md +579 -0
  12. data/LICENSE +20 -0
  13. data/README.md +226 -0
  14. data/Rakefile +49 -0
  15. data/TODO.md +13 -0
  16. data/appveyor.yml +32 -0
  17. data/aruba.gemspec +48 -0
  18. data/bin/aruba +7 -0
  19. data/config/.gitignore +1 -0
  20. data/cucumber.yml +26 -0
  21. data/features/.nav +72 -0
  22. data/features/api/command/find_command.feature +83 -0
  23. data/features/api/command/last_command_started.feature +50 -0
  24. data/features/api/command/last_command_stopped.feature +89 -0
  25. data/features/api/command/run.feature +414 -0
  26. data/features/api/command/run_simple.feature +242 -0
  27. data/features/api/command/send_signal.feature +53 -0
  28. data/features/api/command/stderr.feature +46 -0
  29. data/features/api/command/stdout.feature +46 -0
  30. data/features/api/command/stop.feature +131 -0
  31. data/features/api/command/stop_all_commands.feature +53 -0
  32. data/features/api/command/terminate_all_commands.feature +53 -0
  33. data/features/api/command/which.feature +37 -0
  34. data/features/api/core/expand_path.feature +88 -0
  35. data/features/api/environment/append_environment_variable.feature +128 -0
  36. data/features/api/environment/delete_environment_variable.feature +63 -0
  37. data/features/api/environment/prepend_environment_variable.feature +128 -0
  38. data/features/api/environment/set_environment_variable.feature +376 -0
  39. data/features/api/filesystem/cd.feature +184 -0
  40. data/features/api/filesystem/create_directory.feature +57 -0
  41. data/features/api/filesystem/disk_usage.feature +152 -0
  42. data/features/api/filesystem/does_exist.feature +62 -0
  43. data/features/api/filesystem/fixtures.feature +104 -0
  44. data/features/api/filesystem/is_absolute.feature +48 -0
  45. data/features/api/filesystem/is_directory.feature +53 -0
  46. data/features/api/filesystem/is_file.feature +54 -0
  47. data/features/api/filesystem/is_relative.feature +48 -0
  48. data/features/api/filesystem/move.feature +119 -0
  49. data/features/api/text/extract_text.feature +87 -0
  50. data/features/api/text/replace_variables.feature +45 -0
  51. data/features/api/text/sanitize_text.feature +228 -0
  52. data/features/api/text/unescape_text.feature +127 -0
  53. data/features/cli/console.feature +52 -0
  54. data/features/cli/init.feature +79 -0
  55. data/features/configuration/activate_announcer_on_command_failure.feature +38 -0
  56. data/features/configuration/command_runtime_environment.feature +129 -0
  57. data/features/configuration/console_history_file.feature +38 -0
  58. data/features/configuration/exit_timeout.feature +52 -0
  59. data/features/configuration/fixtures_directories.feature +38 -0
  60. data/features/configuration/fixtures_path_prefix.feature +23 -0
  61. data/features/configuration/home_directory.feature +80 -0
  62. data/features/configuration/io_timeout.feature +30 -0
  63. data/features/configuration/keep_ansi.feature +30 -0
  64. data/features/configuration/log_level.feature +38 -0
  65. data/features/configuration/physical_block_size.feature +53 -0
  66. data/features/configuration/remove_ansi_escape_sequences.feature +38 -0
  67. data/features/configuration/root_directory.feature +30 -0
  68. data/features/configuration/startup_wait_time.feature +48 -0
  69. data/features/configuration/usage.feature +159 -0
  70. data/features/configuration/working_directory.feature +33 -0
  71. data/features/development/build.feature +15 -0
  72. data/features/development/test.feature +24 -0
  73. data/features/getting_started/cleanup.feature +67 -0
  74. data/features/getting_started/install.feature +8 -0
  75. data/features/getting_started/run_commands.feature +177 -0
  76. data/features/getting_started/supported_testing_frameworks.feature +104 -0
  77. data/features/getting_started/writing_good_feature_tests.feature +38 -0
  78. data/features/hooks/after/command.feature +44 -0
  79. data/features/hooks/before/command.feature +71 -0
  80. data/features/matchers/collection/include_an_object.feature +72 -0
  81. data/features/matchers/directory/have_sub_directory.feature +110 -0
  82. data/features/matchers/file/be_a_command_found_in_path.feature +115 -0
  83. data/features/matchers/file/be_existing_executable.feature +88 -0
  84. data/features/matchers/file/be_existing_file.feature +82 -0
  85. data/features/matchers/file/have_file_content.feature +123 -0
  86. data/features/matchers/file/have_file_size.feature +107 -0
  87. data/features/matchers/path/be_an_absolute_path.feature +74 -0
  88. data/features/matchers/path/be_an_existing_path.feature +97 -0
  89. data/features/matchers/path/have_permissions.feature +118 -0
  90. data/features/matchers/timeouts.feature +48 -0
  91. data/features/platforms/jruby.feature +14 -0
  92. data/features/rspec/integration.feature +179 -0
  93. data/features/step_definitions/aruba_dev_steps.rb +56 -0
  94. data/features/step_definitions/hooks.rb +96 -0
  95. data/features/steps/command/debug.feature +92 -0
  96. data/features/steps/command/exit_statuses.feature +136 -0
  97. data/features/steps/command/in_process.feature +485 -0
  98. data/features/steps/command/interactive.feature +90 -0
  99. data/features/steps/command/output.feature +588 -0
  100. data/features/steps/command/run.feature +66 -0
  101. data/features/steps/command/send_signal.feature +104 -0
  102. data/features/steps/command/shell.feature +155 -0
  103. data/features/steps/command/stderr.feature +68 -0
  104. data/features/steps/command/stdout.feature +109 -0
  105. data/features/steps/command/stop.feature +313 -0
  106. data/features/steps/core/announce.feature +283 -0
  107. data/features/steps/environment/append_environment_variable.feature +52 -0
  108. data/features/steps/environment/home_variable.feature +62 -0
  109. data/features/steps/environment/prepend_environment_variable.feature +52 -0
  110. data/features/steps/environment/set_environment_variable.feature +49 -0
  111. data/features/steps/filesystem/append_to_file.feature +45 -0
  112. data/features/steps/filesystem/cd_to_directory.feature +33 -0
  113. data/features/steps/filesystem/check_file_content.feature +61 -0
  114. data/features/steps/filesystem/check_permissions_of_file.feature +39 -0
  115. data/features/steps/filesystem/compare_files.feature +42 -0
  116. data/features/steps/filesystem/copy.feature +45 -0
  117. data/features/steps/filesystem/create_directory.feature +57 -0
  118. data/features/steps/filesystem/create_file.feature +76 -0
  119. data/features/steps/filesystem/existence_of_directory.feature +57 -0
  120. data/features/steps/filesystem/existence_of_file.feature +43 -0
  121. data/features/steps/filesystem/file_content.feature +86 -0
  122. data/features/steps/filesystem/fixtures.feature +64 -0
  123. data/features/steps/filesystem/move.feature +45 -0
  124. data/features/steps/filesystem/non_existence_of_directory.feature +69 -0
  125. data/features/steps/filesystem/non_existence_of_file.feature +80 -0
  126. data/features/steps/filesystem/overwrite_file.feature +72 -0
  127. data/features/steps/filesystem/remove_directory.feature +38 -0
  128. data/features/steps/filesystem/remove_file.feature +38 -0
  129. data/features/steps/filesystem/use_fixture.feature +77 -0
  130. data/features/steps/overview.feature +60 -0
  131. data/features/support/aruba.rb +7 -0
  132. data/features/support/env.rb +33 -0
  133. data/features/support/jruby.rb +5 -0
  134. data/features/support/simplecov_setup.rb +8 -0
  135. data/fixtures/cli-app/.gitignore +9 -0
  136. data/fixtures/cli-app/.rspec +2 -0
  137. data/fixtures/cli-app/README.md +39 -0
  138. data/fixtures/cli-app/Rakefile +1 -0
  139. data/fixtures/cli-app/bin/cli +6 -0
  140. data/fixtures/cli-app/cli-app.gemspec +26 -0
  141. data/fixtures/cli-app/features/support/env.rb +1 -0
  142. data/fixtures/cli-app/lib/cli/app.rb +13 -0
  143. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +15 -0
  144. data/fixtures/cli-app/lib/cli/app/version.rb +5 -0
  145. data/fixtures/cli-app/script/console +14 -0
  146. data/fixtures/cli-app/spec/spec_helper.rb +9 -0
  147. data/fixtures/cli-app/spec/support/aruba.rb +1 -0
  148. data/fixtures/copy/file.txt +1 -0
  149. data/fixtures/empty-app/.gitignore +9 -0
  150. data/fixtures/empty-app/.rspec +2 -0
  151. data/fixtures/empty-app/README.md +24 -0
  152. data/fixtures/empty-app/Rakefile +1 -0
  153. data/fixtures/empty-app/cli-app.gemspec +26 -0
  154. data/fixtures/empty-app/lib/cli/app.rb +13 -0
  155. data/fixtures/empty-app/lib/cli/app/version.rb +5 -0
  156. data/fixtures/getting-started-app/.gitignore +4 -0
  157. data/fixtures/getting-started-app/Gemfile +4 -0
  158. data/fixtures/getting-started-app/README.md +3 -0
  159. data/fixtures/getting-started-app/features/support/env.rb +1 -0
  160. data/fixtures/spawn_process/stderr.sh +3 -0
  161. data/lib/aruba.rb +1 -0
  162. data/lib/aruba/api.rb +34 -0
  163. data/lib/aruba/api/command.rb +307 -0
  164. data/lib/aruba/api/core.rb +191 -0
  165. data/lib/aruba/api/deprecated.rb +897 -0
  166. data/lib/aruba/api/environment.rb +89 -0
  167. data/lib/aruba/api/filesystem.rb +392 -0
  168. data/lib/aruba/api/rvm.rb +44 -0
  169. data/lib/aruba/api/text.rb +56 -0
  170. data/lib/aruba/aruba_path.rb +133 -0
  171. data/lib/aruba/basic_configuration.rb +240 -0
  172. data/lib/aruba/basic_configuration/option.rb +32 -0
  173. data/lib/aruba/cli.rb +26 -0
  174. data/lib/aruba/colorizer.rb +108 -0
  175. data/lib/aruba/command.rb +74 -0
  176. data/lib/aruba/config.rb +108 -0
  177. data/lib/aruba/config/jruby.rb +17 -0
  178. data/lib/aruba/config_wrapper.rb +58 -0
  179. data/lib/aruba/console.rb +70 -0
  180. data/lib/aruba/console/help.rb +35 -0
  181. data/lib/aruba/contracts/absolute_path.rb +20 -0
  182. data/lib/aruba/contracts/enum.rb +26 -0
  183. data/lib/aruba/contracts/is_power_of_two.rb +22 -0
  184. data/lib/aruba/contracts/relative_path.rb +20 -0
  185. data/lib/aruba/cucumber.rb +13 -0
  186. data/lib/aruba/cucumber/command.rb +422 -0
  187. data/lib/aruba/cucumber/core.rb +5 -0
  188. data/lib/aruba/cucumber/environment.rb +42 -0
  189. data/lib/aruba/cucumber/file.rb +201 -0
  190. data/lib/aruba/cucumber/hooks.rb +160 -0
  191. data/lib/aruba/cucumber/rvm.rb +3 -0
  192. data/lib/aruba/cucumber/testing_frameworks.rb +95 -0
  193. data/lib/aruba/errors.rb +37 -0
  194. data/lib/aruba/event_bus.rb +59 -0
  195. data/lib/aruba/event_bus/name_resolver.rb +168 -0
  196. data/lib/aruba/events.rb +39 -0
  197. data/lib/aruba/extensions/string/strip.rb +25 -0
  198. data/lib/aruba/file_size.rb +63 -0
  199. data/lib/aruba/generators/script_file.rb +46 -0
  200. data/lib/aruba/hooks.rb +56 -0
  201. data/lib/aruba/in_config_wrapper.rb +24 -0
  202. data/lib/aruba/in_process.rb +14 -0
  203. data/lib/aruba/initializer.rb +222 -0
  204. data/lib/aruba/jruby.rb +4 -0
  205. data/lib/aruba/matchers/base/base_matcher.rb +96 -0
  206. data/lib/aruba/matchers/base/object_formatter.rb +114 -0
  207. data/lib/aruba/matchers/collection.rb +1 -0
  208. data/lib/aruba/matchers/collection/all.rb +11 -0
  209. data/lib/aruba/matchers/collection/include_an_object.rb +122 -0
  210. data/lib/aruba/matchers/command.rb +1 -0
  211. data/lib/aruba/matchers/command/be_successfully_executed.rb +34 -0
  212. data/lib/aruba/matchers/command/have_exit_status.rb +38 -0
  213. data/lib/aruba/matchers/command/have_finished_in_time.rb +37 -0
  214. data/lib/aruba/matchers/command/have_output.rb +36 -0
  215. data/lib/aruba/matchers/command/have_output_on_stderr.rb +32 -0
  216. data/lib/aruba/matchers/command/have_output_on_stdout.rb +32 -0
  217. data/lib/aruba/matchers/command/have_output_size.rb +28 -0
  218. data/lib/aruba/matchers/directory.rb +1 -0
  219. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +38 -0
  220. data/lib/aruba/matchers/directory/have_sub_directory.rb +53 -0
  221. data/lib/aruba/matchers/environment.rb +1 -0
  222. data/lib/aruba/matchers/file.rb +1 -0
  223. data/lib/aruba/matchers/file/be_a_command_found_in_path.rb +36 -0
  224. data/lib/aruba/matchers/file/be_an_existing_executable.rb +37 -0
  225. data/lib/aruba/matchers/file/be_an_existing_file.rb +38 -0
  226. data/lib/aruba/matchers/file/have_file_content.rb +62 -0
  227. data/lib/aruba/matchers/file/have_file_size.rb +47 -0
  228. data/lib/aruba/matchers/file/have_same_file_content.rb +48 -0
  229. data/lib/aruba/matchers/path.rb +1 -0
  230. data/lib/aruba/matchers/path/a_path_matching_pattern.rb +25 -0
  231. data/lib/aruba/matchers/path/be_an_absolute_path.rb +36 -0
  232. data/lib/aruba/matchers/path/be_an_existing_path.rb +37 -0
  233. data/lib/aruba/matchers/path/have_permissions.rb +64 -0
  234. data/lib/aruba/matchers/path/match_path_pattern.rb +41 -0
  235. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +25 -0
  236. data/lib/aruba/matchers/string.rb +1 -0
  237. data/lib/aruba/matchers/string/include_output_string.rb +36 -0
  238. data/lib/aruba/matchers/string/match_output_string.rb +37 -0
  239. data/lib/aruba/matchers/string/output_string_eq.rb +35 -0
  240. data/lib/aruba/platform.rb +25 -0
  241. data/lib/aruba/platforms/announcer.rb +232 -0
  242. data/lib/aruba/platforms/aruba_file_creator.rb +35 -0
  243. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +35 -0
  244. data/lib/aruba/platforms/aruba_logger.rb +81 -0
  245. data/lib/aruba/platforms/command_monitor.rb +229 -0
  246. data/lib/aruba/platforms/determine_disk_usage.rb +28 -0
  247. data/lib/aruba/platforms/determine_file_size.rb +22 -0
  248. data/lib/aruba/platforms/disk_usage_calculator.rb +20 -0
  249. data/lib/aruba/platforms/filesystem_status.rb +68 -0
  250. data/lib/aruba/platforms/local_environment.rb +29 -0
  251. data/lib/aruba/platforms/simple_table.rb +54 -0
  252. data/lib/aruba/platforms/unix_command_string.rb +27 -0
  253. data/lib/aruba/platforms/unix_environment_variables.rb +220 -0
  254. data/lib/aruba/platforms/unix_platform.rb +276 -0
  255. data/lib/aruba/platforms/unix_which.rb +85 -0
  256. data/lib/aruba/platforms/windows_command_string.rb +31 -0
  257. data/lib/aruba/platforms/windows_environment_variables.rb +89 -0
  258. data/lib/aruba/platforms/windows_platform.rb +42 -0
  259. data/lib/aruba/platforms/windows_which.rb +106 -0
  260. data/lib/aruba/processes/basic_process.rb +143 -0
  261. data/lib/aruba/processes/debug_process.rb +69 -0
  262. data/lib/aruba/processes/in_process.rb +125 -0
  263. data/lib/aruba/processes/spawn_process.rb +278 -0
  264. data/lib/aruba/reporting.rb +126 -0
  265. data/lib/aruba/rspec.rb +107 -0
  266. data/lib/aruba/runtime.rb +96 -0
  267. data/lib/aruba/setup.rb +90 -0
  268. data/lib/aruba/spawn_process.rb +11 -0
  269. data/lib/aruba/version.rb +3 -0
  270. data/script/bootstrap +28 -0
  271. data/script/console +16 -0
  272. data/script/test +3 -0
  273. data/spec/aruba/api/environment/restore_env_spec.rb +65 -0
  274. data/spec/aruba/api/environment/set_env_spec.rb +42 -0
  275. data/spec/aruba/api/filesystem/file_size_spec.rb +28 -0
  276. data/spec/aruba/api/runtime_spec.rb +28 -0
  277. data/spec/aruba/api_spec.rb +1209 -0
  278. data/spec/aruba/aruba_path_spec.rb +103 -0
  279. data/spec/aruba/basic_configuration_spec.rb +5 -0
  280. data/spec/aruba/configuration_spec.rb +5 -0
  281. data/spec/aruba/hooks_spec.rb +17 -0
  282. data/spec/aruba/in_config_wrapper_spec.rb +25 -0
  283. data/spec/aruba/jruby_spec.rb +55 -0
  284. data/spec/aruba/matchers/command/have_output_size_spec.rb +25 -0
  285. data/spec/aruba/matchers/command_spec.rb +174 -0
  286. data/spec/aruba/matchers/directory_spec.rb +57 -0
  287. data/spec/aruba/matchers/file_spec.rb +127 -0
  288. data/spec/aruba/matchers/path_spec.rb +88 -0
  289. data/spec/aruba/platform/simple_table_spec.rb +23 -0
  290. data/spec/aruba/platform/windows_environment_variables_spec.rb +500 -0
  291. data/spec/aruba/rspec_spec.rb +15 -0
  292. data/spec/aruba/runtime_spec.rb +29 -0
  293. data/spec/aruba/spawn_process_spec.rb +60 -0
  294. data/spec/event_bus/name_resolver_spec.rb +68 -0
  295. data/spec/event_bus_spec.rb +160 -0
  296. data/spec/spec_helper.rb +23 -0
  297. data/spec/support/configs/.keep +0 -0
  298. data/spec/support/configs/aruba.rb +5 -0
  299. data/spec/support/configs/pry.rb +3 -0
  300. data/spec/support/configs/rspec.rb +15 -0
  301. data/spec/support/helpers/.keep +0 -0
  302. data/spec/support/helpers/reporting.rb +44 -0
  303. data/spec/support/matchers/.keep +0 -0
  304. data/spec/support/matchers/option.rb +35 -0
  305. data/spec/support/shared_contexts/.keep +0 -0
  306. data/spec/support/shared_contexts/aruba.rb +48 -0
  307. data/spec/support/shared_examples/.keep +0 -0
  308. data/spec/support/shared_examples/configuration.rb +116 -0
  309. data/spec/support/shared_examples/directory.rb +7 -0
  310. data/spec/support/shared_examples/file.rb +7 -0
  311. data/templates/css/console.css +24 -0
  312. data/templates/css/filesystem.css +42 -0
  313. data/templates/css/pygments-autumn.css +59 -0
  314. data/templates/files.erb +14 -0
  315. data/templates/images/LICENSE +22 -0
  316. data/templates/images/folder.png +0 -0
  317. data/templates/images/page_white.png +0 -0
  318. data/templates/images/page_white_gherkin.png +0 -0
  319. data/templates/images/page_white_ruby.png +0 -0
  320. data/templates/index.erb +20 -0
  321. data/templates/js/filesystem.js +5 -0
  322. data/templates/js/jquery-1.11.3.min.js +5 -0
  323. data/templates/main.erb +34 -0
  324. metadata +629 -0
@@ -0,0 +1,16 @@
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
+
9
+ module Aruba
10
+ class MyConsole
11
+ include Aruba::Api
12
+ end
13
+ end
14
+
15
+ include Aruba
16
+ Pry.start MyConsole.new
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ bundle exec rake test $*
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Command Environment' do
4
+ include_context 'uses aruba API'
5
+
6
+ around do |example|
7
+ Aruba.platform.with_environment do
8
+ example.run
9
+ end
10
+ end
11
+
12
+ describe '#restore_env' do
13
+ context 'when non-existing variable' do
14
+ before :each do
15
+ ENV.delete 'LONG_LONG_ENV_VARIABLE'
16
+ end
17
+
18
+ context 'when set single' do
19
+ before :each do
20
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
21
+ @aruba.restore_env
22
+ end
23
+
24
+ it { expect(ENV).not_to be_key 'LONG_LONG_ENV_VARIABLE' }
25
+ end
26
+
27
+ context 'when set multiple times' do
28
+ before :each do
29
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
30
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2'
31
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '3'
32
+ @aruba.restore_env
33
+ end
34
+
35
+ it { expect(ENV).not_to be_key 'LONG_LONG_ENV_VARIABLE' }
36
+ end
37
+ end
38
+
39
+ context 'when existing variable from outer context' do
40
+ before :each do
41
+ ENV['LONG_LONG_ENV_VARIABLE'] = '0'
42
+ end
43
+
44
+ context 'when set single time' do
45
+ before :each do
46
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
47
+ @aruba.restore_env
48
+ end
49
+
50
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '0' }
51
+ end
52
+
53
+ context 'when set multiple times' do
54
+ before :each do
55
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
56
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2'
57
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '3'
58
+ @aruba.restore_env
59
+ end
60
+
61
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '0' }
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Command Environment' do
4
+ include_context 'uses aruba API'
5
+
6
+ around do |example|
7
+ Aruba.platform.with_environment do
8
+ example.run
9
+ end
10
+ end
11
+
12
+ describe '#set_env' do
13
+ context 'when non-existing variable' do
14
+ before :each do
15
+ ENV.delete('LONG_LONG_ENV_VARIABLE')
16
+ end
17
+
18
+ context 'when string' do
19
+ before :each do
20
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
21
+ end
22
+
23
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '1' }
24
+ end
25
+ end
26
+
27
+ context 'when existing variable set by aruba' do
28
+ before :each do
29
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
30
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2'
31
+ end
32
+
33
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '2' }
34
+ end
35
+
36
+ context 'when existing variable by outer context' do
37
+ before :each do
38
+ ENV['LONG_LONG_ENV_VARIABLE'] = '1'
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Filesystem Api' do
4
+ include_context 'uses aruba API'
5
+
6
+ def expand_path(*args)
7
+ @aruba.expand_path(*args)
8
+ end
9
+
10
+ describe '#file_size' do
11
+ let(:name) { @file_name }
12
+ let(:path) { @file_path }
13
+ let(:size) { file_size(name) }
14
+
15
+ context 'when file exist' do
16
+ before :each do
17
+ File.open(path, 'w') { |f| f.print 'a' }
18
+ end
19
+
20
+ it { expect(size).to eq 1 }
21
+ end
22
+
23
+ context 'when file does not exist' do
24
+ let(:name) { 'non_existing_file' }
25
+ it { expect { size }.to raise_error }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'aruba' do
4
+ describe '#config' do
5
+ subject(:config) { aruba.config }
6
+
7
+ if RUBY_VERSION >= '1.9'
8
+ context 'when initialized' do
9
+ it { is_expected.to eq Aruba.config }
10
+ end
11
+ end
12
+
13
+ context 'when changed earlier' do
14
+ context 'values when init' do
15
+ let(:value) { 20 }
16
+ before(:each) { aruba.config.io_wait_timeout = value }
17
+
18
+ it { expect(config.io_wait_timeout).to eq value }
19
+ end
20
+
21
+ context 'default value' do
22
+ let(:value) { 0.1 } # Aruba.config.io_wait_timeout
23
+
24
+ it { expect(config.io_wait_timeout).to eq value }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,1209 @@
1
+ require 'spec_helper'
2
+ require 'securerandom'
3
+ require 'aruba/api'
4
+ require 'fileutils'
5
+
6
+ describe Aruba::Api do
7
+ include_context 'uses aruba API'
8
+
9
+ describe '#all_paths' do
10
+ let(:name) { @file_name }
11
+ let(:path) { @file_path }
12
+
13
+ context 'when file exist' do
14
+ before :each do
15
+ Aruba.platform.write_file(path, '')
16
+ end
17
+
18
+ it { expect(all_paths).to include expand_path(name) }
19
+ end
20
+
21
+ context 'when directory exist' do
22
+ let(:name) { 'test_dir' }
23
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
24
+
25
+ before :each do
26
+ Aruba.platform.mkdir(path)
27
+ end
28
+
29
+ it { expect(all_paths).to include expand_path(name) }
30
+ end
31
+
32
+ context 'when nothing exist' do
33
+ it { expect(all_paths).to eq [] }
34
+ end
35
+ end
36
+
37
+ describe '#all_files' do
38
+ let(:name) { @file_name }
39
+ let(:path) { @file_path }
40
+
41
+ context 'when file exist' do
42
+ before :each do
43
+ Aruba.platform.write_file(path, '')
44
+ end
45
+
46
+ it { expect(all_files).to include expand_path(name) }
47
+ end
48
+
49
+ context 'when directory exist' do
50
+ let(:name) { 'test_dir' }
51
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
52
+
53
+ before :each do
54
+ Aruba.platform.mkdir(path)
55
+ end
56
+
57
+ it { expect(all_files).to eq [] }
58
+ end
59
+
60
+ context 'when nothing exist' do
61
+ it { expect(all_files).to eq [] }
62
+ end
63
+ end
64
+
65
+ describe '#all_directories' do
66
+ let(:name) { @file_name }
67
+ let(:path) { @file_path }
68
+
69
+ context 'when file exist' do
70
+ before :each do
71
+ Aruba.platform.write_file(path, '')
72
+ end
73
+
74
+ it { expect(all_directories).to eq [] }
75
+ end
76
+
77
+ context 'when directory exist' do
78
+ let(:name) { 'test_dir' }
79
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
80
+
81
+ before :each do
82
+ Aruba.platform.mkdir(path)
83
+ end
84
+
85
+ it { expect(all_directories).to include expand_path(name) }
86
+ end
87
+
88
+ context 'when nothing exist' do
89
+ it { expect(all_directories).to eq [] }
90
+ end
91
+ end
92
+
93
+ describe 'directories' do
94
+ before(:each) do
95
+ @directory_name = 'test_dir'
96
+ @directory_path = File.join(@aruba.aruba.current_directory, @directory_name)
97
+ end
98
+
99
+ context '#create_directory' do
100
+ it 'creates a directory' do
101
+ @aruba.create_directory @directory_name
102
+ expect(File.exist?(File.expand_path(@directory_path))).to be_truthy
103
+ end
104
+ end
105
+ end
106
+
107
+ describe '#read' do
108
+ let(:name) { 'test.txt'}
109
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
110
+ let(:content) { 'asdf' }
111
+
112
+ before :each do
113
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
114
+ end
115
+
116
+ context 'when does not exist' do
117
+ it { expect { @aruba.read(name) }.to raise_error ArgumentError }
118
+ end
119
+
120
+ context 'when exists' do
121
+ context 'when file' do
122
+ before :each do
123
+ File.open(File.expand_path(path), 'w') { |f| f << content }
124
+ end
125
+
126
+ context 'when normal file' do
127
+ it { expect(@aruba.read(name)).to eq [content] }
128
+ end
129
+
130
+ context 'when binary file' do
131
+ let(:content) { "\u0000" }
132
+ it { expect(@aruba.read(name)).to eq [content] }
133
+ end
134
+
135
+ context 'when is empty file' do
136
+ let(:content) { '' }
137
+ it { expect(@aruba.read(name)).to eq [] }
138
+ end
139
+
140
+ context 'when path contains ~' do
141
+ let(:string) { random_string }
142
+ let(:name) { File.join('~', string) }
143
+ let(:path) { File.join(@aruba.aruba.current_directory, string) }
144
+
145
+ it { expect(@aruba.read(name)).to eq [content] }
146
+ end
147
+ end
148
+
149
+ context 'when directory' do
150
+ let(:name) { 'test.d' }
151
+
152
+ before :each do
153
+ Array(path).each { |p| Aruba.platform.mkdir p }
154
+ end
155
+
156
+ it { expect { @aruba.read(name) }.to raise_error ArgumentError }
157
+ end
158
+ end
159
+ end
160
+
161
+ describe '#list' do
162
+ let(:name) { 'test.d' }
163
+ let(:content) { %w(subdir.1.d subdir.2.d) }
164
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
165
+
166
+ before :each do
167
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
168
+ end
169
+
170
+ context 'when does not exist' do
171
+ it { expect { @aruba.list(name) }.to raise_error ArgumentError }
172
+ end
173
+
174
+ context 'when exists' do
175
+ context 'when file' do
176
+ let(:name) { 'test.txt' }
177
+
178
+ before :each do
179
+ File.open(File.expand_path(path), 'w') { |f| f << content }
180
+ end
181
+
182
+ context 'when normal file' do
183
+ it { expect{ @aruba.list(name) }.to raise_error ArgumentError }
184
+ end
185
+ end
186
+
187
+ context 'when directory' do
188
+ before :each do
189
+ Array(path).each { |p| Aruba.platform.mkdir p }
190
+ end
191
+
192
+ before :each do
193
+ Array(content).each { |p| Aruba.platform.mkdir File.join(path, p) }
194
+ end
195
+
196
+ context 'when has subdirectories' do
197
+ context 'when is simple path' do
198
+ let(:existing_files) { @aruba.list(name) }
199
+ let(:expected_files) { content.map { |c| File.join(name, c) }.sort }
200
+
201
+ it { expect(expected_files - existing_files).to be_empty}
202
+ end
203
+
204
+ context 'when path contains ~' do
205
+ let(:string) { random_string }
206
+ let(:name) { File.join('~', string) }
207
+ let(:path) { File.join(@aruba.aruba.current_directory, string) }
208
+
209
+ let(:existing_files) { @aruba.list(name) }
210
+ let(:expected_files) { content.map { |c| File.join(string, c) } }
211
+
212
+ it { expect(expected_files - existing_files).to be_empty}
213
+ end
214
+ end
215
+
216
+ context 'when has no subdirectories' do
217
+ let(:content) { [] }
218
+ it { expect(@aruba.list(name)).to eq [] }
219
+ end
220
+ end
221
+ end
222
+ end
223
+
224
+ describe '#remove' do
225
+ let(:name) { 'test.txt'}
226
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
227
+ let(:options) { {} }
228
+
229
+ before :each do
230
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
231
+ end
232
+
233
+ context 'when file' do
234
+ context 'when exists' do
235
+ before :each do
236
+ Array(path).each { |p| File.open(File.expand_path(p), 'w') { |f| f << "" } }
237
+ end
238
+
239
+ before :each do
240
+ @aruba.remove(name, options)
241
+ end
242
+
243
+ context 'when is a single file' do
244
+ it_behaves_like 'a non-existing file'
245
+ end
246
+
247
+ context 'when are multiple files' do
248
+ let(:file_name) { %w(file1 file2 file3) }
249
+ let(:file_path) { %w(file1 file2 file3).map { |p| File.join(@aruba.aruba.current_directory, p) } }
250
+
251
+ it_behaves_like 'a non-existing file'
252
+ end
253
+
254
+ context 'when path contains ~' do
255
+ let(:string) { random_string }
256
+ let(:file_name) { File.join('~', string) }
257
+ let(:file_path) { File.join(@aruba.aruba.current_directory, string) }
258
+
259
+ it_behaves_like 'a non-existing file'
260
+ end
261
+ end
262
+
263
+ context 'when does not exist' do
264
+ before :each do
265
+ @aruba.remove(name, options)
266
+ end
267
+
268
+ context 'when is forced to delete file' do
269
+ let(:options) { { :force => true } }
270
+
271
+ it_behaves_like 'a non-existing file'
272
+ end
273
+ end
274
+ end
275
+
276
+ context 'when is directory' do
277
+ let(:name) { 'test.d' }
278
+
279
+ context 'when exists' do
280
+ before :each do
281
+ Array(path).each { |p| Aruba.platform.mkdir p }
282
+ end
283
+
284
+ before :each do
285
+ @aruba.remove(name, options)
286
+ end
287
+
288
+ context 'when is a single directory' do
289
+ it_behaves_like 'a non-existing directory'
290
+ end
291
+
292
+ context 'when are multiple directorys' do
293
+ let(:directory_name) { %w(directory1 directory2 directory3) }
294
+ let(:directory_path) { %w(directory1 directory2 directory3).map { |p| File.join(@aruba.aruba.current_directory, p) } }
295
+
296
+ it_behaves_like 'a non-existing directory'
297
+ end
298
+
299
+ context 'when path contains ~' do
300
+ let(:string) { random_string }
301
+ let(:directory_name) { File.join('~', string) }
302
+ let(:directory_path) { File.join(@aruba.aruba.current_directory, string) }
303
+
304
+ it_behaves_like 'a non-existing directory'
305
+ end
306
+ end
307
+
308
+ context 'when does not exist' do
309
+ before :each do
310
+ @aruba.remove(name, options)
311
+ end
312
+
313
+ context 'when is forced to delete directory' do
314
+ let(:options) { { :force => true } }
315
+
316
+ it_behaves_like 'a non-existing directory'
317
+ end
318
+ end
319
+ end
320
+ end
321
+
322
+ describe 'files' do
323
+ describe '#touch' do
324
+ let(:name) { @file_name }
325
+ let(:path) { @file_path }
326
+ let(:options) { {} }
327
+
328
+ before :each do
329
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
330
+ end
331
+
332
+ context 'when file' do
333
+ before :each do
334
+ @aruba.touch(name, options)
335
+ end
336
+
337
+ context 'when does not exist' do
338
+ context 'and should be created in existing directory' do
339
+ it { expect(File.size(path)).to eq 0 }
340
+ it_behaves_like 'an existing file'
341
+ end
342
+
343
+ context 'and should be created in non-existing directory' do
344
+ let(:name) { 'directory/test' }
345
+ let(:path) { File.join(@aruba.aruba.current_directory, 'directory/test') }
346
+
347
+ it_behaves_like 'an existing file'
348
+ end
349
+
350
+ context 'and path includes ~' do
351
+ let(:string) { random_string }
352
+ let(:name) { File.join('~', string) }
353
+ let(:path) { File.join(@aruba.aruba.current_directory, string) }
354
+
355
+ it_behaves_like 'an existing file'
356
+ end
357
+
358
+ context 'and the mtime should be set statically' do
359
+ let(:time) { Time.parse('2014-01-01 10:00:00') }
360
+ let(:options) { { :mtime => Time.parse('2014-01-01 10:00:00') } }
361
+
362
+ it_behaves_like 'an existing file'
363
+ it { expect(File.mtime(path)).to eq time }
364
+ end
365
+
366
+ context 'and multiple file names are given' do
367
+ let(:name) { %w(file1 file2 file3) }
368
+ let(:path) { %w(file1 file2 file3).map { |p| File.join(@aruba.aruba.current_directory, p) } }
369
+ it_behaves_like 'an existing file'
370
+ end
371
+ end
372
+ end
373
+
374
+ context 'when directory' do
375
+ let(:name) { %w(directory1) }
376
+ let(:path) { Array(name).map { |p| File.join(@aruba.aruba.current_directory, p) } }
377
+
378
+ context 'when exist' do
379
+ before(:each) { Array(path).each { |p| Aruba.platform.mkdir p } }
380
+
381
+ before :each do
382
+ @aruba.touch(name, options)
383
+ end
384
+
385
+ context 'and the mtime should be set statically' do
386
+ let(:time) { Time.parse('2014-01-01 10:00:00') }
387
+ let(:options) { { :mtime => Time.parse('2014-01-01 10:00:00') } }
388
+
389
+ it_behaves_like 'an existing directory'
390
+ it { Array(path).each { |p| expect(File.mtime(p)).to eq time } }
391
+ end
392
+ end
393
+ end
394
+ end
395
+
396
+ describe '#absolute?' do
397
+ let(:name) { @file_name }
398
+ let(:path) { File.expand_path(File.join(@aruba.aruba.current_directory, name)) }
399
+
400
+ context 'when is absolute path' do
401
+ it { expect(@aruba).to be_absolute(path) }
402
+ end
403
+
404
+ context 'when is relative path' do
405
+ it { expect(@aruba).not_to be_absolute(name) }
406
+ end
407
+ end
408
+
409
+ describe '#relative?' do
410
+ let(:name) { @file_name }
411
+ let(:path) { File.expand_path(File.join(@aruba.aruba.current_directory, name)) }
412
+
413
+ context 'when is absolute path' do
414
+ it { expect(@aruba).not_to be_relative(path) }
415
+ end
416
+
417
+ context 'when is relative path' do
418
+ it { expect(@aruba).to be_relative(name) }
419
+ end
420
+ end
421
+
422
+ describe '#exist?' do
423
+ context 'when is file' do
424
+ let(:name) { @file_name }
425
+ let(:path) { @file_path }
426
+
427
+ context 'when exists' do
428
+ before :each do
429
+ Aruba.platform.write_file(path, '')
430
+ end
431
+
432
+ it { expect(@aruba).to be_exist(name) }
433
+ end
434
+
435
+ context 'when does not exist' do
436
+ it { expect(@aruba).not_to be_exist(name) }
437
+ end
438
+ end
439
+
440
+ context 'when is directory' do
441
+ let(:name) { 'test.d' }
442
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
443
+
444
+ context 'when exists' do
445
+ before :each do
446
+ Aruba.platform.mkdir(path)
447
+ end
448
+
449
+ it { expect(@aruba).to be_exist(name) }
450
+ end
451
+
452
+ context 'when does not exist' do
453
+ it { expect(@aruba).not_to be_exist(name) }
454
+ end
455
+ end
456
+ end
457
+
458
+ describe '#file?' do
459
+ context 'when is file' do
460
+ let(:name) { @file_name }
461
+ let(:path) { @file_path }
462
+
463
+ context 'when exists' do
464
+ before :each do
465
+ Aruba.platform.write_file(path, '')
466
+ end
467
+
468
+ it { expect(@aruba).to be_file(name) }
469
+ end
470
+
471
+ context 'when does not exist' do
472
+ it { expect(@aruba).not_to be_file(name) }
473
+ end
474
+ end
475
+
476
+ context 'when is directory' do
477
+ let(:name) { 'test.d' }
478
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
479
+
480
+ context 'when exists' do
481
+ before :each do
482
+ Aruba.platform.mkdir(path)
483
+ end
484
+
485
+ it { expect(@aruba).not_to be_file(name) }
486
+ end
487
+
488
+ context 'when does not exist' do
489
+ it { expect(@aruba).not_to be_file(name) }
490
+ end
491
+ end
492
+ end
493
+
494
+ describe '#directory?' do
495
+ context 'when is file' do
496
+ let(:name) { @file_name }
497
+ let(:path) { @file_path }
498
+
499
+ context 'when exists' do
500
+ before :each do
501
+ Aruba.platform.write_file(path, '')
502
+ end
503
+
504
+ it { expect(@aruba).not_to be_directory(name) }
505
+ end
506
+
507
+ context 'when does not exist' do
508
+ it { expect(@aruba).not_to be_directory(name) }
509
+ end
510
+ end
511
+
512
+ context 'when is directory' do
513
+ let(:name) { 'test.d' }
514
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
515
+
516
+ context 'when exists' do
517
+ before :each do
518
+ Aruba.platform.mkdir(path)
519
+ end
520
+
521
+ it { expect(@aruba).to be_directory(name) }
522
+ end
523
+
524
+ context 'when does not exist' do
525
+ it { expect(@aruba).not_to be_directory(name) }
526
+ end
527
+ end
528
+ end
529
+
530
+ describe '#copy' do
531
+ let(:source) { 'file.txt' }
532
+ let(:destination) { 'file1.txt' }
533
+
534
+ context 'when source is existing' do
535
+ context 'when destination is non-existing' do
536
+ context 'when source is file' do
537
+ before(:each) { create_test_files(source) }
538
+
539
+ before :each do
540
+ @aruba.copy source, destination
541
+ end
542
+
543
+ context 'when source is plain file' do
544
+ it { expect(destination).to be_an_existing_file }
545
+ end
546
+
547
+ context 'when source is contains "~" in path' do
548
+ let(:source) { '~/file.txt' }
549
+ it { expect(destination).to be_an_existing_file }
550
+ end
551
+
552
+ context 'when source is fixture' do
553
+ let(:source) { '%/copy/file.txt' }
554
+ let(:destination) { 'file.txt' }
555
+ it { expect(destination).to be_an_existing_file }
556
+ end
557
+
558
+ context 'when source is list of files' do
559
+ let(:source) { %w(file1.txt file2.txt file3.txt) }
560
+ let(:destination) { 'file.d' }
561
+ let(:destination_files) { source.map { |s| File.join(destination, s) } }
562
+
563
+ it { expect(destination_files).to all be_an_existing_file }
564
+ end
565
+ end
566
+
567
+ context 'when source is directory' do
568
+ let(:source) { 'src.d' }
569
+ let(:destination) { 'dst.d' }
570
+
571
+ before :each do
572
+ Aruba.platform.mkdir(File.join(@aruba.aruba.current_directory, source))
573
+ end
574
+
575
+ before :each do
576
+ @aruba.copy source, destination
577
+ end
578
+
579
+ context 'when source is single directory' do
580
+ it { expect(destination).to be_an_existing_directory }
581
+ end
582
+
583
+ context 'when source is nested directory' do
584
+ let(:source) { 'src.d/subdir.d' }
585
+ let(:destination) { 'dst.d/' }
586
+
587
+ it { expect(destination).to be_an_existing_directory }
588
+ end
589
+ end
590
+ end
591
+
592
+ context 'when destination is existing' do
593
+ context 'when source is list of files' do
594
+ before(:each) { create_test_files(source) }
595
+
596
+ context 'when destination is directory' do
597
+ let(:source) { %w(file1.txt file2.txt file3.txt) }
598
+ let(:destination) { 'file.d' }
599
+ let(:destination_files) { source.map { |s| File.join(destination, s) } }
600
+
601
+ before :each do
602
+ Aruba.platform.mkdir(File.join(@aruba.aruba.current_directory, destination))
603
+ end
604
+
605
+ before :each do
606
+ @aruba.copy source, destination
607
+ end
608
+
609
+ it { source.each { |s| expect(destination_files).to all be_an_existing_file } }
610
+ end
611
+
612
+ context 'when destination is not a directory' do
613
+ let(:source) { %w(file1.txt file2.txt file3.txt) }
614
+ let(:destination) { 'file.txt' }
615
+
616
+ before(:each) { create_test_files(destination) }
617
+
618
+ it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, "Multiples sources can only be copied to a directory" }
619
+ end
620
+
621
+ context 'when a source is the same like destination' do
622
+ let(:source) { 'file1.txt' }
623
+ let(:destination) { 'file1.txt' }
624
+
625
+ before(:each) { create_test_files(source) }
626
+
627
+ # rubocop:disable Metrics/LineLength
628
+ 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))}) }
629
+ # rubocop:enable Metrics/LineLength
630
+ end
631
+
632
+ context 'when a fixture is destination' do
633
+ let(:source) { '%/copy/file.txt' }
634
+ let(:destination) { '%/copy/file.txt' }
635
+
636
+ it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, "Using a fixture as destination (#{destination}) is not supported" }
637
+ end
638
+ end
639
+ end
640
+
641
+ context 'when source is non-existing' do
642
+ it { expect { @aruba.copy source, destination }.to raise_error ArgumentError}
643
+ end
644
+ end
645
+ end
646
+
647
+ context '#absolute_path' do
648
+ context 'when file_name is array of path names' do
649
+ it { silence(:stderr) { expect(@aruba.absolute_path(['path', @file_name])).to eq File.expand_path(File.join(aruba.current_directory, 'path', @file_name)) } }
650
+ end
651
+ end
652
+
653
+ context '#expand_path' do
654
+ context 'when file_name is given' do
655
+ it { expect(@aruba.expand_path(@file_name)).to eq File.expand_path(@file_path) }
656
+ end
657
+
658
+ context 'when path contains "."' do
659
+ it { expect(@aruba.expand_path('.')).to eq File.expand_path(aruba.current_directory) }
660
+ end
661
+
662
+ context 'when path contains ".."' do
663
+ it { expect(@aruba.expand_path('path/..')).to eq File.expand_path(File.join(aruba.current_directory)) }
664
+ end
665
+
666
+ context 'when path is nil' do
667
+ it { expect { @aruba.expand_path(nil) }.to raise_error ArgumentError }
668
+ end
669
+
670
+ context 'when path is empty' do
671
+ it { expect { @aruba.expand_path('') }.to raise_error ArgumentError }
672
+ end
673
+
674
+ context 'when dir_path is given similar to File.expand_path ' do
675
+ it { expect(@aruba.expand_path(@file_name, 'path')).to eq File.expand_path(File.join(aruba.current_directory, 'path', @file_name)) }
676
+ end
677
+
678
+ context 'when file_name contains fixtures "%" string' do
679
+ let(:runtime) { instance_double('Aruba::Runtime') }
680
+ let(:config) { double('Aruba::Config') }
681
+ let(:environment) { instance_double('Aruba::Environment') }
682
+
683
+ let(:klass) do
684
+ Class.new do
685
+ include Aruba::Api
686
+
687
+ attr_reader :aruba
688
+
689
+ def initialize(aruba)
690
+ @aruba = aruba
691
+ end
692
+ end
693
+ end
694
+
695
+ before :each do
696
+ allow(config).to receive(:fixtures_path_prefix).and_return('%')
697
+ allow(config).to receive(:root_directory).and_return aruba.config.root_directory
698
+ allow(config).to receive(:working_directory).and_return aruba.config.working_directory
699
+ end
700
+
701
+ before :each do
702
+ allow(environment).to receive(:clear)
703
+ allow(environment).to receive(:update).and_return(environment)
704
+ allow(environment).to receive(:to_h).and_return('PATH' => aruba.current_directory.to_s)
705
+ end
706
+
707
+ before :each do
708
+ allow(runtime).to receive(:config).and_return config
709
+ allow(runtime).to receive(:environment).and_return environment
710
+ allow(runtime).to receive(:current_directory).and_return aruba.current_directory
711
+ allow(runtime).to receive(:root_directory).and_return aruba.root_directory
712
+ allow(runtime).to receive(:fixtures_directory).and_return File.join(aruba.root_directory, aruba.current_directory, 'spec', 'fixtures')
713
+ end
714
+
715
+ before :each do
716
+ @aruba = klass.new(runtime)
717
+ @aruba.touch 'spec/fixtures/file1'
718
+ end
719
+
720
+ it { expect(@aruba.expand_path('%/file1')).to eq File.expand_path(File.join(aruba.current_directory, 'spec', 'fixtures', 'file1')) }
721
+ end
722
+ end
723
+
724
+ context '#write_file' do
725
+ it 'writes file' do
726
+ @aruba.write_file(@file_name, '')
727
+
728
+ expect(File.exist?(@file_path)).to eq true
729
+ end
730
+ end
731
+
732
+ context '#write_fixed_size_file' do
733
+ it "should write a fixed sized file" do
734
+ @aruba.write_fixed_size_file(@file_name, @file_size)
735
+ expect(File.exist?(@file_path)).to eq true
736
+ expect(File.size(@file_path)).to eq @file_size
737
+ end
738
+
739
+ it "works with ~ in path name" do
740
+ file_path = File.join('~', random_string)
741
+
742
+ @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
743
+ @aruba.write_fixed_size_file(file_path, @file_size)
744
+
745
+ expect(File.exist?(File.expand_path(file_path))).to eq true
746
+ expect(File.size(File.expand_path(file_path))).to eq @file_size
747
+ end
748
+ end
749
+ end
750
+
751
+ context '#check_file_size' do
752
+ it "should check an existing file size" do
753
+ @aruba.write_fixed_size_file(@file_name, @file_size)
754
+ @aruba.check_file_size([[@file_name, @file_size]])
755
+ end
756
+
757
+ it "should check an existing file size and fail" do
758
+ @aruba.write_fixed_size_file(@file_name, @file_size)
759
+ expect { @aruba.check_file_size([[@file_name, @file_size + 1]]) }.to raise_error
760
+ end
761
+
762
+ it "works with ~ in path name" do
763
+ file_path = File.join('~', random_string)
764
+
765
+ @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
766
+ @aruba.write_fixed_size_file(file_path, @file_size)
767
+ @aruba.check_file_size([[file_path, @file_size]])
768
+ end
769
+ end
770
+
771
+ it "should check an existing file size and fail" do
772
+ @aruba.write_fixed_size_file(@file_name, @file_size)
773
+ expect { @aruba.check_file_size([[@file_name, @file_size + 1]]) }.to raise_error
774
+ end
775
+ end
776
+
777
+ describe '#filesystem_permissions' do
778
+ def actual_permissions
779
+ format( "%o" , File::Stat.new(file_path).mode )[-4,4]
780
+ end
781
+
782
+ let(:file_name) { @file_name }
783
+ let(:file_path) { @file_path }
784
+ let(:permissions) { '0655' }
785
+
786
+ before :each do
787
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
788
+ end
789
+
790
+ before(:each) do
791
+ File.open(file_path, 'w') { |f| f << "" }
792
+ end
793
+
794
+ before(:each) do
795
+ @aruba.filesystem_permissions(permissions, file_name)
796
+ end
797
+
798
+ context 'when file exists' do
799
+ context 'and permissions are given as string' do
800
+ it { expect(actual_permissions).to eq('0655') }
801
+ end
802
+
803
+ context 'and permissions are given as octal number' do
804
+ let(:permissions) { 0655 }
805
+ it { expect(actual_permissions).to eq('0655') }
806
+ end
807
+
808
+ context 'and path has ~ in it' do
809
+ let(:path) { random_string }
810
+ let(:file_name) { File.join('~', path) }
811
+ let(:file_path) { File.join(@aruba.aruba.current_directory, path) }
812
+
813
+ it { expect(actual_permissions).to eq('0655') }
814
+ end
815
+ end
816
+ end
817
+
818
+ describe '#check_filesystem_permissions' do
819
+ let(:file_name) { @file_name }
820
+ let(:file_path) { @file_path }
821
+
822
+ let(:permissions) { '0655' }
823
+
824
+ before :each do
825
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
826
+ end
827
+
828
+ before(:each) do
829
+ File.open(file_path, 'w') { |f| f << "" }
830
+ end
831
+
832
+ before(:each) do
833
+ @aruba.filesystem_permissions(permissions, file_name)
834
+ end
835
+
836
+ context 'when file exists' do
837
+ context 'and should have permissions' do
838
+ context 'and permissions are given as string' do
839
+ it { @aruba.check_filesystem_permissions(permissions, file_name, true) }
840
+ end
841
+
842
+ context 'and permissions are given as octal number' do
843
+ let(:permissions) { 0666 }
844
+
845
+ it { @aruba.check_filesystem_permissions(permissions, file_name, true) }
846
+ end
847
+
848
+ context 'and path includes ~' do
849
+ let(:string) { random_string }
850
+ let(:file_name) { File.join('~', string) }
851
+ let(:file_path) { File.join(@aruba.aruba.current_directory, string) }
852
+
853
+ it { @aruba.check_filesystem_permissions(permissions, file_name, true) }
854
+ end
855
+
856
+ context 'but fails because the permissions are different' do
857
+ let(:expected_permissions) { 0666 }
858
+
859
+ it { expect { @aruba.check_filesystem_permissions(expected_permissions, file_name, true) }.to raise_error }
860
+ end
861
+ end
862
+
863
+ context 'and should not have permissions' do
864
+ context 'and succeeds when the difference is expected and permissions are different' do
865
+ let(:different_permissions) { 0666 }
866
+
867
+ it { @aruba.check_filesystem_permissions(different_permissions, file_name, false) }
868
+ end
869
+
870
+ context 'and fails because the permissions are the same although they should be different' do
871
+ let(:different_permissions) { 0655 }
872
+
873
+ it { expect { @aruba.check_filesystem_permissions(different_permissions, file_name, false) }.to raise_error }
874
+ end
875
+ end
876
+ end
877
+ end
878
+
879
+ context '#check_file_presence' do
880
+ before(:each) { File.open(@file_path, 'w') { |f| f << "" } }
881
+
882
+ it "should check existence using plain match" do
883
+ file_name = 'nested/dir/hello_world.txt'
884
+ file_path = File.join(@aruba.aruba.current_directory, file_name)
885
+
886
+ Aruba.platform.mkdir(File.dirname(file_path))
887
+ File.open(file_path, 'w') { |f| f << "" }
888
+
889
+ @aruba.check_file_presence(file_name)
890
+ @aruba.check_file_presence([file_name])
891
+ @aruba.check_file_presence([file_name], true)
892
+ @aruba.check_file_presence(['asdf'], false)
893
+ end
894
+
895
+ it "should check existence using regex" do
896
+ file_name = 'nested/dir/hello_world.txt'
897
+ file_path = File.join(@aruba.aruba.current_directory, file_name)
898
+
899
+ Aruba.platform.mkdir(File.dirname(file_path))
900
+ File.open(file_path, 'w') { |f| f << "" }
901
+
902
+ @aruba.check_file_presence([ /test123/ ], false )
903
+ @aruba.check_file_presence([ /hello_world.txt$/ ], true )
904
+ @aruba.check_file_presence([ /dir/ ], true )
905
+ @aruba.check_file_presence([ %r{nested/.+/} ], true )
906
+ end
907
+
908
+ it "is no problem to mix both" do
909
+ file_name = 'nested/dir/hello_world.txt'
910
+ file_path = File.join(@aruba.aruba.current_directory, file_name)
911
+
912
+ Aruba.platform.mkdir(File.dirname(file_path))
913
+ File.open(file_path, 'w') { |f| f << "" }
914
+
915
+ @aruba.check_file_presence([ file_name, /nested/ ], true )
916
+ @aruba.check_file_presence([ /test123/, 'asdf' ], false )
917
+ end
918
+
919
+ it "works with ~ in path name" do
920
+ file_path = File.join('~', random_string)
921
+
922
+ @aruba.with_environment 'HOME' => File.expand_path(@aruba.aruba.current_directory) do
923
+ Aruba.platform.mkdir(File.dirname(File.expand_path(file_path)))
924
+ File.open(File.expand_path(file_path), 'w') { |f| f << "" }
925
+
926
+ @aruba.check_file_presence( [ file_path ], true )
927
+ end
928
+ end
929
+ end
930
+
931
+ context "check file content" do
932
+ before :example do
933
+ @aruba.write_file(@file_name, "foo bar baz")
934
+ end
935
+
936
+ describe "#check_binary_file_content" do
937
+ let(:file_name) { @file_name }
938
+ let(:file_path) { @file_path }
939
+
940
+ let(:reference_file) { 'fixture' }
941
+ let(:reference_file_content) { 'foo bar baz' }
942
+
943
+ before :each do
944
+ @aruba.write_file(reference_file, reference_file_content)
945
+ end
946
+
947
+ context 'when files are the same' do
948
+ context 'and this is expected' do
949
+ it { @aruba.check_binary_file_content(file_name, reference_file) }
950
+ it { @aruba.check_binary_file_content(file_name, reference_file, true) }
951
+ end
952
+
953
+ context 'and this is not expected' do
954
+ it { expect { @aruba.check_binary_file_content(file_name, reference_file, false) }.to raise_error }
955
+ end
956
+ end
957
+
958
+ context 'when files are not the same' do
959
+ let(:reference_file_content) { 'bar' }
960
+
961
+ context 'and this is expected' do
962
+ it { @aruba.check_binary_file_content(file_name, reference_file, false) }
963
+ end
964
+
965
+ context 'and this is not expected' do
966
+ it { expect { @aruba.check_binary_file_content(file_name, reference_file, true) }.to raise_error }
967
+ end
968
+ end
969
+ end
970
+
971
+ context "#check_file_content" do
972
+ context "with regexp" do
973
+ let(:matching_content){/bar/}
974
+ let(:non_matching_content){/nothing/}
975
+ it "succeeds if file content matches" do
976
+ @aruba.check_file_content(@file_name, matching_content)
977
+ @aruba.check_file_content(@file_name, matching_content, true)
978
+ end
979
+
980
+ it "succeeds if file content does not match" do
981
+ @aruba.check_file_content(@file_name, non_matching_content, false)
982
+ end
983
+
984
+ it "works with ~ in path name" do
985
+ file_path = File.join('~', random_string)
986
+
987
+ @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
988
+ @aruba.write_file(file_path, "foo bar baz")
989
+ @aruba.check_file_content(file_path, non_matching_content, false)
990
+ end
991
+ end
992
+ end
993
+ context "with string" do
994
+ let(:matching_content){"foo bar baz"}
995
+ let(:non_matching_content){"bar"}
996
+ it "succeeds if file content matches" do
997
+ @aruba.check_file_content(@file_name, matching_content)
998
+ @aruba.check_file_content(@file_name, matching_content, true)
999
+ end
1000
+
1001
+ it "succeeds if file content does not match" do
1002
+ @aruba.check_file_content(@file_name, non_matching_content, false)
1003
+ end
1004
+
1005
+ it "works with ~ in path name" do
1006
+ file_path = File.join('~', random_string)
1007
+
1008
+ @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
1009
+ @aruba.write_file(file_path, "foo bar baz")
1010
+ @aruba.check_file_content(file_path, non_matching_content, false)
1011
+ end
1012
+ end
1013
+ end
1014
+ end
1015
+ end
1016
+
1017
+ context "#with_file_content" do
1018
+ before :each do
1019
+ @aruba.write_file(@file_name, "foo bar baz")
1020
+ end
1021
+
1022
+ it "checks the given file's full content against the expectations in the passed block" do
1023
+ @aruba.with_file_content @file_name do |full_content|
1024
+ expect(full_content).to eq "foo bar baz"
1025
+ end
1026
+ end
1027
+
1028
+ it "works with ~ in path name" do
1029
+ file_path = File.join('~', random_string)
1030
+
1031
+ @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
1032
+ @aruba.write_file(file_path, "foo bar baz")
1033
+
1034
+ @aruba.with_file_content file_path do |full_content|
1035
+ expect(full_content).to eq "foo bar baz"
1036
+ end
1037
+ end
1038
+ end
1039
+
1040
+ context "checking the file's content against the expectations in the block" do
1041
+ it "is successful when the inner expectations match" do
1042
+ expect do
1043
+ @aruba.with_file_content @file_name do |full_content|
1044
+ expect(full_content).to match(/foo/)
1045
+ expect(full_content).not_to match(/zoo/)
1046
+ end
1047
+ end . not_to raise_error
1048
+ end
1049
+
1050
+ it "raises RSpec::Expectations::ExpectationNotMetError when the inner expectations don't match" do
1051
+ expect do
1052
+ @aruba.with_file_content @file_name do |full_content|
1053
+ expect(full_content).to match(/zoo/)
1054
+ expect(full_content).not_to match(/foo/)
1055
+ end
1056
+ end . to raise_error RSpec::Expectations::ExpectationNotMetError
1057
+ end
1058
+ end
1059
+ end #with_file_content
1060
+ end
1061
+
1062
+ describe 'process environment' do
1063
+ context '#with_environment' do
1064
+ it 'modifies env for block' do
1065
+ variable = 'THIS_IS_A_ENV_VAR'
1066
+ ENV[variable] = '1'
1067
+
1068
+ @aruba.with_environment variable => '0' do
1069
+ expect(ENV[variable]).to eq '0'
1070
+ end
1071
+
1072
+ expect(ENV[variable]).to eq '1'
1073
+ end
1074
+ end
1075
+ end
1076
+
1077
+ describe 'tags' do
1078
+ describe '@announce_stdout' do
1079
+ after(:each) { @aruba.all_commands.each(&:stop) }
1080
+
1081
+ context 'enabled' do
1082
+ before :each do
1083
+ @aruba.aruba.announcer = instance_double 'Aruba::Platforms::Announcer'
1084
+ expect(@aruba.aruba.announcer).to receive(:announce).with(:stdout) { "hello world\n" }
1085
+ allow(@aruba.aruba.announcer).to receive(:announce)
1086
+ end
1087
+
1088
+ it "should announce to stdout exactly once" do
1089
+ @aruba.run_simple('echo "hello world"', false)
1090
+ expect(@aruba.all_output).to include('hello world')
1091
+ end
1092
+ end
1093
+
1094
+ context 'disabled' do
1095
+ it "should not announce to stdout" do
1096
+ result = capture(:stdout) do
1097
+ @aruba.run_simple('echo "hello world"', false)
1098
+ end
1099
+
1100
+ expect(result).not_to include('hello world')
1101
+ expect(@aruba.all_output).to include('hello world')
1102
+ end
1103
+ end
1104
+ end
1105
+ end
1106
+
1107
+ describe "#assert_not_matching_output" do
1108
+ before(:each){ @aruba.run_simple("echo foo", false) }
1109
+ after(:each) { @aruba.all_commands.each(&:stop) }
1110
+
1111
+ it "passes when the output doesn't match a regexp" do
1112
+ @aruba.assert_not_matching_output "bar", @aruba.all_output
1113
+ end
1114
+ it "fails when the output does match a regexp" do
1115
+ expect do
1116
+ @aruba.assert_not_matching_output "foo", @aruba.all_output
1117
+ end . to raise_error RSpec::Expectations::ExpectationNotMetError
1118
+ end
1119
+ end
1120
+
1121
+ describe '#run' do
1122
+ before(:each){ @aruba.run 'cat' }
1123
+ after(:each) { @aruba.all_commands.each(&:stop) }
1124
+
1125
+ it "respond to input" do
1126
+ @aruba.type "Hello"
1127
+ @aruba.type ""
1128
+ expect(@aruba.all_output).to eq "Hello\n"
1129
+ end
1130
+
1131
+ it "respond to close_input" do
1132
+ @aruba.type "Hello"
1133
+ @aruba.close_input
1134
+ expect(@aruba.all_output).to eq "Hello\n"
1135
+ end
1136
+
1137
+ it "pipes data" do
1138
+ @aruba.write_file(@file_name, "Hello\nWorld!")
1139
+ @aruba.pipe_in_file(@file_name)
1140
+ @aruba.close_input
1141
+ expect(@aruba.all_output).to eq "Hello\nWorld!"
1142
+ end
1143
+ end
1144
+
1145
+ describe "#run_simple" do
1146
+ before(:each){@aruba.run_simple "true"}
1147
+ after(:each) { @aruba.all_commands.each(&:stop) }
1148
+ describe "get_process" do
1149
+ it "returns a process" do
1150
+ expect(@aruba.get_process("true")).not_to be(nil)
1151
+ end
1152
+
1153
+ it "raises a descriptive exception" do
1154
+ expect { @aruba.get_process("false") }.to raise_error CommandNotFoundError, "No command named 'false' has been started"
1155
+ end
1156
+ end
1157
+ end
1158
+
1159
+ describe 'fixtures' do
1160
+ let(:api) do
1161
+ klass = Class.new do
1162
+ include Aruba::Api
1163
+
1164
+ def root_directory
1165
+ expand_path('.')
1166
+ end
1167
+ end
1168
+
1169
+ klass.new
1170
+ end
1171
+ end
1172
+
1173
+ describe "#set_environment_variable" do
1174
+ after(:each) do
1175
+ @aruba.all_commands.each(&:stop)
1176
+ @aruba.restore_env
1177
+ end
1178
+
1179
+ it "set environment variable" do
1180
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
1181
+ @aruba.run "env"
1182
+ expect(@aruba.all_output).to include("LONG_LONG_ENV_VARIABLE=true")
1183
+ end
1184
+
1185
+ it "overwrites environment variable" do
1186
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
1187
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'false'
1188
+ @aruba.run "env"
1189
+ expect(@aruba.all_output).to include("LONG_LONG_ENV_VARIABLE=false")
1190
+ end
1191
+ end
1192
+
1193
+ describe "#restore_env" do
1194
+ after(:each) { @aruba.all_commands.each(&:stop) }
1195
+ it "restores environment variable" do
1196
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
1197
+ @aruba.restore_env
1198
+ @aruba.run "env"
1199
+ expect(@aruba.all_output).not_to include("LONG_LONG_ENV_VARIABLE")
1200
+ end
1201
+ it "restores environment variable that has been set multiple times" do
1202
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
1203
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'false'
1204
+ @aruba.restore_env
1205
+ @aruba.run "env"
1206
+ expect(@aruba.all_output).not_to include("LONG_LONG_ENV_VARIABLE")
1207
+ end
1208
+ end
1209
+ end # Aruba::Api