jumpstart 0.3.6 → 0.3.7
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.
- data/README.rdoc +30 -3
- data/config/jumpstart_version.yml +1 -1
- data/lib/jumpstart.rb +21 -22
- data/lib/jumpstart/base.rb +505 -481
- data/lib/jumpstart/filetools.rb +11 -11
- data/test/jumpstart/test_base.rb +362 -280
- data/test/test_jumpstart.rb +50 -30
- metadata +3 -3
data/lib/jumpstart/filetools.rb
CHANGED
@@ -26,7 +26,7 @@ module JumpStart::FileTools
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
# For inserting text provided as a string or a target file (source) to a specific line number (line_number) of another file (target_file)
|
29
|
+
# For inserting text provided as a string or a target file (source) to a specific line number (line_number) of another file (target_file)
|
30
30
|
def insert_text_at_line_number(source, target_file, line_number)
|
31
31
|
if line_number > 0
|
32
32
|
line_number -= 1
|
@@ -67,7 +67,7 @@ module JumpStart::FileTools
|
|
67
67
|
else
|
68
68
|
puts
|
69
69
|
puts "The file #{x.red} could not be deleted as it could not be found."
|
70
|
-
end
|
70
|
+
end
|
71
71
|
rescue
|
72
72
|
puts
|
73
73
|
puts "Uh-oh, we've hit a snag with the remove_files method.".red
|
@@ -75,7 +75,7 @@ module JumpStart::FileTools
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
# For removing lines in a file that (A) match a specific pattern, and/or (B) or are specified by line number.
|
80
80
|
# Both types of removal are passed to the method via the arguments hash.
|
81
81
|
# e.g. remove lines macthing a pattern, do FileUtils.remove_lines(target_file, :pattern => "Hello!")
|
@@ -113,7 +113,7 @@ module JumpStart::FileTools
|
|
113
113
|
x.puts new_file
|
114
114
|
end
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
# This method generates string replacements via a hash passed to the method, this enables versatile string replacement.
|
118
118
|
# To replace values in the target file, simply add the name of the key for that replacement in CAPS.
|
119
119
|
# e.g. You might call the method with something like: FileUtils.replace_strings(target_file, :name => "Ian", :country => "England")
|
@@ -128,8 +128,8 @@ module JumpStart::FileTools
|
|
128
128
|
file.puts txt
|
129
129
|
end
|
130
130
|
end
|
131
|
-
|
132
|
-
# For setting up app in Nginx
|
131
|
+
|
132
|
+
# For setting up app in Nginx
|
133
133
|
def config_nginx(source_file, target_file, app_name)
|
134
134
|
if source_file == nil || target_file == nil || app_name == nil
|
135
135
|
puts
|
@@ -195,7 +195,7 @@ module JumpStart::FileTools
|
|
195
195
|
file.puts etc_hosts
|
196
196
|
end
|
197
197
|
puts "Success! #{app_name.green} has been added to #{target_file.green}"
|
198
|
-
puts
|
198
|
+
puts
|
199
199
|
else
|
200
200
|
puts "It doesn't look like you have write access for #{target_file}. Would you like to use sudo to change them?".yellow
|
201
201
|
puts "Type yes (" + "y".yellow + ") or no (" + "n".yellow + ")"
|
@@ -217,7 +217,7 @@ module JumpStart::FileTools
|
|
217
217
|
puts "******************************************************************************************************************************************"
|
218
218
|
puts
|
219
219
|
end
|
220
|
-
|
220
|
+
|
221
221
|
# Checks to see if the source type is a file or a string. If it's a file it reads the lines of the file and returns them as an array. If it's a string it returns unaltered.
|
222
222
|
def check_source_type(source)
|
223
223
|
if File.file?(source)
|
@@ -227,7 +227,7 @@ module JumpStart::FileTools
|
|
227
227
|
end
|
228
228
|
source_file
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
# Method for joining paths together. Paths can be supplied as a mixture of strings and arrays.
|
232
232
|
# If too many or not enough forward slashes are provided at the start/end of the paths, this will be corrected.
|
233
233
|
# Accidentally passing nil values mixed with strings/arrays will be corrected.
|
@@ -263,7 +263,7 @@ module JumpStart::FileTools
|
|
263
263
|
full_path_string.insert(0, '/') if absolute_path == true
|
264
264
|
full_path_string
|
265
265
|
end
|
266
|
-
|
266
|
+
|
267
267
|
# Sorts files and dirs in a path and then returns the result as a hash of two arrays, :files and :dirs
|
268
268
|
def sort_contained_files_and_dirs(path)
|
269
269
|
dirs, files = [], []
|
@@ -281,5 +281,5 @@ module JumpStart::FileTools
|
|
281
281
|
end
|
282
282
|
{:files => files, :dirs => dirs}
|
283
283
|
end
|
284
|
-
|
284
|
+
|
285
285
|
end
|
data/test/jumpstart/test_base.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestJumpstartBase < Test::Unit::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
context "Testing JumpStart::Base\n" do
|
6
|
-
|
6
|
+
|
7
7
|
# A valid project with the project name passed in the argument.
|
8
8
|
# IO has been setup for testing
|
9
9
|
# runs set_config_file_options to set all instance variables
|
@@ -26,7 +26,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
26
26
|
@test_project.stubs(:exit_normal)
|
27
27
|
@test_project.stubs(:exit_with_success)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# 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.
|
31
31
|
# IO has been setup for testing
|
32
32
|
# runs set_config_file_options to set all instance variables
|
@@ -45,7 +45,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
45
45
|
@test_project_2.stubs(:exit_normal)
|
46
46
|
@test_project_2.stubs(:exit_with_success)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
# An invalid project (@template_name), with the project name passed as the argument
|
50
50
|
setup do
|
51
51
|
@test_project_3 = JumpStart::Base.new(["test_jumpstart_project"])
|
@@ -54,16 +54,16 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
54
54
|
@test_project_3.stubs(:exit_normal)
|
55
55
|
@test_project_3.stubs(:exit_with_success)
|
56
56
|
end
|
57
|
-
|
58
|
-
# A valid project with the project name passed as the argument
|
57
|
+
|
58
|
+
# A valid project with the project name passed as the argument
|
59
59
|
setup do
|
60
60
|
@test_project_4 = JumpStart::Base.new(["test_jumpstart_project"])
|
61
61
|
@test_project_4.instance_variable_set(:@template_name, "test_template_2")
|
62
62
|
@test_project_4.instance_variable_set(:@template_path, "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_2")
|
63
63
|
@test_project_4.stubs(:exit_normal)
|
64
|
-
@test_project_4.stubs(:exit_with_success)
|
64
|
+
@test_project_4.stubs(:exit_with_success)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
# An invalid project (@project_name is too short), then passed a valid @project_name through IO.
|
68
68
|
# IO has been setup for testing
|
69
69
|
# runs set_config_file_options to set all instance variables
|
@@ -81,7 +81,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
81
81
|
@test_project_5.stubs(:exit_normal)
|
82
82
|
@test_project_5.stubs(:exit_with_success)
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
# An invalid project (@project_name is nil), then passed a valid @project_name through IO.
|
86
86
|
# IO has been setup for testing
|
87
87
|
# runs set_config_file_options to set all instance variables
|
@@ -99,66 +99,67 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
99
99
|
@test_project_6.stubs(:exit_with_success)
|
100
100
|
@test_project_6.stubs(:jumpstart_menu)
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
teardown do
|
104
104
|
FileUtils.delete_dir_contents("#{JumpStart::ROOT_PATH}/test/destination_dir")
|
105
|
+
JumpStart.templates_path = nil
|
105
106
|
end
|
106
|
-
|
107
|
+
|
107
108
|
context "Tests for the JumpStart::Base#intialize instance method. \n" do
|
108
|
-
|
109
|
+
|
109
110
|
should "set @jumpstart_template_path" do
|
110
111
|
assert_equal "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates", JumpStart.templates_path
|
111
112
|
end
|
112
|
-
|
113
|
+
|
113
114
|
should "set JumpStart.default_template_name" do
|
114
115
|
assert_equal "test_template_1", @test_project.instance_eval {JumpStart.default_template_name}
|
115
116
|
end
|
116
|
-
|
117
|
+
|
117
118
|
should "set @project_name" do
|
118
119
|
assert_equal "test_jumpstart_project", @test_project.instance_eval {@project_name}
|
119
120
|
end
|
120
|
-
|
121
|
+
|
121
122
|
should "set @template_name" do
|
122
123
|
assert_equal "test_template_1", @test_project.instance_eval {@template_name}
|
123
124
|
end
|
124
|
-
|
125
|
+
|
125
126
|
should "set @template_path" do
|
126
127
|
assert_equal "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_template_1", @test_project.instance_eval {@template_path}
|
127
128
|
end
|
128
|
-
|
129
|
+
|
129
130
|
end
|
130
|
-
|
131
|
+
|
131
132
|
context "Tests for the JumpStart::Base#set_config_file_options instance method. \n" do
|
132
|
-
|
133
|
+
|
133
134
|
should "set @config_file" do
|
134
135
|
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)
|
135
136
|
end
|
136
|
-
|
137
|
+
|
137
138
|
should "set @install_path" do
|
138
|
-
assert_equal "#{JumpStart::ROOT_PATH}/test/destination_dir", @test_project_2.instance_variable_get(:@install_path)
|
139
|
+
assert_equal "#{JumpStart::ROOT_PATH}/test/destination_dir", @test_project_2.instance_variable_get(:@install_path)
|
139
140
|
end
|
140
|
-
|
141
|
+
|
141
142
|
should "set @install_command" do
|
142
143
|
assert_equal "rails", @test_project_2.instance_variable_get(:@install_command)
|
143
144
|
end
|
144
|
-
|
145
|
+
|
145
146
|
should "set @install_command_args" do
|
146
147
|
assert_equal "-J -T", @test_project_2.instance_variable_get(:@install_command_args)
|
147
148
|
end
|
148
|
-
|
149
|
+
|
149
150
|
should "set @replace_strings" do
|
150
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)
|
151
152
|
end
|
152
|
-
|
153
|
+
|
153
154
|
should "load the jumpstart menu if the specified yaml config file does not exist" do
|
154
155
|
@test_project_3.stubs(:jumpstart_menu).returns("jumpstart_menu")
|
155
156
|
assert_equal "jumpstart_menu", @test_project_3.set_config_file_options
|
156
157
|
end
|
157
|
-
|
158
|
+
|
158
159
|
end
|
159
|
-
|
160
|
+
|
160
161
|
context "Tests for the JumpStart::Base#check_setup instance method. \n" do
|
161
|
-
|
162
|
+
|
162
163
|
should "run contained methods" do
|
163
164
|
@test_project_4.stubs(:set_config_file_options).returns("set_config_file_options")
|
164
165
|
@test_project_4.stubs(:check_project_name).returns("check_project_name")
|
@@ -172,11 +173,11 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
172
173
|
@test_project_4.expects(:check_install_path).once
|
173
174
|
@test_project_4.check_setup
|
174
175
|
end
|
175
|
-
|
176
|
+
|
176
177
|
end
|
177
|
-
|
178
|
+
|
178
179
|
context "Tests for the JumpStart::Base#start instance method. \n" do
|
179
|
-
|
180
|
+
|
180
181
|
should "run the contained methods" do
|
181
182
|
@test_project.stubs(:execute_install_command).returns("execute_install_command")
|
182
183
|
@test_project.stubs(:run_scripts_from_yaml).with(:run_after_install_command).returns("run_after_install_command")
|
@@ -200,22 +201,22 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
200
201
|
@test_project.expects(:exit_with_success).once
|
201
202
|
@test_project.start
|
202
203
|
end
|
203
|
-
|
204
|
+
|
204
205
|
end
|
205
|
-
|
206
|
+
|
206
207
|
context "Tests for the JumpStart::#check_replace_string_pairs_for_project_name_sub instance method.\n" do
|
207
|
-
|
208
|
+
|
208
209
|
should "find :project_name symbol and return @project_name" do
|
209
210
|
@values = {:project_name => "some_random_name"}
|
210
211
|
@test_project.check_replace_string_pairs_for_project_name_sub(@values)
|
211
212
|
assert_equal "test_jumpstart_project", @values[:project_name]
|
212
213
|
end
|
213
|
-
|
214
|
+
|
214
215
|
should "change values hash as it contains :project_name symbol" do
|
215
216
|
@values = {:project_name => "some_random_name"}
|
216
217
|
assert_equal({:project_name => "test_jumpstart_project"}, @test_project.check_replace_string_pairs_for_project_name_sub(@values))
|
217
218
|
end
|
218
|
-
|
219
|
+
|
219
220
|
should "treat all other symbols normally and not replace anything" do
|
220
221
|
@values = {:womble => "uncle_bulgaria", :jam => "strawberry", :city => "london"}
|
221
222
|
@test_project.check_replace_string_pairs_for_project_name_sub(@values)
|
@@ -223,7 +224,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
223
224
|
assert_equal "strawberry", @values[:jam]
|
224
225
|
assert_equal "london", @values[:city]
|
225
226
|
end
|
226
|
-
|
227
|
+
|
227
228
|
should "find :project_name symbol even if it is mixed with other symbols which should return unchanged" do
|
228
229
|
@values = {:womble => "uncle_bulgaria", :jam => "strawberry", :project_name => "some_random_name", :city => "london"}
|
229
230
|
@test_project.check_replace_string_pairs_for_project_name_sub(@values)
|
@@ -232,76 +233,76 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
232
233
|
assert_equal "london", @values[:city]
|
233
234
|
assert_equal "test_jumpstart_project", @values[:project_name]
|
234
235
|
end
|
235
|
-
|
236
|
+
|
236
237
|
should "return hash even if it is empty" do
|
237
238
|
@values = {}
|
238
239
|
assert_equal @values, @test_project.check_replace_string_pairs_for_project_name_sub(@values)
|
239
240
|
end
|
240
|
-
|
241
|
+
|
241
242
|
end
|
242
|
-
|
243
|
+
|
243
244
|
context "Tests for the JumpStart::Base#check_project_name instance method. \n" do
|
244
|
-
|
245
|
+
|
245
246
|
context "when the project name is over three characters" do
|
246
|
-
|
247
|
+
|
247
248
|
should "return the project name unchanged and without errors" do
|
248
249
|
assert_equal @test_project.instance_eval {@project_name}, @test_project.instance_eval {check_project_name}
|
249
250
|
end
|
250
|
-
|
251
|
+
|
251
252
|
end
|
252
|
-
|
253
|
+
|
253
254
|
context "when the project name is not empty but is not more than 3 characters" do
|
254
|
-
|
255
|
+
|
255
256
|
should "read input from STDIN" do
|
256
257
|
assert_equal "testo\n", @test_project_5.input.string
|
257
258
|
end
|
258
|
-
|
259
|
+
|
259
260
|
should "ask the user to provide a longer project name" do
|
260
261
|
@test_project_5.instance_eval {check_project_name}
|
261
262
|
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
|
262
263
|
end
|
263
|
-
|
264
|
+
|
264
265
|
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
|
265
266
|
@test_project_5.instance_eval {check_project_name}
|
266
267
|
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
|
267
268
|
assert_equal "testo", @test_project_5.instance_eval { check_project_name }
|
268
269
|
end
|
269
|
-
|
270
|
+
|
270
271
|
end
|
271
|
-
|
272
|
+
|
272
273
|
context "when the project name is empty or nil" do
|
273
|
-
|
274
|
+
|
274
275
|
should "ask the user to specify a name for the project if @project_name is empty or nil" do
|
275
276
|
@test_project_6.instance_eval {check_project_name}
|
276
277
|
assert_equal "\e[1m\e[33m\n Enter a name for your project.\e[0m\n", @test_project_6.output.string
|
277
278
|
end
|
278
|
-
|
279
|
+
|
279
280
|
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
|
280
281
|
@test_project_6.instance_eval {check_project_name}
|
281
282
|
assert_equal "\e[1m\e[33m\n Enter a name for your project.\e[0m\n", @test_project_6.output.string
|
282
283
|
assert_equal "testorama", @test_project_6.instance_eval {check_project_name}
|
283
284
|
end
|
284
|
-
|
285
|
+
|
285
286
|
end
|
286
|
-
|
287
|
+
|
287
288
|
context "when the project name begins with a character that is not a number or a letter" do
|
288
|
-
|
289
|
+
|
289
290
|
setup do
|
290
291
|
@test_project_6.instance_variable_set(:@project_name, "/fail_with_invalid_character_at_start")
|
291
292
|
end
|
292
|
-
|
293
|
+
|
293
294
|
should "ask for a valid project name, display an error message and then set project name when a valid string is provided" do
|
294
295
|
assert_equal "/fail_with_invalid_character_at_start", @test_project_6.instance_variable_get(:@project_name)
|
295
296
|
@test_project_6.instance_eval {check_project_name}
|
296
297
|
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
|
297
298
|
end
|
298
|
-
|
299
|
+
|
299
300
|
end
|
300
|
-
|
301
|
+
|
301
302
|
end
|
302
|
-
|
303
|
+
|
303
304
|
context "Tests for the JumpStart::Base#check_template_name instance method. \n" do
|
304
|
-
|
305
|
+
|
305
306
|
should "launch jumpstart menu if nil" do
|
306
307
|
JumpStart.default_template_name = nil
|
307
308
|
@test_project.instance_variable_set(:@template_name, nil)
|
@@ -309,151 +310,151 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
309
310
|
@test_project.expects(:jumpstart_menu).once
|
310
311
|
@test_project.instance_eval {check_template_name}
|
311
312
|
end
|
312
|
-
|
313
|
+
|
313
314
|
should "launch jumpstart menu if empty" do
|
314
315
|
JumpStart.default_template_name = ""
|
315
316
|
@test_project.instance_variable_set(:@template_name, "")
|
316
317
|
@test_project.stubs(:jumpstart_menu).returns("jumpstart_menu")
|
317
318
|
@test_project.expects(:jumpstart_menu).once
|
318
|
-
@test_project.instance_eval {check_template_name}
|
319
|
+
@test_project.instance_eval {check_template_name}
|
319
320
|
end
|
320
|
-
|
321
|
+
|
321
322
|
end
|
322
|
-
|
323
|
+
|
323
324
|
context "Test for the JumpStart::Base#check_template_path instance method." do
|
324
|
-
|
325
|
+
|
325
326
|
should "exit the installation if the @template_path directory cannot be found or accessed." do
|
326
327
|
@test_project.instance_variable_set(:@template_path, "#{JumpStart::ROOT_PATH}/not/a/valid/path")
|
327
328
|
@test_project.expects(:exit_normal).once
|
328
329
|
@test_project.instance_eval {check_template_path}
|
329
330
|
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
|
330
331
|
end
|
331
|
-
|
332
|
+
|
332
333
|
end
|
333
|
-
|
334
|
+
|
334
335
|
context "Test for the JumpStart::Base#check_install_path instance method" do
|
335
|
-
|
336
|
+
|
336
337
|
should "do nothing if a valid path is set in @install_path and @install_path + @project_name path does not exist yet" do
|
337
338
|
assert @test_project.instance_eval {check_install_path}
|
338
339
|
end
|
339
|
-
|
340
|
+
|
340
341
|
should "provide a warning and exit JumpStart if the directory path of @install_path + @project_name already exists" do
|
341
342
|
FileUtils.mkdir(FileUtils.join_paths(@test_project.instance_variable_get(:@install_path), @test_project.instance_variable_get(:@project_name)))
|
342
343
|
@test_project.expects(:exit_normal).once
|
343
344
|
@test_project.instance_eval {check_install_path}
|
344
345
|
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
|
345
346
|
end
|
346
|
-
|
347
|
+
|
347
348
|
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
|
348
349
|
@test_project.instance_variable_set(:@install_path, nil)
|
349
350
|
assert(@test_project.instance_eval {check_install_path})
|
350
351
|
assert_equal JumpStart::ROOT_PATH , @test_project.instance_variable_get(:@install_path)
|
351
352
|
end
|
352
|
-
|
353
|
+
|
353
354
|
end
|
354
|
-
|
355
|
+
|
355
356
|
context "Tests for the JumpStart::Base#create_template instance method. \n" do
|
356
|
-
|
357
|
+
|
357
358
|
setup do
|
358
359
|
JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
|
359
360
|
@test_project.instance_variable_set(:@template_name, "testing_create_template")
|
360
361
|
end
|
361
|
-
|
362
|
+
|
362
363
|
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
|
363
364
|
@test_project.instance_eval {create_template}
|
364
365
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/testing_create_template/jumpstart_config/testing_create_template.yml")
|
365
366
|
end
|
366
|
-
|
367
|
+
|
367
368
|
should "give a message and exit if a directory with the same name as @template_name exists in the JumpStart.templates_path dir" do
|
368
369
|
FileUtils.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir/testing_create_template")
|
369
370
|
@test_project.expects(:exit_normal).once
|
370
371
|
@test_project.instance_eval {create_template}
|
371
372
|
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
|
372
373
|
end
|
373
|
-
|
374
|
+
|
374
375
|
end
|
375
|
-
|
376
|
+
|
376
377
|
context "Tests for the JumpStart::Base#jumpstart_menu instance method." do
|
377
|
-
|
378
|
+
|
378
379
|
should "output the users options to the screen and call jumpstart_menu_options" do
|
379
380
|
@test_project.stubs(:jumpstart_menu_options)
|
380
381
|
@test_project.expects(:jumpstart_menu_options).once
|
381
382
|
@test_project.instance_eval {jumpstart_menu}
|
382
383
|
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
|
383
384
|
end
|
384
|
-
|
385
|
+
|
385
386
|
end
|
386
|
-
|
387
|
+
|
387
388
|
context "Tests for the JumpStart::Base#jumpstart_menu_options instance method. \n" do
|
388
|
-
|
389
|
+
|
389
390
|
setup do
|
390
391
|
@test_project.stubs(:new_project_from_template_menu)
|
391
392
|
@test_project.stubs(:new_template_menu)
|
392
393
|
@test_project.stubs(:set_default_template_menu)
|
393
394
|
@test_project.stubs(:templates_dir_menu)
|
394
395
|
end
|
395
|
-
|
396
|
+
|
396
397
|
should "run new_project_from_template_menu if input is '1'" do
|
397
398
|
@test_project.instance_variable_set(:@input, StringIO.new("1\n"))
|
398
399
|
@test_project.expects(:new_project_from_template_menu).once
|
399
400
|
@test_project.instance_eval {jumpstart_menu_options}
|
400
401
|
end
|
401
|
-
|
402
|
+
|
402
403
|
should "run new_template_menu if input is '2'" do
|
403
404
|
@test_project.instance_variable_set(:@input, StringIO.new("2\n"))
|
404
405
|
@test_project.expects(:new_template_menu).once
|
405
|
-
@test_project.instance_eval {jumpstart_menu_options}
|
406
|
+
@test_project.instance_eval {jumpstart_menu_options}
|
406
407
|
end
|
407
|
-
|
408
|
+
|
408
409
|
should "run set_default_template_menu if input is '3'" do
|
409
410
|
@test_project.instance_variable_set(:@input, StringIO.new("3\n"))
|
410
411
|
@test_project.expects(:set_default_template_menu).once
|
411
|
-
@test_project.instance_eval {jumpstart_menu_options}
|
412
|
+
@test_project.instance_eval {jumpstart_menu_options}
|
412
413
|
end
|
413
|
-
|
414
|
+
|
414
415
|
should "run templates_dir_menu if input is '4'" do
|
415
416
|
@test_project.instance_variable_set(:@input, StringIO.new("4\n"))
|
416
417
|
@test_project.expects(:templates_dir_menu).once
|
417
|
-
@test_project.instance_eval {jumpstart_menu_options}
|
418
|
+
@test_project.instance_eval {jumpstart_menu_options}
|
418
419
|
end
|
419
|
-
|
420
|
+
|
420
421
|
should "exit if input is 'x'" do
|
421
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
422
|
+
@test_project.instance_variable_set(:@input, StringIO.new("X\n"))
|
422
423
|
@test_project.expects(:exit_normal).once
|
423
|
-
@test_project.instance_eval {jumpstart_menu_options}
|
424
|
+
@test_project.instance_eval {jumpstart_menu_options}
|
424
425
|
end
|
425
|
-
|
426
|
+
|
426
427
|
# 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.
|
427
428
|
should "ask for another input if the value entered is not '1,2,3,4 or x'. Test with 'blarg'" do
|
428
429
|
@test_project.instance_variable_set(:@input, StringIO.new("blarg\n"))
|
429
430
|
assert_raises(NoMethodError) {@test_project.instance_eval {jumpstart_menu_options}}
|
430
431
|
end
|
431
|
-
|
432
|
+
|
432
433
|
# 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.
|
433
434
|
should "ask for another input if the value entered is not '1,2,3,4 or x'. Test with 'a'" do
|
434
435
|
@test_project.instance_variable_set(:@input, StringIO.new("a\n"))
|
435
436
|
assert_raises(NoMethodError) {@test_project.instance_eval {jumpstart_menu_options}}
|
436
437
|
end
|
437
|
-
|
438
|
+
|
438
439
|
end
|
439
|
-
|
440
|
+
|
440
441
|
context "Tests for the JumpStart::Base#new_project_from_template_menu instance method." do
|
441
|
-
|
442
|
+
|
442
443
|
should "display options and run new_project_from_template_options" do
|
443
444
|
@test_project.stubs(:new_project_from_template_options)
|
444
445
|
@test_project.expects(:new_project_from_template_options).once
|
445
446
|
@test_project.instance_eval {new_project_from_template_menu}
|
446
447
|
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 \e[32mtest_template_1\e[0m\n \e[1m\e[33m2\e[0m \e[32mtest_template_2\e[0m\n \e[1m\e[33m3\e[0m \e[32mtest_template_3\e[0m\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
|
447
448
|
end
|
448
|
-
|
449
|
+
|
449
450
|
end
|
450
|
-
|
451
|
+
|
451
452
|
context "Tests for the JumpStart::Base#new_project_from_template_options instance method." do
|
452
|
-
|
453
|
+
|
453
454
|
setup do
|
454
455
|
@test_project.stubs(:jumpstart_menu)
|
455
456
|
end
|
456
|
-
|
457
|
+
|
457
458
|
# TODO Look into testing this method in a different way. The fact that a new class object is instantiated makes it difficult to test with mocha.
|
458
459
|
should "create a new project with the specified template name, checking that the project name is valid when a valid number is entered" do
|
459
460
|
JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
|
@@ -464,30 +465,29 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
464
465
|
assert File.directory?("#{JumpStart::ROOT_PATH}/test_jumpstart_project")
|
465
466
|
FileUtils.remove_dir("#{JumpStart::ROOT_PATH}/test_jumpstart_project")
|
466
467
|
end
|
467
|
-
|
468
|
+
|
468
469
|
should "launch the jumpstart_menu method if 'b' is entered" do
|
469
470
|
@test_project.expects(:jumpstart_menu).once
|
470
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
471
|
+
@test_project.instance_variable_set(:@input, StringIO.new("B\n"))
|
471
472
|
@test_project.instance_eval {new_project_from_template_options}
|
472
473
|
end
|
473
|
-
|
474
|
+
|
474
475
|
should "exit JumpStart if 'x' is entered." do
|
475
476
|
@test_project.expects(:exit_normal).once
|
476
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
477
|
-
@test_project.instance_eval {new_project_from_template_options}
|
477
|
+
@test_project.instance_variable_set(:@input, StringIO.new("X\n"))
|
478
|
+
@test_project.instance_eval {new_project_from_template_options}
|
478
479
|
end
|
479
|
-
|
480
|
+
|
480
481
|
# Raises a NoMethodError in the test as loop is not stopped by user input and cannot perform chomp on nil.
|
481
482
|
should "output a message saying that the input has not been understood for any other input" do
|
482
483
|
@test_project.instance_variable_set(:@input, StringIO.new("blarg\n"))
|
483
484
|
assert_raises(NoMethodError) {@test_project.instance_eval {new_project_from_template_options}}
|
484
|
-
# assert_equal "\e[31mThat command hasn't been understood. Try again!\e[0m\n", @test_project.output.string
|
485
485
|
end
|
486
|
-
|
486
|
+
|
487
487
|
end
|
488
|
-
|
488
|
+
|
489
489
|
context "Tests for the JumpStart::Base#new_template_menu instance method." do
|
490
|
-
|
490
|
+
|
491
491
|
should "display output and call new_template_options" do
|
492
492
|
@test_project.stubs(:new_template_options)
|
493
493
|
@test_project.expects(:display_existing_templates).once
|
@@ -495,34 +495,46 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
495
495
|
@test_project.instance_eval {new_template_menu}
|
496
496
|
assert_equal "\n\n******************************************************************************************************************************************\n\n\e[1m\e[35m CREATE A NEW JUMPSTART TEMPLATE\n\e[0m\n Existing templates:\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", @test_project.output.string
|
497
497
|
end
|
498
|
-
|
498
|
+
|
499
499
|
end
|
500
|
-
|
500
|
+
|
501
501
|
context "Tests for the JumpStart::Base#new_template_options instance method." do
|
502
|
-
|
502
|
+
|
503
503
|
setup do
|
504
|
-
|
505
|
-
@test_project.stubs(:
|
504
|
+
@test_project.stubs(:jumpstart_menu)
|
505
|
+
@test_project.stubs(:duplicate_template)
|
506
506
|
end
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
@test_project.
|
511
|
-
|
507
|
+
|
508
|
+
should "call duplicate_template if the name given is already taken " do
|
509
|
+
@test_project.instance_variable_set(:@input, StringIO.new("test_template_1\n") )
|
510
|
+
@test_project.expects(:duplicate_template).with("test_template_1").once
|
511
|
+
@test_project.send(:new_template_options)
|
512
|
+
end
|
513
|
+
|
514
|
+
should "call jumpstart_menu if input = 'B'" do
|
515
|
+
@test_project.instance_variable_set(:@input, StringIO.new("B\n") )
|
516
|
+
@test_project.expects(:jumpstart_menu).once
|
517
|
+
@test_project.instance_exec {new_template_options}
|
512
518
|
end
|
513
|
-
|
519
|
+
|
520
|
+
should "call jumpstart_menu if input = 'X'" do
|
521
|
+
@test_project.instance_variable_set(:@input, StringIO.new("X\n") )
|
522
|
+
@test_project.expects(:exit_normal).once
|
523
|
+
@test_project.instance_exec {new_template_options}
|
524
|
+
end
|
525
|
+
|
514
526
|
# 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.
|
515
527
|
should "ask for another template name if the name given is less than 3 characters long." do
|
516
528
|
@test_project.instance_variable_set(:@input, StringIO.new("on\n"))
|
517
529
|
assert_raises(NoMethodError) {@test_project.instance_eval {new_template_options}}
|
518
530
|
end
|
519
|
-
|
531
|
+
|
520
532
|
# 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.
|
521
533
|
should "ask for another template name if the name given begins with a character that is not a number or a letter." do
|
522
534
|
@test_project.instance_variable_set(:@input, StringIO.new("/one\n"))
|
523
535
|
assert_raises(NoMethodError) {@test_project.instance_eval {new_template_options}}
|
524
536
|
end
|
525
|
-
|
537
|
+
|
526
538
|
should "create a new template in the jumpstart templates directory if the name given is valid." do
|
527
539
|
@test_project.instance_variable_set(:@input, StringIO.new("four\n"))
|
528
540
|
@test_project.instance_eval {new_template_options}
|
@@ -532,29 +544,80 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
532
544
|
assert_equal original_file_contents, created_file_contents
|
533
545
|
FileUtils.remove_dir("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/four")
|
534
546
|
end
|
535
|
-
|
547
|
+
|
548
|
+
end
|
549
|
+
|
550
|
+
context "Tests for the JumpStart::Base#duplicate_template instance method." do
|
551
|
+
|
552
|
+
setup do
|
553
|
+
@test_project.stubs(:jumpstart_menu)
|
554
|
+
end
|
555
|
+
|
556
|
+
should "call jumpstart_menu if input = 'B'" do
|
557
|
+
@test_project.instance_variable_set(:@input, StringIO.new("B\n") )
|
558
|
+
@test_project.expects(:jumpstart_menu).once
|
559
|
+
@test_project.instance_exec {new_template_options}
|
560
|
+
end
|
561
|
+
|
562
|
+
should "call jumpstart_menu if input = 'X'" do
|
563
|
+
@test_project.instance_variable_set(:@input, StringIO.new("X\n") )
|
564
|
+
@test_project.expects(:exit_normal).once
|
565
|
+
@test_project.instance_exec {new_template_options}
|
566
|
+
end
|
567
|
+
|
568
|
+
# 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.
|
569
|
+
should "call itself when the name specified already exists" do
|
570
|
+
@test_project.instance_variable_set(:@input, StringIO.new("test_template_1\n") )
|
571
|
+
assert_raises(NoMethodError) {@test_project.instance_exec {new_template_options}}
|
572
|
+
end
|
573
|
+
|
574
|
+
# 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.
|
575
|
+
should "call itself when the name specified is under 3 characters long" do
|
576
|
+
@test_project.instance_variable_set(:@input, StringIO.new("df\n") )
|
577
|
+
assert_raises(NoMethodError) {@test_project.instance_exec {new_template_options}}
|
578
|
+
end
|
579
|
+
|
580
|
+
# 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.
|
581
|
+
should "call itself when the name specified begins with a character that is not a number or letter." do
|
582
|
+
@test_project.instance_variable_set(:@input, StringIO.new("/Yarr\n") )
|
583
|
+
assert_raises(NoMethodError) {@test_project.instance_exec {new_template_options}}
|
584
|
+
end
|
585
|
+
|
586
|
+
# 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.
|
587
|
+
should "call itself when the name specified ends with a character that is not a number or letter." do
|
588
|
+
@test_project.instance_variable_set(:@input, StringIO.new("Yarr/\n") )
|
589
|
+
assert_raises(NoMethodError) {@test_project.instance_exec {new_template_options}}
|
590
|
+
end
|
591
|
+
|
592
|
+
should "duplicate the template and call jumpstart_menu when a valid name is provided." do
|
593
|
+
@test_project.instance_variable_set(:@input, StringIO.new("unique_name\n") )
|
594
|
+
@test_project.expects(:jumpstart_menu).once
|
595
|
+
@test_project.instance_exec {duplicate_template("test_template_1")}
|
596
|
+
FileUtils.remove_dir("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/unique_name")
|
597
|
+
end
|
598
|
+
|
536
599
|
end
|
537
|
-
|
600
|
+
|
538
601
|
context "Tests for the JumpStart::Base#set_default_template_menu instance method." do
|
539
|
-
|
602
|
+
|
540
603
|
should "display menu containing contents of JumpStart.existing_templates" do
|
541
604
|
@test_project.stubs(:set_default_template_options)
|
542
605
|
@test_project.expects(:set_default_template_options).once
|
543
606
|
@test_project.instance_eval {set_default_template_menu}
|
544
607
|
assert_equal "\n\n******************************************************************************************************************************************\n\n\e[1m\e[35m SELECT A DEFAULT JUMPSTART TEMPLATE\n\n\e[0m\n \e[1m\e[33m1\e[0m \e[32mtest_template_1\e[0m\n \e[1m\e[33m2\e[0m \e[32mtest_template_2\e[0m\n \e[1m\e[33m3\e[0m \e[32mtest_template_3\e[0m\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
|
545
608
|
end
|
546
|
-
|
609
|
+
|
547
610
|
end
|
548
|
-
|
611
|
+
|
549
612
|
context "Tests for the JumpStart::Base#set_default_template_options instance method." do
|
550
|
-
|
613
|
+
|
551
614
|
setup do
|
552
615
|
@test_project.stubs(:jumpstart_menu)
|
553
616
|
JumpStart.stubs(:dump_jumpstart_setup_yaml)
|
554
617
|
JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
|
555
618
|
JumpStart.default_template_name = "temp_default"
|
556
619
|
end
|
557
|
-
|
620
|
+
|
558
621
|
should "set the default template if a number corresponding to an existing template is entered." do
|
559
622
|
@test_project.instance_variable_set(:@input, StringIO.new("1\n"))
|
560
623
|
@test_project.expects(:jumpstart_menu).once
|
@@ -562,129 +625,148 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
562
625
|
@test_project.instance_eval {set_default_template_options}
|
563
626
|
assert_equal "test_template_1", JumpStart.default_template_name
|
564
627
|
end
|
565
|
-
|
628
|
+
|
566
629
|
should "go back to the main jumpstart menu if 'b' is entered." do
|
567
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
630
|
+
@test_project.instance_variable_set(:@input, StringIO.new("B\n"))
|
568
631
|
@test_project.expects(:jumpstart_menu).once
|
569
632
|
@test_project.instance_eval {set_default_template_options}
|
570
633
|
assert_equal "temp_default", JumpStart.default_template_name
|
571
634
|
end
|
572
|
-
|
635
|
+
|
573
636
|
should "exit jumpstart if 'x' is entered" do
|
574
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
637
|
+
@test_project.instance_variable_set(:@input, StringIO.new("X\n"))
|
575
638
|
@test_project.expects(:exit_normal).once
|
576
639
|
@test_project.instance_eval {set_default_template_options}
|
577
|
-
assert_equal "temp_default", JumpStart.default_template_name
|
640
|
+
assert_equal "temp_default", JumpStart.default_template_name
|
578
641
|
end
|
579
|
-
|
642
|
+
|
580
643
|
# 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.
|
581
644
|
should "restart the set_default_template_options method if the command is not understood" do
|
582
645
|
@test_project.instance_variable_set(:@input, StringIO.new("super_blarg\n"))
|
583
646
|
assert_raises(NoMethodError) {@test_project.instance_eval {set_default_template_options}}
|
584
647
|
end
|
585
|
-
|
648
|
+
|
586
649
|
end
|
587
|
-
|
650
|
+
|
588
651
|
context "Tests for the JumpStart::Base#templates_dir_menu instance method." do
|
589
|
-
|
652
|
+
|
590
653
|
should "display options and call templates_dir_options method." do
|
591
654
|
@test_project.stubs(:templates_dir_options)
|
592
655
|
@test_project.expects(:templates_dir_options).once
|
593
656
|
@test_project.instance_eval {templates_dir_menu}
|
594
657
|
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
|
595
658
|
end
|
596
|
-
|
659
|
+
|
597
660
|
end
|
598
|
-
|
661
|
+
|
599
662
|
context "Tests for the JumpStart::Base#templates_dir_options instance method." do
|
600
|
-
|
663
|
+
|
601
664
|
setup do
|
602
665
|
@test_project.stubs(:set_templates_dir)
|
603
666
|
@test_project.stubs(:reset_templates_dir_to_default_check)
|
604
667
|
@test_project.stubs(:jumpstart_menu)
|
605
668
|
end
|
606
|
-
|
669
|
+
|
607
670
|
should "run the set_templates_dir method when '1' is entered." do
|
608
671
|
@test_project.instance_variable_set(:@input, StringIO.new("1\n"))
|
609
672
|
@test_project.expects(:set_templates_dir).once
|
610
673
|
@test_project.instance_eval {templates_dir_options}
|
611
674
|
end
|
612
|
-
|
675
|
+
|
613
676
|
should "run the reset_templates_dir_to_default method when '2' is entered." do
|
614
677
|
@test_project.instance_variable_set(:@input, StringIO.new("2\n"))
|
615
678
|
@test_project.expects(:reset_templates_dir_to_default_check).once
|
616
679
|
@test_project.instance_eval {templates_dir_options}
|
617
680
|
end
|
618
|
-
|
681
|
+
|
619
682
|
should "run the jumpstart_menu method when 'b' is entered." do
|
620
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
683
|
+
@test_project.instance_variable_set(:@input, StringIO.new("B\n"))
|
621
684
|
@test_project.expects(:jumpstart_menu).once
|
622
685
|
@test_project.instance_eval {templates_dir_options}
|
623
686
|
end
|
624
|
-
|
687
|
+
|
625
688
|
should "run the exit_normal when 'x' is entered." do
|
626
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
689
|
+
@test_project.instance_variable_set(:@input, StringIO.new("X\n"))
|
627
690
|
@test_project.expects(:exit_normal).once
|
628
691
|
@test_project.instance_eval {templates_dir_options}
|
629
692
|
end
|
630
|
-
|
693
|
+
|
631
694
|
# 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.
|
632
695
|
should "restart the method if the command entered is not understood" do
|
633
696
|
@test_project.instance_variable_set(:@input, StringIO.new("blarg\n"))
|
634
697
|
assert_raises(NoMethodError) {@test_project.instance_eval {templates_dir_options}}
|
635
698
|
end
|
636
|
-
|
699
|
+
|
637
700
|
end
|
638
|
-
|
701
|
+
|
639
702
|
context "Tests for the JumpStart::Base#set_templates_dir instance method." do
|
640
|
-
|
703
|
+
|
641
704
|
setup do
|
642
705
|
JumpStart.stubs(:dump_jumpstart_setup_yaml)
|
643
706
|
@test_project.stubs(:jumpstart_menu)
|
707
|
+
@test_project.stubs(:set_templates_dir_to_existing_dir)
|
708
|
+
end
|
709
|
+
|
710
|
+
should "call jumpstart_menu if the input is 'b'" do
|
711
|
+
@test_project.instance_variable_set(:@input, StringIO.new("B\n"))
|
712
|
+
@test_project.expects(:jumpstart_menu).once
|
713
|
+
@test_project.instance_eval {set_templates_dir}
|
714
|
+
end
|
715
|
+
|
716
|
+
should "call exit_normal if the input is 'x'" do
|
717
|
+
@test_project.instance_variable_set(:@input, StringIO.new("X\n"))
|
718
|
+
@test_project.expects(:exit_normal).once
|
719
|
+
@test_project.instance_eval {set_templates_dir}
|
644
720
|
end
|
645
|
-
|
721
|
+
|
722
|
+
should "call set_templates_dir_to_existing_dir if the directory specified already exists." do
|
723
|
+
@test_project.expects(:set_templates_dir_to_existing_dir).once
|
724
|
+
@test_project.instance_variable_set(:@input, StringIO.new("#{JumpStart::ROOT_PATH}/test/destination_dir"))
|
725
|
+
@test_project.instance_eval {set_templates_dir}
|
726
|
+
end
|
727
|
+
|
646
728
|
# 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.
|
647
|
-
should "restart the method if the directory path provided
|
648
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
729
|
+
should "restart the method if the directory path provided cannot be found." do
|
730
|
+
@test_project.instance_variable_set(:@input, StringIO.new("blarg\n"))
|
649
731
|
assert_raises(NoMethodError) {@test_project.instance_eval {set_templates_dir}}
|
650
732
|
end
|
651
|
-
|
652
|
-
should "create a new directory and copy existing templates into it, then set JumpStart.templates_path to the new location." do
|
733
|
+
|
734
|
+
should "create a new directory and copy existing templates into it, then set JumpStart.templates_path to the new location if the dir specified does not exist but it's parent directory does." do
|
653
735
|
@test_project.instance_variable_set(:@input, StringIO.new("#{JumpStart::ROOT_PATH}/test/destination_dir/a_name_that_does_not_exist"))
|
654
736
|
JumpStart.expects(:dump_jumpstart_setup_yaml).once
|
655
737
|
@test_project.expects(:jumpstart_menu).once
|
656
738
|
@test_project.instance_eval {set_templates_dir}
|
657
|
-
assert_equal "\nCopying existing templates to /Users/i0n/Sites/jumpstart/test/destination_dir/a_name_that_does_not_exist\n\e[32m\
|
739
|
+
assert_equal "\nCopying existing templates to /Users/i0n/Sites/jumpstart/test/destination_dir/a_name_that_does_not_exist\n\e[32m\n Transfer complete!\e[0m\n\n The directory \e[32m/Users/i0n/Sites/jumpstart/test/destination_dir/a_name_that_does_not_exist\e[0m has been set as the JumpStart templates directory.\n", @test_project.output.string
|
658
740
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/a_name_that_does_not_exist/test_template_1/jumpstart_config/test_template_1.yml")
|
659
741
|
end
|
660
|
-
|
742
|
+
|
661
743
|
end
|
662
|
-
|
744
|
+
|
663
745
|
context "Tests for the JumpStart::Base#reset_templates_dir_to_default_check instance method." do
|
664
|
-
|
746
|
+
|
665
747
|
setup do
|
666
748
|
@test_project.stubs(:templates_dir_menu)
|
667
749
|
@test_project.stubs(:reset_templates_dir_to_default_set)
|
668
750
|
end
|
669
|
-
|
751
|
+
|
670
752
|
should "output a message and run templates_dir_menu if JumpStart.templates_path is set to it's standard starting position." do
|
671
753
|
JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/jumpstart_templates"
|
672
754
|
@test_project.expects(:templates_dir_menu).once
|
673
755
|
@test_project.instance_eval {reset_templates_dir_to_default_check}
|
674
756
|
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\e[0m\n", @test_project.output.string
|
675
757
|
end
|
676
|
-
|
758
|
+
|
677
759
|
should "run reset_templates_dir_to_default_set if the current JumpStart.templates_path is not the default." do
|
678
760
|
JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
|
679
761
|
@test_project.expects(:reset_templates_dir_to_default_set).once
|
680
762
|
@test_project.instance_eval {reset_templates_dir_to_default_check}
|
681
763
|
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
|
682
764
|
end
|
683
|
-
|
765
|
+
|
684
766
|
end
|
685
|
-
|
767
|
+
|
686
768
|
context "Tests for the JumpStart::Base#reset_templates_dir_to_default_set instance method." do
|
687
|
-
|
769
|
+
|
688
770
|
setup do
|
689
771
|
JumpStart.stubs(:dump_jumpstart_setup_yaml)
|
690
772
|
@test_project.stubs(:templates_dir_menu)
|
@@ -694,53 +776,53 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
694
776
|
JumpStart.templates_path = "#{@normal_root_path}/test/test_jumpstart_templates/test_base"
|
695
777
|
@test_project.instance_variable_set(:@current_files_and_dirs, {:files => ['current_files_and_dirs_test_file.txt'], :dirs => ['current_files_and_dirs_test_dir']})
|
696
778
|
end
|
697
|
-
|
779
|
+
|
698
780
|
teardown do
|
699
781
|
JumpStart::ROOT_PATH = @normal_root_path
|
700
782
|
end
|
701
|
-
|
783
|
+
|
702
784
|
should "reset jumpstart templates directory to default if input is 'y'" do
|
703
785
|
@test_project.expects(:templates_dir_menu)
|
704
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
786
|
+
@test_project.instance_variable_set(:@input, StringIO.new("Y\n"))
|
705
787
|
@test_project.instance_eval {reset_templates_dir_to_default_set}
|
706
788
|
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
|
707
789
|
assert File.exists?("#{JumpStart::ROOT_PATH}/jumpstart_templates/current_files_and_dirs_test_file.txt")
|
708
790
|
assert File.directory?("#{JumpStart::ROOT_PATH}/jumpstart_templates/current_files_and_dirs_test_dir")
|
709
791
|
end
|
710
|
-
|
792
|
+
|
711
793
|
should "reset jumpstart templates directory to default if input is 'yes'" do
|
712
794
|
@test_project.expects(:templates_dir_menu)
|
713
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
795
|
+
@test_project.instance_variable_set(:@input, StringIO.new("YES\n"))
|
714
796
|
@test_project.instance_eval {reset_templates_dir_to_default_set}
|
715
797
|
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
|
716
798
|
assert File.exists?("#{JumpStart::ROOT_PATH}/jumpstart_templates/current_files_and_dirs_test_file.txt")
|
717
799
|
assert File.directory?("#{JumpStart::ROOT_PATH}/jumpstart_templates/current_files_and_dirs_test_dir")
|
718
800
|
end
|
719
|
-
|
801
|
+
|
720
802
|
should "run templates_dir_menu if input is 'n'" do
|
721
803
|
@test_project.expects(:templates_dir_menu)
|
722
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
804
|
+
@test_project.instance_variable_set(:@input, StringIO.new("N\n"))
|
723
805
|
@test_project.instance_eval {reset_templates_dir_to_default_set}
|
724
806
|
assert_equal "\n You have chosen not to move the jumpstart templates directory, nothing has been changed.\n", @test_project.output.string
|
725
807
|
end
|
726
|
-
|
808
|
+
|
727
809
|
should "run templates_dir_menu if input is 'no'" do
|
728
810
|
@test_project.expects(:templates_dir_menu)
|
729
|
-
@test_project.instance_variable_set(:@input, StringIO.new("
|
811
|
+
@test_project.instance_variable_set(:@input, StringIO.new("NO\n"))
|
730
812
|
@test_project.instance_eval {reset_templates_dir_to_default_set}
|
731
813
|
assert_equal "\n You have chosen not to move the jumpstart templates directory, nothing has been changed.\n", @test_project.output.string
|
732
814
|
end
|
733
|
-
|
815
|
+
|
734
816
|
# 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.
|
735
817
|
should "restart the method if the input is not understood" do
|
736
818
|
@test_project.instance_variable_set(:@input, StringIO.new("blarg\n"))
|
737
819
|
assert_raises(NoMethodError) {@test_project.instance_eval {reset_templates_dir_to_default_set}}
|
738
820
|
end
|
739
|
-
|
821
|
+
|
740
822
|
end
|
741
|
-
|
823
|
+
|
742
824
|
context "Tests for the JumpStart::Base#execute_install_command instance method." do
|
743
|
-
|
825
|
+
|
744
826
|
should "do nothing if @install_command is nil" do
|
745
827
|
@test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
|
746
828
|
@test_project.instance_variable_set(:@install_command, nil)
|
@@ -748,7 +830,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
748
830
|
@test_project.instance_eval {execute_install_command}
|
749
831
|
assert_equal "", @test_project.output.string
|
750
832
|
end
|
751
|
-
|
833
|
+
|
752
834
|
should "do nothing if @install_command is empty" do
|
753
835
|
@test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
|
754
836
|
@test_project.instance_variable_set(:@install_command, "")
|
@@ -756,7 +838,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
756
838
|
@test_project.instance_eval {execute_install_command}
|
757
839
|
assert_equal "", @test_project.output.string
|
758
840
|
end
|
759
|
-
|
841
|
+
|
760
842
|
should "execute @install_command if it contains a string" do
|
761
843
|
@test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
|
762
844
|
@test_project.instance_variable_set(:@install_command, "echo")
|
@@ -764,19 +846,19 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
764
846
|
@test_project.expects(:system).once
|
765
847
|
@test_project.instance_eval {execute_install_command}
|
766
848
|
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
|
767
|
-
end
|
768
|
-
|
849
|
+
end
|
850
|
+
|
769
851
|
should "raise an error if the @install_path does not exist" do
|
770
852
|
@test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir/this/dir/does/not/exist")
|
771
853
|
@test_project.instance_variable_set(:@install_command, "echo")
|
772
854
|
@test_project.instance_variable_set(:@install_command_args, "install command args")
|
773
855
|
assert_raises(Errno::ENOENT) {@test_project.instance_eval {execute_install_command}}
|
774
|
-
end
|
775
|
-
|
856
|
+
end
|
857
|
+
|
776
858
|
end
|
777
|
-
|
859
|
+
|
778
860
|
context "Tests for the JumpStart::Base#parse_template_dir instance method." do
|
779
|
-
|
861
|
+
|
780
862
|
setup do
|
781
863
|
@test_project.instance_variable_set(:@template_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
|
782
864
|
FileUtils.mkdir_p("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config")
|
@@ -800,39 +882,39 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
800
882
|
FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/whole_test_4.txt")
|
801
883
|
@test_project.instance_eval {parse_template_dir}
|
802
884
|
end
|
803
|
-
|
885
|
+
|
804
886
|
should "populate @dir_list with directories contained in @template_path" do
|
805
887
|
assert_equal ['', '/parse_template_dir'], @test_project.instance_variable_get(:@dir_list).sort
|
806
888
|
end
|
807
|
-
|
889
|
+
|
808
890
|
should "populate @append_templates with files that are prefixed with _._ _l._ or _L._ and do not contain a directory called jumpstart_config." do
|
809
891
|
assert_equal ["/parse_template_dir/_._append_test_5.txt",
|
810
892
|
"/parse_template_dir/_._append_test_6",
|
811
893
|
"/parse_template_dir/_L._append_test_8.txt",
|
812
894
|
"/parse_template_dir/_l._append_test_7.txt"], @test_project.instance_variable_get(:@append_templates).sort
|
813
895
|
end
|
814
|
-
|
896
|
+
|
815
897
|
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
|
816
898
|
assert_equal ["/parse_template_dir/_1._line_test_3.txt",
|
817
899
|
"/parse_template_dir/_10000._line_test_4.txt"], @test_project.instance_variable_get(:@line_templates).sort
|
818
900
|
end
|
819
|
-
|
901
|
+
|
820
902
|
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
|
821
903
|
assert_equal ["/parse_template_dir/whole_test_3", "/parse_template_dir/whole_test_4.txt"], @test_project.instance_variable_get(:@whole_templates).sort
|
822
904
|
end
|
823
|
-
|
905
|
+
|
824
906
|
should "populate @nginx_local_template if a file matching jumpstart_config/nginx.local.conf is found" do
|
825
907
|
assert_equal "#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/nginx.local.conf", @test_project.instance_variable_get(:@nginx_local_template)
|
826
908
|
end
|
827
|
-
|
909
|
+
|
828
910
|
should "populate @nginx_remote_template if a file matching jumpstart_config/nginx.remote.conf is found" do
|
829
911
|
assert_equal "#{JumpStart::ROOT_PATH}/test/destination_dir/parse_template_dir/jumpstart_config/nginx.remote.conf", @test_project.instance_variable_get(:@nginx_remote_template)
|
830
912
|
end
|
831
|
-
|
913
|
+
|
832
914
|
end
|
833
|
-
|
915
|
+
|
834
916
|
context "Tests for the JumpStart::Base#create_dirs instance method." do
|
835
|
-
|
917
|
+
|
836
918
|
should "create dirs even if paths have too many or too few forward slashes" do
|
837
919
|
@test_project.instance_variable_set(:@install_path, "#{JumpStart::ROOT_PATH}/test/destination_dir")
|
838
920
|
@test_project.instance_variable_set(:@project_name, 'create_dirs_test' )
|
@@ -845,11 +927,11 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
845
927
|
assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/create_dirs_test/5")
|
846
928
|
assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/create_dirs_test/6")
|
847
929
|
end
|
848
|
-
|
930
|
+
|
849
931
|
end
|
850
|
-
|
932
|
+
|
851
933
|
context "Tests for the JumpStart::Base#populate_files_from_whole_templates instance method." do
|
852
|
-
|
934
|
+
|
853
935
|
should "create files from @whole_templates" do
|
854
936
|
@test_project.instance_eval {parse_template_dir}
|
855
937
|
@test_project.instance_eval {create_dirs}
|
@@ -858,11 +940,11 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
858
940
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_whole_file_with_extension.txt")
|
859
941
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_whole_file_without_extension")
|
860
942
|
end
|
861
|
-
|
943
|
+
|
862
944
|
end
|
863
|
-
|
945
|
+
|
864
946
|
context "Tests for the JumpStart::Base#populate_files_from_append_templates instance method." do
|
865
|
-
|
947
|
+
|
866
948
|
should "append contents of append template to file." do
|
867
949
|
@test_project.instance_eval {parse_template_dir}
|
868
950
|
@test_project.instance_eval {create_dirs}
|
@@ -885,11 +967,11 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
885
967
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_2.txt")
|
886
968
|
assert !File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_l._test_append_to_end_of_file_remove_last_line_2.txt")
|
887
969
|
end
|
888
|
-
|
970
|
+
|
889
971
|
end
|
890
|
-
|
972
|
+
|
891
973
|
context "Tests for the JumpStart::Base#populate_files_from_line_templates instance method. \n" do
|
892
|
-
|
974
|
+
|
893
975
|
should "append contents of line templates to the relevant file." do
|
894
976
|
@test_project.instance_eval {parse_template_dir}
|
895
977
|
@test_project.instance_eval {create_dirs}
|
@@ -904,107 +986,107 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
904
986
|
file_lines = IO.readlines(file)
|
905
987
|
assert_equal( "Lorem\n", file_lines[19])
|
906
988
|
end
|
907
|
-
|
989
|
+
|
908
990
|
end
|
909
|
-
|
991
|
+
|
910
992
|
context "Tests for the JumpStart::Base#check_local_nginx_configuration instance method. \n" do
|
911
|
-
|
993
|
+
|
912
994
|
setup do
|
913
995
|
FileUtils.stubs(:config_nginx)
|
914
996
|
FileUtils.stubs(:config_hosts)
|
915
997
|
end
|
916
|
-
|
998
|
+
|
917
999
|
should "produce an error and not try to configure Nginx if @nginx_local_template is nil" do
|
918
1000
|
@test_project.instance_variable_set(:@config_file, {:local_nginx_conf => "something"})
|
919
1001
|
@test_project.instance_variable_set(:@nginx_local_template, nil)
|
920
1002
|
@test_project.instance_eval {check_local_nginx_configuration}
|
921
|
-
assert_equal " \nNginx will not be configured as options have not been set for this.\n", @test_project.output.string
|
1003
|
+
assert_equal " \nNginx will not be configured as options have not been set for this.\n", @test_project.output.string
|
922
1004
|
end
|
923
|
-
|
1005
|
+
|
924
1006
|
should "produce an error and not try to configure Nginx if @config_file[:local_nginx_conf] is nil" do
|
925
1007
|
@test_project.instance_variable_set(:@config_file, {:local_nginx_conf => nil})
|
926
1008
|
@test_project.instance_variable_set(:@nginx_local_template, "something")
|
927
1009
|
@test_project.instance_eval {check_local_nginx_configuration}
|
928
1010
|
assert_equal " \nNginx will not be configured as options have not been set for this.\n", @test_project.output.string
|
929
1011
|
end
|
930
|
-
|
1012
|
+
|
931
1013
|
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
|
932
1014
|
@test_project.instance_variable_set(:@config_file, {:local_nginx_conf => "something"})
|
933
1015
|
@test_project.instance_variable_set(:@nginx_local_template, "something")
|
934
1016
|
FileUtils.expects(:config_nginx).once
|
935
1017
|
FileUtils.expects(:config_hosts).once
|
936
|
-
@test_project.instance_eval {check_local_nginx_configuration}
|
1018
|
+
@test_project.instance_eval {check_local_nginx_configuration}
|
937
1019
|
end
|
938
|
-
|
1020
|
+
|
939
1021
|
end
|
940
|
-
|
1022
|
+
|
941
1023
|
context "Tests for the JumpStart::Base#remove_unwanted_files instance method. \n" do
|
942
|
-
|
1024
|
+
|
943
1025
|
setup do
|
944
1026
|
@test_project.instance_eval {@project_name = "test_remove"}
|
945
1027
|
Dir.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir/test_remove")
|
946
1028
|
Dir.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir/test_remove/test_remove_files")
|
947
1029
|
end
|
948
|
-
|
1030
|
+
|
949
1031
|
should "run remove_unwanted_files method, remove files and return true." do
|
950
|
-
["/file_with_extension.txt", "/file_without_extension"].each do |x|
|
1032
|
+
["/file_with_extension.txt", "/file_without_extension"].each do |x|
|
951
1033
|
FileUtils.touch("#{JumpStart::ROOT_PATH}/test/destination_dir/test_remove/test_remove_files#{x}")
|
952
1034
|
end
|
953
1035
|
assert @test_project.instance_eval {remove_unwanted_files}
|
954
1036
|
end
|
955
|
-
|
1037
|
+
|
956
1038
|
should "do nothing if passed nil" do
|
957
1039
|
@test_project.instance_eval {@config_files = {:remove_files => nil}}
|
958
1040
|
assert @test_project.instance_eval {remove_unwanted_files}
|
959
1041
|
end
|
960
|
-
|
1042
|
+
|
961
1043
|
end
|
962
|
-
|
1044
|
+
|
963
1045
|
context "Tests for the JumpStart::Base#run_scripts_from_yaml instance method.\n" do
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
1046
|
+
|
1047
|
+
should "run run_scripts_from_yaml method with the contents of :run_after_install_command symbol from ROOT_PATH/test/test_template_1/jumpstart_config/test_template_1.yml Should be nil because the install directory does not exist." do
|
1048
|
+
assert_nil @test_project.instance_eval {run_scripts_from_yaml(:run_after_install_command)}
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
should "run the :run_after_install_command symbols scripts from ROOT_PATH/test/test_template_1/jumpstart_config/test_template_1.yml. Should work this time as I will create the directory for the script beforehand." do
|
1052
|
+
Dir.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project")
|
1053
|
+
assert_equal ["echo \"run after install command\""], @test_project.instance_eval {run_scripts_from_yaml(:run_after_install_command)}
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
should "run run_scripts_from_yaml method with the contents of :run_after_jumpstart symbol from ROOT_PATH/test/test_template_1/jumpstart_config/test_template_1.yml Should be nil because the install directory does not exist." do
|
1057
|
+
assert_nil @test_project.instance_eval {run_scripts_from_yaml(:run_after_jumpstart)}
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
should "run the :run_after_jumpstart symbols scripts from ROOT_PATH/test/test_template_1/jumpstart_config/test_template_1.yml. Should work this time as I will create the directory for the script beforehand." do
|
1061
|
+
Dir.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project")
|
1062
|
+
assert_equal ["echo \"run after jumpstart 1st command!\"","echo \"run after jumpstart 2nd command!\""], @test_project.instance_eval {run_scripts_from_yaml(:run_after_jumpstart)}
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
should "return nil if a symbol that is not specified in YAML is passed as an argument and the install directory does not exist" do
|
1066
|
+
assert_nil @test_project.instance_eval {run_scripts_from_yaml(:this_section_does_not_exist)}
|
1067
|
+
end
|
1068
|
+
|
1069
|
+
should "return nil if a symbol that is not specified in the YAML is passed as an argument and the install directory has been created" do
|
1070
|
+
Dir.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project")
|
1071
|
+
assert_nil @test_project.instance_eval {run_scripts_from_yaml(:this_section_does_not_exist)}
|
1072
|
+
end
|
1073
|
+
|
1074
|
+
end
|
1075
|
+
|
994
1076
|
context "Tests for the JumpStart::Base#check_for_strings_to_replace instance method.\n" do
|
995
|
-
|
1077
|
+
|
996
1078
|
setup do
|
997
1079
|
output = StringIO.new
|
998
1080
|
@test_project.instance_eval {@output = output}
|
999
1081
|
end
|
1000
|
-
|
1082
|
+
|
1001
1083
|
should "return true if @replace_strings array contains hash data that is formatted correctly" do
|
1002
1084
|
FileUtils.mkdir_p(FileUtils.join_paths(JumpStart::ROOT_PATH, "test/destination_dir/test_jumpstart_project/test"))
|
1003
1085
|
FileUtils.touch(FileUtils.join_paths(JumpStart::ROOT_PATH, "test/destination_dir/test_jumpstart_project/test/replace_strings.txt"))
|
1004
1086
|
@test_project.instance_eval {@replace_strings = [{:target_path => "/test/replace_strings.txt", :symbols => {:jam => "strawberry", :city => "london"}}]}
|
1005
1087
|
assert(@test_project.instance_eval {check_for_strings_to_replace})
|
1006
1088
|
end
|
1007
|
-
|
1089
|
+
|
1008
1090
|
should "output message if data formatted correctly" do
|
1009
1091
|
FileUtils.mkdir_p(FileUtils.join_paths(JumpStart::ROOT_PATH, "test/destination_dir/test_jumpstart_project/test"))
|
1010
1092
|
FileUtils.touch(FileUtils.join_paths(JumpStart::ROOT_PATH, "test/destination_dir/test_jumpstart_project/test/replace_strings.txt"))
|
@@ -1012,41 +1094,41 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1012
1094
|
@test_project.instance_eval {check_for_strings_to_replace}
|
1013
1095
|
assert_equal("\nChecking for strings to replace inside files...\n\nTarget file: \e[32m/test/replace_strings.txt\e[0m\nStrings to replace:\n\nKey: \e[32mjam\e[0m\nValue: \e[32mstrawberry\e[0m\n\nKey: \e[32mcity\e[0m\nValue: \e[32mlondon\e[0m\n\n\n", @test_project.output.string)
|
1014
1096
|
end
|
1015
|
-
|
1097
|
+
|
1016
1098
|
should "return false if @replace_strings is empty." do
|
1017
1099
|
@test_project.instance_eval {@replace_strings = []}
|
1018
1100
|
assert !@test_project.instance_eval {check_for_strings_to_replace}
|
1019
1101
|
end
|
1020
|
-
|
1102
|
+
|
1021
1103
|
should "return false if @replace_strings is populated with an empty entry." do
|
1022
1104
|
@test_project.instance_eval {@replace_strings = [{:target_path => nil, :symbols => nil}]}
|
1023
1105
|
assert !@test_project.instance_eval {check_for_strings_to_replace}
|
1024
1106
|
end
|
1025
|
-
|
1107
|
+
|
1026
1108
|
end
|
1027
|
-
|
1109
|
+
|
1028
1110
|
context "Tests for the JumpStart::Base#exit_with_success instance method." do
|
1029
1111
|
# As these methods are very simple exit (end script) methods, and are already patched for testing, seems pointless to write tests for them.
|
1030
1112
|
end
|
1031
|
-
|
1113
|
+
|
1032
1114
|
context "Tests for the JumpStart::Base#exit_normal instance method." do
|
1033
1115
|
# As these methods are very simple exit (end script) methods, and are already patched for testing, seems pointless to write tests for them.
|
1034
1116
|
end
|
1035
|
-
|
1117
|
+
|
1036
1118
|
context "Tests for the JumpStart::Base.get_line_number class method.\n" do
|
1037
|
-
|
1119
|
+
|
1038
1120
|
should "return line number as 1" do
|
1039
1121
|
assert_equal 1, JumpStart::Base.get_line_number("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_base/_1._test_file1.txt")
|
1040
1122
|
end
|
1041
|
-
|
1123
|
+
|
1042
1124
|
should "return line number as 10" do
|
1043
1125
|
assert_equal 10, JumpStart::Base.get_line_number("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_base/_10._test_file2.txt")
|
1044
1126
|
end
|
1045
|
-
|
1127
|
+
|
1046
1128
|
should "return line number as 99999" do
|
1047
1129
|
assert_equal 99999, JumpStart::Base.get_line_number("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_base/_99999._test_file3.txt")
|
1048
1130
|
end
|
1049
|
-
|
1131
|
+
|
1050
1132
|
should "return line number as false" do
|
1051
1133
|
assert_equal false, JumpStart::Base.get_line_number("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_base/test_file")
|
1052
1134
|
assert_equal false, JumpStart::Base.get_line_number("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_base/_._test_file.txt")
|
@@ -1054,11 +1136,11 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1054
1136
|
assert_equal false, JumpStart::Base.get_line_number("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_base/test_file_.6txt")
|
1055
1137
|
assert_equal false, JumpStart::Base.get_line_number("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_base/_a._test_file4.txt")
|
1056
1138
|
end
|
1057
|
-
|
1139
|
+
|
1058
1140
|
end
|
1059
|
-
|
1141
|
+
|
1060
1142
|
context "Tests for the JumpStart::Base.remove_last_line? class method.\n" do
|
1061
|
-
|
1143
|
+
|
1062
1144
|
should "return false" do
|
1063
1145
|
assert !JumpStart::Base.remove_last_line?("/path/to/file.txt")
|
1064
1146
|
assert !JumpStart::Base.remove_last_line?("/path/to/_._file.txt")
|
@@ -1068,36 +1150,36 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1068
1150
|
assert !JumpStart::Base.remove_last_line?("/path/to/_1._file.txt")
|
1069
1151
|
assert !JumpStart::Base.remove_last_line?("/path/to/_111._file.txt")
|
1070
1152
|
end
|
1071
|
-
|
1153
|
+
|
1072
1154
|
should "return true" do
|
1073
1155
|
assert JumpStart::Base.remove_last_line?("/path/to/_L._file.txt")
|
1074
1156
|
assert JumpStart::Base.remove_last_line?("_L._file.txt")
|
1075
1157
|
assert JumpStart::Base.remove_last_line?("/path/to/_l._file.txt")
|
1076
1158
|
assert JumpStart::Base.remove_last_line?("_l._file.txt")
|
1077
1159
|
end
|
1078
|
-
|
1160
|
+
|
1079
1161
|
end
|
1080
|
-
|
1162
|
+
|
1081
1163
|
context "Tests for initializing and running JumpStart instances\n" do
|
1082
|
-
|
1164
|
+
|
1083
1165
|
context "Create jumpstart with the project name argument passed to it but do not start.\n" do
|
1084
|
-
|
1166
|
+
|
1085
1167
|
should "be able to create a new jumpstart with the project name as the first argument" do
|
1086
1168
|
assert @test_project
|
1087
1169
|
end
|
1088
|
-
|
1170
|
+
|
1089
1171
|
should "have set @project_name variable to 'test_jumpstart_project'" do
|
1090
1172
|
assert_equal "test_jumpstart_project", @test_project.instance_eval {@project_name}
|
1091
1173
|
end
|
1092
|
-
|
1174
|
+
|
1093
1175
|
should "have set @template_name variable to 'test_template_1'" do
|
1094
1176
|
assert_equal "test_template_1", @test_project.instance_eval {@template_name}
|
1095
1177
|
end
|
1096
|
-
|
1178
|
+
|
1097
1179
|
should "have set @install_path to 'ROOT_PATH/test/destination_dir'" do
|
1098
1180
|
assert_equal "#{JumpStart::ROOT_PATH}/test/destination_dir", @test_project.instance_eval {@install_path}
|
1099
1181
|
end
|
1100
|
-
|
1182
|
+
|
1101
1183
|
should "generate a test project in ROOT_PATH/test/destination_dir/test_jumpstart_project with the test_template_1 template" do
|
1102
1184
|
@test_project.start
|
1103
1185
|
assert File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project")
|
@@ -1120,7 +1202,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1120
1202
|
assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_2.txt")
|
1121
1203
|
assert !File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_l._test_append_to_end_of_file_remove_last_line_2.txt")
|
1122
1204
|
end
|
1123
|
-
|
1205
|
+
|
1124
1206
|
should "remove last lines from files and append template info" do
|
1125
1207
|
@test_project.start
|
1126
1208
|
file_1 = IO.readlines("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_1.txt")
|
@@ -1132,10 +1214,10 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1132
1214
|
assert !file_1[10]
|
1133
1215
|
assert !file_2[10]
|
1134
1216
|
end
|
1135
|
-
|
1217
|
+
|
1136
1218
|
end
|
1137
|
-
|
1219
|
+
|
1138
1220
|
end
|
1139
|
-
|
1221
|
+
|
1140
1222
|
end
|
1141
|
-
end
|
1223
|
+
end
|