jumpstart 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -55,6 +55,11 @@ task :version do
55
55
  puts "\nJumpStart Version: #{JumpStart::VERSION}"
56
56
  end
57
57
 
58
+ task :existing_templates do
59
+ puts "\n Existing JumpStart templates:"
60
+ puts JumpStart.existing_templates
61
+ end
62
+
58
63
  def git_actions
59
64
  Dir.chdir("#{JumpStart::ROOT_PATH}")
60
65
  system "git add ."
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :jumpstart_version_major: 0
3
3
  :jumpstart_version_minor: 2
4
- :jumpstart_version_patch: 2
4
+ :jumpstart_version_patch: 3
@@ -4,6 +4,17 @@ require 'find'
4
4
  require 'fileutils'
5
5
  require 'yaml'
6
6
  require 'rbconfig'
7
+ require 'jumpstart/base'
8
+ require 'jumpstart/filetools'
9
+ require 'jumpstart/stringtools'
10
+
11
+ # Included as a module so that extension methods will be better defined in class/module chain.
12
+ FileUtils.extend JumpStart::FileTools
13
+
14
+ # Included as a module so that extension methods will be better defined in class/module chain.
15
+ class String
16
+ include JumpStart::StringTools
17
+ end
7
18
 
8
19
  # Sets up coloured terminal output in windows
9
20
  if RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin|mingw32/
@@ -23,10 +34,6 @@ module JumpStart
23
34
  IGNORE_DIRS = ['.','..']
24
35
  LAUNCH_PATH = FileUtils.pwd
25
36
 
26
- require 'jumpstart/base'
27
- require 'jumpstart/filetools'
28
- require 'jumpstart/stringtools'
29
-
30
37
  @jumpstart_setup_yaml = YAML.load_file("#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml")
31
38
  @jumpstart_version_yaml = YAML.load_file("#{JumpStart::CONFIG_PATH}/jumpstart_version.yml")
32
39
 
@@ -34,18 +41,10 @@ module JumpStart
34
41
  @version_minor = @jumpstart_version_yaml[:jumpstart_version_minor]
35
42
  @version_patch = @jumpstart_version_yaml[:jumpstart_version_patch]
36
43
 
37
- # sets the default template to use if it has not been passed as an argument.
38
- # Set as a module instance variable.
39
- @default_template_name = @jumpstart_setup_yaml[:jumpstart_default_template_name]
40
-
41
- # The path to the jumpstart templates directory.
42
- # Set as a module instance variable.
43
- @templates_path = @jumpstart_setup_yaml[:jumpstart_templates_path]
44
-
45
44
  class << self
46
45
 
47
46
  attr_accessor :default_template_name, :version_major, :version_minor, :version_patch
48
-
47
+
49
48
  # Set the jumpstart templates path back to default if it has not been set
50
49
  def templates_path
51
50
  if @templates_path.nil? || @templates_path.empty?
@@ -59,6 +58,22 @@ module JumpStart
59
58
  @templates_path = value
60
59
  end
61
60
 
61
+ # TODO JumpStart#lookup_existing_templates class instance method needs tests
62
+ def existing_templates
63
+ templates = []
64
+ template_dirs = Dir.entries(templates_path) - IGNORE_DIRS
65
+ template_dirs.each do |x|
66
+ if File.directory?(FileUtils.join_paths(templates_path, x))
67
+ if Dir.entries(FileUtils.join_paths(templates_path, x)).include? "jumpstart_config"
68
+ if File.exists?(FileUtils.join_paths(templates_path, x, '/jumpstart_config/', "#{x}.yml"))
69
+ templates << x
70
+ end
71
+ end
72
+ end
73
+ end
74
+ templates
75
+ end
76
+
62
77
  # Method for writing to config/jumpstart_setup.yml
63
78
  def dump_jumpstart_setup_yaml
64
79
  File.open( "#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml", 'w' ) do |out|
@@ -113,13 +128,17 @@ module JumpStart
113
128
 
114
129
  end
115
130
 
116
- end
117
-
118
- # Included as a module so that extension methods will be better defined in class/module chain.
119
- FileUtils.extend JumpStart::FileTools
120
-
121
- # Included as a module so that extension methods will be better defined in class/module chain.
122
- class String
123
- include JumpStart::StringTools
131
+ # sets the default template to use if it has not been passed as an argument.
132
+ # Set as a module instance variable.
133
+ if !@jumpstart_setup_yaml[:jumpstart_default_template_name].nil?
134
+ @default_template_name = @jumpstart_setup_yaml[:jumpstart_default_template_name] if existing_templates.include?(@jumpstart_setup_yaml[:jumpstart_default_template_name])
135
+ end
136
+
137
+ # The path to the jumpstart templates directory.
138
+ # Set as a module instance variable.
139
+ if !@jumpstart_setup_yaml[:jumpstart_templates_path].nil?
140
+ @templates_path = @jumpstart_setup_yaml[:jumpstart_templates_path] if Dir.exists?(@jumpstart_setup_yaml[:jumpstart_templates_path])
141
+ end
142
+
124
143
  end
125
144
 
@@ -52,28 +52,12 @@ module JumpStart
52
52
  # Pre-install project configuration checking.
53
53
  def check_setup
54
54
  set_config_file_options
55
- lookup_existing_templates
56
55
  check_project_name
57
56
  check_template_name
58
57
  check_template_path
59
58
  check_install_path
60
59
  end
61
60
 
62
- # set up instance variable containing an array that will be populated with existing jumpstart templates
63
- def lookup_existing_templates
64
- @existing_templates = []
65
- template_dirs = Dir.entries(JumpStart.templates_path) - IGNORE_DIRS
66
- template_dirs.each do |x|
67
- if File.directory?(FileUtils.join_paths(JumpStart.templates_path, x))
68
- if Dir.entries(FileUtils.join_paths(JumpStart.templates_path, x)).include? "jumpstart_config"
69
- if File.exists?(FileUtils.join_paths(JumpStart.templates_path, x, '/jumpstart_config/', "#{x}.yml"))
70
- @existing_templates << x
71
- end
72
- end
73
- end
74
- end
75
- end
76
-
77
61
  # Runs the configuration, generating the new project from the chosen template.
78
62
  def start
79
63
  puts "\n******************************************************************************************************************************************\n\n"
@@ -193,7 +177,6 @@ module JumpStart
193
177
 
194
178
  # Captures user input for the main jumpstart menu and calls the appropriate method
195
179
  def jumpstart_menu_options
196
- lookup_existing_templates
197
180
  input = gets.chomp.strip
198
181
  case
199
182
  when input == "1"
@@ -218,8 +201,8 @@ module JumpStart
218
201
  puts " CREATE A NEW JUMPSTART PROJECT FROM AN EXISTING TEMPLATE\n\n".purple
219
202
  puts " Type a number for the template that you want.\n\n"
220
203
  count = 0
221
- unless @existing_templates.nil? || @existing_templates.empty?
222
- @existing_templates.each do |t|
204
+ unless JumpStart.existing_templates.empty?
205
+ JumpStart.existing_templates.each do |t|
223
206
  count += 1
224
207
  puts " #{count.to_s.yellow} #{t.green}"
225
208
  end
@@ -235,8 +218,8 @@ module JumpStart
235
218
  def new_project_from_template_options
236
219
  input = gets.chomp.strip
237
220
  case
238
- when input.to_i <= @existing_templates.count && input.to_i > 0
239
- @template_name = @existing_templates[(input.to_i - 1)]
221
+ when input.to_i <= JumpStart.existing_templates.count && input.to_i > 0
222
+ @template_name = JumpStart.existing_templates[(input.to_i - 1)]
240
223
  check_project_name
241
224
  project = JumpStart::Base.new([@project_name, @template_name])
242
225
  project.check_setup
@@ -256,9 +239,10 @@ module JumpStart
256
239
  puts "\n\n******************************************************************************************************************************************\n\n"
257
240
  puts " CREATE A NEW JUMPSTART TEMPLATE\n".purple
258
241
  puts " Existing templates:\n"
259
- lookup_existing_templates
260
- @existing_templates.each do |x|
261
- puts " #{x.green}\n"
242
+ unless JumpStart.existing_templates.nil?
243
+ JumpStart.existing_templates.each do |x|
244
+ puts " #{x.green}\n"
245
+ end
262
246
  end
263
247
  puts "\n b".yellow + " Back to main menu."
264
248
  puts "\n x".yellow + " Exit jumpstart\n\n"
@@ -275,7 +259,7 @@ module JumpStart
275
259
  jumpstart_menu
276
260
  when input == "x"
277
261
  exit_normal
278
- when @existing_templates.include?(input)
262
+ when JumpStart.existing_templates.include?(input)
279
263
  puts " A template of the name ".red + input.red_bold + " already exists.".red
280
264
  new_template_options
281
265
  when input.length < 3
@@ -297,9 +281,11 @@ module JumpStart
297
281
  puts "\n\n******************************************************************************************************************************************\n\n"
298
282
  puts " SELECT A DEFAULT JUMPSTART TEMPLATE\n\n".purple
299
283
  count = 0
300
- @existing_templates.each do |t|
301
- count += 1
302
- puts " #{count.to_s.yellow} #{t.green}"
284
+ unless JumpStart.existing_templates.nil?
285
+ JumpStart.existing_templates.each do |t|
286
+ count += 1
287
+ puts " #{count.to_s.yellow} #{t.green}"
288
+ end
303
289
  end
304
290
  puts "\n b".yellow + " Back to main menu.\n\n"
305
291
  puts " x".yellow + " Exit jumpstart\n\n"
@@ -311,8 +297,8 @@ module JumpStart
311
297
  def set_default_template_options
312
298
  input = gets.chomp.strip
313
299
  case
314
- when input.to_i <= @existing_templates.count && input.to_i > 0
315
- JumpStart.default_template_name = @existing_templates[(input.to_i - 1)]
300
+ when input.to_i <= JumpStart.existing_templates.count && input.to_i > 0
301
+ JumpStart.default_template_name = JumpStart.existing_templates[(input.to_i - 1)]
316
302
  JumpStart.dump_jumpstart_setup_yaml
317
303
  puts " The default jumpstart template has been set to: ".green + JumpStart.default_template_name.green_bold
318
304
  jumpstart_menu
@@ -161,13 +161,11 @@ class TestJumpstartBase < Test::Unit::TestCase
161
161
 
162
162
  should "run contained methods" do
163
163
  @test_project_4.stubs(:set_config_file_options).returns("set_config_file_options")
164
- @test_project_4.stubs(:lookup_existing_templates).returns("lookup_existing_templates")
165
164
  @test_project_4.stubs(:check_project_name).returns("check_project_name")
166
165
  @test_project_4.stubs(:check_template_name).returns("check_template_name")
167
166
  @test_project_4.stubs(:check_template_path).returns("check_template_path")
168
167
  @test_project_4.stubs(:check_install_path).returns("check_install_path")
169
168
  @test_project_4.expects(:set_config_file_options).once
170
- @test_project_4.expects(:lookup_existing_templates).once
171
169
  @test_project_4.expects(:check_project_name).once
172
170
  @test_project_4.expects(:check_template_name).once
173
171
  @test_project_4.expects(:check_template_path).once
@@ -176,16 +174,7 @@ class TestJumpstartBase < Test::Unit::TestCase
176
174
  end
177
175
 
178
176
  end
179
-
180
- context "Tests for the JumpStart::Base#lookup_existing_projects instance method. \n" do
181
-
182
- should "run lookup_existing_projects method and return an array of existing templates" do
183
- @test_project.lookup_existing_templates
184
- assert_equal %w[test_template_1 test_template_2 test_template_3], @test_project.instance_eval {@existing_templates}
185
- end
186
-
187
- end
188
-
177
+
189
178
  context "Tests for the JumpStart::Base#start instance method. \n" do
190
179
 
191
180
  should "run the contained methods" do
@@ -398,7 +387,6 @@ class TestJumpstartBase < Test::Unit::TestCase
398
387
  context "Tests for the JumpStart::Base#jumpstart_menu_options instance method. \n" do
399
388
 
400
389
  setup do
401
- @test_project.stubs(:lookup_existing_templates)
402
390
  @test_project.stubs(:new_project_from_template_menu)
403
391
  @test_project.stubs(:new_template_menu)
404
392
  @test_project.stubs(:set_default_template_menu)
@@ -454,10 +442,8 @@ class TestJumpstartBase < Test::Unit::TestCase
454
442
  should "display options and run new_project_from_template_options" do
455
443
  @test_project.stubs(:new_project_from_template_options)
456
444
  @test_project.expects(:new_project_from_template_options).once
457
- @test_project.instance_variable_set(:@existing_templates, %w[project1 project2 project3])
458
445
  @test_project.instance_eval {new_project_from_template_menu}
459
- 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[32mproject1\e[0m\n \e[1m\e[33m2\e[0m \e[32mproject2\e[0m\n \e[1m\e[33m3\e[0m \e[32mproject3\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
460
- assert_equal ['project1', 'project2', 'project3'], @test_project.instance_variable_get(:@existing_templates)
446
+ 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
461
447
  end
462
448
 
463
449
  end
@@ -466,7 +452,6 @@ class TestJumpstartBase < Test::Unit::TestCase
466
452
 
467
453
  setup do
468
454
  @test_project.stubs(:jumpstart_menu)
469
- @test_project.instance_eval {lookup_existing_templates}
470
455
  end
471
456
 
472
457
  # 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.
@@ -504,14 +489,11 @@ class TestJumpstartBase < Test::Unit::TestCase
504
489
  context "Tests for the JumpStart::Base#new_template_menu instance method." do
505
490
 
506
491
  should "display output and call new_template_options" do
507
- @test_project.stubs(:lookup_existing_templates)
508
492
  @test_project.stubs(:new_template_options)
509
- @test_project.instance_variable_set(:@existing_templates, %w[project1 project2 project3])
510
- @test_project.expects(:lookup_existing_templates).once
493
+ JumpStart.expects(:existing_templates).once
511
494
  @test_project.expects(:new_template_options).once
512
495
  @test_project.instance_eval {new_template_menu}
513
- 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\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", @test_project.output.string
514
- assert_equal %w[project1 project2 project3], @test_project.instance_variable_get(:@existing_templates)
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\n", @test_project.output.string
515
497
  end
516
498
 
517
499
  end
@@ -519,14 +501,13 @@ class TestJumpstartBase < Test::Unit::TestCase
519
501
  context "Tests for the JumpStart::Base#new_template_options instance method." do
520
502
 
521
503
  setup do
522
- JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
504
+ # JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
523
505
  @test_project.stubs(:jumpstart_menu).returns("jumpstart_menu")
524
- @test_project.instance_variable_set(:@existing_templates, %w[one two three])
525
506
  end
526
507
 
527
508
  # 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.
528
509
  should "ask for another template name if the name given is already taken " do
529
- @test_project.instance_variable_set(:@input, StringIO.new("one\n"))
510
+ @test_project.instance_variable_set(:@input, StringIO.new("test_template_1\n"))
530
511
  assert_raises(NoMethodError) {@test_project.instance_eval {new_template_options}}
531
512
  end
532
513
 
@@ -545,22 +526,22 @@ class TestJumpstartBase < Test::Unit::TestCase
545
526
  should "create a new template in the jumpstart templates directory if the name given is valid." do
546
527
  @test_project.instance_variable_set(:@input, StringIO.new("four\n"))
547
528
  @test_project.instance_eval {new_template_options}
548
- assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/four/jumpstart_config/four.yml")
529
+ assert File.exists?("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/four/jumpstart_config/four.yml")
549
530
  original_file_contents = IO.read("#{JumpStart::ROOT_PATH}/source_templates/template_config.yml")
550
- created_file_contents = IO.read("#{JumpStart::ROOT_PATH}/test/destination_dir/four/jumpstart_config/four.yml")
531
+ created_file_contents = IO.read("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/four/jumpstart_config/four.yml")
551
532
  assert_equal original_file_contents, created_file_contents
533
+ FileUtils.remove_dir("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/four")
552
534
  end
553
535
 
554
536
  end
555
537
 
556
538
  context "Tests for the JumpStart::Base#set_default_template_menu instance method." do
557
539
 
558
- should "display menu containing contents of @existing_templates" do
559
- @test_project.instance_variable_set(:@existing_templates, %w[one two three])
540
+ should "display menu containing contents of JumpStart.existing_templates" do
560
541
  @test_project.stubs(:set_default_template_options)
561
542
  @test_project.expects(:set_default_template_options).once
562
543
  @test_project.instance_eval {set_default_template_menu}
563
- 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[32mone\e[0m\n \e[1m\e[33m2\e[0m \e[32mtwo\e[0m\n \e[1m\e[33m3\e[0m \e[32mthree\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
544
+ 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
564
545
  end
565
546
 
566
547
  end
@@ -570,7 +551,7 @@ class TestJumpstartBase < Test::Unit::TestCase
570
551
  setup do
571
552
  @test_project.stubs(:jumpstart_menu)
572
553
  JumpStart.stubs(:dump_jumpstart_setup_yaml)
573
- @test_project.instance_variable_set(:@existing_templates, %w[template1 template2 template3])
554
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
574
555
  JumpStart.default_template_name = "temp_default"
575
556
  end
576
557
 
@@ -579,7 +560,7 @@ class TestJumpstartBase < Test::Unit::TestCase
579
560
  @test_project.expects(:jumpstart_menu).once
580
561
  JumpStart.expects(:dump_jumpstart_setup_yaml).once
581
562
  @test_project.instance_eval {set_default_template_options}
582
- assert_equal "template1", JumpStart.default_template_name
563
+ assert_equal "test_template_1", JumpStart.default_template_name
583
564
  end
584
565
 
585
566
  should "go back to the main jumpstart menu if 'b' is entered." do
@@ -38,6 +38,22 @@ class TestJumpstart < Test::Unit::TestCase
38
38
 
39
39
  end
40
40
 
41
+ context "Tests for the JumpStart#existing_projects class method. \n" do
42
+
43
+ setup do
44
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
45
+ end
46
+
47
+ teardown do
48
+ JumpStart.templates_path = nil
49
+ end
50
+
51
+ should "run existing_projects method and return an array of existing templates" do
52
+ assert_equal %w[test_template_1 test_template_2 test_template_3], JumpStart.existing_templates
53
+ end
54
+
55
+ end
56
+
41
57
  context "Tests for the JumpStart#dump_jumpstart_setup_yaml class method." do
42
58
  should "call File.open and Yaml.dump for jumpstart_setup.yml" do
43
59
  YAML.stubs(:dump)
@@ -55,7 +55,6 @@ class TestJumpStartWithDefaultTemplateSet < Test::Unit::TestCase
55
55
  @project = JumpStart::Base.new(["hello", "test_template_1"])
56
56
  @project.stubs(:jumpstart_menu)
57
57
  @project.expects(:set_config_file_options)
58
- @project.expects(:lookup_existing_templates)
59
58
  @project.expects(:check_project_name)
60
59
  @project.expects(:check_template_name)
61
60
  @project.expects(:check_template_path)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ian Alexander Wood (i0n)