jumpstart 0.1.14 → 0.1.15
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/LICENSE +1 -1
- data/README.md +32 -4
- data/Rakefile +0 -4
- data/config/jumpstart_version.yml +1 -1
- data/lib/jumpstart.rb +5 -5
- data/lib/jumpstart/base.rb +45 -16
- data/lib/jumpstart/filetools.rb +3 -0
- data/lib/jumpstart/setup.rb +10 -2
- data/lib/jumpstart/stringtools.rb +1 -0
- data/test/jumpstart/test_base.rb +1 -10
- data/test/jumpstart/test_setup.rb +111 -0
- data/test/test_jumpstart.rb +131 -0
- metadata +6 -5
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,38 @@
|
|
1
|
-
|
1
|
+
#JumpStart
|
2
2
|
|
3
|
-
|
3
|
+
Jumpstart is a gem for quickly creating projects.
|
4
4
|
It does this by running options from a YAML file that you can create, or you can let the gem do it for you.
|
5
5
|
It's dead easy to do.
|
6
6
|
|
7
|
-
|
7
|
+
## Features
|
8
|
+
With jumpstart you can:
|
9
|
+
|
10
|
+
* Run many terminal commands in a specific order
|
11
|
+
* Create new projects of any type quickly from templates
|
12
|
+
* Create files from three different kinds of templates:
|
13
|
+
* **Whole templates**. A like for like copy from the template to the new project.
|
14
|
+
* **Append templates**. The template is appended to a file generated by a terminal command (e.g. rails)
|
15
|
+
* **Line templates**. The template is inserted into a file generated by a terminal command at a specific line number.
|
16
|
+
* Replace strings in the newly generated project with specified tags (like the project name)
|
17
|
+
* Automatically configure local Nginx and hosts entries for a new project. (I'm using OS X so this is tailored for the Mac.)
|
18
|
+
* Remove unwanted files that may have been created by a terminal command (e.g. rails)
|
19
|
+
|
20
|
+
# Installation
|
21
|
+
`gem install jumpstart` should do it.
|
22
|
+
- - - - -
|
23
|
+
Or you can clone this git repo: `git://github.com/i0n/jumpstart.git`
|
24
|
+
Build jumpstart from the git repo's gemspec: `gem build jumpstart.gemspec`
|
25
|
+
Install the newly created gem: `gem install jumpstart-WHATEVER_THE_CURRENT_VERSION_IS.gem`
|
26
|
+
|
27
|
+
## Getting Started
|
28
|
+
There are a couple of ways to use jumpstart.
|
29
|
+
|
30
|
+
If you have already created a template, you can create a new project with a single command from the terminal.
|
31
|
+
e.g. **`jumpstart my_new_project_name`**
|
32
|
+
|
33
|
+
If you haven't created any templates yet, or you want to change one of the configuration options (which I'll get to), just call **`jumpstart`** without any arguments. This will launch the jumpstart menu.
|
34
|
+
|
35
|
+
###Note on Patches/Pull Requests
|
8
36
|
|
9
37
|
* Fork the project.
|
10
38
|
* Make your feature addition or bug fix.
|
@@ -14,6 +42,6 @@ It's dead easy to do.
|
|
14
42
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
15
43
|
* Send me a pull request. Bonus points for topic branches.
|
16
44
|
|
17
|
-
|
45
|
+
**Copyright**
|
18
46
|
|
19
47
|
Copyright (c) 2010 i0n. See LICENSE for details.
|
data/Rakefile
CHANGED
data/lib/jumpstart.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'bundler'
|
2
3
|
require 'find'
|
3
4
|
require 'fileutils'
|
4
5
|
require 'yaml'
|
@@ -6,6 +7,7 @@ require 'rbconfig'
|
|
6
7
|
|
7
8
|
# Sets up coloured terminal output in windows
|
8
9
|
if RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin|mingw32/
|
10
|
+
Bundler.setup(:windows)
|
9
11
|
begin
|
10
12
|
require 'Win32/Console/ANSI'
|
11
13
|
rescue LoadError
|
@@ -32,12 +34,10 @@ module JumpStart
|
|
32
34
|
|
33
35
|
end
|
34
36
|
|
35
|
-
module
|
36
|
-
|
37
|
-
include JumpStart::FileTools
|
38
|
-
end
|
39
|
-
end
|
37
|
+
# Included as a module so that extension methods will be better defined in class/module chain.
|
38
|
+
FileUtils.extend JumpStart::FileTools
|
40
39
|
|
40
|
+
# Included as a module so that extension methods will be better defined in class/module chain.
|
41
41
|
class String
|
42
42
|
include JumpStart::StringTools
|
43
43
|
end
|
data/lib/jumpstart/base.rb
CHANGED
@@ -14,6 +14,7 @@ module JumpStart
|
|
14
14
|
@output.puts(*args)
|
15
15
|
end
|
16
16
|
|
17
|
+
# Sets up JumpStart::Base object with preliminary instance variables.
|
17
18
|
def initialize(args)
|
18
19
|
# setup for testing input
|
19
20
|
@input = $stdin
|
@@ -23,21 +24,14 @@ module JumpStart
|
|
23
24
|
@project_name = args.shift.dup if args[0] != nil
|
24
25
|
if args[0] != nil
|
25
26
|
@template_name = args.shift.dup
|
26
|
-
elsif JumpStart::Setup.default_template_name
|
27
|
+
elsif JumpStart::Setup.default_template_name != nil
|
27
28
|
@template_name = JumpStart::Setup.default_template_name
|
28
29
|
end
|
29
30
|
# set instance variable @template_path as the directory to read templates from.
|
30
31
|
@template_path = FileUtils.join_paths(JumpStart::Setup.templates_path, @template_name)
|
31
32
|
end
|
32
|
-
|
33
|
-
# TODO Ensure that if jumpstart is launched with two arguments they are parsed as @project_name and @template_name, and the command is launched without any menu display.
|
34
|
-
# TODO Ensure that if jumpstart is launched with one argument it is parsed as @project_name, and if JumpStart::Setup.default_template_name exists then the command is launched without any menu display.
|
35
|
-
# TODO Write integration tests.
|
36
|
-
# TODO Document methods for RDOC
|
37
|
-
# Finish README etc for github
|
38
|
-
# TODO try and find a way to automatically reset jumpstart_setup.yml while in development.
|
39
33
|
|
40
|
-
#
|
34
|
+
# Sets up instance variables from YAML file
|
41
35
|
def set_config_file_options
|
42
36
|
if @template_name.nil? || @template_path.nil?
|
43
37
|
jumpstart_menu
|
@@ -52,6 +46,7 @@ module JumpStart
|
|
52
46
|
end
|
53
47
|
end
|
54
48
|
|
49
|
+
# Pre-install project configuration checking.
|
55
50
|
def check_setup
|
56
51
|
set_config_file_options
|
57
52
|
lookup_existing_templates
|
@@ -76,6 +71,7 @@ module JumpStart
|
|
76
71
|
end
|
77
72
|
end
|
78
73
|
|
74
|
+
# Runs the configuration, generating the new project from the chosen template.
|
79
75
|
def start
|
80
76
|
puts "\n******************************************************************************************************************************************\n\n"
|
81
77
|
puts " JumpStarting....\n".purple
|
@@ -94,6 +90,7 @@ module JumpStart
|
|
94
90
|
exit_with_success
|
95
91
|
end
|
96
92
|
|
93
|
+
# Checks replace string values for :project_name and replaces these with the value of @project_name if found. This enables PROJECT_NAME entries in projects to be dynamically populated with the current project name.
|
97
94
|
def check_replace_string_pairs_for_project_name_sub(hash)
|
98
95
|
unless @project_name.nil?
|
99
96
|
hash.each do |key, value|
|
@@ -107,6 +104,8 @@ module JumpStart
|
|
107
104
|
|
108
105
|
private
|
109
106
|
|
107
|
+
# Makes sure that the chosen project name is suitable. (Not nil or empty, at least 3 characters long, and starts with a letter or a number.)
|
108
|
+
# Returns with the value of @project_name
|
110
109
|
def check_project_name
|
111
110
|
if @project_name.nil? || @project_name.empty?
|
112
111
|
puts "\n Enter a name for your project.".yellow
|
@@ -125,12 +124,14 @@ module JumpStart
|
|
125
124
|
end
|
126
125
|
end
|
127
126
|
|
127
|
+
# Launches the JumpStart menu system if a template has not been specified.
|
128
128
|
def check_template_name
|
129
129
|
if @template_name.nil? || @template_name.empty?
|
130
130
|
jumpstart_menu
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
+
# Ensures that the template path specified exists and can be accessed. Exits if an error occurs.
|
134
135
|
def check_template_path
|
135
136
|
begin
|
136
137
|
Dir.chdir(@template_path)
|
@@ -140,7 +141,9 @@ module JumpStart
|
|
140
141
|
end
|
141
142
|
end
|
142
143
|
|
143
|
-
#
|
144
|
+
# Sets the install path to executing directory if @install_path varibale is nil or empty. This should result in projects being created in directory from which the jumpstart command was called, if the template specified does not set this option.
|
145
|
+
# Checks the install path set in @install_path.
|
146
|
+
# Checks that a directory with the same name as the project does not already exist in the install path.
|
144
147
|
def check_install_path
|
145
148
|
@install_path = FileUtils.pwd if @install_path.nil? || @install_path.empty?
|
146
149
|
if File.directory?(FileUtils.join_paths(@install_path, @project_name))
|
@@ -149,7 +152,8 @@ module JumpStart
|
|
149
152
|
end
|
150
153
|
true
|
151
154
|
end
|
152
|
-
|
155
|
+
|
156
|
+
# Creates a new blank template in whichever directory the default templates directory has been set to.
|
153
157
|
def create_template
|
154
158
|
if File.directory?(FileUtils.join_paths(JumpStart::Setup.templates_path, @template_name))
|
155
159
|
puts "\nThe directory #{FileUtils.join_paths(JumpStart::Setup.templates_path, @template_name).red} already exists. The template will not be created."
|
@@ -164,6 +168,7 @@ module JumpStart
|
|
164
168
|
end
|
165
169
|
end
|
166
170
|
|
171
|
+
# Displays options for the main jumpstart menu.
|
167
172
|
def jumpstart_menu
|
168
173
|
puts "\n\n******************************************************************************************************************************************\n\n"
|
169
174
|
puts " JUMPSTART MENU\n".purple
|
@@ -177,6 +182,7 @@ module JumpStart
|
|
177
182
|
jumpstart_menu_options
|
178
183
|
end
|
179
184
|
|
185
|
+
# Captures user input for the main jumpstart menu and calls the appropriate method
|
180
186
|
def jumpstart_menu_options
|
181
187
|
lookup_existing_templates
|
182
188
|
input = gets.chomp.strip
|
@@ -197,6 +203,7 @@ module JumpStart
|
|
197
203
|
end
|
198
204
|
end
|
199
205
|
|
206
|
+
# Displays options for the "create a new jumpstart project from an existing template" menu
|
200
207
|
def new_project_from_template_menu
|
201
208
|
puts "\n\n******************************************************************************************************************************************\n\n"
|
202
209
|
puts " CREATE A NEW JUMPSTART PROJECT FROM AN EXISTING TEMPLATE\n\n".purple
|
@@ -214,6 +221,8 @@ module JumpStart
|
|
214
221
|
new_project_from_template_options
|
215
222
|
end
|
216
223
|
|
224
|
+
# Captures user input for the "create a new jumpstart project from an existing template" menu and calls the appropriate method.
|
225
|
+
# When the input matches a template number a project will be created from that template
|
217
226
|
def new_project_from_template_options
|
218
227
|
input = gets.chomp.strip
|
219
228
|
case
|
@@ -232,6 +241,7 @@ module JumpStart
|
|
232
241
|
end
|
233
242
|
end
|
234
243
|
|
244
|
+
# Displays output for the "create a new jumpstart template" menu
|
235
245
|
def new_template_menu
|
236
246
|
puts "\n\n******************************************************************************************************************************************\n\n"
|
237
247
|
puts " CREATE A NEW JUMPSTART TEMPLATE\n".purple
|
@@ -242,8 +252,9 @@ module JumpStart
|
|
242
252
|
end
|
243
253
|
new_template_options
|
244
254
|
end
|
245
|
-
|
246
|
-
#
|
255
|
+
|
256
|
+
# Captures user input for "create a new jumpstart template" menu and calls the appropriate action.
|
257
|
+
# If the template name provided meets the methods requirements then a directory of that name containing a jumpstart_config dir and matching yaml file are created.
|
247
258
|
def new_template_options
|
248
259
|
puts "\n Enter a unique name for the new template.\n".yellow
|
249
260
|
input = gets.chomp.strip
|
@@ -265,6 +276,7 @@ module JumpStart
|
|
265
276
|
end
|
266
277
|
end
|
267
278
|
|
279
|
+
# Displays output for the "jumpstart default template options menu"
|
268
280
|
def set_default_template_menu
|
269
281
|
puts "\n\n******************************************************************************************************************************************\n\n"
|
270
282
|
puts " JUMPSTART DEFAULT TEMPLATE OPTIONS\n\n".purple
|
@@ -279,7 +291,7 @@ module JumpStart
|
|
279
291
|
set_default_template_options
|
280
292
|
end
|
281
293
|
|
282
|
-
# Sets the default template to be used by JumpStart.
|
294
|
+
# Sets the default template to be used by JumpStart and writes it to a YAML file.
|
283
295
|
def set_default_template_options
|
284
296
|
input = gets.chomp.strip
|
285
297
|
case
|
@@ -298,6 +310,7 @@ module JumpStart
|
|
298
310
|
end
|
299
311
|
end
|
300
312
|
|
313
|
+
# Displays output for the "jumpstart templates directory options" menu.
|
301
314
|
def templates_dir_menu
|
302
315
|
puts "\n\n******************************************************************************************************************************************\n\n"
|
303
316
|
puts " JUMPSTART TEMPLATES DIRECTORY OPTIONS\n\n".purple
|
@@ -309,6 +322,7 @@ module JumpStart
|
|
309
322
|
templates_dir_options
|
310
323
|
end
|
311
324
|
|
325
|
+
# Captures user input for the "jumpstart templates directory options" menu and calls the appropriate method.
|
312
326
|
def templates_dir_options
|
313
327
|
input = gets.chomp.strip
|
314
328
|
case
|
@@ -327,6 +341,8 @@ module JumpStart
|
|
327
341
|
end
|
328
342
|
|
329
343
|
# Sets the path for templates to be used by JumpStart.
|
344
|
+
# Copies templates in the existing template dir to the new location.
|
345
|
+
# The folder specified must not exist yet, but it's parent should.
|
330
346
|
def set_templates_dir
|
331
347
|
puts "Please enter the absolute path for the directory that you would like to contain your jumpstart templates."
|
332
348
|
input = gets.chomp.strip
|
@@ -388,6 +404,7 @@ module JumpStart
|
|
388
404
|
end
|
389
405
|
end
|
390
406
|
|
407
|
+
# Runs the main install command specified in the selected templates YAML file.
|
391
408
|
def execute_install_command
|
392
409
|
Dir.chdir(@install_path)
|
393
410
|
unless @install_command.nil? || @install_command.empty?
|
@@ -396,6 +413,7 @@ module JumpStart
|
|
396
413
|
end
|
397
414
|
end
|
398
415
|
|
416
|
+
# Parses the contents of the @template_path and sorts ready for template creation.
|
399
417
|
def parse_template_dir
|
400
418
|
@dir_list = []
|
401
419
|
file_list = []
|
@@ -425,16 +443,17 @@ module JumpStart
|
|
425
443
|
end
|
426
444
|
end
|
427
445
|
|
428
|
-
#
|
446
|
+
# Makes folders for the project
|
429
447
|
def create_dirs
|
430
448
|
@dir_list.each {|dir| FileUtils.mkdir_p(FileUtils.join_paths(@install_path, @project_name, dir)) } unless @dir_list.nil?
|
431
449
|
end
|
432
450
|
|
433
|
-
#
|
451
|
+
# Create files from whole templates
|
434
452
|
def populate_files_from_whole_templates
|
435
453
|
@whole_templates.each {|x| FileUtils.cp(FileUtils.join_paths(@template_path, x), FileUtils.join_paths(@install_path, @project_name, x)) } unless @whole_templates.nil?
|
436
454
|
end
|
437
455
|
|
456
|
+
# Create files from append (_._ _l._ or _L._) templates
|
438
457
|
def populate_files_from_append_templates
|
439
458
|
@append_templates.each do |x|
|
440
459
|
new_name = x.sub(/_([lL]?)\._{1}/, '')
|
@@ -443,6 +462,7 @@ module JumpStart
|
|
443
462
|
end
|
444
463
|
end
|
445
464
|
|
465
|
+
# Create files from line number templates (e.g. _12._ or _1._)
|
446
466
|
def populate_files_from_line_templates
|
447
467
|
@line_templates.each do |x|
|
448
468
|
new_name = x.sub(/_(\d+)\._{1}/, '')
|
@@ -451,6 +471,7 @@ module JumpStart
|
|
451
471
|
end
|
452
472
|
end
|
453
473
|
|
474
|
+
# Checks to see if options for configuring a local Nginx environment have been specified in the template. If they have, runs the relevant JumpStart::FileTools class methods (included in FileUtils module.)
|
454
475
|
def check_local_nginx_configuration
|
455
476
|
if @nginx_local_template.nil? || @config_file[:local_nginx_conf].nil?
|
456
477
|
puts " \nNginx will not be configured as options have not been set for this."
|
@@ -460,6 +481,7 @@ module JumpStart
|
|
460
481
|
end
|
461
482
|
end
|
462
483
|
|
484
|
+
# Removes files specified in templates YAML
|
463
485
|
def remove_unwanted_files
|
464
486
|
file_array = []
|
465
487
|
root_path = FileUtils.join_paths(@install_path, @project_name)
|
@@ -469,6 +491,7 @@ module JumpStart
|
|
469
491
|
FileUtils.remove_files(file_array)
|
470
492
|
end
|
471
493
|
|
494
|
+
# Runs additional scripts specified in YAML. Runs one set after the install command has executed, and another after the templates have been generated.
|
472
495
|
def run_scripts_from_yaml(script_name)
|
473
496
|
unless @config_file[script_name].nil? || @config_file[script_name].empty?
|
474
497
|
begin
|
@@ -483,6 +506,7 @@ module JumpStart
|
|
483
506
|
end
|
484
507
|
end
|
485
508
|
|
509
|
+
# Looks for strings IN_CAPS that are specified for replacement in the templates YAML
|
486
510
|
def check_for_strings_to_replace
|
487
511
|
if @replace_strings.nil? || @replace_strings.empty?
|
488
512
|
false
|
@@ -503,6 +527,7 @@ module JumpStart
|
|
503
527
|
end
|
504
528
|
end
|
505
529
|
|
530
|
+
# Exit after creating a project, dumping current setup information to YAML
|
506
531
|
def exit_with_success
|
507
532
|
puts "\n\n Exiting JumpStart...".purple
|
508
533
|
puts "\n Success! ".green + @project_name.green_bold + " has been created at: ".green + FileUtils.join_paths(@install_path, @project_name).green_bold + "\n\n".green
|
@@ -511,6 +536,7 @@ module JumpStart
|
|
511
536
|
exit
|
512
537
|
end
|
513
538
|
|
539
|
+
# Exit normally, dumping current setup information to YAML
|
514
540
|
def exit_normal
|
515
541
|
puts "\n\n Exiting JumpStart...".purple
|
516
542
|
puts "\n Goodbye!\n\n"
|
@@ -521,6 +547,7 @@ module JumpStart
|
|
521
547
|
|
522
548
|
class << self
|
523
549
|
|
550
|
+
# Class instance method that returns an integer to be used as the line number for line templates. Returns false if no match is found.
|
524
551
|
def get_line_number(file_name)
|
525
552
|
if file_name.match(/_(\d+)\._\w*/)
|
526
553
|
number = file_name.match(/_(\d+)\._\w*/)[1]
|
@@ -530,6 +557,8 @@ module JumpStart
|
|
530
557
|
end
|
531
558
|
end
|
532
559
|
|
560
|
+
# Class instance method that returns true or false for removing the last line of a file.
|
561
|
+
# Append templates with the _l._ or _L._ prefix will return true.
|
533
562
|
def remove_last_line?(file_name)
|
534
563
|
if file_name.match(/_([lL]{1})\._{1}\w*/)
|
535
564
|
true
|
data/lib/jumpstart/filetools.rb
CHANGED
@@ -51,6 +51,7 @@ module JumpStart::FileTools
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
# Removes files provided as an array.
|
54
55
|
def remove_files(file_array)
|
55
56
|
file_array.each do |x|
|
56
57
|
begin
|
@@ -217,6 +218,7 @@ module JumpStart::FileTools
|
|
217
218
|
puts
|
218
219
|
end
|
219
220
|
|
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.
|
220
222
|
def check_source_type(source)
|
221
223
|
if File.file?(source)
|
222
224
|
source_file = IO.readlines(source)
|
@@ -262,6 +264,7 @@ module JumpStart::FileTools
|
|
262
264
|
full_path_string
|
263
265
|
end
|
264
266
|
|
267
|
+
# Sorts files and dirs in a path and then returns the result as a hash of two arrays, :files and :dirs
|
265
268
|
def sort_contained_files_and_dirs(path)
|
266
269
|
dirs, files = [], []
|
267
270
|
if path != nil && File.directory?(path)
|
data/lib/jumpstart/setup.rb
CHANGED
@@ -48,14 +48,22 @@ module JumpStart
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# Method for bumping version number types.
|
51
|
+
# Resets @version_minor and @version_patch to 0 if bumping @version_major.
|
52
|
+
# Resets @version_pacth to 0 if bumping @version_minor
|
51
53
|
def self.bump(version_type)
|
52
|
-
|
54
|
+
value = instance_variable_get("@#{version_type}")
|
55
|
+
instance_variable_set("@#{version_type}", (value + 1))
|
56
|
+
if version_type == "version_major"
|
57
|
+
@version_minor, @version_patch = 0, 0
|
58
|
+
elsif version_type == "version_minor"
|
59
|
+
@version_patch = 0
|
60
|
+
end
|
53
61
|
dump_jumpstart_version_yaml
|
54
62
|
end
|
55
63
|
|
56
64
|
# Handles calls to JumpStart::Setup.bump_version_major, JumpStart::Setup.bump_version_minor and JumpStart::Setup.bump_version_patch class methods.
|
57
65
|
def self.method_missing(method, *args)
|
58
|
-
if method.match(/bump_version_(major|minor|patch)/)
|
66
|
+
if method.to_s.match(/bump_version_(major|minor|patch)/)
|
59
67
|
version_type = method.to_s.sub('bump_', '')
|
60
68
|
self.send(:bump, "#{version_type}")
|
61
69
|
else
|
data/test/jumpstart/test_base.rb
CHANGED
@@ -1086,16 +1086,7 @@ class TestJumpstartBase < Test::Unit::TestCase
|
|
1086
1086
|
end
|
1087
1087
|
|
1088
1088
|
end
|
1089
|
-
|
1090
|
-
context "Tests for the JumpStart::Setup#dump_jumpstart_setup_yaml class method." do
|
1091
|
-
should "call File.open and Yaml.dump for jumpstart_setup.yml" do
|
1092
|
-
YAML.stubs(:dump)
|
1093
|
-
File.stubs(:open)
|
1094
|
-
File.expects(:open).once
|
1095
|
-
JumpStart::Setup.dump_jumpstart_setup_yaml
|
1096
|
-
end
|
1097
|
-
end
|
1098
|
-
|
1089
|
+
|
1099
1090
|
context "Tests for initializing and running JumpStart instances\n" do
|
1100
1091
|
|
1101
1092
|
context "Create jumpstart with the project name argument passed to it but do not start.\n" do
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestJumpstartSetup < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Testing JumpStart::Setup" do
|
6
|
+
|
7
|
+
context "Tests for the JumpStart::Base#templates_path class method" do
|
8
|
+
|
9
|
+
should "return default path if @templates_path is nil when called" do
|
10
|
+
JumpStart::Setup.class_eval {@templates_path = nil}
|
11
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.templates_path
|
12
|
+
end
|
13
|
+
|
14
|
+
should "return default path if @templates_path is empty when called" do
|
15
|
+
JumpStart::Setup.class_eval {@templates_path = ""}
|
16
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.templates_path
|
17
|
+
end
|
18
|
+
|
19
|
+
should "return the path set" do
|
20
|
+
JumpStart::Setup.class_eval {@templates_path = "a/path/for/templates"}
|
21
|
+
assert_equal "a/path/for/templates", JumpStart::Setup.templates_path
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context "Tests for the JumpStart::Setup#dump_jumpstart_setup_yaml class method." do
|
27
|
+
should "call File.open and Yaml.dump for jumpstart_setup.yml" do
|
28
|
+
YAML.stubs(:dump)
|
29
|
+
File.stubs(:open)
|
30
|
+
File.expects(:open).once
|
31
|
+
JumpStart::Setup.dump_jumpstart_setup_yaml
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "Tests for the JumpStart::Setup#dump_jumpstart_version_yaml class method." do
|
36
|
+
should "call File.open and Yaml.dump for jumpstart_version.yml" do
|
37
|
+
YAML.stubs(:dump)
|
38
|
+
File.stubs(:open)
|
39
|
+
File.expects(:open).once
|
40
|
+
JumpStart::Setup.dump_jumpstart_version_yaml
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "Tests for the JumpStart::Setup#bump class method." do
|
45
|
+
|
46
|
+
setup do
|
47
|
+
JumpStart::Setup.stubs(:dump_jumpstart_version_yaml)
|
48
|
+
end
|
49
|
+
|
50
|
+
should "add 1 to @version_major class instance variable, set @version_minor and @version_patch to 0 and call dump_jumpstart_version_yaml" do
|
51
|
+
JumpStart::Setup.class_eval {@version_major = 1; @version_minor = 1; @version_patch = 1 }
|
52
|
+
JumpStart::Setup.expects(:dump_jumpstart_version_yaml).once
|
53
|
+
JumpStart::Setup.bump("version_major")
|
54
|
+
assert_equal 2, JumpStart::Setup.version_major
|
55
|
+
assert_equal 0, JumpStart::Setup.version_minor
|
56
|
+
assert_equal 0, JumpStart::Setup.version_patch
|
57
|
+
end
|
58
|
+
|
59
|
+
should "add 1 to @version_minor class instance variable, set @version_patch to 0 and call dump_jumpstart_version_yaml" do
|
60
|
+
JumpStart::Setup.class_eval {@version_major = 1; @version_minor = 1; @version_patch = 1 }
|
61
|
+
JumpStart::Setup.expects(:dump_jumpstart_version_yaml).once
|
62
|
+
JumpStart::Setup.bump("version_minor")
|
63
|
+
assert_equal 1, JumpStart::Setup.version_major
|
64
|
+
assert_equal 2, JumpStart::Setup.version_minor
|
65
|
+
assert_equal 0, JumpStart::Setup.version_patch
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
should "add 1 to @version_patch class instance variable and call dump_jumpstart_version_yaml" do
|
70
|
+
JumpStart::Setup.class_eval {@version_major = 1; @version_minor = 1; @version_patch = 1 }
|
71
|
+
JumpStart::Setup.expects(:dump_jumpstart_version_yaml).once
|
72
|
+
JumpStart::Setup.bump("version_patch")
|
73
|
+
assert_equal 1, JumpStart::Setup.version_major
|
74
|
+
assert_equal 1, JumpStart::Setup.version_minor
|
75
|
+
assert_equal 2, JumpStart::Setup.version_patch
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
context "Tests for the JumpStart::Setup#method_missing class method." do
|
82
|
+
|
83
|
+
setup do
|
84
|
+
JumpStart::Setup.stubs(:bump).returns(:result)
|
85
|
+
JumpStart::Setup.stubs(:dump_jumpstart_version_yaml)
|
86
|
+
end
|
87
|
+
|
88
|
+
should "recognise JumpStart::Setup#bump_version_major class instance method calls and forward them to JumpStart::Setup#bump to set @version_major." do
|
89
|
+
JumpStart::Setup.expects(:bump).with("version_major").once
|
90
|
+
JumpStart::Setup.bump_version_major
|
91
|
+
end
|
92
|
+
|
93
|
+
should "recognise JumpStart::Setup#bump_version_minor class instance method calls and forward them to JumpStart::Setup#bump to set @version_minor." do
|
94
|
+
JumpStart::Setup.expects(:bump).with("version_minor").once
|
95
|
+
JumpStart::Setup.bump_version_minor
|
96
|
+
end
|
97
|
+
|
98
|
+
should "recognise JumpStart::Setup#bump_version_patch class instance method calls and forward them to JumpStart::Setup#bump to set @version_patch." do
|
99
|
+
JumpStart::Setup.expects(:bump).with("version_patch").once
|
100
|
+
JumpStart::Setup.bump_version_patch
|
101
|
+
end
|
102
|
+
|
103
|
+
should "return method_missing to super as normal if method name is not recognised." do
|
104
|
+
assert_raises(NoMethodError) {JumpStart::Setup.bump_version_blarg}
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
data/test/test_jumpstart.rb
CHANGED
@@ -6,4 +6,135 @@ class TestJumpstart < Test::Unit::TestCase
|
|
6
6
|
assert(File.exists?("#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml"))
|
7
7
|
end
|
8
8
|
|
9
|
+
should "be able to find jumpstart_version.yml" do
|
10
|
+
assert(File.exists?("#{JumpStart::CONFIG_PATH}/jumpstart_version.yml"))
|
11
|
+
end
|
12
|
+
|
13
|
+
context "Test for JumpStart.version class instance method" do
|
14
|
+
should "return 1.1.1" do
|
15
|
+
JumpStart::Setup.version_major = 1
|
16
|
+
JumpStart::Setup.version_minor = 1
|
17
|
+
JumpStart::Setup.version_patch = 1
|
18
|
+
assert_equal "1.1.1", JumpStart.version
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "Tests for launching JumpStart with various configurations set" do
|
23
|
+
|
24
|
+
context "JumpStart::Setup.templates_path and JumpStart::Setup.default_template_name are both set to nil as @jumpstart_setup_yaml is not loaded" do
|
25
|
+
|
26
|
+
setup do
|
27
|
+
JumpStart::Setup.class_eval {@jumpstart_setup_yaml = nil}
|
28
|
+
@project.stubs(:jumpstart_menu)
|
29
|
+
end
|
30
|
+
|
31
|
+
should "launch menu when passed nil. JumpStart::Setup.templates_path should be set to default." do
|
32
|
+
@project = JumpStart::Base.new([nil])
|
33
|
+
@project.expects(:jumpstart_menu).once
|
34
|
+
@project.set_config_file_options
|
35
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.class_eval {@templates_path}
|
36
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
|
37
|
+
assert_equal nil, @project.instance_eval {@template_name}
|
38
|
+
end
|
39
|
+
|
40
|
+
should "launch menu when passed empty. JumpStart::Setup.templates_path should be set to default." do
|
41
|
+
@project = JumpStart::Base.new([""])
|
42
|
+
@project.expects(:jumpstart_menu).once
|
43
|
+
@project.set_config_file_options
|
44
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.class_eval {@templates_path}
|
45
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
|
46
|
+
assert_equal nil, @project.instance_eval {@template_name}
|
47
|
+
end
|
48
|
+
|
49
|
+
should "launch menu when passed one argument under 3 characters. JumpStart::Setup.templates_path should be set to default." do
|
50
|
+
@project = JumpStart::Base.new(["no"])
|
51
|
+
@project.expects(:jumpstart_menu).once
|
52
|
+
@project.set_config_file_options
|
53
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.class_eval {@templates_path}
|
54
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
|
55
|
+
assert_equal nil, @project.instance_eval {@template_name}
|
56
|
+
end
|
57
|
+
|
58
|
+
should "launch menu when passed an ivalid first argument (that starts with a character that is not a letter or number.). JumpStart::Setup.templates_path should be set to default." do
|
59
|
+
@project = JumpStart::Base.new(["$hello"])
|
60
|
+
@project.expects(:jumpstart_menu).once
|
61
|
+
@project.set_config_file_options
|
62
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.class_eval {@templates_path}
|
63
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
|
64
|
+
assert_equal nil, @project.instance_eval {@template_name}
|
65
|
+
end
|
66
|
+
|
67
|
+
should "launch menu when passed a valid first argument. JumpStart::Setup.templates_path should be set to default." do
|
68
|
+
@project = JumpStart::Base.new(["hello"])
|
69
|
+
@project.expects(:jumpstart_menu).once
|
70
|
+
@project.set_config_file_options
|
71
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.class_eval {@templates_path}
|
72
|
+
assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
|
73
|
+
assert_equal nil, @project.instance_eval {@template_name}
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
context "JumpStart::Setup.templates_path is set to and JumpStart::Setup.default_template_name is nil as @jumpstart_setup_yaml is not loaded" do
|
79
|
+
|
80
|
+
setup do
|
81
|
+
JumpStart::Setup.class_eval {@templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"}
|
82
|
+
end
|
83
|
+
|
84
|
+
should "loop on check_project_name method when passed one argument under 3 characters and a valid second argument. JumpStart::Setup.templates_path should be set to default." do
|
85
|
+
# From the prompt this method would repeat until a valid project name was entered.
|
86
|
+
@project = JumpStart::Base.new(["no", "test_template_1"])
|
87
|
+
@project.stubs(:jumpstart_menu)
|
88
|
+
@project.expects(:check_template_name)
|
89
|
+
@project.expects(:check_project_name)
|
90
|
+
@project.check_setup
|
91
|
+
end
|
92
|
+
|
93
|
+
should "loop on check_project_name method when passed one argument under 3 characters and an invalid second argument. JumpStart::Setup.templates_path should be set to default." do
|
94
|
+
# From the prompt this method would repeat until a valid project name was entered.
|
95
|
+
@project = JumpStart::Base.new(["no", "this_template_does_not_exist"])
|
96
|
+
@project.stubs(:jumpstart_menu)
|
97
|
+
@project.expects(:check_template_name)
|
98
|
+
@project.expects(:check_project_name)
|
99
|
+
@project.check_setup
|
100
|
+
end
|
101
|
+
|
102
|
+
should "loop on check_project_name method when passed an ivalid first argument and a valid second argument (that starts with a character that is not a letter or number.). JumpStart::Setup.templates_path should be set to default." do
|
103
|
+
# From the prompt this method would repeat until a valid project name was entered.
|
104
|
+
@project = JumpStart::Base.new(["$hello", "test_template_1"])
|
105
|
+
@project.stubs(:jumpstart_menu)
|
106
|
+
@project.expects(:check_template_name)
|
107
|
+
@project.expects(:check_project_name)
|
108
|
+
@project.check_setup
|
109
|
+
end
|
110
|
+
|
111
|
+
should "loop on check_project_name method when passed an ivalid first argument and an invalid second argument (that starts with a character that is not a letter or number.). JumpStart::Setup.templates_path should be set to default." do
|
112
|
+
# From the prompt this method would repeat until a valid project name was entered.
|
113
|
+
@project = JumpStart::Base.new(["$hello", "this_template_does_not_exist"])
|
114
|
+
@project.stubs(:jumpstart_menu)
|
115
|
+
@project.expects(:check_template_name)
|
116
|
+
@project.expects(:check_project_name)
|
117
|
+
@project.check_setup
|
118
|
+
end
|
119
|
+
|
120
|
+
should "set @install_path to executing directory when it is not set in the template and when passed a valid first and second argument. JumpStart::Setup.templates_path should be set to default." do
|
121
|
+
@project = JumpStart::Base.new(["hello", "test_template_1"])
|
122
|
+
# FileUtils.stubs(:pwd)
|
123
|
+
@project.stubs(:jumpstart_menu)
|
124
|
+
@project.expects(:set_config_file_options)
|
125
|
+
@project.expects(:lookup_existing_templates)
|
126
|
+
@project.expects(:check_project_name)
|
127
|
+
@project.expects(:check_template_name)
|
128
|
+
@project.expects(:check_template_path)
|
129
|
+
@project.expects(:check_install_path)
|
130
|
+
@project.expects(:jumpstart_menu).never
|
131
|
+
# FileUtils.expects(:pwd)
|
132
|
+
@project.check_setup
|
133
|
+
# assert_equal "hello", @project.instance_variable_get(:@install_path)
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
9
140
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 15
|
9
|
+
version: 0.1.15
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ian Alexander Wood (i0n)
|
@@ -14,12 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-29 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: shoulda
|
22
|
-
prerelease: false
|
23
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
23
|
none: false
|
25
24
|
requirements:
|
@@ -29,10 +28,10 @@ dependencies:
|
|
29
28
|
- 0
|
30
29
|
version: "0"
|
31
30
|
type: :development
|
31
|
+
prerelease: false
|
32
32
|
version_requirements: *id001
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: mocha
|
35
|
-
prerelease: false
|
36
35
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
36
|
none: false
|
38
37
|
requirements:
|
@@ -42,6 +41,7 @@ dependencies:
|
|
42
41
|
- 0
|
43
42
|
version: "0"
|
44
43
|
type: :development
|
44
|
+
prerelease: false
|
45
45
|
version_requirements: *id002
|
46
46
|
description: |-
|
47
47
|
JumpStart is a script runner and template parser written in Ruby with Ruby projects in mind.
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- test/helper.rb
|
71
71
|
- test/jumpstart/test_base.rb
|
72
72
|
- test/jumpstart/test_filetools.rb
|
73
|
+
- test/jumpstart/test_setup.rb
|
73
74
|
- test/jumpstart/test_stringutils.rb
|
74
75
|
- test/test_jumpstart.rb
|
75
76
|
- test/test_jumpstart_templates/test_base/_._test_file.txt
|