aruba 0.14.2 → 0.14.3

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.
@@ -22,7 +22,7 @@ RSpec.describe 'Filesystem Api' do
22
22
 
23
23
  context 'when file does not exist' do
24
24
  let(:name) { 'non_existing_file' }
25
- it { expect { size }.to raise_error }
25
+ it { expect { size }.to raise_error RSpec::Expectations::ExpectationNotMetError }
26
26
  end
27
27
  end
28
28
  end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'securerandom'
3
2
  require 'aruba/api'
4
3
  require 'fileutils'
5
4
 
@@ -748,33 +747,7 @@ describe Aruba::Api do
748
747
  end
749
748
  end
750
749
 
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
750
+ describe '#chmod' do
778
751
  def actual_permissions
779
752
  format( "%o" , File::Stat.new(file_path).mode )[-4,4]
780
753
  end
@@ -792,7 +765,7 @@ describe Aruba::Api do
792
765
  end
793
766
 
794
767
  before(:each) do
795
- @aruba.filesystem_permissions(permissions, file_name)
768
+ @aruba.chmod(permissions, file_name)
796
769
  end
797
770
 
798
771
  context 'when file exists' do
@@ -815,205 +788,6 @@ describe Aruba::Api do
815
788
  end
816
789
  end
817
790
 
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
791
  context "#with_file_content" do
1018
792
  before :each do
1019
793
  @aruba.write_file(@file_name, "foo bar baz")
@@ -1087,7 +861,7 @@ describe Aruba::Api do
1087
861
 
1088
862
  it "should announce to stdout exactly once" do
1089
863
  @aruba.run_simple('echo "hello world"', false)
1090
- expect(@aruba.all_output).to include('hello world')
864
+ expect(@aruba.last_command_started.output).to include('hello world')
1091
865
  end
1092
866
  end
1093
867
 
@@ -1098,26 +872,12 @@ describe Aruba::Api do
1098
872
  end
1099
873
 
1100
874
  expect(result).not_to include('hello world')
1101
- expect(@aruba.all_output).to include('hello world')
875
+ expect(@aruba.last_command_started.output).to include('hello world')
1102
876
  end
1103
877
  end
1104
878
  end
1105
879
  end
1106
880
 
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
881
  describe '#run' do
1122
882
  before(:each){ @aruba.run 'cat' }
1123
883
  after(:each) { @aruba.all_commands.each(&:stop) }
@@ -1125,34 +885,20 @@ describe Aruba::Api do
1125
885
  it "respond to input" do
1126
886
  @aruba.type "Hello"
1127
887
  @aruba.type ""
1128
- expect(@aruba.all_output).to eq "Hello\n"
888
+ expect(@aruba.last_command_started).to have_output "Hello"
1129
889
  end
1130
890
 
1131
891
  it "respond to close_input" do
1132
892
  @aruba.type "Hello"
1133
893
  @aruba.close_input
1134
- expect(@aruba.all_output).to eq "Hello\n"
894
+ expect(@aruba.last_command_started).to have_output "Hello"
1135
895
  end
1136
896
 
1137
897
  it "pipes data" do
1138
898
  @aruba.write_file(@file_name, "Hello\nWorld!")
1139
899
  @aruba.pipe_in_file(@file_name)
1140
900
  @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
901
+ expect(@aruba.last_command_started).to have_output "Hello\nWorld!"
1156
902
  end
1157
903
  end
1158
904
 
@@ -1173,37 +919,21 @@ describe Aruba::Api do
1173
919
  describe "#set_environment_variable" do
1174
920
  after(:each) do
1175
921
  @aruba.all_commands.each(&:stop)
1176
- @aruba.restore_env
1177
922
  end
1178
923
 
1179
924
  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")
925
+ @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', 'true'
926
+ @aruba.run_simple "env"
927
+ expect(@aruba.last_command_started.output).
928
+ to include("LONG_LONG_ENV_VARIABLE=true")
1183
929
  end
1184
930
 
1185
931
  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")
932
+ @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', 'true'
933
+ @aruba.set_environment_variable 'LONG_LONG_ENV_VARIABLE', 'false'
934
+ @aruba.run_simple "env"
935
+ expect(@aruba.last_command_started.output).
936
+ to include("LONG_LONG_ENV_VARIABLE=false")
1207
937
  end
1208
938
  end
1209
939
  end # Aruba::Api
@@ -81,7 +81,7 @@ RSpec.describe 'Command Matchers' do
81
81
  File.open(expand_path('cmd.sh'), 'w') { |f| f.puts string }
82
82
 
83
83
  File.chmod 0755, expand_path('cmd.sh')
84
- prepend_environment_variable 'PATH', "#{expand_path('.')}:"
84
+ prepend_environment_variable 'PATH', "#{expand_path('.')}#{File::PATH_SEPARATOR}"
85
85
  end
86
86
 
87
87
  let(:cmd) { "cmd.sh #{output}" }
@@ -118,7 +118,7 @@ RSpec.describe 'Command Matchers' do
118
118
  File.open(expand_path('cmd.sh'), 'w') { |f| f.puts string }
119
119
 
120
120
  File.chmod 0755, expand_path('cmd.sh')
121
- prepend_environment_variable 'PATH', "#{expand_path('.')}:"
121
+ prepend_environment_variable 'PATH', "#{expand_path('.')}#{File::PATH_SEPARATOR}"
122
122
  end
123
123
 
124
124
  let(:cmd) { "cmd.sh #{output}" }
@@ -155,7 +155,7 @@ RSpec.describe 'Command Matchers' do
155
155
  File.open(expand_path('cmd.sh'), 'w') { |f| f.puts string }
156
156
 
157
157
  File.chmod 0755, expand_path('cmd.sh')
158
- prepend_environment_variable 'PATH', "#{expand_path('.')}:"
158
+ prepend_environment_variable 'PATH', "#{expand_path('.')}#{File::PATH_SEPARATOR}"
159
159
  end
160
160
 
161
161
  let(:cmd) { "cmd.sh #{output}" }
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Deprecated matchers' do
4
+ include_context 'uses aruba API'
5
+
6
+ before do
7
+ allow(Aruba.platform).to receive(:deprecated)
8
+ end
9
+
10
+ describe 'to_match_path_pattern' do
11
+ context 'when pattern is string' do
12
+ context 'when there is file which matches path pattern' do
13
+ before :each do
14
+ Aruba.platform.write_file(@file_path, '')
15
+ end
16
+
17
+ it { expect(all_paths).to match_path_pattern(expand_path(@file_name)) }
18
+ end
19
+
20
+ context 'when there is not file which matches path pattern' do
21
+ it { expect(all_paths).not_to match_path_pattern('test') }
22
+ end
23
+ end
24
+
25
+ context 'when pattern is regex' do
26
+ context 'when there is file which matches path pattern' do
27
+ before :each do
28
+ Aruba.platform.write_file(@file_path, '')
29
+ end
30
+
31
+ it { expect(all_paths).to match_path_pattern(/test/) }
32
+ end
33
+
34
+ context 'when there is not file which matches path pattern' do
35
+ it { expect(all_paths).not_to match_path_pattern(/test/) }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -8,7 +8,7 @@ RSpec.describe 'Directory Matchers' do
8
8
 
9
9
  describe 'to_be_an_existing_directory' do
10
10
  let(:name) { 'test.d' }
11
- let(:path) { File.join(@aruba.current_directory, name) }
11
+ let(:path) { @aruba.expand_path(name) }
12
12
 
13
13
  context 'when directory exists' do
14
14
  before :each do
@@ -25,7 +25,7 @@ RSpec.describe 'Directory Matchers' do
25
25
 
26
26
  describe 'to_have_sub_directory' do
27
27
  let(:name) { 'test.d' }
28
- let(:path) { File.join(@aruba.current_directory, name) }
28
+ let(:path) { @aruba.expand_path(name) }
29
29
  let(:content) { %w(subdir.1.d subdir.2.d) }
30
30
 
31
31
  context 'when directory exists' do