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,6 +1,8 @@
1
1
  require 'aruba/processes/in_process'
2
2
  require 'aruba/platform'
3
3
 
4
+ Aruba.platform.deprecated('The use of "Aruba::InProcess" is deprecated. Use "Aruba::Processes::InProcess" instead.')
5
+
4
6
  # Aruba
5
7
  module Aruba
6
8
  # @deprecated
@@ -15,7 +15,7 @@
15
15
  #
16
16
  # RSpec.describe do
17
17
  # it { expect(last_command_started).to have_output output_string_eq string) }
18
- # it { expect(last_command_started).to have_output an_output_string_begin_eq string) }
18
+ # it { expect(last_command_started).to have_output an_output_string_being_eq string) }
19
19
  # end
20
20
  RSpec::Matchers.define :output_string_eq do |expected|
21
21
  match do |actual|
@@ -1,7 +1,7 @@
1
1
  require 'shellwords'
2
2
  require 'aruba/colorizer'
3
3
 
4
- Aruba::AnsiColor.coloring = false if !STDOUT.tty? && !ENV.key?("AUTOTEST")
4
+ Aruba::Colorizer.coloring = false if !STDOUT.tty? && !ENV.key?("AUTOTEST")
5
5
 
6
6
  # Aruba
7
7
  module Aruba
@@ -125,7 +125,6 @@ module Aruba
125
125
  find(cmd).stderr
126
126
  end
127
127
 
128
- # @deprecated
129
128
  # Get stdout of all commands
130
129
  #
131
130
  # @return [String]
@@ -140,7 +139,6 @@ module Aruba
140
139
  end
141
140
  end
142
141
 
143
- # @deprecated
144
142
  # Get stderr of all commands
145
143
  #
146
144
  # @return [String]
@@ -155,7 +153,6 @@ module Aruba
155
153
  end
156
154
  end
157
155
 
158
- # @deprecated
159
156
  # Get stderr and stdout of all commands
160
157
  #
161
158
  # @return [String]
@@ -25,17 +25,29 @@ module Aruba
25
25
 
26
26
  # Create process
27
27
  #
28
- # @params [String] cmd
28
+ # @param [String] cmd
29
29
  # Command string
30
30
  #
31
- # @params [Integer] exit_timeout
31
+ # @param [Numeric] exit_timeout
32
32
  # The timeout until we expect the command to be finished
33
33
  #
34
- # @params [Integer] io_wait_timeout
34
+ # @param [Numeric] io_wait_timeout
35
35
  # The timeout until we expect the io to be finished
36
36
  #
37
- # @params [String] working_directory
37
+ # @param [String] working_directory
38
38
  # The directory where the command will be executed
39
+ #
40
+ # @param [Hash] environment
41
+ # Environment variables
42
+ #
43
+ # @param [Class] main_class
44
+ # E.g. Cli::App::Runner
45
+ #
46
+ # @param [String] stop_signal
47
+ # Name of signal to send to stop process. E.g. 'HUP'.
48
+ #
49
+ # @param [Numeric] startup_wait_time
50
+ # The amount of seconds to wait after Aruba has started a command.
39
51
  def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
40
52
  super
41
53
 
@@ -262,7 +274,7 @@ module Aruba
262
274
  end
263
275
 
264
276
  def wait_for_io(time_to_wait, &block)
265
- sleep time_to_wait.to_i
277
+ sleep time_to_wait
266
278
  yield
267
279
  end
268
280
 
@@ -1,9 +1,12 @@
1
1
  require 'aruba/processes/spawn_process'
2
+ require 'aruba/platform'
3
+
4
+ Aruba.platform.deprecated('The use of "Aruba::SpawnProcess" is deprecated. Use "Aruba::Processes::SpawnProcess" instead.')
2
5
 
3
6
  module Aruba
4
7
  class SpawnProcess < Aruba::Processes::SpawnProcess
5
8
  def initialize(*args)
6
- warn('The use of "Aruba::SpawnProcess" is deprecated. Use "Aruba::Processes::SpawnProcess" instead.')
9
+ Aruba.platform.deprecated('The use of "Aruba::SpawnProcess" is deprecated. Use "Aruba::Processes::SpawnProcess" instead.')
7
10
 
8
11
  super
9
12
  end
@@ -1,3 +1,3 @@
1
1
  module Aruba
2
- VERSION = '0.14.9'.freeze
2
+ VERSION = '0.14.10'.freeze
3
3
  end
@@ -17,10 +17,6 @@ echo -ne "$info_msg Checking if bash installed? "
17
17
  which 'bash' >/dev/null 2>error.log || ( echo -e "$error_msg\n\nCould not find \`bash\`. Please install bash or add it to PATH"; output_error_log; exit 1 )
18
18
  echo OK
19
19
 
20
- echo -ne "$info_msg Checking if zsh installed? "
21
- which 'zsh' >/dev/null 2>error.log || ( echo -e "$error_msg\n\nCould not find \`zsh\`. Please install zsh or add it to PATH"; output_error_log; exit 1 )
22
- echo OK
23
-
24
20
  echo -e "$info_msg rubygem \"bundler\" "
25
21
  which bundle > /dev/null || gem install bundler --version '~> 1.17.3'
26
22
 
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+ require 'aruba/api'
3
+ require 'fileutils'
4
+
5
+ RSpec.describe Aruba::Api::Core do
6
+ include_context 'uses aruba API'
7
+
8
+ describe '#expand_path' do
9
+ context 'when file_name is given' do
10
+ it { expect(@aruba.expand_path(@file_name)).to eq File.expand_path(@file_path) }
11
+ end
12
+
13
+ context 'when file_path is given' do
14
+ it { expect(@aruba.expand_path(@file_path)).to eq @file_path }
15
+ end
16
+
17
+ context 'when path contains "."' do
18
+ it { expect(@aruba.expand_path('.')).to eq File.expand_path(aruba.current_directory) }
19
+ end
20
+
21
+ context 'when path contains ".."' do
22
+ it { expect(@aruba.expand_path('path/..')).to eq File.expand_path(File.join(aruba.current_directory)) }
23
+ end
24
+
25
+ context 'when path is nil' do
26
+ it { expect { @aruba.expand_path(nil) }.to raise_error ArgumentError }
27
+ end
28
+
29
+ context 'when path is empty' do
30
+ it { expect { @aruba.expand_path('') }.to raise_error ArgumentError }
31
+ end
32
+
33
+ context 'when second argument is given' do
34
+ it 'behaves similar to File.expand_path' do
35
+ expect(@aruba.expand_path(@file_name, 'path')).
36
+ to eq File.expand_path(File.join(aruba.current_directory, 'path', @file_name))
37
+ end
38
+ end
39
+
40
+ context 'when file_name contains fixtures "%" string' do
41
+ it 'finds files in the fixtures directory' do
42
+ expect(@aruba.expand_path('%/cli-app')).
43
+ to eq File.expand_path('cli-app', File.join(aruba.fixtures_directory))
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '#in_current_directory' do
49
+ let(:directory_path) { @aruba.aruba.current_directory }
50
+ let!(:full_path) { File.expand_path(directory_path) }
51
+
52
+ context 'with a block given' do
53
+ it 'runs the passed block in the given directory' do
54
+ @aruba.in_current_directory do
55
+ expect(Dir.pwd).to eq full_path
56
+ end
57
+ expect(Dir.pwd).not_to eq full_path
58
+ end
59
+
60
+ it 'sets directory environment in the passed block' do
61
+ old_pwd = ENV['PWD']
62
+ @aruba.in_current_directory do
63
+ expect(ENV['PWD']).to eq full_path
64
+ expect(ENV['OLDPWD']).to eq old_pwd
65
+ end
66
+ end
67
+
68
+ it 'sets aruba environment in the passed block' do
69
+ @aruba.set_environment_variable('FOO', 'bar')
70
+ @aruba.in_current_directory do
71
+ expect(ENV['FOO']).to eq 'bar'
72
+ end
73
+ end
74
+
75
+ it 'does not touch other environment variables in the passed block' do
76
+ keys = ENV.keys - ['PWD', 'OLDPWD']
77
+ old_values = ENV.values_at(*keys)
78
+ @aruba.in_current_directory do
79
+ expect(ENV.values_at(*keys)).to eq old_values
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ describe '#cd' do
86
+ before do
87
+ @directory_name = 'test_dir'
88
+ @directory_path = File.join(@aruba.aruba.current_directory, @directory_name)
89
+ end
90
+
91
+ context 'with a block given' do
92
+ it 'runs the passed block in the given directory' do
93
+ @aruba.create_directory @directory_name
94
+ full_path = File.expand_path(@directory_path)
95
+ @aruba.cd @directory_name do
96
+ expect(Dir.pwd).to eq full_path
97
+ end
98
+ expect(Dir.pwd).not_to eq full_path
99
+ end
100
+
101
+ it 'sets directory environment in the passed block' do
102
+ @aruba.create_directory @directory_name
103
+ old_pwd = ENV['PWD']
104
+ full_path = File.expand_path(@directory_path)
105
+ @aruba.cd @directory_name do
106
+ expect(ENV['PWD']).to eq full_path
107
+ expect(ENV['OLDPWD']).to eq old_pwd
108
+ end
109
+ end
110
+
111
+ it 'sets aruba environment in the passed block' do
112
+ @aruba.create_directory @directory_name
113
+ @aruba.set_environment_variable('FOO', 'bar')
114
+ @aruba.cd @directory_name do
115
+ expect(ENV['FOO']).to eq 'bar'
116
+ end
117
+ end
118
+
119
+ it 'does not touch other environment variables in the passed block' do
120
+ keys = ENV.keys - ['PWD', 'OLDPWD']
121
+ old_values = ENV.values_at(*keys)
122
+ @aruba.create_directory @directory_name
123
+ @aruba.cd @directory_name do
124
+ expect(ENV.values_at(*keys)).to eq old_values
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ describe '#with_environment' do
131
+ it 'modifies env for block' do
132
+ variable = 'THIS_IS_A_ENV_VAR'
133
+ ENV[variable] = '1'
134
+
135
+ @aruba.with_environment variable => '0' do
136
+ expect(ENV[variable]).to eq '0'
137
+ end
138
+
139
+ expect(ENV[variable]).to eq '1'
140
+ end
141
+ end
142
+ end
@@ -13,6 +13,12 @@ RSpec.describe 'Deprecated API' do
13
13
  allow(Aruba.platform).to receive(:deprecated)
14
14
  end
15
15
 
16
+ describe '#absolute_path' do
17
+ context 'when file_name is array of path names' do
18
+ it { expect(@aruba.absolute_path(['path', @file_name])).to eq File.expand_path(File.join(aruba.current_directory, 'path', @file_name)) }
19
+ end
20
+ end
21
+
16
22
  describe "#assert_not_matching_output" do
17
23
  before(:each){ @aruba.run_simple("echo foo", false) }
18
24
  after(:each) { @aruba.all_commands.each(&:stop) }
@@ -305,4 +311,111 @@ RSpec.describe 'Deprecated API' do
305
311
  expect { @aruba.get_process("false") }.to raise_error Aruba::CommandNotFoundError, "No command named 'false' has been started"
306
312
  end
307
313
  end
314
+
315
+ describe '#set_env' do
316
+ context 'when non-existing variable' do
317
+ before :each do
318
+ ENV.delete('LONG_LONG_ENV_VARIABLE')
319
+ end
320
+
321
+ context 'when string' do
322
+ before :each do
323
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
324
+ end
325
+
326
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '1' }
327
+ end
328
+ end
329
+
330
+ context 'when existing variable set by aruba' do
331
+ before :each do
332
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
333
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2'
334
+ end
335
+
336
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '2' }
337
+ end
338
+
339
+ context 'when existing variable by outer context' do
340
+ before :each do
341
+ ENV['LONG_LONG_ENV_VARIABLE'] = '1'
342
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2'
343
+ end
344
+
345
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '2' }
346
+ end
347
+ end
348
+
349
+ describe '#restore_env' do
350
+ context 'when non-existing variable' do
351
+ before :each do
352
+ ENV.delete 'LONG_LONG_ENV_VARIABLE'
353
+ end
354
+
355
+ context 'when set once' do
356
+ before :each do
357
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
358
+ @aruba.restore_env
359
+ end
360
+
361
+ it { expect(ENV).not_to have_key 'LONG_LONG_ENV_VARIABLE' }
362
+ end
363
+
364
+ context 'when set multiple times' do
365
+ before :each do
366
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
367
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2'
368
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '3'
369
+ @aruba.restore_env
370
+ end
371
+
372
+ it { expect(ENV).not_to have_key 'LONG_LONG_ENV_VARIABLE' }
373
+ end
374
+ end
375
+
376
+ context 'when existing variable from outer context' do
377
+ before :each do
378
+ ENV['LONG_LONG_ENV_VARIABLE'] = '0'
379
+ end
380
+
381
+ context 'when set once' do
382
+ before :each do
383
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
384
+ @aruba.restore_env
385
+ end
386
+
387
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '0' }
388
+ end
389
+
390
+ context 'when set multiple times' do
391
+ before :each do
392
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '1'
393
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '2'
394
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', '3'
395
+ @aruba.restore_env
396
+ end
397
+
398
+ it { expect(ENV['LONG_LONG_ENV_VARIABLE']).to eq '0' }
399
+ end
400
+ end
401
+ end
402
+
403
+ describe "#restore_env" do
404
+ after(:each) { @aruba.all_commands.each(&:stop) }
405
+
406
+ it "restores environment variable" do
407
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
408
+ @aruba.restore_env
409
+ @aruba.run "env"
410
+ expect(@aruba.all_output).not_to include("LONG_LONG_ENV_VARIABLE")
411
+ end
412
+
413
+ it "restores environment variable that has been set multiple times" do
414
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'true'
415
+ @aruba.set_env 'LONG_LONG_ENV_VARIABLE', 'false'
416
+ @aruba.restore_env
417
+ @aruba.run "env"
418
+ expect(@aruba.all_output).not_to include("LONG_LONG_ENV_VARIABLE")
419
+ end
420
+ end
308
421
  end
@@ -0,0 +1,746 @@
1
+ require 'spec_helper'
2
+ require 'aruba/api'
3
+
4
+ RSpec.describe Aruba::Api::Filesystem do
5
+ include_context 'uses aruba API'
6
+
7
+ def expand_path(*args)
8
+ @aruba.expand_path(*args)
9
+ end
10
+
11
+ describe '#all_paths' do
12
+ let(:name) { @file_name }
13
+ let(:path) { @file_path }
14
+
15
+ context 'when file exists' do
16
+ before :each do
17
+ Aruba.platform.write_file(path, '')
18
+ end
19
+
20
+ it { expect(all_paths).to include expand_path(name) }
21
+ end
22
+
23
+ context 'when directory exists' do
24
+ let(:name) { 'test_dir' }
25
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
26
+
27
+ before :each do
28
+ Aruba.platform.mkdir(path)
29
+ end
30
+
31
+ it { expect(all_paths).to include expand_path(name) }
32
+ end
33
+
34
+ context 'when nothing exists' do
35
+ it { expect(all_paths).to eq [] }
36
+ end
37
+ end
38
+
39
+ describe '#all_files' do
40
+ let(:name) { @file_name }
41
+ let(:path) { @file_path }
42
+
43
+ context 'when file exists' do
44
+ before :each do
45
+ Aruba.platform.write_file(path, '')
46
+ end
47
+
48
+ it { expect(all_files).to include expand_path(name) }
49
+ end
50
+
51
+ context 'when directory exists' do
52
+ let(:name) { 'test_dir' }
53
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
54
+
55
+ before :each do
56
+ Aruba.platform.mkdir(path)
57
+ end
58
+
59
+ it { expect(all_files).to eq [] }
60
+ end
61
+
62
+ context 'when nothing exists' do
63
+ it { expect(all_files).to eq [] }
64
+ end
65
+ end
66
+
67
+ describe '#all_directories' do
68
+ let(:name) { @file_name }
69
+ let(:path) { @file_path }
70
+
71
+ context 'when file exists' do
72
+ before :each do
73
+ Aruba.platform.write_file(path, '')
74
+ end
75
+
76
+ it { expect(all_directories).to eq [] }
77
+ end
78
+
79
+ context 'when directory exists' do
80
+ let(:name) { 'test_dir' }
81
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
82
+
83
+ before :each do
84
+ Aruba.platform.mkdir(path)
85
+ end
86
+
87
+ it { expect(all_directories).to include expand_path(name) }
88
+ end
89
+
90
+ context 'when nothing exists' do
91
+ it { expect(all_directories).to eq [] }
92
+ end
93
+ end
94
+
95
+ describe '#file_size' do
96
+ let(:name) { @file_name }
97
+ let(:path) { @file_path }
98
+ let(:size) { file_size(name) }
99
+
100
+ context 'when file exists' do
101
+ before :each do
102
+ File.open(path, 'w') { |f| f.print 'a' }
103
+ end
104
+
105
+ it { expect(size).to eq 1 }
106
+ end
107
+
108
+ context 'when file does not exist' do
109
+ let(:name) { 'non_existing_file' }
110
+ it { expect { size }.to raise_error ArgumentError }
111
+ end
112
+ end
113
+
114
+ describe '#touch' do
115
+ let(:name) { @file_name }
116
+ let(:path) { @file_path }
117
+ let(:options) { {} }
118
+
119
+ before :each do
120
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
121
+ end
122
+
123
+ context 'when touching a file that does not exist' do
124
+ before :each do
125
+ @aruba.touch(name, options)
126
+ end
127
+
128
+ context 'and should be created in an existing directory' do
129
+ it { expect(File.size(path)).to eq 0 }
130
+ it_behaves_like 'an existing file'
131
+ end
132
+
133
+ context 'and should be created in a non-existing directory' do
134
+ let(:name) { 'directory/test' }
135
+ let(:path) { File.join(@aruba.aruba.current_directory, 'directory/test') }
136
+
137
+ it_behaves_like 'an existing file'
138
+ end
139
+
140
+ context 'and path includes ~' 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_behaves_like 'an existing file'
146
+ end
147
+
148
+ context 'and the mtime should be set statically' do
149
+ let(:time) { Time.parse('2014-01-01 10:00:00') }
150
+ let(:options) { { :mtime => Time.parse('2014-01-01 10:00:00') } }
151
+
152
+ it_behaves_like 'an existing file'
153
+ it { expect(File.mtime(path)).to eq time }
154
+ end
155
+
156
+ context 'and multiple file names are given' do
157
+ let(:name) { %w(file1 file2 file3) }
158
+ let(:path) { %w(file1 file2 file3).map { |p| File.join(@aruba.aruba.current_directory, p) } }
159
+ it_behaves_like 'an existing file'
160
+ end
161
+ end
162
+
163
+ context 'when touching an existing directory' do
164
+ let(:name) { %w(directory1) }
165
+ let(:path) { Array(name).map { |p| File.join(@aruba.aruba.current_directory, p) } }
166
+
167
+ before do
168
+ Array(path).each { |p| Aruba.platform.mkdir p }
169
+ @aruba.touch(name, options)
170
+ end
171
+
172
+ context 'and the mtime should be set statically' do
173
+ let(:time) { Time.parse('2014-01-01 10:00:00') }
174
+ let(:options) { { :mtime => Time.parse('2014-01-01 10:00:00') } }
175
+
176
+ it_behaves_like 'an existing directory'
177
+ it { Array(path).each { |p| expect(File.mtime(p)).to eq time } }
178
+ end
179
+ end
180
+ end
181
+
182
+ describe '#absolute?' do
183
+ let(:name) { @file_name }
184
+ let(:path) { File.expand_path(File.join(@aruba.aruba.current_directory, name)) }
185
+
186
+ context 'when given an absolute path' do
187
+ it { expect(@aruba).to be_absolute(path) }
188
+ end
189
+
190
+ context 'when given a relative path' do
191
+ it { expect(@aruba).not_to be_absolute(name) }
192
+ end
193
+ end
194
+
195
+ describe '#relative?' do
196
+ let(:name) { @file_name }
197
+ let(:path) { File.expand_path(File.join(@aruba.aruba.current_directory, name)) }
198
+
199
+ context 'when given an absolute path' do
200
+ it { expect(@aruba).not_to be_relative(path) }
201
+ end
202
+
203
+ context 'when given a relative path' do
204
+ it { expect(@aruba).to be_relative(name) }
205
+ end
206
+ end
207
+
208
+ describe '#exist?' do
209
+ context 'when given a file' do
210
+ let(:name) { @file_name }
211
+ let(:path) { @file_path }
212
+
213
+ context 'when it exists' do
214
+ before :each do
215
+ Aruba.platform.write_file(path, '')
216
+ end
217
+
218
+ it { expect(@aruba).to be_exist(name) }
219
+ end
220
+
221
+ context 'when it does not exist' do
222
+ it { expect(@aruba).not_to be_exist(name) }
223
+ end
224
+ end
225
+
226
+ context 'when given a directory' do
227
+ let(:name) { 'test.d' }
228
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
229
+
230
+ context 'when it exists' do
231
+ before :each do
232
+ Aruba.platform.mkdir(path)
233
+ end
234
+
235
+ it { expect(@aruba).to be_exist(name) }
236
+ end
237
+
238
+ context 'when it does not exist' do
239
+ it { expect(@aruba).not_to be_exist(name) }
240
+ end
241
+ end
242
+ end
243
+
244
+ describe '#file?' do
245
+ context 'when given a file' do
246
+ let(:name) { @file_name }
247
+ let(:path) { @file_path }
248
+
249
+ context 'when it exists' do
250
+ before :each do
251
+ Aruba.platform.write_file(path, '')
252
+ end
253
+
254
+ it { expect(@aruba).to be_file(name) }
255
+ end
256
+
257
+ context 'when does not exist' do
258
+ it { expect(@aruba).not_to be_file(name) }
259
+ end
260
+ end
261
+
262
+ context 'when given a directory' do
263
+ let(:name) { 'test.d' }
264
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
265
+
266
+ context 'when it exists' do
267
+ before :each do
268
+ Aruba.platform.mkdir(path)
269
+ end
270
+
271
+ it { expect(@aruba).not_to be_file(name) }
272
+ end
273
+
274
+ context 'when it does not exist' do
275
+ it { expect(@aruba).not_to be_file(name) }
276
+ end
277
+ end
278
+ end
279
+
280
+ describe '#directory?' do
281
+ context 'when given a file' do
282
+ let(:name) { @file_name }
283
+ let(:path) { @file_path }
284
+
285
+ context 'when it exists' do
286
+ before :each do
287
+ Aruba.platform.write_file(path, '')
288
+ end
289
+
290
+ it { expect(@aruba).not_to be_directory(name) }
291
+ end
292
+
293
+ context 'when it does not exist' do
294
+ it { expect(@aruba).not_to be_directory(name) }
295
+ end
296
+ end
297
+
298
+ context 'when given a directory' do
299
+ let(:name) { 'test.d' }
300
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
301
+
302
+ context 'when it exists' do
303
+ before :each do
304
+ Aruba.platform.mkdir(path)
305
+ end
306
+
307
+ it { expect(@aruba).to be_directory(name) }
308
+ end
309
+
310
+ context 'when does not exist' do
311
+ it { expect(@aruba).not_to be_directory(name) }
312
+ end
313
+ end
314
+ end
315
+
316
+ describe '#copy' do
317
+ let(:source) { 'file.txt' }
318
+ let(:destination) { 'file1.txt' }
319
+
320
+ context 'when source is existing' do
321
+ context 'when destination is non-existing' do
322
+ context 'when source is file' do
323
+ before(:each) { create_test_files(source) }
324
+
325
+ before :each do
326
+ @aruba.copy source, destination
327
+ end
328
+
329
+ context 'when source is plain file' do
330
+ it { expect(destination).to be_an_existing_file }
331
+ end
332
+
333
+ context 'when source is contains "~" in path' do
334
+ let(:source) { '~/file.txt' }
335
+ it { expect(destination).to be_an_existing_file }
336
+ end
337
+
338
+ context 'when source is fixture' do
339
+ let(:source) { '%/copy/file.txt' }
340
+ let(:destination) { 'file.txt' }
341
+ it { expect(destination).to be_an_existing_file }
342
+ end
343
+
344
+ context 'when source is list of files' do
345
+ let(:source) { %w(file1.txt file2.txt file3.txt) }
346
+ let(:destination) { 'file.d' }
347
+ let(:destination_files) { source.map { |s| File.join(destination, s) } }
348
+
349
+ it { expect(destination_files).to all be_an_existing_file }
350
+ end
351
+ end
352
+
353
+ context 'when source is directory' do
354
+ let(:source) { 'src.d' }
355
+ let(:destination) { 'dst.d' }
356
+
357
+ before :each do
358
+ Aruba.platform.mkdir(File.join(@aruba.aruba.current_directory, source))
359
+ end
360
+
361
+ before :each do
362
+ @aruba.copy source, destination
363
+ end
364
+
365
+ context 'when source is single directory' do
366
+ it { expect(destination).to be_an_existing_directory }
367
+ end
368
+
369
+ context 'when source is nested directory' do
370
+ let(:source) { 'src.d/subdir.d' }
371
+ let(:destination) { 'dst.d/' }
372
+
373
+ it { expect(destination).to be_an_existing_directory }
374
+ end
375
+ end
376
+ end
377
+
378
+ context 'when destination is existing' do
379
+ context 'when source is list of files' do
380
+ before(:each) { create_test_files(source) }
381
+
382
+ context 'when destination is directory' do
383
+ let(:source) { %w(file1.txt file2.txt file3.txt) }
384
+ let(:destination) { 'file.d' }
385
+ let(:destination_files) { source.map { |s| File.join(destination, s) } }
386
+
387
+ before :each do
388
+ Aruba.platform.mkdir(File.join(@aruba.aruba.current_directory, destination))
389
+ end
390
+
391
+ before :each do
392
+ @aruba.copy source, destination
393
+ end
394
+
395
+ it { source.each { |s| expect(destination_files).to all be_an_existing_file } }
396
+ end
397
+
398
+ context 'when destination is not a directory' do
399
+ let(:source) { %w(file1.txt file2.txt file3.txt) }
400
+ let(:destination) { 'file.txt' }
401
+
402
+ before(:each) { create_test_files(destination) }
403
+
404
+ it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, "Multiples sources can only be copied to a directory" }
405
+ end
406
+
407
+ context 'when a source is the same like destination' do
408
+ let(:source) { 'file1.txt' }
409
+ let(:destination) { 'file1.txt' }
410
+
411
+ before(:each) { create_test_files(source) }
412
+
413
+ # rubocop:disable Metrics/LineLength
414
+ 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))}) }
415
+ # rubocop:enable Metrics/LineLength
416
+ end
417
+
418
+ context 'when a fixture is destination' do
419
+ let(:source) { '%/copy/file.txt' }
420
+ let(:destination) { '%/copy/file.txt' }
421
+
422
+ it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, "Using a fixture as destination (#{destination}) is not supported" }
423
+ end
424
+ end
425
+ end
426
+
427
+ context 'when source is non-existing' do
428
+ it { expect { @aruba.copy source, destination }.to raise_error ArgumentError }
429
+ end
430
+ end
431
+ end
432
+
433
+ context '#write_file' do
434
+ it 'writes file' do
435
+ @aruba.write_file(@file_name, '')
436
+
437
+ expect(File.exist?(@file_path)).to eq true
438
+ end
439
+ end
440
+
441
+ context '#write_fixed_size_file' do
442
+ it "should write a fixed sized file" do
443
+ @aruba.write_fixed_size_file(@file_name, @file_size)
444
+ expect(File.exist?(@file_path)).to eq true
445
+ expect(File.size(@file_path)).to eq @file_size
446
+ end
447
+
448
+ it "works with ~ in path name" do
449
+ file_path = File.join('~', random_string)
450
+
451
+ @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
452
+ @aruba.write_fixed_size_file(file_path, @file_size)
453
+
454
+ expect(File.exist?(File.expand_path(file_path))).to eq true
455
+ expect(File.size(File.expand_path(file_path))).to eq @file_size
456
+ end
457
+ end
458
+ end
459
+
460
+ describe '#chmod' do
461
+ def actual_permissions
462
+ format("%o" , File::Stat.new(file_path).mode )[-4,4]
463
+ end
464
+
465
+ let(:file_name) { @file_name }
466
+ let(:file_path) { @file_path }
467
+ let(:permissions) { '0655' }
468
+
469
+ before :each do
470
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
471
+ end
472
+
473
+ before(:each) do
474
+ File.open(file_path, 'w') { |f| f << "" }
475
+ end
476
+
477
+ before(:each) do
478
+ @aruba.chmod(permissions, file_name)
479
+ end
480
+
481
+ context 'when file exists' do
482
+ context 'and permissions are given as string' do
483
+ it { expect(actual_permissions).to eq('0655') }
484
+ end
485
+
486
+ context 'and permissions are given as octal number' do
487
+ let(:permissions) { 0o655 }
488
+ it { expect(actual_permissions).to eq('0655') }
489
+ end
490
+
491
+ context 'and path has ~ in it' do
492
+ let(:path) { random_string }
493
+ let(:file_name) { File.join('~', path) }
494
+ let(:file_path) { File.join(@aruba.aruba.current_directory, path) }
495
+
496
+ it { expect(actual_permissions).to eq('0655') }
497
+ end
498
+ end
499
+ end
500
+
501
+ context "#with_file_content" do
502
+ before :each do
503
+ @aruba.write_file(@file_name, "foo bar baz")
504
+ end
505
+
506
+ it "passes the given file's full content to the given block" do
507
+ @aruba.with_file_content @file_name do |full_content|
508
+ expect(full_content).to eq "foo bar baz"
509
+ end
510
+ end
511
+
512
+ it "works with ~ in path name" do
513
+ file_path = File.join('~', random_string)
514
+
515
+ @aruba.with_environment 'HOME' => File.expand_path(aruba.current_directory) do
516
+ @aruba.write_file(file_path, "foo bar baz")
517
+
518
+ @aruba.with_file_content file_path do |full_content|
519
+ expect(full_content).to eq "foo bar baz"
520
+ end
521
+ end
522
+ end
523
+ end
524
+
525
+ describe '#create_directory' do
526
+ before(:each) do
527
+ @directory_name = 'test_dir'
528
+ @directory_path = File.join(@aruba.aruba.current_directory, @directory_name)
529
+ end
530
+
531
+ it 'creates a directory' do
532
+ @aruba.create_directory @directory_name
533
+ expect(File.exist?(File.expand_path(@directory_path))).to be_truthy
534
+ end
535
+ end
536
+
537
+ describe '#read' do
538
+ let(:name) { 'test.txt' }
539
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
540
+ let(:content) { 'asdf' }
541
+
542
+ before :each do
543
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
544
+ end
545
+
546
+ context 'when does not exist' do
547
+ it { expect { @aruba.read(name) }.to raise_error ArgumentError }
548
+ end
549
+
550
+ context 'when it exists' do
551
+ context 'when file' do
552
+ before :each do
553
+ File.open(File.expand_path(path), 'w') { |f| f << content }
554
+ end
555
+
556
+ context 'when normal file' do
557
+ it { expect(@aruba.read(name)).to eq [content] }
558
+ end
559
+
560
+ context 'when binary file' do
561
+ let(:content) { "\u0000" }
562
+ it { expect(@aruba.read(name)).to eq [content] }
563
+ end
564
+
565
+ context 'when is empty file' do
566
+ let(:content) { '' }
567
+ it { expect(@aruba.read(name)).to eq [] }
568
+ end
569
+
570
+ context 'when path contains ~' do
571
+ let(:string) { random_string }
572
+ let(:name) { File.join('~', string) }
573
+ let(:path) { File.join(@aruba.aruba.current_directory, string) }
574
+
575
+ it { expect(@aruba.read(name)).to eq [content] }
576
+ end
577
+ end
578
+
579
+ context 'when directory' do
580
+ let(:name) { 'test.d' }
581
+
582
+ before do
583
+ Array(path).each { |p| Aruba.platform.mkdir p }
584
+ end
585
+
586
+ it { expect { @aruba.read(name) }.to raise_error ArgumentError }
587
+ end
588
+ end
589
+ end
590
+
591
+ describe '#list' do
592
+ let(:name) { 'test.d' }
593
+ let(:content) { %w(subdir.1.d subdir.2.d) }
594
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
595
+
596
+ before :each do
597
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
598
+ end
599
+
600
+ context 'when does not exist' do
601
+ it { expect { @aruba.list(name) }.to raise_error ArgumentError }
602
+ end
603
+
604
+ context 'when it exists' do
605
+ context 'when file' do
606
+ let(:name) { 'test.txt' }
607
+
608
+ before :each do
609
+ File.open(File.expand_path(path), 'w') { |f| f << content }
610
+ end
611
+
612
+ context 'when normal file' do
613
+ it { expect { @aruba.list(name) }.to raise_error ArgumentError }
614
+ end
615
+ end
616
+
617
+ context 'when directory' do
618
+ before do
619
+ Array(path).each { |p| Aruba.platform.mkdir p }
620
+ Array(content).each { |p| Aruba.platform.mkdir File.join(path, p) }
621
+ end
622
+
623
+ context 'when has subdirectories' do
624
+ context 'when is simple path' do
625
+ let(:existing_files) { @aruba.list(name) }
626
+ let(:expected_files) { content.map { |c| File.join(name, c) }.sort }
627
+
628
+ it { expect(expected_files - existing_files).to be_empty }
629
+ end
630
+
631
+ context 'when path contains ~' do
632
+ let(:string) { random_string }
633
+ let(:name) { File.join('~', string) }
634
+ let(:path) { File.join(@aruba.aruba.current_directory, string) }
635
+
636
+ let(:existing_files) { @aruba.list(name) }
637
+ let(:expected_files) { content.map { |c| File.join(string, c) } }
638
+
639
+ it { expect(expected_files - existing_files).to be_empty }
640
+ end
641
+ end
642
+
643
+ context 'when has no subdirectories' do
644
+ let(:content) { [] }
645
+ it { expect(@aruba.list(name)).to eq [] }
646
+ end
647
+ end
648
+ end
649
+ end
650
+
651
+ describe '#remove' do
652
+ let(:name) { 'test.txt' }
653
+ let(:path) { File.join(@aruba.aruba.current_directory, name) }
654
+ let(:options) { {} }
655
+
656
+ before :each do
657
+ @aruba.set_environment_variable 'HOME', File.expand_path(@aruba.aruba.current_directory)
658
+ end
659
+
660
+ context 'when given a file' do
661
+ context 'when it exists' do
662
+ before do
663
+ Array(path).each { |p| File.open(File.expand_path(p), 'w') { |f| f << "" } }
664
+
665
+ @aruba.remove(name, options)
666
+ end
667
+
668
+ context 'when is a single file' do
669
+ it_behaves_like 'a non-existing file'
670
+ end
671
+
672
+ context 'when are multiple files' do
673
+ let(:file_name) { %w(file1 file2 file3) }
674
+ let(:file_path) { %w(file1 file2 file3).map { |p| File.join(@aruba.aruba.current_directory, p) } }
675
+
676
+ it_behaves_like 'a non-existing file'
677
+ end
678
+
679
+ context 'when path contains ~' do
680
+ let(:string) { random_string }
681
+ let(:file_name) { File.join('~', string) }
682
+ let(:file_path) { File.join(@aruba.aruba.current_directory, string) }
683
+
684
+ it_behaves_like 'a non-existing file'
685
+ end
686
+ end
687
+
688
+ context 'when it does not exist' do
689
+ before do
690
+ @aruba.remove(name, options)
691
+ end
692
+
693
+ context 'when forced to delete file' do
694
+ let(:options) { { :force => true } }
695
+
696
+ it_behaves_like 'a non-existing file'
697
+ end
698
+ end
699
+ end
700
+
701
+ context 'when given a directory' do
702
+ let(:name) { 'test.d' }
703
+
704
+ context 'when it exists' do
705
+ before do
706
+ Array(path).each { |p| Aruba.platform.mkdir p }
707
+ end
708
+
709
+ before :each do
710
+ @aruba.remove(name, options)
711
+ end
712
+
713
+ context 'when is a single directory' do
714
+ it_behaves_like 'a non-existing directory'
715
+ end
716
+
717
+ context 'when are multiple directorys' do
718
+ let(:directory_name) { %w(directory1 directory2 directory3) }
719
+ let(:directory_path) { %w(directory1 directory2 directory3).map { |p| File.join(@aruba.aruba.current_directory, p) } }
720
+
721
+ it_behaves_like 'a non-existing directory'
722
+ end
723
+
724
+ context 'when path contains ~' do
725
+ let(:string) { random_string }
726
+ let(:directory_name) { File.join('~', string) }
727
+ let(:directory_path) { File.join(@aruba.aruba.current_directory, string) }
728
+
729
+ it_behaves_like 'a non-existing directory'
730
+ end
731
+ end
732
+
733
+ context 'when it does not exist' do
734
+ before :each do
735
+ @aruba.remove(name, options)
736
+ end
737
+
738
+ context 'when is forced to delete directory' do
739
+ let(:options) { { :force => true } }
740
+
741
+ it_behaves_like 'a non-existing directory'
742
+ end
743
+ end
744
+ end
745
+ end
746
+ end