jumpstart 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/jumpstart.gemspec +1 -1
- data/lib/jumpstart/filetools.rb +3 -4
- data/test/helper.rb +1 -1
- data/test/jumpstart/test_base.rb +46 -48
- data/test/jumpstart/test_filetools.rb +6 -6
- metadata +2 -2
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/jumpstart.gemspec
CHANGED
data/lib/jumpstart/filetools.rb
CHANGED
@@ -42,11 +42,10 @@ module JumpStart::FileTools
|
|
42
42
|
|
43
43
|
# Deletes all files and folders in a directory. Leaves target_dir intact.
|
44
44
|
def delete_dir_contents(target_dir)
|
45
|
-
|
46
|
-
files_and_dirs.each do |x|
|
45
|
+
Find.find(target_dir) do |x|
|
47
46
|
if File.file?(x)
|
48
47
|
FileUtils.rm(x)
|
49
|
-
elsif File.directory?(x) && x != target_dir
|
48
|
+
elsif File.directory?(x) && x != target_dir
|
50
49
|
FileUtils.remove_dir(x)
|
51
50
|
end
|
52
51
|
end
|
@@ -122,7 +121,7 @@ module JumpStart::FileTools
|
|
122
121
|
def replace_strings(target_file, args)
|
123
122
|
txt = IO.read(target_file)
|
124
123
|
args.each do |x, y|
|
125
|
-
txt.gsub!(/#{x.upcase}/, y)
|
124
|
+
txt.gsub!(/#{x.to_s.upcase}/, y)
|
126
125
|
end
|
127
126
|
File.open(target_file, "w") do |file|
|
128
127
|
file.puts txt
|
data/test/helper.rb
CHANGED
data/test/jumpstart/test_base.rb
CHANGED
@@ -14,14 +14,12 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
14
14
|
output = StringIO.new
|
15
15
|
FileUtils.delete_dir_contents("#{JumpStart::ROOT_PATH}/test/destination_dir")
|
16
16
|
@test_project = JumpStart::Base.new(["test_jumpstart_project"])
|
17
|
-
@test_project.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@install_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
|
24
|
-
end
|
17
|
+
@test_project.instance_variable_set(:@input, input)
|
18
|
+
@test_project.instance_variable_set(:@output, output)
|
19
|
+
@test_project.instance_variable_set(:@template_name, "test_template_1")
|
20
|
+
@test_project.instance_variable_set(:@template_path, "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_1")
|
21
|
+
@test_project.instance_eval {set_config_file_options}
|
22
|
+
@test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
|
25
23
|
@test_project.stubs(:exit_normal)
|
26
24
|
@test_project.stubs(:exit_with_success)
|
27
25
|
end
|
@@ -152,7 +150,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
152
150
|
should "set @replace_strings" do
|
153
151
|
assert_equal [{:target_path=>"/config/deploy.rb", :symbols=>{:project_name=>"name_of_my_app", :remote_server=>"thoughtplant"}}], @test_project_2.instance_variable_get(:@replace_strings)
|
154
152
|
end
|
155
|
-
|
153
|
+
|
156
154
|
should "load the jumpstart menu if the specified yaml config file does not exist" do
|
157
155
|
@test_project_3.stubs(:jumpstart_menu).returns("jumpstart_menu")
|
158
156
|
assert_equal "jumpstart_menu", @test_project_3.set_config_file_options
|
@@ -443,7 +441,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
443
441
|
@test_project.instance_variable_set(:@input, StringIO.new("blarg\n"))
|
444
442
|
assert_raises(NoMethodError) {@test_project.instance_eval {jumpstart_menu_options}}
|
445
443
|
end
|
446
|
-
|
444
|
+
|
447
445
|
# Due to the recursive nature of this code, the only successful way to test is to check for the NoMethodError that is raised when the method is called for a second time, this time with @input as nil. I'd be interested to find another way to test this.
|
448
446
|
should "ask for another input if the value entered is not '1,2,3,4 or x'. Test with 'a'" do
|
449
447
|
@test_project.instance_variable_set(:@input, StringIO.new("a\n"))
|
@@ -630,19 +628,19 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
630
628
|
@test_project.expects(:set_templates_dir).once
|
631
629
|
@test_project.instance_eval {templates_dir_options}
|
632
630
|
end
|
633
|
-
|
631
|
+
|
634
632
|
should "run the reset_templates_dir_to_default method when '2' is entered." do
|
635
633
|
@test_project.instance_variable_set(:@input, StringIO.new("2\n"))
|
636
634
|
@test_project.expects(:reset_templates_dir_to_default_check).once
|
637
635
|
@test_project.instance_eval {templates_dir_options}
|
638
636
|
end
|
639
|
-
|
637
|
+
|
640
638
|
should "run the jumpstart_menu method when 'b' is entered." do
|
641
639
|
@test_project.instance_variable_set(:@input, StringIO.new("b\n"))
|
642
640
|
@test_project.expects(:jumpstart_menu).once
|
643
641
|
@test_project.instance_eval {templates_dir_options}
|
644
642
|
end
|
645
|
-
|
643
|
+
|
646
644
|
should "run the exit_normal when 'x' is entered." do
|
647
645
|
@test_project.instance_variable_set(:@input, StringIO.new("x\n"))
|
648
646
|
@test_project.expects(:exit_normal).once
|
@@ -656,7 +654,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
656
654
|
end
|
657
655
|
|
658
656
|
end
|
659
|
-
|
657
|
+
|
660
658
|
context "Tests for the JumpStart::Base#set_templates_dir instance method." do
|
661
659
|
|
662
660
|
setup do
|
@@ -715,7 +713,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
715
713
|
JumpStart.templates_path = "#{@normal_root_path}/test/test_jumpstart_templates/test_base"
|
716
714
|
@test_project.instance_variable_set(:@current_files_and_dirs, {:files => ['current_files_and_dirs_test_file.txt'], :dirs => ['current_files_and_dirs_test_dir']})
|
717
715
|
end
|
718
|
-
|
716
|
+
|
719
717
|
teardown do
|
720
718
|
JumpStart::ROOT_PATH = @normal_root_path
|
721
719
|
end
|
@@ -728,7 +726,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
728
726
|
assert File.exists?("#{JumpStart::ROOT_PATH}/jumpstart_templates/current_files_and_dirs_test_file.txt")
|
729
727
|
assert File.directory?("#{JumpStart::ROOT_PATH}/jumpstart_templates/current_files_and_dirs_test_dir")
|
730
728
|
end
|
731
|
-
|
729
|
+
|
732
730
|
should "reset jumpstart templates directory to default if input is 'yes'" do
|
733
731
|
@test_project.expects(:templates_dir_menu)
|
734
732
|
@test_project.instance_variable_set(:@input, StringIO.new("yes\n"))
|
@@ -744,7 +742,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
744
742
|
@test_project.instance_eval {reset_templates_dir_to_default_set}
|
745
743
|
assert_equal "\n You have chosen not to move the jumpstart templates directory, nothing has been changed.\n", @test_project.output.string
|
746
744
|
end
|
747
|
-
|
745
|
+
|
748
746
|
should "run templates_dir_menu if input is 'no'" do
|
749
747
|
@test_project.expects(:templates_dir_menu)
|
750
748
|
@test_project.instance_variable_set(:@input, StringIO.new("no\n"))
|
@@ -759,7 +757,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
759
757
|
end
|
760
758
|
|
761
759
|
end
|
762
|
-
|
760
|
+
|
763
761
|
context "Tests for the JumpStart::Base#execute_install_command instance method." do
|
764
762
|
|
765
763
|
should "do nothing if @install_command is nil" do
|
@@ -777,7 +775,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
777
775
|
@test_project.instance_eval {execute_install_command}
|
778
776
|
assert_equal "", @test_project.output.string
|
779
777
|
end
|
780
|
-
|
778
|
+
|
781
779
|
should "execute @install_command if it contains a string" do
|
782
780
|
@test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
|
783
781
|
@test_project.instance_variable_set(:@install_command, "echo")
|
@@ -786,7 +784,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
786
784
|
@test_project.instance_eval {execute_install_command}
|
787
785
|
assert_equal "Executing command: \e[32mecho\e[0m \e[32mtest_jumpstart_project\e[0m \e[32minstall command args\e[0m\n", @test_project.output.string
|
788
786
|
end
|
789
|
-
|
787
|
+
|
790
788
|
should "raise an error if the @install_path does not exist" do
|
791
789
|
@test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir/this/dir/does/not/exist")
|
792
790
|
@test_project.instance_variable_set(:@install_command, "echo")
|
@@ -795,7 +793,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
795
793
|
end
|
796
794
|
|
797
795
|
end
|
798
|
-
|
796
|
+
|
799
797
|
context "Tests for the JumpStart::Base#parse_template_dir instance method." do
|
800
798
|
|
801
799
|
setup do
|
@@ -823,29 +821,29 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
823
821
|
end
|
824
822
|
|
825
823
|
should "populate @dir_list with directories contained in @template_path" do
|
826
|
-
assert_equal ['', '/parse_template_dir'], @test_project.instance_variable_get(:@dir_list)
|
824
|
+
assert_equal ['', '/parse_template_dir'], @test_project.instance_variable_get(:@dir_list).sort
|
827
825
|
end
|
828
826
|
|
829
827
|
should "populate @append_templates with files that are prefixed with _._ _l._ or _L._ and do not contain a directory called jumpstart_config." do
|
830
828
|
assert_equal ["/parse_template_dir/_._append_test_5.txt",
|
831
829
|
"/parse_template_dir/_._append_test_6",
|
832
830
|
"/parse_template_dir/_L._append_test_8.txt",
|
833
|
-
"/parse_template_dir/_l._append_test_7.txt"], @test_project.instance_variable_get(:@append_templates)
|
831
|
+
"/parse_template_dir/_l._append_test_7.txt"], @test_project.instance_variable_get(:@append_templates).sort
|
834
832
|
end
|
835
833
|
|
836
834
|
should "populate @line_templates with files that are prefixed with _(number)._ e.g. _1._ or _1000._. File paths that include a directory called jumpstart_config should be excluded." do
|
837
835
|
assert_equal ["/parse_template_dir/_1._line_test_3.txt",
|
838
|
-
"/parse_template_dir/_10000._line_test_4.txt"], @test_project.instance_variable_get(:@line_templates)
|
836
|
+
"/parse_template_dir/_10000._line_test_4.txt"], @test_project.instance_variable_get(:@line_templates).sort
|
839
837
|
end
|
840
838
|
|
841
839
|
should "populate @whole_templates with a files that do not match append or line templates and do not contain a directory called jumpstart_config in their path." do
|
842
|
-
assert_equal ["/parse_template_dir/whole_test_3", "/parse_template_dir/whole_test_4.txt"], @test_project.instance_variable_get(:@whole_templates)
|
840
|
+
assert_equal ["/parse_template_dir/whole_test_3", "/parse_template_dir/whole_test_4.txt"], @test_project.instance_variable_get(:@whole_templates).sort
|
843
841
|
end
|
844
842
|
|
845
843
|
should "populate @nginx_local_template if a file matching jumpstart_config/nginx.local.conf is found" do
|
846
844
|
assert_equal "#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/nginx.local.conf", @test_project.instance_variable_get(:@nginx_local_template)
|
847
845
|
end
|
848
|
-
|
846
|
+
|
849
847
|
should "populate @nginx_remote_template if a file matching jumpstart_config/nginx.remote.conf is found" do
|
850
848
|
assert_equal "#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/nginx.remote.conf", @test_project.instance_variable_get(:@nginx_remote_template)
|
851
849
|
end
|
@@ -868,7 +866,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
868
866
|
end
|
869
867
|
|
870
868
|
end
|
871
|
-
|
869
|
+
|
872
870
|
context "Tests for the JumpStart::Base#populate_files_from_whole_templates instance method." do
|
873
871
|
|
874
872
|
should "create files from @whole_templates" do
|
@@ -881,7 +879,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
881
879
|
end
|
882
880
|
|
883
881
|
end
|
884
|
-
|
882
|
+
|
885
883
|
context "Tests for the JumpStart::Base#populate_files_from_append_templates instance method." do
|
886
884
|
|
887
885
|
should "append contents of append template to file." do
|
@@ -895,20 +893,20 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
895
893
|
assert_equal "THIS IS THE LAST LINE\n", file_2[9]
|
896
894
|
assert_equal "9\n", file_1[8]
|
897
895
|
assert_equal "9\n", file_2[8]
|
898
|
-
|
899
|
-
|
896
|
+
assert !file_1[10]
|
897
|
+
assert !file_2[10]
|
900
898
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_file_with_extension.txt")
|
901
899
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_file_without_extension")
|
902
900
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_append_file_with_extension.txt")
|
903
901
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_append_file_without_extension")
|
904
902
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_1.txt")
|
905
|
-
|
903
|
+
assert !File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_L._test_append_to_end_of_file_remove_last_line_1.txt")
|
906
904
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_2.txt")
|
907
|
-
|
905
|
+
assert !File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_l._test_append_to_end_of_file_remove_last_line_2.txt")
|
908
906
|
end
|
909
907
|
|
910
908
|
end
|
911
|
-
|
909
|
+
|
912
910
|
context "Tests for the JumpStart::Base#populate_files_from_line_templates instance method. \n" do
|
913
911
|
|
914
912
|
should "append contents of line templates to the relevant file." do
|
@@ -927,7 +925,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
927
925
|
end
|
928
926
|
|
929
927
|
end
|
930
|
-
|
928
|
+
|
931
929
|
context "Tests for the JumpStart::Base#check_local_nginx_configuration instance method. \n" do
|
932
930
|
|
933
931
|
setup do
|
@@ -1032,7 +1030,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1032
1030
|
|
1033
1031
|
should "return false if @replace_strings is empty." do
|
1034
1032
|
@test_project.instance_eval {@replace_strings = []}
|
1035
|
-
|
1033
|
+
assert !@test_project.instance_eval {check_for_strings_to_replace}
|
1036
1034
|
end
|
1037
1035
|
|
1038
1036
|
end
|
@@ -1083,13 +1081,13 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1083
1081
|
context "Tests for the JumpStart::Base.remove_last_line? class method.\n" do
|
1084
1082
|
|
1085
1083
|
should "return false" do
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1084
|
+
assert !JumpStart::Base.remove_last_line?("/path/to/file.txt")
|
1085
|
+
assert !JumpStart::Base.remove_last_line?("/path/to/_._file.txt")
|
1086
|
+
assert !JumpStart::Base.remove_last_line?("_.__file.txt")
|
1087
|
+
assert !JumpStart::Base.remove_last_line?("/path/to/_R._file.txt")
|
1088
|
+
assert !JumpStart::Base.remove_last_line?("/path/to/_.1_file.txt")
|
1089
|
+
assert !JumpStart::Base.remove_last_line?("/path/to/_1._file.txt")
|
1090
|
+
assert !JumpStart::Base.remove_last_line?("/path/to/_111._file.txt")
|
1093
1091
|
end
|
1094
1092
|
|
1095
1093
|
should "return true" do
|
@@ -1106,7 +1104,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1106
1104
|
context "Create jumpstart with the project name argument passed to it but do not start.\n" do
|
1107
1105
|
|
1108
1106
|
should "be able to create a new jumpstart with the project name as the first argument" do
|
1109
|
-
|
1107
|
+
assert @test_project
|
1110
1108
|
end
|
1111
1109
|
|
1112
1110
|
should "have set @project_name variable to 'test_jumpstart_project'" do
|
@@ -1139,9 +1137,9 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1139
1137
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_replace_strings/replace_strings_1.rb")
|
1140
1138
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_replace_strings/replace_strings_2.txt")
|
1141
1139
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_1.txt")
|
1142
|
-
|
1140
|
+
assert !File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_L._test_append_to_end_of_file_remove_last_line_1.txt")
|
1143
1141
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_2.txt")
|
1144
|
-
|
1142
|
+
assert !File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_l._test_append_to_end_of_file_remove_last_line_2.txt")
|
1145
1143
|
end
|
1146
1144
|
|
1147
1145
|
should "remove last lines from files and append template info" do
|
@@ -1152,13 +1150,13 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1152
1150
|
assert_equal "THIS IS THE LAST LINE\n", file_2[9]
|
1153
1151
|
assert_equal "9\n", file_1[8]
|
1154
1152
|
assert_equal "9\n", file_2[8]
|
1155
|
-
|
1156
|
-
|
1153
|
+
assert !file_1[10]
|
1154
|
+
assert !file_2[10]
|
1157
1155
|
end
|
1158
1156
|
|
1159
1157
|
end
|
1160
1158
|
|
1161
1159
|
end
|
1162
|
-
|
1160
|
+
|
1163
1161
|
end
|
1164
1162
|
end
|
@@ -119,16 +119,16 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
119
119
|
file = FileUtils.join_paths(@file_path, "/remove_files_test_1.txt")
|
120
120
|
@file_array << file
|
121
121
|
FileUtils.remove_files(@file_array)
|
122
|
-
|
122
|
+
assert !File.exists?("#{@file_path}/remove_files_test_1.txt")
|
123
123
|
end
|
124
124
|
|
125
125
|
should "delete all three test files" do
|
126
126
|
@file_array << "/remove_files_test_1.txt" << "/remove_files_test_2.txt" << "/remove_files_test_3.txt"
|
127
127
|
@file_array.map!{|x| FileUtils.join_paths(@file_path, x)}
|
128
128
|
FileUtils.remove_files(@file_array)
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
assert !File.exists?("#{@file_path}/remove_files_test_1.txt")
|
130
|
+
assert !File.exists?("#{@file_path}/remove_files_test_2.txt")
|
131
|
+
assert !File.exists?("#{@file_path}/remove_files_test_3.txt")
|
132
132
|
end
|
133
133
|
|
134
134
|
end
|
@@ -360,11 +360,11 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
360
360
|
"/folder_1/file_3.txt",
|
361
361
|
"/folder_1/folder_2/file_4.txt",
|
362
362
|
"/folder_1/folder_2/folder_3/file_5.txt",
|
363
|
-
"/folder_1/folder_2/folder_4/file_6.txt"], results[:files]
|
363
|
+
"/folder_1/folder_2/folder_4/file_6.txt"], results[:files].sort
|
364
364
|
assert_equal ["/folder_1",
|
365
365
|
"/folder_1/folder_2",
|
366
366
|
"/folder_1/folder_2/folder_3",
|
367
|
-
"/folder_1/folder_2/folder_4"], results[:dirs]
|
367
|
+
"/folder_1/folder_2/folder_4"], results[:dirs].sort
|
368
368
|
end
|
369
369
|
|
370
370
|
should "return an empty hash when passed nil" do
|