jumpstart 0.1.0 → 0.1.1

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 (107) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +2 -1
  3. data/VERSION +1 -1
  4. data/config/jumpstart_setup.yml +1 -0
  5. data/jumpstart.gemspec +15 -89
  6. data/jumpstart_templates/{i0n_rails_3/lib/generators/formtastic_erb/controller/templates/view.html.erb → .gitignore} +0 -0
  7. data/lib/jumpstart.rb +15 -39
  8. data/lib/jumpstart/base.rb +111 -111
  9. data/lib/jumpstart/filetools.rb +11 -7
  10. data/lib/jumpstart/stringtools.rb +41 -0
  11. data/test/helper.rb +12 -6
  12. data/test/jumpstart/test_base.rb +848 -106
  13. data/test/jumpstart/test_filetools.rb +42 -10
  14. data/test/jumpstart/test_stringutils.rb +67 -0
  15. data/test/test_jumpstart_templates/test_base/current_files_and_dirs_test_file.txt +1 -0
  16. data/{jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/controller/templates/view.html.haml → test/test_jumpstart_templates/test_fileutils/sort_contained_files_and_dirs_test/file_1.txt} +0 -0
  17. data/{jumpstart_templates/i0n_rails_3/lib/generators/haml/controller/templates/view.html.haml → test/test_jumpstart_templates/test_fileutils/sort_contained_files_and_dirs_test/file_2} +0 -0
  18. data/test/test_jumpstart_templates/test_fileutils/sort_contained_files_and_dirs_test/folder_1/file_3.txt +0 -0
  19. data/test/test_jumpstart_templates/test_fileutils/sort_contained_files_and_dirs_test/folder_1/folder_2/file_4.txt +0 -0
  20. data/test/test_jumpstart_templates/test_fileutils/sort_contained_files_and_dirs_test/folder_1/folder_2/folder_3/file_5.txt +0 -0
  21. data/test/test_jumpstart_templates/test_fileutils/sort_contained_files_and_dirs_test/folder_1/folder_2/folder_4/file_6.txt +0 -0
  22. data/test/test_jumpstart_templates/test_template_1/_20._test_line_file_without_extension +1 -1
  23. data/test/test_jumpstart_templates/test_template_2/jumpstart_config/test_template_2.yml +83 -1
  24. metadata +15 -89
  25. data/.bundle/config +0 -2
  26. data/jumpstart_templates/i0n_rails_3/.gitignore +0 -11
  27. data/jumpstart_templates/i0n_rails_3/_._Gemfile +0 -5
  28. data/jumpstart_templates/i0n_rails_3/app/views/home/index.haml +0 -4
  29. data/jumpstart_templates/i0n_rails_3/app/views/layouts/application.haml +0 -32
  30. data/jumpstart_templates/i0n_rails_3/config/_2._routes.rb +0 -1
  31. data/jumpstart_templates/i0n_rails_3/config/_L._database.yml +0 -1
  32. data/jumpstart_templates/i0n_rails_3/config/deploy.rb +0 -62
  33. data/jumpstart_templates/i0n_rails_3/config/environments/_18._development.rb +0 -5
  34. data/jumpstart_templates/i0n_rails_3/config/environments/_27._test.rb +0 -1
  35. data/jumpstart_templates/i0n_rails_3/config/environments/_41._production.rb +0 -3
  36. data/jumpstart_templates/i0n_rails_3/config/initializers/setup_mail.rb +0 -14
  37. data/jumpstart_templates/i0n_rails_3/jumpstart_config/i0n_rails_3.yml +0 -40
  38. data/jumpstart_templates/i0n_rails_3/jumpstart_config/nginx.local.conf +0 -11
  39. data/jumpstart_templates/i0n_rails_3/jumpstart_config/nginx.remote.conf +0 -37
  40. data/jumpstart_templates/i0n_rails_3/lib/development_mail_interceptor.rb +0 -8
  41. data/jumpstart_templates/i0n_rails_3/lib/generators/authlogic.rb +0 -11
  42. data/jumpstart_templates/i0n_rails_3/lib/generators/authlogic/session/session_generator.rb +0 -18
  43. data/jumpstart_templates/i0n_rails_3/lib/generators/authlogic/session/templates/session.rb +0 -2
  44. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper.rb +0 -80
  45. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/migration/migration_generator.rb +0 -26
  46. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/migration/templates/migration.rb +0 -21
  47. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/model/model_generator.rb +0 -29
  48. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/model/templates/migration.rb +0 -17
  49. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/model/templates/model.rb +0 -10
  50. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/observer/observer_generator.rb +0 -15
  51. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/observer/templates/observer.rb +0 -5
  52. data/jumpstart_templates/i0n_rails_3/lib/generators/factory_girl.rb +0 -11
  53. data/jumpstart_templates/i0n_rails_3/lib/generators/factory_girl/model/model_generator.rb +0 -14
  54. data/jumpstart_templates/i0n_rails_3/lib/generators/factory_girl/model/templates/fixtures.rb +0 -7
  55. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb.rb +0 -9
  56. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/USAGE +0 -8
  57. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/controller/controller_generator.rb +0 -24
  58. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/scaffold_generator.rb +0 -27
  59. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/_form.html.erb +0 -12
  60. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/edit.html.erb +0 -6
  61. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/index.html.erb +0 -27
  62. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/layout.html.erb +0 -16
  63. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/new.html.erb +0 -5
  64. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/show.html.erb +0 -10
  65. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml.rb +0 -9
  66. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/USAGE +0 -8
  67. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/controller/controller_generator.rb +0 -24
  68. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/scaffold_generator.rb +0 -23
  69. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/_form.haml.erb +0 -9
  70. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/edit.haml.erb +0 -7
  71. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/index.haml.erb +0 -23
  72. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/layout.haml.erb +0 -9
  73. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/new.haml.erb +0 -5
  74. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/show.haml.erb +0 -9
  75. data/jumpstart_templates/i0n_rails_3/lib/generators/haml.rb +0 -9
  76. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/controller/controller_generator.rb +0 -24
  77. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/scaffold_generator.rb +0 -26
  78. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/_form.haml.erb +0 -9
  79. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/edit.haml.erb +0 -7
  80. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/index.haml.erb +0 -23
  81. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/layout.haml.erb +0 -9
  82. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/new.haml.erb +0 -5
  83. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/show.haml.erb +0 -9
  84. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist.rb +0 -11
  85. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist/model/model_generator.rb +0 -19
  86. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist/model/templates/blueprint.rb +0 -5
  87. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist/model/templates/machinist_initializer.rb +0 -19
  88. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper.rb +0 -80
  89. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper/model/model_generator.rb +0 -29
  90. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper/model/templates/model.rb +0 -24
  91. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper/observer/observer_generator.rb +0 -15
  92. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda.rb +0 -11
  93. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/controller/controller_generator.rb +0 -16
  94. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/controller/templates/controller.rb +0 -84
  95. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/model/model_generator.rb +0 -16
  96. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/model/templates/model.rb +0 -7
  97. data/jumpstart_templates/i0n_rails_3/lib/tasks/populate.rake +0 -91
  98. data/jumpstart_templates/i0n_rails_3/public/javascripts/init.js +0 -6
  99. data/jumpstart_templates/i0n_rails_3/public/javascripts/jquery-1.4.2.min.js +0 -154
  100. data/jumpstart_templates/i0n_rails_3/public/javascripts/jquery-ui-1.8.custom.min.js +0 -404
  101. data/jumpstart_templates/i0n_rails_3/public/javascripts/rails.js +0 -126
  102. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/_setup.sass +0 -86
  103. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/global.sass +0 -58
  104. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/handheld.sass +0 -7
  105. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/ie.sass +0 -40
  106. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/print.sass +0 -57
  107. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/screen.sass +0 -170
@@ -46,7 +46,7 @@ module JumpStart::FileTools
46
46
  files_and_dirs.each do |x|
47
47
  if File.file?(x)
48
48
  FileUtils.rm(x)
49
- elsif File.directory?(x) && x != target_dir && Dir.exists?(x)
49
+ elsif File.directory?(x) && x != target_dir && File.directory?(x)
50
50
  FileUtils.remove_dir(x)
51
51
  end
52
52
  end
@@ -256,12 +256,16 @@ module JumpStart::FileTools
256
256
 
257
257
  def sort_contained_files_and_dirs(path)
258
258
  dirs, files = [], []
259
- Find.find(path) do |x|
260
- case
261
- when File.directory?(x)
262
- dirs << x.sub(path, '')
263
- when File.file?(x)
264
- files << x.sub(path, '')
259
+ if path != nil && File.directory?(path)
260
+ Find.find(path) do |x|
261
+ case
262
+ when File.directory?(x)
263
+ x.sub!(path, '')
264
+ dirs << x unless x.length == 0
265
+ when File.file?(x)
266
+ x.sub!(path, '')
267
+ files << x unless x.length == 0
268
+ end
265
269
  end
266
270
  end
267
271
  {:files => files, :dirs => dirs}
@@ -0,0 +1,41 @@
1
+ module JumpStart::StringTools
2
+
3
+ def red; colourise(self, "\e[31m"); end
4
+ def red_bold; colourise(self, "\e[1m\e[31m"); end
5
+ def green; colourise(self, "\e[32m"); end
6
+ def green_bold; colourise(self, "\e[1m\e[32m"); end
7
+ def yellow; colourise(self, "\e[1m\e[33m"); end
8
+ def blue; colourise(self, "\e[34m"); end
9
+ def blue_bold; colourise(self, "\e[1m\e[34m"); end
10
+ def purple; colourise(self, "\e[1m\e[35m"); end
11
+
12
+ def colourise(text, colour_code) "#{colour_code}#{text}\e[0m" end
13
+
14
+ # Codes for changing output text:
15
+
16
+ # 0 Turn off all attributes
17
+ # 1 Set bright mode
18
+ # 4 Set underline mode
19
+ # 5 Set blink mode
20
+ # 7 Exchange foreground and background colors
21
+ # 8 Hide text (foreground colour would be the same as background)
22
+ # 30 Black text
23
+ # 31 Red text
24
+ # 32 Green text
25
+ # 33 Yellow text
26
+ # 34 Blue text
27
+ # 35 Magenta text
28
+ # 36 Cyan text
29
+ # 37 White text
30
+ # 39 Default text colour
31
+ # 40 Black background
32
+ # 41 Red background
33
+ # 42 Green background
34
+ # 43 Yellow background
35
+ # 44 Blue background
36
+ # 45 Magenta background
37
+ # 46 Cyan background
38
+ # 47 White background
39
+ # 49 Default background colour
40
+
41
+ end
@@ -1,31 +1,37 @@
1
1
  require 'rubygems'
2
- require 'test/unit'
2
+ require 'minitest/unit'
3
3
  require 'shoulda'
4
+ require 'mocha'
4
5
 
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
8
  require 'jumpstart'
8
9
 
9
10
  class Test::Unit::TestCase
10
-
11
+
11
12
  end
12
13
 
13
14
  module JumpStart
15
+
14
16
  class Base
15
-
17
+
18
+ # Added monkeypatch for exit methods back until I find a more elegant way to stop generated jumpstarts (jumpstarts that are started programatically during testing) from actually running the exit method.
19
+ # Tests that use this patch:
20
+ # new_project_from_template_options tests. Starting around line 478 of test_base.rb
16
21
  def exit_with_success
17
22
  puts "\n\n Exiting JumpStart...".purple
18
23
  puts "\n Success! ".green + @project_name.green_bold + " has been created at: ".green + FileUtils.join_paths(@install_path, @project_name).green_bold + "\n\n".green
19
24
  puts "******************************************************************************************************************************************\n"
20
- @test_project = nil
25
+ project = nil
21
26
  end
22
-
27
+
23
28
  def exit_normal
24
29
  puts "\n\n Exiting JumpStart...".purple
25
30
  puts "\n Goodbye!\n\n"
26
31
  puts "******************************************************************************************************************************************\n"
27
- @test_project = nil
32
+ project = nil
28
33
  end
29
34
 
30
35
  end
36
+
31
37
  end
@@ -2,43 +2,255 @@ require 'helper'
2
2
 
3
3
  class TestJumpstartBase < Test::Unit::TestCase
4
4
 
5
- context "Testing JumpStart::Base with a @default_template_name and @jumpstart_templates_path specified.\n" do
5
+ context "Testing JumpStart::Base\n" do
6
6
 
7
+ # A valid project with the project name passed in the argument.
8
+ # IO has been setup for testing
9
+ # runs set_config_file_options to set all instance variables
7
10
  setup do
11
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
12
+ JumpStart.default_template_name = "test_template_1"
13
+ input = StringIO.new
14
+ output = StringIO.new
8
15
  FileUtils.delete_dir_contents("#{JumpStart::ROOT_PATH}/test/destination_dir")
9
16
  @test_project = JumpStart::Base.new(["test_jumpstart_project"])
10
17
  @test_project.instance_eval do
11
- @jumpstart_templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
12
- @default_template_name = "test_template_1"
18
+ @input = input
19
+ @output = output
13
20
  @template_name = "test_template_1"
14
21
  @template_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_1"
15
22
  set_config_file_options
16
23
  @install_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
17
24
  end
25
+ @test_project.stubs(:exit_normal)
26
+ @test_project.stubs(:exit_with_success)
18
27
  end
19
28
 
29
+ # A valid project but with an invalid template name passed in the argument with a valid project name. Project ends up valid as JumpStart.default_template_name is valid and it falls back on this.
30
+ # IO has been setup for testing
31
+ # runs set_config_file_options to set all instance variables
32
+ setup do
33
+ input = StringIO.new
34
+ output = StringIO.new
35
+ FileUtils.delete_dir_contents("#{JumpStart::ROOT_PATH}/test/destination_dir")
36
+ @test_project_2 = JumpStart::Base.new(["test_jumpstart_project", "a_name_that_does_not_exist"])
37
+ @test_project_2.instance_eval do
38
+ @input = input
39
+ @output = output
40
+ @template_name = "test_template_2"
41
+ @template_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_2"
42
+ set_config_file_options
43
+ @install_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
44
+ end
45
+ @test_project_2.stubs(:exit_normal)
46
+ @test_project_2.stubs(:exit_with_success)
47
+ end
48
+
49
+ # An invalid project (@template_name), with the project name passed as the argument
50
+ setup do
51
+ FileUtils.delete_dir_contents("#{JumpStart::ROOT_PATH}/test/destination_dir")
52
+ @test_project_3 = JumpStart::Base.new(["test_jumpstart_project"])
53
+ @test_project_3.instance_variable_set(:@template_name, "a_name_that_does_not_exist")
54
+ @test_project_3.instance_variable_set(:@template_path, "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_2")
55
+ @test_project_3.stubs(:exit_normal)
56
+ @test_project_3.stubs(:exit_with_success)
57
+ end
58
+
59
+ # A valid project with the project name passed as the argument
60
+ setup do
61
+ FileUtils.delete_dir_contents("#{JumpStart::ROOT_PATH}/test/destination_dir")
62
+ @test_project_4 = JumpStart::Base.new(["test_jumpstart_project"])
63
+ @test_project_4.instance_variable_set(:@template_name, "test_template_2")
64
+ @test_project_4.instance_variable_set(:@template_path, "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_2")
65
+ @test_project_4.stubs(:exit_normal)
66
+ @test_project_4.stubs(:exit_with_success)
67
+ end
68
+
69
+ # An invalid project (@project_name is too short), then passed a valid @project_name through IO.
70
+ # IO has been setup for testing
71
+ # runs set_config_file_options to set all instance variables
72
+ setup do
73
+ input = StringIO.new("testo\n")
74
+ output = StringIO.new
75
+ @test_project_5 = JumpStart::Base.new(["tr"])
76
+ @test_project_5.instance_eval do
77
+ @input = input
78
+ @output = output
79
+ @template_name = "test_template_1"
80
+ set_config_file_options
81
+ @install_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
82
+ end
83
+ @test_project_5.stubs(:exit_normal)
84
+ @test_project_5.stubs(:exit_with_success)
85
+ end
86
+
87
+ # An invalid project (@project_name is nil), then passed a valid @project_name through IO.
88
+ # IO has been setup for testing
89
+ # runs set_config_file_options to set all instance variables
90
+ setup do
91
+ input = StringIO.new("testorama\n")
92
+ output = StringIO.new
93
+ @test_project_6 = JumpStart::Base.new([nil])
94
+ @test_project_6.instance_eval do
95
+ @input = input
96
+ @output = output
97
+ @template_name = "test_template_1"
98
+ set_config_file_options
99
+ @install_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
100
+ end
101
+ @test_project_6.stubs(:exit_normal)
102
+ @test_project_6.stubs(:exit_with_success)
103
+ end
104
+
20
105
  teardown do
21
106
  FileUtils.delete_dir_contents("#{JumpStart::ROOT_PATH}/test/destination_dir")
107
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/.gitignore")
22
108
  end
23
109
 
24
110
  context "Tests for the JumpStart::Base#intialize instance method. \n" do
111
+
112
+ should "set @jumpstart_template_path" do
113
+ assert_equal "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates", @test_project.instance_eval {JumpStart.templates_path}
114
+ end
25
115
 
26
- should "run intialize method and set instance variables" do
116
+ should "set JumpStart.default_template_name" do
117
+ assert_equal "test_template_1", @test_project.instance_eval {JumpStart.default_template_name}
118
+ end
119
+
120
+ should "set @project_name" do
27
121
  assert_equal "test_jumpstart_project", @test_project.instance_eval {@project_name}
122
+ end
123
+
124
+ should "set @template_name" do
28
125
  assert_equal "test_template_1", @test_project.instance_eval {@template_name}
29
- assert_equal YAML.load_file("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/#{@test_project.instance_eval {@template_name}}/jumpstart_config/#{@test_project.instance_eval {@template_name}}.yml"), @test_project.instance_eval {@config_file}
30
- assert_equal "#{JumpStart::ROOT_PATH}/test/destination_dir", @test_project.instance_eval {@install_path}
126
+ end
127
+
128
+ should "set @template_path" do
31
129
  assert_equal "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_1", @test_project.instance_eval {@template_path}
32
130
  end
33
131
 
34
132
  end
35
133
 
134
+ context "Tests for the JumpStart::Base#set_config_file_options instance method. \n" do
135
+
136
+ should "set @config_file" do
137
+ assert_equal YAML.load_file("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/#{@test_project_2.instance_variable_get(:@template_name)}/jumpstart_config/#{@test_project_2.instance_variable_get(:@template_name)}.yml"), @test_project_2.instance_variable_get(:@config_file)
138
+ end
139
+
140
+ should "set @install_path" do
141
+ assert_equal "#{JumpStart::ROOT_PATH}/test/destination_dir", @test_project_2.instance_variable_get(:@install_path)
142
+ end
143
+
144
+ should "set @install_command" do
145
+ assert_equal "rails", @test_project_2.instance_variable_get(:@install_command)
146
+ end
147
+
148
+ should "set @install_command_args" do
149
+ assert_equal "-J -T", @test_project_2.instance_variable_get(:@install_command_args)
150
+ end
151
+
152
+ should "set @replace_strings" do
153
+ 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
+ end
155
+
156
+ should "load the jumpstart menu if the specified yaml config file does not exist" do
157
+ @test_project_3.stubs(:jumpstart_menu).returns("jumpstart_menu")
158
+ assert_equal "jumpstart_menu", @test_project_3.set_config_file_options
159
+ end
160
+
161
+ end
162
+
163
+ context "Tests for the JumpStart::Base#check_setup instance method. \n" do
164
+
165
+ should "run contained methods" do
166
+ @test_project_4.stubs(:set_config_file_options).returns("set_config_file_options")
167
+ @test_project_4.stubs(:lookup_existing_templates).returns("lookup_existing_templates")
168
+ @test_project_4.stubs(:check_project_name).returns("check_project_name")
169
+ @test_project_4.stubs(:check_template_name).returns("check_template_name")
170
+ @test_project_4.stubs(:check_template_path).returns("check_template_path")
171
+ @test_project_4.stubs(:check_install_path).returns("check_install_path")
172
+ @test_project_4.expects(:set_config_file_options).once
173
+ @test_project_4.expects(:lookup_existing_templates).once
174
+ @test_project_4.expects(:check_project_name).once
175
+ @test_project_4.expects(:check_template_name).once
176
+ @test_project_4.expects(:check_template_path).once
177
+ @test_project_4.expects(:check_install_path).once
178
+ @test_project_4.check_setup
179
+ end
180
+
181
+ end
182
+
36
183
  context "Tests for the JumpStart::Base#lookup_existing_projects instance method. \n" do
37
184
 
38
185
  should "run lookup_existing_projects method and return an array of existing templates" do
39
186
  @test_project.lookup_existing_templates
40
187
  assert_equal %w[test_template_1 test_template_2 test_template_3], @test_project.instance_eval {@existing_templates}
41
188
  end
189
+
190
+ end
191
+
192
+ context "Tests for the JumpStart::Base#start instance method. \n" do
193
+
194
+ should "run the contained methods" do
195
+ @test_project.stubs(:execute_install_command).returns("execute_install_command")
196
+ @test_project.stubs(:run_scripts_from_yaml).with(:run_after_install_command).returns("run_after_install_command")
197
+ @test_project.stubs(:parse_template_dir).returns("parse_template_dir")
198
+ @test_project.stubs(:populate_files_from_append_templates).returns("populate_files_from_append_templates")
199
+ @test_project.stubs(:populate_files_from_line_templates).returns("populate_files_from_line_templates")
200
+ @test_project.stubs(:remove_unwanted_files).returns("remove_unwanted_files")
201
+ @test_project.stubs(:run_scripts_from_yaml).with(:run_after_jumpstart).returns("run_after_jumpstart")
202
+ @test_project.stubs(:check_for_strings_to_replace).returns("check_for_strings_to_replace")
203
+ @test_project.stubs(:check_local_nginx_configuration).returns("check_local_nginx_configuration")
204
+ @test_project.expects(:check_setup).once
205
+ @test_project.expects(:execute_install_command).once
206
+ @test_project.expects(:run_scripts_from_yaml).with(:run_after_install_command).once
207
+ @test_project.expects(:parse_template_dir).once
208
+ @test_project.expects(:populate_files_from_append_templates).once
209
+ @test_project.expects(:populate_files_from_line_templates).once
210
+ @test_project.expects(:remove_unwanted_files).once
211
+ @test_project.expects(:run_scripts_from_yaml).with(:run_after_jumpstart).once
212
+ @test_project.expects(:check_for_strings_to_replace).once
213
+ @test_project.expects(:check_local_nginx_configuration).once
214
+ @test_project.expects(:exit_with_success).once
215
+ @test_project.start
216
+ end
217
+
218
+ end
219
+
220
+ context "Tests for the JumpStart::#check_replace_string_pairs_for_project_name_sub instance method.\n" do
221
+
222
+ should "find :project_name symbol and return @project_name" do
223
+ @values = {:project_name => "some_random_name"}
224
+ @test_project.check_replace_string_pairs_for_project_name_sub(@values)
225
+ assert_equal "test_jumpstart_project", @values[:project_name]
226
+ end
227
+
228
+ should "change values hash as it contains :project_name symbol" do
229
+ @values = {:project_name => "some_random_name"}
230
+ assert_equal({:project_name => "test_jumpstart_project"}, @test_project.check_replace_string_pairs_for_project_name_sub(@values))
231
+ end
232
+
233
+ should "treat all other symbols normally and not replace anything" do
234
+ @values = {:womble => "uncle_bulgaria", :jam => "strawberry", :city => "london"}
235
+ @test_project.check_replace_string_pairs_for_project_name_sub(@values)
236
+ assert_equal "uncle_bulgaria", @values[:womble]
237
+ assert_equal "strawberry", @values[:jam]
238
+ assert_equal "london", @values[:city]
239
+ end
240
+
241
+ should "find :project_name symbol even if it is mixed with other symbols which should return unchanged" do
242
+ @values = {:womble => "uncle_bulgaria", :jam => "strawberry", :project_name => "some_random_name", :city => "london"}
243
+ @test_project.check_replace_string_pairs_for_project_name_sub(@values)
244
+ assert_equal "uncle_bulgaria", @values[:womble]
245
+ assert_equal "strawberry", @values[:jam]
246
+ assert_equal "london", @values[:city]
247
+ assert_equal "test_jumpstart_project", @values[:project_name]
248
+ end
249
+
250
+ should "return hash even if it is empty" do
251
+ @values = {}
252
+ assert_equal @values, @test_project.check_replace_string_pairs_for_project_name_sub(@values)
253
+ end
42
254
 
43
255
  end
44
256
 
@@ -53,152 +265,700 @@ class TestJumpstartBase < Test::Unit::TestCase
53
265
  end
54
266
 
55
267
  context "when the project name is not empty but is not more than 3 characters" do
56
-
57
- setup do
58
- input = StringIO.new("testo\n")
59
- output = StringIO.new
60
- @test_project = JumpStart::Base.new(["tr"])
61
- @test_project.instance_eval do
62
- @input = input
63
- @output = output
64
- @jumpstart_templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
65
- @default_template_name = "test_template_1"
66
- @template_name = "test_template_1"
67
- set_config_file_options
68
- @install_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
69
- end
70
- end
71
-
268
+
72
269
  should "read input from STDIN" do
73
- assert_equal "testo\n", @test_project.input.string
270
+ assert_equal "testo\n", @test_project_5.input.string
74
271
  end
75
272
 
76
273
  should "ask the user to provide a longer project name" do
77
- @test_project.instance_eval {check_project_name}
78
- assert_equal "\e[31m\n The name tr is too short. Please enter a name at least 3 characters long.\e[0m\n" , @test_project.output.string
274
+ @test_project_5.instance_eval {check_project_name}
275
+ assert_equal "\e[31m\n The name tr is too short. Please enter a name at least 3 characters long.\e[0m\n" , @test_project_5.output.string
79
276
  end
80
277
 
81
278
  should "ask the user to provide a longer project name and then return the name of the project when a name longer than three characters is provided" do
82
- @test_project.instance_eval {check_project_name}
83
- assert_equal "\e[31m\n The name tr is too short. Please enter a name at least 3 characters long.\e[0m\n" , @test_project.output.string
84
- assert_equal "testo", @test_project.instance_eval {check_project_name}
279
+ @test_project_5.instance_eval {check_project_name}
280
+ assert_equal "\e[31m\n The name tr is too short. Please enter a name at least 3 characters long.\e[0m\n" , @test_project_5.output.string
281
+ assert_equal "testo", @test_project_5.instance_eval { check_project_name }
85
282
  end
86
283
 
87
284
  end
88
285
 
89
286
  context "when the project name is empty or nil" do
287
+
288
+ should "ask the user to specify a name for the project if @project_name is empty or nil" do
289
+ @test_project_6.instance_eval {check_project_name}
290
+ assert_equal "\e[1m\e[33m\n Enter a name for your project.\e[0m\n", @test_project_6.output.string
291
+ end
90
292
 
91
- setup do
92
- input = StringIO.new("testorama\n")
93
- output = StringIO.new
94
- @test_project = JumpStart::Base.new([nil])
95
- @test_project.instance_eval do
96
- @input = input
97
- @output = output
98
- @jumpstart_templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
99
- @default_template_name = "test_template_1"
100
- @template_name = "test_template_1"
101
- set_config_file_options
102
- @install_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
103
- end
293
+ should "ask the user to specify a name for the project if @project_name is empty or nil and then set it when a name of at least 3 characters is provided" do
294
+ @test_project_6.instance_eval {check_project_name}
295
+ assert_equal "\e[1m\e[33m\n Enter a name for your project.\e[0m\n", @test_project_6.output.string
296
+ assert_equal "testorama", @test_project_6.instance_eval {check_project_name}
104
297
  end
105
298
 
106
- should "ask the user to specify a name for the project if @project_name is empty or nil" do
107
- @test_project.instance_eval {check_project_name}
108
- assert_equal "\e[1m\e[33m\n Enter a name for your project.\e[0m\n", @test_project.output.string
299
+ end
300
+
301
+ context "when the project name begins with a character that is not a number or a letter" do
302
+
303
+ setup do
304
+ @test_project_6.instance_variable_set(:@project_name, "/fail_with_invalid_character_at_start")
109
305
  end
110
306
 
111
- should "ask the user to specify a name for the project if @project_name is empty or nil and then set it when a name of at least 3 characters is provided" do
112
- @test_project.instance_eval {check_project_name}
113
- assert_equal "\e[1m\e[33m\n Enter a name for your project.\e[0m\n", @test_project.output.string
114
- assert_equal "testorama", @test_project.instance_eval {check_project_name}
307
+ should "ask for a valid project name, display an error message and then set project name when a valid string is provided" do
308
+ assert_equal "/fail_with_invalid_character_at_start", @test_project_6.instance_variable_get(:@project_name)
309
+ @test_project_6.instance_eval {check_project_name}
310
+ assert_equal "\e[31m\n /fail_with_invalid_character_at_start begins with an invalid character. Please enter a name thats starts with a letter or a number.\e[0m\n", @test_project_6.output.string
115
311
  end
116
312
 
117
- end
313
+ end
118
314
 
119
315
  end
120
316
 
121
317
  context "Tests for the JumpStart::Base#check_template_name instance method. \n" do
122
318
 
123
- should "run check_template_name method" do
319
+ should "launch jumpstart menu if nil" do
320
+ JumpStart.default_template_name = nil
321
+ @test_project.instance_variable_set(:@template_name, nil)
322
+ @test_project.stubs(:jumpstart_menu).returns("jumpstart_menu")
323
+ @test_project.expects(:jumpstart_menu).once
324
+ @test_project.instance_eval {check_template_name}
325
+ end
326
+
327
+ should "launch jumpstart menu if empty" do
328
+ JumpStart.default_template_name = ""
329
+ @test_project.instance_variable_set(:@template_name, "")
330
+ @test_project.stubs(:jumpstart_menu).returns("jumpstart_menu")
331
+ @test_project.expects(:jumpstart_menu).once
332
+ @test_project.instance_eval {check_template_name}
333
+ end
334
+
335
+ end
336
+
337
+ context "Test for the JumpStart::Base#check_template_path instance method." do
338
+
339
+ should "exit the installation if the @template_path directory cannot be found or accessed." do
340
+ @test_project.instance_variable_set(:@template_path, "#{JumpStart::ROOT_PATH}/not/a/valid/path")
341
+ @test_project.expects(:exit_normal).once
342
+ @test_project.instance_eval {check_template_path}
343
+ assert_equal "\nThe directory \e[31m/Users/i0n/Sites/jumpstart/not/a/valid/path\e[0m could not be found, or you do not have the correct permissions to access it.\n", @test_project.output.string
344
+ end
345
+
346
+ end
347
+
348
+ context "Test for the JumpStart::Base#check_install_path instance method" do
349
+
350
+ should "do nothing if a valid path is set in @install_path and @install_path + @project_name path does not exist yet" do
351
+ assert @test_project.instance_eval {check_install_path}
352
+ end
353
+
354
+ should "provide a warning and exit JumpStart if the directory path of @install_path + @project_name already exists" do
355
+ FileUtils.mkdir(FileUtils.join_paths(@test_project.instance_variable_get(:@install_path), @test_project.instance_variable_get(:@project_name)))
356
+ @test_project.expects(:exit_normal).once
357
+ @test_project.instance_eval {check_install_path}
358
+ assert_equal "\nThe directory \e[31m/Users/i0n/Sites/jumpstart/test/destination_dir/test_jumpstart_project\e[0m already exists.\nAs this is the location you have specified for creating your new project jumpstart will now exit to avoid overwriting anything.\n", @test_project.output.string
359
+ end
124
360
 
361
+ should "set the install path to the current directory if @install_path is nil and then run the method again, checking the path of @install_path + @project_name" do
362
+ @test_project.instance_variable_set(:@install_path, nil)
363
+ assert(@test_project.instance_eval {check_install_path})
364
+ assert_equal FileUtils.pwd , @test_project.instance_variable_get(:@install_path)
125
365
  end
126
366
 
127
367
  end
128
368
 
129
369
  context "Tests for the JumpStart::Base#create_template instance method. \n" do
130
370
 
131
- should "run create_template method" do
371
+ setup do
372
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
373
+ @test_project.instance_variable_set(:@template_name, "testing_create_template")
374
+ end
132
375
 
376
+ should "create a template direcotry named after @template_name in the JumpStart.templates_path directory. Inside this dir it will create a /jumpstart_config directory, and inside that it will create a yaml config file called @template_name.yml and populated with JumpStart::ROOT_PATH/source_templates/template_config.yml " do
377
+ @test_project.instance_eval {create_template}
378
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/testing_create_template/jumpstart_config/testing_create_template.yml")
379
+ end
380
+
381
+ should "give a message and exit if a directory with the same name as @template_name exists in the JumpStart.templates_path dir" do
382
+ FileUtils.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir/testing_create_template")
383
+ @test_project.expects(:exit_normal).once
384
+ @test_project.instance_eval {create_template}
385
+ assert_equal "\nThe directory \e[31m/Users/i0n/Sites/jumpstart/test/destination_dir/testing_create_template\e[0m already exists. The template will not be created.\n", @test_project.output.string
133
386
  end
134
387
 
135
388
  end
136
389
 
137
- context "Tests for the JumpStart::Base#jumpstart_options instance method. \n" do
390
+ context "Tests for the JumpStart::Base#jumpstart_menu instance method." do
138
391
 
139
- should "run jumpstart_options method" do
392
+ should "output the users options to the screen and call jumpstart_menu_options" do
393
+ @test_project.stubs(:jumpstart_menu_options)
394
+ @test_project.expects(:jumpstart_menu_options).once
395
+ @test_project.instance_eval {jumpstart_menu}
396
+ assert_equal "\n\n******************************************************************************************************************************************\n\n\e[1m\e[35m JUMPSTART MENU\n\e[0m\n Here are your options:\n\n\e[1m\e[33m 1\e[0m Create a new project from an existing template.\n\e[1m\e[33m 2\e[0m Create a new template.\n\e[1m\e[33m 3\e[0m Set the default template.\n\e[1m\e[33m 4\e[0m Set the templates directory.\n\n\e[1m\e[33m x\e[0m Exit jumpstart\n\n******************************************************************************************************************************************\n\n", @test_project.output.string
397
+ end
140
398
 
141
- end
399
+ end
400
+
401
+ context "Tests for the JumpStart::Base#jumpstart_menu_options instance method. \n" do
402
+
403
+ setup do
404
+ @test_project.stubs(:lookup_existing_templates)
405
+ @test_project.stubs(:new_project_from_template_menu)
406
+ @test_project.stubs(:new_template_menu)
407
+ @test_project.stubs(:set_default_template_menu)
408
+ @test_project.stubs(:templates_dir_menu)
409
+ end
410
+
411
+ should "run new_project_from_template_menu if input is '1'" do
412
+ @test_project.instance_variable_set(:@input, StringIO.new("1\n"))
413
+ @test_project.expects(:new_project_from_template_menu).once
414
+ @test_project.instance_eval {jumpstart_menu_options}
415
+ end
416
+
417
+ should "run new_template_menu if input is '2'" do
418
+ @test_project.instance_variable_set(:@input, StringIO.new("2\n"))
419
+ @test_project.expects(:new_template_menu).once
420
+ @test_project.instance_eval {jumpstart_menu_options}
421
+ end
422
+
423
+ should "run set_default_template_menu if input is '3'" do
424
+ @test_project.instance_variable_set(:@input, StringIO.new("3\n"))
425
+ @test_project.expects(:set_default_template_menu).once
426
+ @test_project.instance_eval {jumpstart_menu_options}
427
+ end
428
+
429
+ should "run templates_dir_menu if input is '4'" do
430
+ @test_project.instance_variable_set(:@input, StringIO.new("4\n"))
431
+ @test_project.expects(:templates_dir_menu).once
432
+ @test_project.instance_eval {jumpstart_menu_options}
433
+ end
434
+
435
+ should "exit if input is 'x'" do
436
+ @test_project.instance_variable_set(:@input, StringIO.new("x\n"))
437
+ @test_project.expects(:exit_normal).once
438
+ @test_project.instance_eval {jumpstart_menu_options}
439
+ end
440
+
441
+ # 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.
442
+ should "ask for another input if the value entered is not '1,2,3,4 or x'. Test with 'blarg'" do
443
+ @test_project.instance_variable_set(:@input, StringIO.new("blarg\n"))
444
+ assert_raises(NoMethodError) {@test_project.instance_eval {jumpstart_menu_options}}
445
+ end
446
+
447
+ # 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
+ should "ask for another input if the value entered is not '1,2,3,4 or x'. Test with 'a'" do
449
+ @test_project.instance_variable_set(:@input, StringIO.new("a\n"))
450
+ assert_raises(NoMethodError) {@test_project.instance_eval {jumpstart_menu_options}}
451
+ end
452
+
453
+ end
454
+
455
+ context "Tests for the JumpStart::Base#new_project_from_template_menu instance method." do
456
+
457
+ should "display options and run new_project_from_template_options" do
458
+ @test_project.stubs(:new_project_from_template_options)
459
+ @test_project.expects(:new_project_from_template_options).once
460
+ @test_project.instance_variable_set(:@existing_templates, %w[project1 project2 project3])
461
+ @test_project.instance_eval {new_project_from_template_menu}
462
+ assert_equal "\n\n******************************************************************************************************************************************\n\n\e[1m\e[35m CREATE A NEW JUMPSTART PROJECT FROM AN EXISTING TEMPLATE\n\n\e[0m\n Type a number for the template that you want.\n\n \e[1m\e[33m1\e[0m project1\n \e[1m\e[33m2\e[0m project2\n \e[1m\e[33m3\e[0m project3\n\e[1m\e[33m\n b\e[0m Back to main menu.\n\e[1m\e[33m\n x\e[0m Exit jumpstart\n\n******************************************************************************************************************************************\n\n", @test_project.output.string
463
+ assert_equal ['project1', 'project2', 'project3'], @test_project.instance_variable_get(:@existing_templates)
464
+ end
142
465
 
143
466
  end
144
467
 
145
- context "Tests for the JumpStart::Base#configure_jumpstart instance method. \n" do
468
+ context "Tests for the JumpStart::Base#new_project_from_template_options instance method." do
469
+
470
+ setup do
471
+ @test_project.stubs(:jumpstart_menu)
472
+ @test_project.instance_eval {lookup_existing_templates}
473
+ end
146
474
 
147
- should "run configure_jumpstart method" do
475
+ should "create a new project with the specified template name, checking that the project name is valid when a valid number is entered" do
476
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
477
+ JumpStart.default_template_name = "test_template_1"
478
+ @test_project.expects(:check_project_name).once
479
+ @test_project.instance_variable_set(:@input, StringIO.new("1\n"))
480
+ @test_project.instance_eval {new_project_from_template_options}
481
+ # project will be created from directory where command is run as @install_papth cannot currently be set for generated jumpstart project.
482
+ assert File.directory?("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_1/test_jumpstart_project")
483
+ FileUtils.remove_dir("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_1/test_jumpstart_project")
484
+ end
485
+
486
+ should "launch the jumpstart_menu method if 'b' is entered" do
487
+ @test_project.expects(:jumpstart_menu).once
488
+ @test_project.instance_variable_set(:@input, StringIO.new("b\n"))
489
+ @test_project.instance_eval {new_project_from_template_options}
490
+ end
148
491
 
492
+ should "exit JumpStart if 'x' is entered." do
493
+ @test_project.expects(:exit_normal).once
494
+ @test_project.instance_variable_set(:@input, StringIO.new("x\n"))
495
+ @test_project.instance_eval {new_project_from_template_options}
496
+ end
497
+
498
+ should "output a message saying that the input has not been understood for any other input" do
499
+ @test_project.instance_variable_set(:@input, StringIO.new("blarg\n"))
500
+ @test_project.instance_eval {new_project_from_template_options}
501
+ assert_equal "\e[31mThat command hasn't been understood. Try again!\e[0m\n", @test_project.output.string
149
502
  end
150
503
 
151
504
  end
505
+
506
+ context "Tests for the JumpStart::Base#new_template_menu instance method." do
507
+
508
+ should "display output and call new_template_options" do
509
+ @test_project.stubs(:lookup_existing_templates)
510
+ @test_project.stubs(:new_template_options)
511
+ @test_project.instance_variable_set(:@existing_templates, %w[project1 project2 project3])
512
+ @test_project.expects(:lookup_existing_templates).once
513
+ @test_project.expects(:new_template_options).once
514
+ @test_project.instance_eval {new_template_menu}
515
+ assert_equal "\n\n******************************************************************************************************************************************\n\n\e[1m\e[35m CREATE A NEW JUMPSTART TEMPLATE\n\e[0m\n Existing templates:\n \e[32mproject1\e[0m\n \e[32mproject2\e[0m\n \e[32mproject3\e[0m\n", @test_project.output.string
516
+ assert_equal %w[project1 project2 project3], @test_project.instance_variable_get(:@existing_templates)
517
+ end
152
518
 
153
- context "Tests for the JumpStart::Base#check_install_paths instance method. \n" do
519
+ end
520
+
521
+ context "Tests for the JumpStart::Base#new_template_options instance method." do
154
522
 
155
- should "run check_install_paths method" do
523
+ setup do
524
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
525
+ @test_project.stubs(:jumpstart_menu).returns("jumpstart_menu")
526
+ @test_project.instance_variable_set(:@existing_templates, %w[one two three])
527
+ end
156
528
 
157
- end
529
+ # 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.
530
+ should "ask for another template name if the name given is already taken " do
531
+ @test_project.instance_variable_set(:@input, StringIO.new("one\n"))
532
+ assert_raises(NoMethodError) {@test_project.instance_eval {new_template_options}}
533
+ end
534
+
535
+ # 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.
536
+ should "ask for another template name if the name given is less than 3 characters long." do
537
+ @test_project.instance_variable_set(:@input, StringIO.new("on\n"))
538
+ assert_raises(NoMethodError) {@test_project.instance_eval {new_template_options}}
539
+ end
540
+
541
+ # 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.
542
+ should "ask for another template name if the name given begins with a character that is not a number or a letter." do
543
+ @test_project.instance_variable_set(:@input, StringIO.new("/one\n"))
544
+ assert_raises(NoMethodError) {@test_project.instance_eval {new_template_options}}
545
+ end
546
+
547
+ should "create a new template in the jumpstart templates directory if the name given is valid." do
548
+ @test_project.instance_variable_set(:@input, StringIO.new("four\n"))
549
+ @test_project.instance_eval {new_template_options}
550
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/four/jumpstart_config/four.yml")
551
+ original_file_contents = IO.read("#{JumpStart::ROOT_PATH}/source_templates/template_config.yml")
552
+ created_file_contents = IO.read("#{JumpStart::ROOT_PATH}/test/destination_dir/four/jumpstart_config/four.yml")
553
+ assert_equal original_file_contents, created_file_contents
554
+ end
555
+
556
+ end
557
+
558
+ context "Tests for the JumpStart::Base#set_default_template_menu instance method." do
559
+
560
+ should "display menu containing contents of @existing_templates" do
561
+ @test_project.instance_variable_set(:@existing_templates, %w[one two three])
562
+ @test_project.stubs(:set_default_template_options)
563
+ @test_project.expects(:set_default_template_options).once
564
+ @test_project.instance_eval {set_default_template_menu}
565
+ assert_equal "\n\n******************************************************************************************************************************************\n\n\e[1m\e[35m JUMPSTART DEFAULT TEMPLATE OPTIONS\n\n\e[0m\n \e[1m\e[33m1\e[0m one\n \e[1m\e[33m2\e[0m two\n \e[1m\e[33m3\e[0m three\n\e[1m\e[33m\n b\e[0m Back to main menu.\n\n\e[1m\e[33m x\e[0m Exit jumpstart\n\n******************************************************************************************************************************************\n\n", @test_project.output.string
566
+ end
158
567
 
159
568
  end
569
+
570
+ context "Tests for the JumpStart::Base#set_default_template_options instance method." do
160
571
 
161
- context "Tests for the JumpStart::Base#create_project method instance method. \n" do
572
+ setup do
573
+ @test_project.stubs(:jumpstart_menu)
574
+ @test_project.stubs(:dump_global_yaml)
575
+ @test_project.instance_variable_set(:@existing_templates, %w[template1 template2 template3])
576
+ JumpStart.default_template_name = "temp_default"
577
+ end
578
+
579
+ should "set the default template if a number corresponding to an existing template is entered." do
580
+ @test_project.instance_variable_set(:@input, StringIO.new("1\n"))
581
+ @test_project.expects(:jumpstart_menu).once
582
+ @test_project.expects(:dump_global_yaml).once
583
+ @test_project.instance_eval {set_default_template_options}
584
+ assert_equal "template1", JumpStart.default_template_name
585
+ end
586
+
587
+ should "go back to the main jumpstart menu if 'b' is entered." do
588
+ @test_project.instance_variable_set(:@input, StringIO.new("b\n"))
589
+ @test_project.expects(:jumpstart_menu).once
590
+ @test_project.instance_eval {set_default_template_options}
591
+ assert_equal "temp_default", JumpStart.default_template_name
592
+ end
593
+
594
+ should "exit jumpstart if 'x' is entered" do
595
+ @test_project.instance_variable_set(:@input, StringIO.new("x\n"))
596
+ @test_project.expects(:exit_normal).once
597
+ @test_project.instance_eval {set_default_template_options}
598
+ assert_equal "temp_default", JumpStart.default_template_name
599
+ end
600
+
601
+ # 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.
602
+ should "restart the set_default_template_options method if the command is not understood" do
603
+ @test_project.instance_variable_set(:@input, StringIO.new("super_blarg\n"))
604
+ assert_raises(NoMethodError) {@test_project.instance_eval {set_default_template_options}}
605
+ end
606
+
607
+ end
608
+
609
+ context "Tests for the JumpStart::Base#templates_dir_menu instance method." do
610
+
611
+ should "display options and call templates_dir_options method." do
612
+ @test_project.stubs(:templates_dir_options)
613
+ @test_project.expects(:templates_dir_options).once
614
+ @test_project.instance_eval {templates_dir_menu}
615
+ assert_equal "\n\n******************************************************************************************************************************************\n\n\e[1m\e[35m JUMPSTART TEMPLATES DIRECTORY OPTIONS\n\n\e[0m\n\e[1m\e[33m 1\e[0m Set templates directory.\n\e[1m\e[33m 2\e[0m Reset templates directory to default\n\n\e[1m\e[33m b\e[0m Back to main menu.\n\n\e[1m\e[33m x\e[0m Exit jumpstart\n\n******************************************************************************************************************************************\n\n", @test_project.output.string
616
+ end
617
+
618
+ end
619
+
620
+ context "Tests for the JumpStart::Base#templates_dir_options instance method." do
621
+
622
+ setup do
623
+ @test_project.stubs(:set_templates_dir)
624
+ @test_project.stubs(:reset_templates_dir_to_default_check)
625
+ @test_project.stubs(:jumpstart_menu)
626
+ end
162
627
 
163
- should "run create_project method" do
628
+ should "run the set_templates_dir method when '1' is entered." do
629
+ @test_project.instance_variable_set(:@input, StringIO.new("1\n"))
630
+ @test_project.expects(:set_templates_dir).once
631
+ @test_project.instance_eval {templates_dir_options}
632
+ end
633
+
634
+ should "run the reset_templates_dir_to_default method when '2' is entered." do
635
+ @test_project.instance_variable_set(:@input, StringIO.new("2\n"))
636
+ @test_project.expects(:reset_templates_dir_to_default_check).once
637
+ @test_project.instance_eval {templates_dir_options}
638
+ end
639
+
640
+ should "run the jumpstart_menu method when 'b' is entered." do
641
+ @test_project.instance_variable_set(:@input, StringIO.new("b\n"))
642
+ @test_project.expects(:jumpstart_menu).once
643
+ @test_project.instance_eval {templates_dir_options}
644
+ end
645
+
646
+ should "run the exit_normal when 'x' is entered." do
647
+ @test_project.instance_variable_set(:@input, StringIO.new("x\n"))
648
+ @test_project.expects(:exit_normal).once
649
+ @test_project.instance_eval {templates_dir_options}
650
+ end
164
651
 
652
+ # 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.
653
+ should "restart the method if the command entered is not understood" do
654
+ @test_project.instance_variable_set(:@input, StringIO.new("blarg\n"))
655
+ assert_raises(NoMethodError) {@test_project.instance_eval {templates_dir_options}}
165
656
  end
166
657
 
167
658
  end
659
+
660
+ context "Tests for the JumpStart::Base#set_templates_dir instance method." do
168
661
 
169
- context "Tests for the JumpStart::Base#parse_template_dir instance method. \n" do
662
+ setup do
663
+ @test_project.stubs(:dump_global_yaml)
664
+ @test_project.stubs(:jumpstart_menu)
665
+ end
170
666
 
171
- should "run parse_template_dir method" do
667
+ # 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.
668
+ should "restart the method if the directory path provided already exists." do
669
+ @test_project.instance_variable_set(:@input, StringIO.new("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_1"))
670
+ assert_raises(NoMethodError) {@test_project.instance_eval {set_templates_dir}}
671
+ end
172
672
 
673
+ should "create a new directory and copy existing templates into it, then set JumpStart.templates_path to the new location." do
674
+ @test_project.instance_variable_set(:@input, StringIO.new("#{JumpStart::ROOT_PATH}/test/destination_dir/a_name_that_does_not_exist"))
675
+ @test_project.expects(:dump_global_yaml).once
676
+ @test_project.expects(:jumpstart_menu).once
677
+ @test_project.instance_eval {set_templates_dir}
678
+ assert_equal "Please enter the absolute path for the directory that you would like to contain your jumpstart templates.\n\nCopying existing templates to /Users/i0n/Sites/jumpstart/test/destination_dir/a_name_that_does_not_exist\n\e[32m\nTransfer complete!\e[0m\n", @test_project.output.string
679
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/a_name_that_does_not_exist/test_template_1/jumpstart_config/test_template_1.yml")
173
680
  end
174
681
 
175
682
  end
176
-
177
- context "Tests for the JumpStart::Base#populate_files_from_append_templates instance method. \n" do
683
+
684
+ context "Tests for the JumpStart::Base#reset_templates_dir_to_default_check instance method." do
178
685
 
179
- should "run populate_files_from_append_templates method" do
686
+ setup do
687
+ @test_project.stubs(:templates_dir_menu)
688
+ @test_project.stubs(:reset_templates_dir_to_default_set)
689
+ end
690
+
691
+ should "output a message and run templates_dir_menu if JumpStart.templates_path is set to it's standard starting position." do
692
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/jumpstart_templates"
693
+ @test_project.expects(:templates_dir_menu).once
694
+ @test_project.instance_eval {reset_templates_dir_to_default_check}
695
+ assert_equal "\e[31m You do not need to reset the jumpstart templates directory, it is already set to: /Users/i0n/Sites/jumpstart/jumpstart_templates\n\n\e[0m\n", @test_project.output.string
696
+ end
180
697
 
698
+ should "run reset_templates_dir_to_default_set if the current JumpStart.templates_path is not the default." do
699
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
700
+ @test_project.expects(:reset_templates_dir_to_default_set).once
701
+ @test_project.instance_eval {reset_templates_dir_to_default_check}
702
+ assert_equal " Resetting the jumpstart templates directory to the default: /Users/i0n/Sites/jumpstart/jumpstart_templates\n\n\e[1m\e[33m Moving your jumpstart templates back to the default directory will delete any templates that are currently there. Proceed?\n\e[0m\n Type yes (\e[1m\e[33my\e[0m) or no (\e[1m\e[33mn\e[0m)\n\n", @test_project.output.string
181
703
  end
182
704
 
183
705
  end
706
+
707
+ context "Tests for the JumpStart::Base#reset_templates_dir_to_default_set instance method." do
184
708
 
709
+ setup do
710
+ @test_project.stubs(:dump_global_yaml)
711
+ @test_project.stubs(:templates_dir_menu)
712
+ FileUtils.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir/jumpstart_templates")
713
+ @normal_root_path = JumpStart::ROOT_PATH.dup
714
+ JumpStart::ROOT_PATH = "#{@normal_root_path}/test/destination_dir"
715
+ JumpStart.templates_path = "#{@normal_root_path}/test/test_jumpstart_templates/test_base"
716
+ @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
+ end
718
+
719
+ teardown do
720
+ JumpStart::ROOT_PATH = @normal_root_path
721
+ end
185
722
 
186
- context "Tests for the JumpStart::Base#populate_files_from_line_templates instance method. \n" do
723
+ should "reset jumpstart templates directory to default if input is 'y'" do
724
+ @test_project.expects(:templates_dir_menu)
725
+ @test_project.instance_variable_set(:@input, StringIO.new("y\n"))
726
+ @test_project.instance_eval {reset_templates_dir_to_default_set}
727
+ assert_equal "\e[32m\n SUCCESS! the jumpstart templates directory has been set to the default: /Users/i0n/Sites/jumpstart/test/destination_dir/jumpstart_templates\e[0m\n", @test_project.output.string
728
+ assert File.exists?("#{JumpStart::ROOT_PATH}/jumpstart_templates/current_files_and_dirs_test_file.txt")
729
+ assert File.directory?("#{JumpStart::ROOT_PATH}/jumpstart_templates/current_files_and_dirs_test_dir")
730
+ end
731
+
732
+ should "reset jumpstart templates directory to default if input is 'yes'" do
733
+ @test_project.expects(:templates_dir_menu)
734
+ @test_project.instance_variable_set(:@input, StringIO.new("yes\n"))
735
+ @test_project.instance_eval {reset_templates_dir_to_default_set}
736
+ assert_equal "\e[32m\n SUCCESS! the jumpstart templates directory has been set to the default: /Users/i0n/Sites/jumpstart/test/destination_dir/jumpstart_templates\e[0m\n", @test_project.output.string
737
+ assert File.exists?("#{JumpStart::ROOT_PATH}/jumpstart_templates/current_files_and_dirs_test_file.txt")
738
+ assert File.directory?("#{JumpStart::ROOT_PATH}/jumpstart_templates/current_files_and_dirs_test_dir")
739
+ end
740
+
741
+ should "run templates_dir_menu if input is 'n'" do
742
+ @test_project.expects(:templates_dir_menu)
743
+ @test_project.instance_variable_set(:@input, StringIO.new("n\n"))
744
+ @test_project.instance_eval {reset_templates_dir_to_default_set}
745
+ assert_equal "\n You have chosen not to move the jumpstart templates directory, nothing has been changed.\n", @test_project.output.string
746
+ end
747
+
748
+ should "run templates_dir_menu if input is 'no'" do
749
+ @test_project.expects(:templates_dir_menu)
750
+ @test_project.instance_variable_set(:@input, StringIO.new("no\n"))
751
+ @test_project.instance_eval {reset_templates_dir_to_default_set}
752
+ assert_equal "\n You have chosen not to move the jumpstart templates directory, nothing has been changed.\n", @test_project.output.string
753
+ end
754
+
755
+ # 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.
756
+ should "restart the method if the input is not understood" do
757
+ @test_project.instance_variable_set(:@input, StringIO.new("blarg\n"))
758
+ assert_raises(NoMethodError) {@test_project.instance_eval {reset_templates_dir_to_default_set}}
759
+ end
187
760
 
188
- should "run populate_files_from_line_templates method" do
761
+ end
762
+
763
+ context "Tests for the JumpStart::Base#execute_install_command instance method." do
764
+
765
+ should "do nothing if @install_command is nil" do
766
+ @test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
767
+ @test_project.instance_variable_set(:@install_command, nil)
768
+ @test_project.instance_variable_set(:@install_command_args, "test")
769
+ @test_project.instance_eval {execute_install_command}
770
+ assert_equal "", @test_project.output.string
771
+ end
189
772
 
773
+ should "do nothing if @install_command is empty" do
774
+ @test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
775
+ @test_project.instance_variable_set(:@install_command, "")
776
+ @test_project.instance_variable_set(:@install_command_args, "test")
777
+ @test_project.instance_eval {execute_install_command}
778
+ assert_equal "", @test_project.output.string
779
+ end
780
+
781
+ should "execute @install_command if it contains a string" do
782
+ @test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
783
+ @test_project.instance_variable_set(:@install_command, "echo")
784
+ @test_project.instance_variable_set(:@install_command_args, "install command args")
785
+ @test_project.expects(:system).once
786
+ @test_project.instance_eval {execute_install_command}
787
+ 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
+ end
789
+
790
+ should "raise an error if the @install_path does not exist" do
791
+ @test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir/this/dir/does/not/exist")
792
+ @test_project.instance_variable_set(:@install_command, "echo")
793
+ @test_project.instance_variable_set(:@install_command_args, "install command args")
794
+ assert_raises(Errno::ENOENT) {@test_project.instance_eval {execute_install_command}}
795
+ end
796
+
797
+ end
798
+
799
+ context "Tests for the JumpStart::Base#parse_template_dir instance method." do
800
+
801
+ setup do
802
+ @test_project.instance_variable_set(:@template_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
803
+ FileUtils.mkdir_p("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config")
804
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/nginx.local.conf")
805
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/nginx.remote.conf")
806
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/_._append_test_1.txt")
807
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/_._append_test_2")
808
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/_l._append_test_3.txt")
809
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/_L._append_test_4.txt")
810
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/_._append_test_5.txt")
811
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/_._append_test_6")
812
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/_l._append_test_7.txt")
813
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/_L._append_test_8.txt")
814
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/_1._line_test_1.txt")
815
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/_1._line_test_2")
816
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/_1._line_test_3.txt")
817
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/_10000._line_test_4.txt")
818
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/whole_test_1.txt")
819
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/whole_test_2")
820
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/whole_test_3")
821
+ FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/whole_test_4.txt")
822
+ @test_project.instance_eval {parse_template_dir}
823
+ end
824
+
825
+ should "populate @dir_list with directories contained in @template_path" do
826
+ assert_equal ['', '/parse_template_dir'], @test_project.instance_variable_get(:@dir_list)
827
+ end
828
+
829
+ should "populate @append_templates with files that are prefixed with _._ _l._ or _L._ and do not contain a directory called jumpstart_config." do
830
+ assert_equal ["/parse_template_dir/_._append_test_5.txt",
831
+ "/parse_template_dir/_._append_test_6",
832
+ "/parse_template_dir/_L._append_test_8.txt",
833
+ "/parse_template_dir/_l._append_test_7.txt"], @test_project.instance_variable_get(:@append_templates)
834
+ end
835
+
836
+ 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
+ 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)
839
+ end
840
+
841
+ 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)
843
+ end
844
+
845
+ should "populate @nginx_local_template if a file matching jumpstart_config/nginx.local.conf is found" do
846
+ 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
+ end
848
+
849
+ should "populate @nginx_remote_template if a file matching jumpstart_config/nginx.remote.conf is found" do
850
+ assert_equal "#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/nginx.remote.conf", @test_project.instance_variable_get(:@nginx_remote_template)
190
851
  end
191
852
 
192
853
  end
193
854
 
855
+ context "Tests for the JumpStart::Base#create_dirs instance method." do
856
+
857
+ should "create dirs even if paths have too many or too few forward slashes" do
858
+ @test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
859
+ @test_project.instance_variable_set(:@project_name, 'create_dirs_test' )
860
+ @test_project.instance_variable_set(:@dir_list, %w[1 //2// /3 ///4 5/// /6/] )
861
+ @test_project.instance_eval {create_dirs}
862
+ assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/create_dirs_test/1")
863
+ assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/create_dirs_test/2")
864
+ assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/create_dirs_test/3")
865
+ assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/create_dirs_test/4")
866
+ assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/create_dirs_test/5")
867
+ assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/create_dirs_test/6")
868
+ end
869
+
870
+ end
871
+
872
+ context "Tests for the JumpStart::Base#populate_files_from_whole_templates instance method." do
873
+
874
+ should "create files from @whole_templates" do
875
+ @test_project.instance_eval {parse_template_dir}
876
+ @test_project.instance_eval {create_dirs}
877
+ @test_project.instance_eval {populate_files_from_whole_templates}
878
+ assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project")
879
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_whole_file_with_extension.txt")
880
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_whole_file_without_extension")
881
+ end
882
+
883
+ end
884
+
885
+ context "Tests for the JumpStart::Base#populate_files_from_append_templates instance method." do
886
+
887
+ should "append contents of append template to file." do
888
+ @test_project.instance_eval {parse_template_dir}
889
+ @test_project.instance_eval {create_dirs}
890
+ @test_project.instance_eval {populate_files_from_whole_templates}
891
+ @test_project.instance_eval {populate_files_from_append_templates}
892
+ file_1 = IO.readlines("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_1.txt")
893
+ file_2 = IO.readlines("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_2.txt")
894
+ assert_equal "THIS IS THE LAST LINE\n", file_1[9]
895
+ assert_equal "THIS IS THE LAST LINE\n", file_2[9]
896
+ assert_equal "9\n", file_1[8]
897
+ assert_equal "9\n", file_2[8]
898
+ refute file_1[10]
899
+ refute file_2[10]
900
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_file_with_extension.txt")
901
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_file_without_extension")
902
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_append_file_with_extension.txt")
903
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_append_file_without_extension")
904
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_1.txt")
905
+ refute File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_L._test_append_to_end_of_file_remove_last_line_1.txt")
906
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_2.txt")
907
+ refute File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_l._test_append_to_end_of_file_remove_last_line_2.txt")
908
+ end
909
+
910
+ end
911
+
912
+ context "Tests for the JumpStart::Base#populate_files_from_line_templates instance method. \n" do
913
+
914
+ should "append contents of line templates to the relevant file." do
915
+ @test_project.instance_eval {parse_template_dir}
916
+ @test_project.instance_eval {create_dirs}
917
+ @test_project.instance_eval {populate_files_from_whole_templates}
918
+ @test_project.instance_eval {populate_files_from_append_templates}
919
+ @test_project.instance_eval {populate_files_from_line_templates}
920
+ file = "#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_line_file_without_extension"
921
+ assert File.exists?(file)
922
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_line_file_with_extension.txt")
923
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_line_file_with_extension.txt")
924
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_line_file_without_extension")
925
+ file_lines = IO.readlines(file)
926
+ assert_equal( "Lorem\n", file_lines[19])
927
+ end
928
+
929
+ end
930
+
194
931
  context "Tests for the JumpStart::Base#check_local_nginx_configuration instance method. \n" do
195
932
 
196
- should "run check_local_nginx_configuration method" do
933
+ setup do
934
+ FileUtils.stubs(:config_nginx)
935
+ FileUtils.stubs(:config_hosts)
936
+ end
937
+
938
+ should "produce an error and not try to configure Nginx if @nginx_local_template is nil" do
939
+ @test_project.instance_variable_set(:@config_file, {:local_nginx_conf => "something"})
940
+ @test_project.instance_variable_set(:@nginx_local_template, nil)
941
+ @test_project.instance_eval {check_local_nginx_configuration}
942
+ assert_equal " \nNginx will not be configured as options have not been set for this.\n", @test_project.output.string
943
+ end
944
+
945
+ should "produce an error and not try to configure Nginx if @config_file[:local_nginx_conf] is nil" do
946
+ @test_project.instance_variable_set(:@config_file, {:local_nginx_conf => nil})
947
+ @test_project.instance_variable_set(:@nginx_local_template, "something")
948
+ @test_project.instance_eval {check_local_nginx_configuration}
949
+ assert_equal " \nNginx will not be configured as options have not been set for this.\n", @test_project.output.string
950
+ end
197
951
 
952
+ should "try and run FileUtils.config_nginx and FileUtils.config_hosts if both @nginx_local_template and @config_file[:local_nginx_conf] are set." do
953
+ @test_project.instance_variable_set(:@config_file, {:local_nginx_conf => "something"})
954
+ @test_project.instance_variable_set(:@nginx_local_template, "something")
955
+ FileUtils.expects(:config_nginx).once
956
+ FileUtils.expects(:config_hosts).once
957
+ @test_project.instance_eval {check_local_nginx_configuration}
198
958
  end
199
959
 
200
960
  end
201
-
961
+
202
962
  context "Tests for the JumpStart::Base#remove_unwanted_files instance method. \n" do
203
963
 
204
964
  setup do
@@ -248,7 +1008,7 @@ class TestJumpstartBase < Test::Unit::TestCase
248
1008
 
249
1009
  end
250
1010
 
251
- context "Tests for the JumpStart::#check_for_strings_to_replace instance method.\n" do
1011
+ context "Tests for the JumpStart::Base#check_for_strings_to_replace instance method.\n" do
252
1012
 
253
1013
  setup do
254
1014
  output = StringIO.new
@@ -276,44 +1036,26 @@ class TestJumpstartBase < Test::Unit::TestCase
276
1036
  end
277
1037
 
278
1038
  end
1039
+
1040
+ context "Tests for the JumpStart::Base#dump_global_yaml instance method." do
279
1041
 
280
- context "Tests for the JumpStart::#check_replace_string_pairs_for_project_name_sub instance method.\n" do
281
-
282
- should "find :project_name symbol and return @project_name" do
283
- @values = {:project_name => "some_random_name"}
284
- @test_project.check_replace_string_pairs_for_project_name_sub(@values)
285
- assert_equal "test_jumpstart_project", @values[:project_name]
286
- end
287
-
288
- should "change values hash as it contains :project_name symbol" do
289
- @values = {:project_name => "some_random_name"}
290
- assert_equal({:project_name => "test_jumpstart_project"}, @test_project.check_replace_string_pairs_for_project_name_sub(@values))
291
- end
292
-
293
- should "treat all other symbols normally and not replace anything" do
294
- @values = {:womble => "uncle_bulgaria", :jam => "strawberry", :city => "london"}
295
- @test_project.check_replace_string_pairs_for_project_name_sub(@values)
296
- assert_equal "uncle_bulgaria", @values[:womble]
297
- assert_equal "strawberry", @values[:jam]
298
- assert_equal "london", @values[:city]
299
- end
300
-
301
- should "find :project_name symbol even if it is mixed with other symbols which should return unchanged" do
302
- @values = {:womble => "uncle_bulgaria", :jam => "strawberry", :project_name => "some_random_name", :city => "london"}
303
- @test_project.check_replace_string_pairs_for_project_name_sub(@values)
304
- assert_equal "uncle_bulgaria", @values[:womble]
305
- assert_equal "strawberry", @values[:jam]
306
- assert_equal "london", @values[:city]
307
- assert_equal "test_jumpstart_project", @values[:project_name]
308
- end
309
-
310
- should "return hash even if it is empty" do
311
- @values = {}
312
- assert_equal @values, @test_project.check_replace_string_pairs_for_project_name_sub(@values)
1042
+ should "call File.open and Yaml.dump for jumpstart_setup.yml" do
1043
+ YAML.stubs(:dump)
1044
+ File.stubs(:open)
1045
+ File.expects(:open).once
1046
+ @test_project.instance_eval {dump_global_yaml}
313
1047
  end
314
1048
 
315
1049
  end
316
-
1050
+
1051
+ context "Tests for the JumpStart::Base#exit_with_success instance method." do
1052
+ # As these methods are very simple exit (end script) methods, and are already patched for testing, seems pointless to write tests for them.
1053
+ end
1054
+
1055
+ context "Tests for the JumpStart::Base#exit_normal instance method." do
1056
+ # As these methods are very simple exit (end script) methods, and are already patched for testing, seems pointless to write tests for them.
1057
+ end
1058
+
317
1059
  context "Tests for the JumpStart::Base.get_line_number class method.\n" do
318
1060
 
319
1061
  should "return line number as 1" do
@@ -381,7 +1123,7 @@ class TestJumpstartBase < Test::Unit::TestCase
381
1123
 
382
1124
  should "generate a test project in ROOT_PATH/test/destination_dir/test_jumpstart_project with the test_template_1 template" do
383
1125
  @test_project.start
384
- assert Dir.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project")
1126
+ assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project")
385
1127
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_file_with_extension.txt")
386
1128
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_file_without_extension")
387
1129
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_line_file_with_extension.txt")