jumpstart 0.1.19 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,34 +30,66 @@ Install the newly created gem:
30
30
  NOTE! If you install jumpstart using sudo then you will probably need to run jumpstart with it as well to grant writes to the YAML files in the gem.
31
31
 
32
32
  == Getting Started
33
- There are a couple of ways to use jumpstart.
33
+ There are a few ways to use jumpstart.
34
34
 
35
- If you have already created a template and set it as your default, you can create a new project with a single command from the terminal. e.g.
36
- jumpstart my_new_project_name
35
+ If you have a template and you would like to create a new project with it, pass the jumpstart command two arguments, the first being the new projects name, the second being the existing jumpstart template name. e.g.
36
+ jumpstart my_new_project my_existing_template
37
+
38
+ If you have already created a template and set it as the default jumpstart template (you can do this in the jumpstart menu), you can create a new project using it by passing just the new projects name to jumpstart. e.g.
39
+ jumpstart my_new_project
37
40
 
38
41
  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:
39
42
  jumpstart
40
43
  This will launch the jumpstart menu.
41
44
 
42
- ==Example YAML files.
45
+ == Template File Syntax
46
+ One of the core ideas behind jumpstart is the notion of generating files in a new project automatically from template files. The idea being that you specify a generator of some kind in the jumpstart YAML (the install command), which sets up a generic project (for example rails). Once this has happened the jumpstart template will be parsed for template files to apply to the new project. Anything inside the jumpstart_config directory will not be copied to the project, this is where the templates configuration YAML lives. Everything else is evaluated from the root of the template directory and applied to the new project, again with the projects containing folder treated as the beginning of file paths. So as an example, a jumpstart template called "my_template" containing the path /folder1/folder2/file.txt when parsed would generate the same path in the new project. e.g. my_project/folder1/folder2/file.txt The template files contained in a jumpstart template come in three flavours:
47
+
48
+ * Whole templates.
49
+ Whole templates are copied to the new project verbatim. Any file that is not recognised as an append or line template is treated as a whole template.
50
+
51
+ * Append templates: _._ or _L._
52
+ Append templates append their contents to an existing file. You can get jumpstart to parse a file as an append template by prefixing the file name with _._ So for example say you have a jumpstart template that runs the rails command. After the new rails project has been generated you want jumpstart to append some information to the newly created Gemfile. You could use a whole template and overwrite everything, but this is a bit cumbersome. If things change in Rails (as they do all the time) then you will need to make constant changes to keep the template current. Better to just append what you need to the created file, just like you would do if handling the task manually. To create an append template for the Gemfile, you would create a file called: _._Gemfile
53
+ There is one more option to bare in mind with append templates. If you specify an L as well, like this: _L._
54
+ The last line of the source file (ignoring whitespace) will be removed, and then the append template will be added as normal. Honestly, it's handy.
55
+
56
+ * Line templates: e.g. _123._
57
+ Line templates insert their contents into a file at a specified line, pushing existing contents down the page. This is very handy. Say for example that you want to insert some extra configuration information into your new rails projects config/environments/development.rb at line 18. In your jumpstart template you would create a file called config/environments/_18._development.rb
58
+ If the file you specify doesn't have as many lines as you said it would, whitespace will be added until the specified number is reached.
59
+
60
+ == The JumpStart Command
61
+
62
+ == The JumpStart Menu
63
+
64
+ == YAML Options
65
+
66
+ == Task Execution Order
67
+
68
+ ==Example YAML files
43
69
  Example 1: Sets up a new Rails project, creating MySQL Dbs and other options. Creates a home controller. Removes superfluous files created by Rails generator. Capifys the project. Creates a git repo and checks everything in to it. Replaces PROJECT_NAME string in capistrano deploy.rb with the name of the new project. Creates and appends to files generated by Rails to get everything ready to go straight away. Configures local Nginx environment. Not bad for one YAML!
44
70
  ---
45
71
  :install_path: /Users/i0n/Sites
72
+
46
73
  :install_command: rails
74
+
47
75
  :install_command_args: -d mysql -J -T
76
+
48
77
  :run_after_install_command:
49
78
  - rails g controller home
79
+
50
80
  :remove_files:
51
81
  - /app/views/layouts/application.html.erb
52
82
  - /public/index.html
53
83
  - /public/favicon.ico
54
84
  - /public/images/rails.png
85
+
55
86
  :run_after_jumpstart:
56
87
  - rake db:create
57
88
  - capify .
58
89
  - git init
59
90
  - git add .
60
91
  - git commit -q -v -a -m "Initial commit"
92
+
61
93
  :replace_strings:
62
94
  - :target_path: /config/deploy.rb
63
95
  :symbols:
@@ -72,12 +104,14 @@ Example 1: Sets up a new Rails project, creating MySQL Dbs and other options. Cr
72
104
  - :target_path: /config/environments/production.rb
73
105
  :symbols:
74
106
  :project_name: name_of_my_app
107
+
75
108
  :local_nginx_conf: /usr/local/nginx/conf/nginx.conf
76
109
 
77
110
  Example 2: A blank YAML with commenting to make it easy to see your options when creating templates.
78
111
  ---
79
112
  # The commands in a jumpstart config file are executed in the order displayed in this file.
80
113
 
114
+ ## Can be omitted or left blank. If :install_path: is omitted, the new project will be created in whatever directory you are in when you run the command.
81
115
  # The path to where the project directory will be created
82
116
  # e.g. :install_path: /Users/i0n/Sites
83
117
  :install_path:
data/Rakefile CHANGED
@@ -26,31 +26,27 @@ namespace :deploy do
26
26
 
27
27
  end
28
28
 
29
- namespace :version do
29
+ namespace :bump do
30
30
 
31
- namespace :bump do
32
-
33
- desc "Bumps major version number by 1"
34
- task :major do
35
- JumpStart::Setup.bump_version_major
36
- git_actions
37
- rubygems_actions
38
- end
31
+ desc "Bumps major version number by 1"
32
+ task :major do
33
+ JumpStart.bump_version_major
34
+ git_actions
35
+ rubygems_actions
36
+ end
39
37
 
40
- desc "Bumps minor version number by 1"
41
- task :minor do
42
- JumpStart::Setup.bump_version_minor
43
- git_actions
44
- rubygems_actions
45
- end
38
+ desc "Bumps minor version number by 1"
39
+ task :minor do
40
+ JumpStart.bump_version_minor
41
+ git_actions
42
+ rubygems_actions
43
+ end
46
44
 
47
- desc "Bumps patch version number by 1"
48
- task :patch do
49
- JumpStart::Setup.bump_version_patch
50
- git_actions
51
- rubygems_actions
52
- end
53
-
45
+ desc "Bumps patch version number by 1"
46
+ task :patch do
47
+ JumpStart.bump_version_patch
48
+ git_actions
49
+ rubygems_actions
54
50
  end
55
51
 
56
52
  end
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  :jumpstart_templates_path:
3
- :jumpstart_default_template_name:
3
+ :jumpstart_default_template_name:
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :jumpstart_version_major: 0
3
- :jumpstart_version_minor: 1
4
- :jumpstart_version_patch: 19
3
+ :jumpstart_version_minor: 2
4
+ :jumpstart_version_patch: 0
@@ -23,14 +23,85 @@ module JumpStart
23
23
  IGNORE_DIRS = ['.','..']
24
24
  LAUNCH_PATH = FileUtils.pwd
25
25
 
26
- require 'jumpstart/setup'
27
26
  require 'jumpstart/base'
28
27
  require 'jumpstart/filetools'
29
28
  require 'jumpstart/stringtools'
30
29
 
31
- # Looks up the current version of JumpStart
32
- def self.version
33
- "#{JumpStart::Setup.version_major}.#{JumpStart::Setup.version_minor}.#{JumpStart::Setup.version_patch}"
30
+ @jumpstart_setup_yaml = YAML.load_file("#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml")
31
+ @jumpstart_version_yaml = YAML.load_file("#{JumpStart::CONFIG_PATH}/jumpstart_version.yml")
32
+
33
+ @version_major = @jumpstart_version_yaml[:jumpstart_version_major]
34
+ @version_minor = @jumpstart_version_yaml[:jumpstart_version_minor]
35
+ @version_patch = @jumpstart_version_yaml[:jumpstart_version_patch]
36
+
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
+ class << self
46
+
47
+ attr_accessor :default_template_name, :version_major, :version_minor, :version_patch
48
+
49
+ # Set the jumpstart templates path back to default if it has not been set
50
+ def templates_path
51
+ if @templates_path.nil? || @templates_path.empty?
52
+ @templates_path = "#{JumpStart::ROOT_PATH}/jumpstart_templates"
53
+ else
54
+ @templates_path
55
+ end
56
+ end
57
+
58
+ def templates_path=(value)
59
+ @templates_path = value
60
+ end
61
+
62
+ # Method for writing to config/jumpstart_setup.yml
63
+ def dump_jumpstart_setup_yaml
64
+ File.open( "#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml", 'w' ) do |out|
65
+ YAML.dump( {:jumpstart_templates_path => @templates_path, :jumpstart_default_template_name => @default_template_name}, out )
66
+ end
67
+ end
68
+
69
+ # Method for writing to config/jumpstart_version.yml
70
+ def dump_jumpstart_version_yaml
71
+ File.open( "#{JumpStart::CONFIG_PATH}/jumpstart_version.yml", 'w' ) do |out|
72
+ YAML.dump( {:jumpstart_version_major => @version_major, :jumpstart_version_minor => @version_minor, :jumpstart_version_patch => @version_patch}, out )
73
+ end
74
+ end
75
+
76
+ # Method for bumping version number types.
77
+ # Resets @version_minor and @version_patch to 0 if bumping @version_major.
78
+ # Resets @version_pacth to 0 if bumping @version_minor
79
+ def bump(version_type)
80
+ value = instance_variable_get("@#{version_type}")
81
+ instance_variable_set("@#{version_type}", (value + 1))
82
+ if version_type == "version_major"
83
+ @version_minor, @version_patch = 0, 0
84
+ elsif version_type == "version_minor"
85
+ @version_patch = 0
86
+ end
87
+ dump_jumpstart_version_yaml
88
+ end
89
+
90
+ # Handles calls to JumpStart::Setup.bump_version_major, JumpStart::Setup.bump_version_minor and JumpStart::Setup.bump_version_patch class methods.
91
+ def method_missing(method, *args)
92
+ if method.to_s.match(/bump_version_(major|minor|patch)/)
93
+ version_type = method.to_s.sub('bump_', '')
94
+ self.send(:bump, "#{version_type}")
95
+ else
96
+ super
97
+ end
98
+ end
99
+
100
+ # Looks up the current version of JumpStart
101
+ def version
102
+ "#{version_major}.#{version_minor}.#{version_patch}"
103
+ end
104
+
34
105
  end
35
106
 
36
107
  end
@@ -20,18 +20,18 @@ module JumpStart
20
20
  @input = $stdin
21
21
  # setup for testing output
22
22
  @output = $stdout
23
- # set the name of the project from the first argument passed, or from the module instance variable JumpStart::Setup.default_template_name if no argument passed.
23
+ # set the name of the project from the first argument passed, or from the module instance variable JumpStart.default_template_name if no argument passed.
24
24
  @project_name = args[0].dup unless args[0].nil?
25
25
  @template_name = args[1].dup unless args[1].nil?
26
26
  case
27
27
  when args.nil?
28
- @template_name = JumpStart::Setup.default_template_name unless JumpStart::Setup.default_template_name.nil?
28
+ @template_name = JumpStart.default_template_name unless JumpStart.default_template_name.nil?
29
29
  jumpstart_menu
30
- when args[0] != nil && args[1].nil?
31
- @template_name = JumpStart::Setup.default_template_name unless JumpStart::Setup.default_template_name.nil?
30
+ when !args[0].nil? && args[1].nil?
31
+ @template_name = JumpStart.default_template_name unless JumpStart.default_template_name.nil?
32
32
  end
33
33
  # set instance variable @template_path as the directory to read templates from.
34
- @template_path = FileUtils.join_paths(JumpStart::Setup.templates_path, @template_name)
34
+ @template_path = FileUtils.join_paths(JumpStart.templates_path, @template_name)
35
35
  end
36
36
 
37
37
  # Sets up instance variables from YAML file
@@ -62,11 +62,11 @@ module JumpStart
62
62
  # set up instance variable containing an array that will be populated with existing jumpstart templates
63
63
  def lookup_existing_templates
64
64
  @existing_templates = []
65
- template_dirs = Dir.entries(JumpStart::Setup.templates_path) - IGNORE_DIRS
65
+ template_dirs = Dir.entries(JumpStart.templates_path) - IGNORE_DIRS
66
66
  template_dirs.each do |x|
67
- if File.directory?(FileUtils.join_paths(JumpStart::Setup.templates_path, x))
68
- if Dir.entries(FileUtils.join_paths(JumpStart::Setup.templates_path, x)).include? "jumpstart_config"
69
- if File.exists?(FileUtils.join_paths(JumpStart::Setup.templates_path, x, '/jumpstart_config/', "#{x}.yml"))
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
70
  @existing_templates << x
71
71
  end
72
72
  end
@@ -158,13 +158,13 @@ module JumpStart
158
158
 
159
159
  # Creates a new blank template in whichever directory the default templates directory has been set to.
160
160
  def create_template
161
- if File.directory?(FileUtils.join_paths(JumpStart::Setup.templates_path, @template_name))
162
- puts "\nThe directory #{FileUtils.join_paths(JumpStart::Setup.templates_path, @template_name).red} already exists. The template will not be created."
161
+ if File.directory?(FileUtils.join_paths(JumpStart.templates_path, @template_name))
162
+ puts "\nThe directory #{FileUtils.join_paths(JumpStart.templates_path, @template_name).red} already exists. The template will not be created."
163
163
  exit_normal
164
164
  else
165
- FileUtils.mkdir_p(FileUtils.join_paths(JumpStart::Setup.templates_path, @template_name, "/jumpstart_config"))
165
+ FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, @template_name, "/jumpstart_config"))
166
166
  yaml = IO.read(FileUtils.join_paths(ROOT_PATH, "/source_templates/template_config.yml"))
167
- File.open(FileUtils.join_paths(JumpStart::Setup.templates_path, @template_name, "/jumpstart_config", "#{@template_name}.yml"), 'w') do |file|
167
+ File.open(FileUtils.join_paths(JumpStart.templates_path, @template_name, "/jumpstart_config", "#{@template_name}.yml"), 'w') do |file|
168
168
  file.puts yaml
169
169
  end
170
170
  puts "The template #{@template_name.green} has been generated.\n"
@@ -272,9 +272,9 @@ module JumpStart
272
272
  puts " The template name ".red + input.red_bold + " begins with an invalid character. Please enter a name that begins with a letter or a number.".red
273
273
  new_template_options
274
274
  else
275
- FileUtils.mkdir_p(FileUtils.join_paths(JumpStart::Setup.templates_path, input, "jumpstart_config"))
276
- FileUtils.cp(FileUtils.join_paths(ROOT_PATH, "source_templates/template_config.yml"), FileUtils.join_paths(JumpStart::Setup.templates_path, input, "jumpstart_config", "#{input}.yml"))
277
- puts " The template ".green + input.green_bold + " has been created in your default jumpstart template directory ".green + JumpStart::Setup.templates_path.green_bold + " ready for editing.".green
275
+ FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config"))
276
+ FileUtils.cp(FileUtils.join_paths(ROOT_PATH, "source_templates/template_config.yml"), FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config", "#{input}.yml"))
277
+ puts " The template ".green + input.green_bold + " has been created in your default jumpstart template directory ".green + JumpStart.templates_path.green_bold + " ready for editing.".green
278
278
  jumpstart_menu
279
279
  end
280
280
  end
@@ -299,9 +299,9 @@ module JumpStart
299
299
  input = gets.chomp.strip
300
300
  case
301
301
  when input.to_i <= @existing_templates.count && input.to_i > 0
302
- JumpStart::Setup.default_template_name = @existing_templates[(input.to_i - 1)]
303
- JumpStart::Setup.dump_jumpstart_setup_yaml
304
- puts " The default jumpstart template has been set to: #{JumpStart::Setup.default_template_name.green}"
302
+ JumpStart.default_template_name = @existing_templates[(input.to_i - 1)]
303
+ JumpStart.dump_jumpstart_setup_yaml
304
+ puts " The default jumpstart template has been set to: #{JumpStart.default_template_name.green}"
305
305
  jumpstart_menu
306
306
  when input == "b"
307
307
  jumpstart_menu
@@ -358,12 +358,12 @@ module JumpStart
358
358
  begin
359
359
  Dir.chdir(root_path)
360
360
  Dir.mkdir(input)
361
- files_and_dirs = FileUtils.sort_contained_files_and_dirs(JumpStart::Setup.templates_path)
361
+ files_and_dirs = FileUtils.sort_contained_files_and_dirs(JumpStart.templates_path)
362
362
  puts "\nCopying existing templates to #{input}"
363
363
  files_and_dirs[:dirs].each {|x| FileUtils.mkdir_p(FileUtils.join_paths(input, x))}
364
- files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(JumpStart::Setup.templates_path, x), FileUtils.join_paths(input, x)) }
365
- JumpStart::Setup.templates_path = input.to_s
366
- JumpStart::Setup.dump_jumpstart_setup_yaml
364
+ files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(JumpStart.templates_path, x), FileUtils.join_paths(input, x)) }
365
+ JumpStart.templates_path = input.to_s
366
+ JumpStart.dump_jumpstart_setup_yaml
367
367
  puts "\nTransfer complete!".green
368
368
  jumpstart_menu
369
369
  rescue
@@ -374,12 +374,12 @@ module JumpStart
374
374
 
375
375
  # Checks to see if the JumpStart template directory should be reset to the default location. (within the gem.)
376
376
  def reset_templates_dir_to_default_check
377
- if JumpStart::Setup.templates_path == "#{ROOT_PATH}/jumpstart_templates"
377
+ if JumpStart.templates_path == "#{ROOT_PATH}/jumpstart_templates"
378
378
  puts " You do not need to reset the jumpstart templates directory, it is already set to: #{ROOT_PATH}/jumpstart_templates\n\n".red
379
379
  templates_dir_menu
380
380
  else
381
381
  puts " Resetting the jumpstart templates directory to the default: #{ROOT_PATH}/jumpstart_templates\n\n"
382
- @current_files_and_dirs = FileUtils.sort_contained_files_and_dirs(JumpStart::Setup.templates_path)
382
+ @current_files_and_dirs = FileUtils.sort_contained_files_and_dirs(JumpStart.templates_path)
383
383
  puts " Moving your jumpstart templates back to the default directory will delete any templates that are currently there. Proceed?\n".yellow
384
384
  puts " Type yes (" + "y".yellow + ") or no (" + "n".yellow + ")\n\n"
385
385
  reset_templates_dir_to_default_set
@@ -393,9 +393,9 @@ module JumpStart
393
393
  FileUtils.delete_dir_contents(FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates'))
394
394
  FileUtils.touch(FileUtils.join_paths(ROOT_PATH, '.gitignore'))
395
395
  @current_files_and_dirs[:dirs].each {|x| FileUtils.mkdir_p(FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates', x))}
396
- @current_files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(JumpStart::Setup.templates_path, x), FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates', x)) }
397
- JumpStart::Setup.templates_path = FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates')
398
- JumpStart::Setup.dump_jumpstart_setup_yaml
396
+ @current_files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(JumpStart.templates_path, x), FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates', x)) }
397
+ JumpStart.templates_path = FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates')
398
+ JumpStart.dump_jumpstart_setup_yaml
399
399
  puts "\n SUCCESS! the jumpstart templates directory has been set to the default: #{ROOT_PATH}/jumpstart_templates".green
400
400
  templates_dir_menu
401
401
  elsif input == "no" || input == "n"
@@ -541,7 +541,7 @@ module JumpStart
541
541
  puts "\n\n Exiting JumpStart...".purple
542
542
  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
543
543
  puts "******************************************************************************************************************************************\n"
544
- JumpStart::Setup.dump_jumpstart_setup_yaml
544
+ JumpStart.dump_jumpstart_setup_yaml
545
545
  exit
546
546
  end
547
547
 
@@ -550,7 +550,7 @@ module JumpStart
550
550
  puts "\n\n Exiting JumpStart...".purple
551
551
  puts "\n Goodbye!\n\n"
552
552
  puts "******************************************************************************************************************************************\n"
553
- JumpStart::Setup.dump_jumpstart_setup_yaml
553
+ JumpStart.dump_jumpstart_setup_yaml
554
554
  exit
555
555
  end
556
556
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  # The commands in a jumpstart config file are executed in the order displayed in this file.
3
3
 
4
+ ## Can be omitted or left blank. If :install_path: is omitted, the new project will be created in whatever directory you are in when you run the command.
4
5
  # The path to where the project directory will be created
5
6
  # e.g. :install_path: /Users/i0n/Sites
6
7
  :install_path:
@@ -9,6 +9,14 @@ require 'jumpstart'
9
9
 
10
10
  class Test::Unit::TestCase
11
11
 
12
+ def reset_global_defaults
13
+ JumpStart.module_eval do
14
+ @jumpstart_setup_yaml = YAML.load_file("#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml")
15
+ @jumpstart_version_yaml = YAML.load_file("#{JumpStart::CONFIG_PATH}/jumpstart_version.yml")
16
+ @templates_path = nil
17
+ end
18
+ end
19
+
12
20
  end
13
21
 
14
22
  module JumpStart
@@ -12,8 +12,8 @@ class TestJumpstartBase < Test::Unit::TestCase
12
12
  unless File.directory?("#{JumpStart::ROOT_PATH}/test/destination_dir")
13
13
  Dir.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir")
14
14
  end
15
- JumpStart::Setup.templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
16
- JumpStart::Setup.default_template_name = "test_template_1"
15
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
16
+ JumpStart.default_template_name = "test_template_1"
17
17
  input = StringIO.new
18
18
  output = StringIO.new
19
19
  @test_project = JumpStart::Base.new(["test_jumpstart_project"])
@@ -27,7 +27,7 @@ class TestJumpstartBase < Test::Unit::TestCase
27
27
  @test_project.stubs(:exit_with_success)
28
28
  end
29
29
 
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::Setup.default_template_name is valid and it falls back on this.
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
33
33
  setup do
@@ -107,11 +107,11 @@ class TestJumpstartBase < Test::Unit::TestCase
107
107
  context "Tests for the JumpStart::Base#intialize instance method. \n" do
108
108
 
109
109
  should "set @jumpstart_template_path" do
110
- assert_equal "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates", JumpStart::Setup.templates_path
110
+ assert_equal "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates", JumpStart.templates_path
111
111
  end
112
112
 
113
- should "set JumpStart::Setup.default_template_name" do
114
- assert_equal "test_template_1", @test_project.instance_eval {JumpStart::Setup.default_template_name}
113
+ should "set JumpStart.default_template_name" do
114
+ assert_equal "test_template_1", @test_project.instance_eval {JumpStart.default_template_name}
115
115
  end
116
116
 
117
117
  should "set @project_name" do
@@ -314,7 +314,7 @@ class TestJumpstartBase < Test::Unit::TestCase
314
314
  context "Tests for the JumpStart::Base#check_template_name instance method. \n" do
315
315
 
316
316
  should "launch jumpstart menu if nil" do
317
- JumpStart::Setup.default_template_name = nil
317
+ JumpStart.default_template_name = nil
318
318
  @test_project.instance_variable_set(:@template_name, nil)
319
319
  @test_project.stubs(:jumpstart_menu).returns("jumpstart_menu")
320
320
  @test_project.expects(:jumpstart_menu).once
@@ -322,7 +322,7 @@ class TestJumpstartBase < Test::Unit::TestCase
322
322
  end
323
323
 
324
324
  should "launch jumpstart menu if empty" do
325
- JumpStart::Setup.default_template_name = ""
325
+ JumpStart.default_template_name = ""
326
326
  @test_project.instance_variable_set(:@template_name, "")
327
327
  @test_project.stubs(:jumpstart_menu).returns("jumpstart_menu")
328
328
  @test_project.expects(:jumpstart_menu).once
@@ -366,16 +366,16 @@ class TestJumpstartBase < Test::Unit::TestCase
366
366
  context "Tests for the JumpStart::Base#create_template instance method. \n" do
367
367
 
368
368
  setup do
369
- JumpStart::Setup.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
369
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
370
370
  @test_project.instance_variable_set(:@template_name, "testing_create_template")
371
371
  end
372
372
 
373
- should "create a template direcotry named after @template_name in the JumpStart::Setup.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
373
+ 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
374
374
  @test_project.instance_eval {create_template}
375
375
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/testing_create_template/jumpstart_config/testing_create_template.yml")
376
376
  end
377
377
 
378
- should "give a message and exit if a directory with the same name as @template_name exists in the JumpStart::Setup.templates_path dir" do
378
+ should "give a message and exit if a directory with the same name as @template_name exists in the JumpStart.templates_path dir" do
379
379
  FileUtils.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir/testing_create_template")
380
380
  @test_project.expects(:exit_normal).once
381
381
  @test_project.instance_eval {create_template}
@@ -471,8 +471,8 @@ class TestJumpstartBase < Test::Unit::TestCase
471
471
 
472
472
  # 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.
473
473
  should "create a new project with the specified template name, checking that the project name is valid when a valid number is entered" do
474
- JumpStart::Setup.templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
475
- JumpStart::Setup.default_template_name = "test_template_1"
474
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
475
+ JumpStart.default_template_name = "test_template_1"
476
476
  @test_project.expects(:check_project_name).once
477
477
  @test_project.instance_variable_set(:@input, StringIO.new("1\n"))
478
478
  @test_project.instance_eval {new_project_from_template_options}
@@ -518,7 +518,7 @@ class TestJumpstartBase < Test::Unit::TestCase
518
518
  context "Tests for the JumpStart::Base#new_template_options instance method." do
519
519
 
520
520
  setup do
521
- JumpStart::Setup.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
521
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
522
522
  @test_project.stubs(:jumpstart_menu).returns("jumpstart_menu")
523
523
  @test_project.instance_variable_set(:@existing_templates, %w[one two three])
524
524
  end
@@ -568,31 +568,31 @@ class TestJumpstartBase < Test::Unit::TestCase
568
568
 
569
569
  setup do
570
570
  @test_project.stubs(:jumpstart_menu)
571
- JumpStart::Setup.stubs(:dump_jumpstart_setup_yaml)
571
+ JumpStart.stubs(:dump_jumpstart_setup_yaml)
572
572
  @test_project.instance_variable_set(:@existing_templates, %w[template1 template2 template3])
573
- JumpStart::Setup.default_template_name = "temp_default"
573
+ JumpStart.default_template_name = "temp_default"
574
574
  end
575
575
 
576
576
  should "set the default template if a number corresponding to an existing template is entered." do
577
577
  @test_project.instance_variable_set(:@input, StringIO.new("1\n"))
578
578
  @test_project.expects(:jumpstart_menu).once
579
- JumpStart::Setup.expects(:dump_jumpstart_setup_yaml).once
579
+ JumpStart.expects(:dump_jumpstart_setup_yaml).once
580
580
  @test_project.instance_eval {set_default_template_options}
581
- assert_equal "template1", JumpStart::Setup.default_template_name
581
+ assert_equal "template1", JumpStart.default_template_name
582
582
  end
583
583
 
584
584
  should "go back to the main jumpstart menu if 'b' is entered." do
585
585
  @test_project.instance_variable_set(:@input, StringIO.new("b\n"))
586
586
  @test_project.expects(:jumpstart_menu).once
587
587
  @test_project.instance_eval {set_default_template_options}
588
- assert_equal "temp_default", JumpStart::Setup.default_template_name
588
+ assert_equal "temp_default", JumpStart.default_template_name
589
589
  end
590
590
 
591
591
  should "exit jumpstart if 'x' is entered" do
592
592
  @test_project.instance_variable_set(:@input, StringIO.new("x\n"))
593
593
  @test_project.expects(:exit_normal).once
594
594
  @test_project.instance_eval {set_default_template_options}
595
- assert_equal "temp_default", JumpStart::Setup.default_template_name
595
+ assert_equal "temp_default", JumpStart.default_template_name
596
596
  end
597
597
 
598
598
  # 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.
@@ -657,7 +657,7 @@ class TestJumpstartBase < Test::Unit::TestCase
657
657
  context "Tests for the JumpStart::Base#set_templates_dir instance method." do
658
658
 
659
659
  setup do
660
- JumpStart::Setup.stubs(:dump_jumpstart_setup_yaml)
660
+ JumpStart.stubs(:dump_jumpstart_setup_yaml)
661
661
  @test_project.stubs(:jumpstart_menu)
662
662
  end
663
663
 
@@ -667,9 +667,9 @@ class TestJumpstartBase < Test::Unit::TestCase
667
667
  assert_raises(NoMethodError) {@test_project.instance_eval {set_templates_dir}}
668
668
  end
669
669
 
670
- should "create a new directory and copy existing templates into it, then set JumpStart::Setup.templates_path to the new location." do
670
+ should "create a new directory and copy existing templates into it, then set JumpStart.templates_path to the new location." do
671
671
  @test_project.instance_variable_set(:@input, StringIO.new("#{JumpStart::ROOT_PATH}/test/destination_dir/a_name_that_does_not_exist"))
672
- JumpStart::Setup.expects(:dump_jumpstart_setup_yaml).once
672
+ JumpStart.expects(:dump_jumpstart_setup_yaml).once
673
673
  @test_project.expects(:jumpstart_menu).once
674
674
  @test_project.instance_eval {set_templates_dir}
675
675
  assert_equal "Please enter the absolute path for the directory that you would like to contain your jumpstart templates.\n\nCopying existing templates to /Users/i0n/Sites/jumpstart/test/destination_dir/a_name_that_does_not_exist\n\e[32m\nTransfer complete!\e[0m\n", @test_project.output.string
@@ -685,15 +685,15 @@ class TestJumpstartBase < Test::Unit::TestCase
685
685
  @test_project.stubs(:reset_templates_dir_to_default_set)
686
686
  end
687
687
 
688
- should "output a message and run templates_dir_menu if JumpStart::Setup.templates_path is set to it's standard starting position." do
689
- JumpStart::Setup.templates_path = "#{JumpStart::ROOT_PATH}/jumpstart_templates"
688
+ should "output a message and run templates_dir_menu if JumpStart.templates_path is set to it's standard starting position." do
689
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/jumpstart_templates"
690
690
  @test_project.expects(:templates_dir_menu).once
691
691
  @test_project.instance_eval {reset_templates_dir_to_default_check}
692
692
  assert_equal "\e[31m You do not need to reset the jumpstart templates directory, it is already set to: /Users/i0n/Sites/jumpstart/jumpstart_templates\n\n\e[0m\n", @test_project.output.string
693
693
  end
694
694
 
695
- should "run reset_templates_dir_to_default_set if the current JumpStart::Setup.templates_path is not the default." do
696
- JumpStart::Setup.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
695
+ should "run reset_templates_dir_to_default_set if the current JumpStart.templates_path is not the default." do
696
+ JumpStart.templates_path = "#{JumpStart::ROOT_PATH}/test/destination_dir"
697
697
  @test_project.expects(:reset_templates_dir_to_default_set).once
698
698
  @test_project.instance_eval {reset_templates_dir_to_default_check}
699
699
  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
@@ -704,12 +704,12 @@ class TestJumpstartBase < Test::Unit::TestCase
704
704
  context "Tests for the JumpStart::Base#reset_templates_dir_to_default_set instance method." do
705
705
 
706
706
  setup do
707
- JumpStart::Setup.stubs(:dump_jumpstart_setup_yaml)
707
+ JumpStart.stubs(:dump_jumpstart_setup_yaml)
708
708
  @test_project.stubs(:templates_dir_menu)
709
709
  FileUtils.mkdir("#{JumpStart::ROOT_PATH}/test/destination_dir/jumpstart_templates")
710
710
  @normal_root_path = JumpStart::ROOT_PATH.dup
711
711
  JumpStart::ROOT_PATH = "#{@normal_root_path}/test/destination_dir"
712
- JumpStart::Setup.templates_path = "#{@normal_root_path}/test/test_jumpstart_templates/test_base"
712
+ JumpStart.templates_path = "#{@normal_root_path}/test/test_jumpstart_templates/test_base"
713
713
  @test_project.instance_variable_set(:@current_files_and_dirs, {:files => ['current_files_and_dirs_test_file.txt'], :dirs => ['current_files_and_dirs_test_dir']})
714
714
  end
715
715
 
@@ -12,126 +12,113 @@ class TestJumpstart < Test::Unit::TestCase
12
12
 
13
13
  context "Test for JumpStart.version class instance method" do
14
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
15
+ JumpStart.version_major = 1
16
+ JumpStart.version_minor = 1
17
+ JumpStart.version_patch = 1
18
18
  assert_equal "1.1.1", JumpStart.version
19
19
  end
20
20
  end
21
21
 
22
- # TODO not sure why but shoulda/test-unit/mocha is loading things in a strange order which is messing up class_eval. Look to split tests for this area into seperate files to try and solve this problem.
23
- context "Tests for launching JumpStart with various configurations set" do
22
+ context "Tests for the JumpStart::Base#templates_path class method" do
24
23
 
25
- context "JumpStart::Setup.templates_path and JumpStart::Setup.default_template_name are both set to nil as @jumpstart_setup_yaml is not loaded" do
26
-
27
- setup do
28
- JumpStart::Setup.class_eval {@jumpstart_setup_yaml = nil}
29
- @project.stubs(:jumpstart_menu)
30
- end
31
-
32
- should "launch menu when passed nil. JumpStart::Setup.templates_path should be set to default." do
33
- @project = JumpStart::Base.new([nil])
34
- @project.expects(:jumpstart_menu).once
35
- @project.set_config_file_options
36
- assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.class_eval {@templates_path}
37
- assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
38
- assert_equal nil, @project.instance_eval {@template_name}
39
- end
24
+ should "return default path if @templates_path is nil when called" do
25
+ JumpStart.module_eval {@templates_path = nil}
26
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart.templates_path
27
+ end
40
28
 
41
- should "launch menu when passed empty. JumpStart::Setup.templates_path should be set to default." do
42
- @project = JumpStart::Base.new([""])
43
- @project.expects(:jumpstart_menu).once
44
- @project.set_config_file_options
45
- assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.class_eval {@templates_path}
46
- assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
47
- assert_equal nil, @project.instance_eval {@template_name}
48
- end
29
+ should "return default path if @templates_path is empty when called" do
30
+ JumpStart.module_eval {@templates_path = ""}
31
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart.templates_path
32
+ end
33
+
34
+ should "return the path set" do
35
+ JumpStart.module_eval {@templates_path = "a/path/for/templates"}
36
+ assert_equal "a/path/for/templates", JumpStart.templates_path
37
+ end
38
+
39
+ end
40
+
41
+ context "Tests for the JumpStart#dump_jumpstart_setup_yaml class method." do
42
+ should "call File.open and Yaml.dump for jumpstart_setup.yml" do
43
+ YAML.stubs(:dump)
44
+ File.stubs(:open)
45
+ File.expects(:open).once
46
+ JumpStart.dump_jumpstart_setup_yaml
47
+ end
48
+ end
49
49
 
50
- should "launch menu when passed one argument under 3 characters. JumpStart::Setup.templates_path should be set to default." do
51
- @project = JumpStart::Base.new(["no"])
52
- @project.expects(:jumpstart_menu).once
53
- @project.set_config_file_options
54
- assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.class_eval {@templates_path}
55
- assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
56
- assert_equal nil, @project.instance_eval {@template_name}
57
- end
50
+ context "Tests for the JumpStart#dump_jumpstart_version_yaml class method." do
51
+ should "call File.open and Yaml.dump for jumpstart_version.yml" do
52
+ YAML.stubs(:dump)
53
+ File.stubs(:open)
54
+ File.expects(:open).once
55
+ JumpStart.dump_jumpstart_version_yaml
56
+ end
57
+ end
58
58
 
59
- 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
60
- @project = JumpStart::Base.new(["$hello"])
61
- @project.expects(:jumpstart_menu).once
62
- @project.set_config_file_options
63
- assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.class_eval {@templates_path}
64
- assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
65
- assert_equal nil, @project.instance_eval {@template_name}
66
- end
59
+ context "Tests for the JumpStart#bump class method." do
60
+
61
+ setup do
62
+ JumpStart.stubs(:dump_jumpstart_version_yaml)
63
+ end
64
+
65
+ should "add 1 to @version_major class instance variable, set @version_minor and @version_patch to 0 and call dump_jumpstart_version_yaml" do
66
+ JumpStart.module_eval {@version_major = 1; @version_minor = 1; @version_patch = 1 }
67
+ JumpStart.expects(:dump_jumpstart_version_yaml).once
68
+ JumpStart.bump("version_major")
69
+ assert_equal 2, JumpStart.version_major
70
+ assert_equal 0, JumpStart.version_minor
71
+ assert_equal 0, JumpStart.version_patch
72
+ end
73
+
74
+ should "add 1 to @version_minor class instance variable, set @version_patch to 0 and call dump_jumpstart_version_yaml" do
75
+ JumpStart.module_eval {@version_major = 1; @version_minor = 1; @version_patch = 1 }
76
+ JumpStart.expects(:dump_jumpstart_version_yaml).once
77
+ JumpStart.bump("version_minor")
78
+ assert_equal 1, JumpStart.version_major
79
+ assert_equal 2, JumpStart.version_minor
80
+ assert_equal 0, JumpStart.version_patch
67
81
 
68
- should "launch menu when passed a valid first argument. JumpStart::Setup.templates_path should be set to default." do
69
- @project = JumpStart::Base.new(["hello"])
70
- @project.expects(:jumpstart_menu).once
71
- @project.set_config_file_options
72
- assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart::Setup.class_eval {@templates_path}
73
- assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
74
- assert_equal nil, @project.instance_eval {@template_name}
75
- end
76
-
77
82
  end
78
83
 
79
- context "JumpStart::Setup.templates_path is set to and JumpStart::Setup.default_template_name is nil as @jumpstart_setup_yaml is not loaded" do
80
-
81
- setup do
82
- JumpStart::Setup.class_eval {@templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"}
83
- end
84
-
85
- 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
86
- # From the prompt this method would repeat until a valid project name was entered.
87
- @project = JumpStart::Base.new(["no", "test_template_1"])
88
- @project.stubs(:jumpstart_menu)
89
- @project.expects(:check_template_name)
90
- @project.expects(:check_project_name)
91
- @project.check_setup
92
- end
84
+ should "add 1 to @version_patch class instance variable and call dump_jumpstart_version_yaml" do
85
+ JumpStart.module_eval {@version_major = 1; @version_minor = 1; @version_patch = 1 }
86
+ JumpStart.expects(:dump_jumpstart_version_yaml).once
87
+ JumpStart.bump("version_patch")
88
+ assert_equal 1, JumpStart.version_major
89
+ assert_equal 1, JumpStart.version_minor
90
+ assert_equal 2, JumpStart.version_patch
93
91
 
94
- 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
95
- # From the prompt this method would repeat until a valid project name was entered.
96
- @project = JumpStart::Base.new(["no", "this_template_does_not_exist"])
97
- @project.stubs(:jumpstart_menu)
98
- @project.expects(:check_template_name)
99
- @project.expects(:check_project_name)
100
- @project.check_setup
101
- end
92
+ end
93
+
94
+ end
95
+
96
+ context "Tests for the JumpStart#method_missing class method." do
97
+
98
+ setup do
99
+ JumpStart.stubs(:bump).returns(:result)
100
+ JumpStart.stubs(:dump_jumpstart_version_yaml)
101
+ end
102
+
103
+ should "recognise JumpStart#bump_version_major class instance method calls and forward them to JumpStart#bump to set @version_major." do
104
+ JumpStart.expects(:bump).with("version_major").once
105
+ JumpStart.bump_version_major
106
+ end
102
107
 
103
- 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
104
- # From the prompt this method would repeat until a valid project name was entered.
105
- @project = JumpStart::Base.new(["$hello", "test_template_1"])
106
- @project.stubs(:jumpstart_menu)
107
- @project.expects(:check_template_name)
108
- @project.expects(:check_project_name)
109
- @project.check_setup
110
- end
108
+ should "recognise JumpStart#bump_version_minor class instance method calls and forward them to JumpStart#bump to set @version_minor." do
109
+ JumpStart.expects(:bump).with("version_minor").once
110
+ JumpStart.bump_version_minor
111
+ end
111
112
 
112
- 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
113
- # From the prompt this method would repeat until a valid project name was entered.
114
- @project = JumpStart::Base.new(["$hello", "this_template_does_not_exist"])
115
- @project.stubs(:jumpstart_menu)
116
- @project.expects(:check_template_name)
117
- @project.expects(:check_project_name)
118
- @project.check_setup
119
- end
113
+ should "recognise JumpStart#bump_version_patch class instance method calls and forward them to JumpStart#bump to set @version_patch." do
114
+ JumpStart.expects(:bump).with("version_patch").once
115
+ JumpStart.bump_version_patch
116
+ end
120
117
 
121
- 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
122
- @project = JumpStart::Base.new(["hello", "test_template_1"])
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
- @project.check_setup
132
- end
133
-
118
+ should "return method_missing to super as normal if method name is not recognised." do
119
+ assert_raises(NoMethodError) {JumpStart.bump_version_blarg}
134
120
  end
135
-
136
- end
121
+
122
+ end
123
+
137
124
  end
@@ -0,0 +1,69 @@
1
+ require 'helper'
2
+
3
+ class TestJumpStartWithDefaultTemplateSet < Test::Unit::TestCase
4
+
5
+ context "JumpStart::Setup.templates_path is set to and JumpStart::Setup.default_template_name is nil as @jumpstart_setup_yaml is not loaded" do
6
+
7
+ setup do
8
+ JumpStart.module_eval do
9
+ @jumpstart_setup_yaml = nil
10
+ @templates_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates"
11
+ end
12
+ end
13
+
14
+ teardown do
15
+ reset_global_defaults
16
+ end
17
+
18
+ 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
19
+ # From the prompt this method would repeat until a valid project name was entered.
20
+ @project = JumpStart::Base.new(["no", "test_template_1"])
21
+ @project.stubs(:jumpstart_menu)
22
+ @project.expects(:check_template_name)
23
+ @project.expects(:check_project_name)
24
+ @project.check_setup
25
+ end
26
+
27
+ 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
28
+ # From the prompt this method would repeat until a valid project name was entered.
29
+ @project = JumpStart::Base.new(["no", "this_template_does_not_exist"])
30
+ @project.stubs(:jumpstart_menu)
31
+ @project.expects(:check_template_name)
32
+ @project.expects(:check_project_name)
33
+ @project.check_setup
34
+ end
35
+
36
+ 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
37
+ # From the prompt this method would repeat until a valid project name was entered.
38
+ @project = JumpStart::Base.new(["$hello", "test_template_1"])
39
+ @project.stubs(:jumpstart_menu)
40
+ @project.expects(:check_template_name)
41
+ @project.expects(:check_project_name)
42
+ @project.check_setup
43
+ end
44
+
45
+ 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
46
+ # From the prompt this method would repeat until a valid project name was entered.
47
+ @project = JumpStart::Base.new(["$hello", "this_template_does_not_exist"])
48
+ @project.stubs(:jumpstart_menu)
49
+ @project.expects(:check_template_name)
50
+ @project.expects(:check_project_name)
51
+ @project.check_setup
52
+ end
53
+
54
+ 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
55
+ @project = JumpStart::Base.new(["hello", "test_template_1"])
56
+ @project.stubs(:jumpstart_menu)
57
+ @project.expects(:set_config_file_options)
58
+ @project.expects(:lookup_existing_templates)
59
+ @project.expects(:check_project_name)
60
+ @project.expects(:check_template_name)
61
+ @project.expects(:check_template_path)
62
+ @project.expects(:check_install_path)
63
+ @project.expects(:jumpstart_menu).never
64
+ @project.check_setup
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,63 @@
1
+ require 'helper'
2
+
3
+ class TestJumpStartWithNoGlobalDefaults < Test::Unit::TestCase
4
+
5
+ context "JumpStart::Setup.templates_path and JumpStart::Setup.default_template_name are both set to nil as @jumpstart_setup_yaml is not loaded" do
6
+
7
+ setup do
8
+ JumpStart.module_eval {@jumpstart_setup_yaml = nil}
9
+ @project.stubs(:jumpstart_menu)
10
+ end
11
+
12
+ teardown do
13
+ reset_global_defaults
14
+ end
15
+
16
+ should "launch menu when passed nil. JumpStart::Setup.templates_path should be set to default." do
17
+ @project = JumpStart::Base.new([nil])
18
+ @project.expects(:jumpstart_menu).once
19
+ @project.set_config_file_options
20
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart.module_eval {@templates_path}
21
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
22
+ assert_equal nil, @project.instance_eval {@template_name}
23
+ end
24
+
25
+ should "launch menu when passed empty. JumpStart::Setup.templates_path should be set to default." do
26
+ @project = JumpStart::Base.new([""])
27
+ @project.expects(:jumpstart_menu).once
28
+ @project.set_config_file_options
29
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart.module_eval {@templates_path}
30
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
31
+ assert_equal nil, @project.instance_eval {@template_name}
32
+ end
33
+
34
+ should "launch menu when passed one argument under 3 characters. JumpStart::Setup.templates_path should be set to default." do
35
+ @project = JumpStart::Base.new(["no"])
36
+ @project.expects(:jumpstart_menu).once
37
+ @project.set_config_file_options
38
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart.module_eval {@templates_path}
39
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
40
+ assert_equal nil, @project.instance_eval {@template_name}
41
+ end
42
+
43
+ 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
44
+ @project = JumpStart::Base.new(["$hello"])
45
+ @project.expects(:jumpstart_menu).once
46
+ @project.set_config_file_options
47
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart.module_eval {@templates_path}
48
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
49
+ assert_equal nil, @project.instance_eval {@template_name}
50
+ end
51
+
52
+ should "launch menu when passed a valid first argument. JumpStart::Setup.templates_path should be set to default." do
53
+ @project = JumpStart::Base.new(["hello"])
54
+ @project.expects(:jumpstart_menu).once
55
+ @project.set_config_file_options
56
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", JumpStart.module_eval {@templates_path}
57
+ assert_equal "#{JumpStart::ROOT_PATH}/jumpstart_templates", @project.instance_variable_get(:@template_path)
58
+ assert_equal nil, @project.instance_eval {@template_name}
59
+ end
60
+
61
+ end
62
+
63
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 19
9
- version: 0.1.19
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ian Alexander Wood (i0n)
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-29 00:00:00 +01:00
17
+ date: 2010-05-30 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -61,7 +61,6 @@ files:
61
61
  - jumpstart_templates/empty_template/jumpstart_config/empty_template.yml
62
62
  - lib/jumpstart/base.rb
63
63
  - lib/jumpstart/filetools.rb
64
- - lib/jumpstart/setup.rb
65
64
  - lib/jumpstart/stringtools.rb
66
65
  - lib/jumpstart.rb
67
66
  - source_templates/template_config.yml
@@ -70,7 +69,6 @@ files:
70
69
  - test/helper.rb
71
70
  - test/jumpstart/test_base.rb
72
71
  - test/jumpstart/test_filetools.rb
73
- - test/jumpstart/test_setup.rb
74
72
  - test/jumpstart/test_stringutils.rb
75
73
  - test/test_jumpstart.rb
76
74
  - test/test_jumpstart_templates/test_base/_._test_file.txt
@@ -135,6 +133,8 @@ files:
135
133
  - test/test_jumpstart_templates/test_template_1/test_whole_file_without_extension
136
134
  - test/test_jumpstart_templates/test_template_2/jumpstart_config/test_template_2.yml
137
135
  - test/test_jumpstart_templates/test_template_3/jumpstart_config/test_template_3.yml
136
+ - test/test_jumpstart_with_default_template_set.rb
137
+ - test/test_jumpstart_with_no_global_defaults.rb
138
138
  - LICENSE
139
139
  - Rakefile
140
140
  - README.rdoc
@@ -1,75 +0,0 @@
1
- module JumpStart
2
- class Setup
3
-
4
- class << self
5
- attr_accessor :default_template_name, :version_major, :version_minor, :version_patch
6
- end
7
-
8
- @jumpstart_setup_yaml = YAML.load_file("#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml")
9
- @jumpstart_version_yaml = YAML.load_file("#{JumpStart::CONFIG_PATH}/jumpstart_version.yml")
10
-
11
- @version_major = @jumpstart_version_yaml[:jumpstart_version_major]
12
- @version_minor = @jumpstart_version_yaml[:jumpstart_version_minor]
13
- @version_patch = @jumpstart_version_yaml[:jumpstart_version_patch]
14
-
15
- @templates_path = @jumpstart_setup_yaml[:jumpstart_templates_path]
16
- # The path to the jumpstart templates directory.
17
- # Set as a module instance variable.
18
- def self.templates_path
19
- if @templates_path.nil? || @templates_path.empty?
20
- @templates_path = "#{JumpStart::ROOT_PATH}/jumpstart_templates"
21
- else
22
- @templates_path
23
- end
24
- end
25
-
26
- def self.templates_path=(value)
27
- @templates_path = value
28
- end
29
-
30
- # sets the default template to use if it has not been passed as an argument.
31
- # Set as a module instance variable.
32
- @default_template_name = @jumpstart_setup_yaml[:jumpstart_default_template_name]
33
-
34
- # Set the jumpstart templates path back to default if it has not been set
35
-
36
- # Method for writing to config/jumpstart_setup.yml
37
- def self.dump_jumpstart_setup_yaml
38
- File.open( "#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml", 'w' ) do |out|
39
- YAML.dump( {:jumpstart_templates_path => @templates_path, :jumpstart_default_template_name => @default_template_name}, out )
40
- end
41
- end
42
-
43
- # Method for writing to config/jumpstart_version.yml
44
- def self.dump_jumpstart_version_yaml
45
- File.open( "#{JumpStart::CONFIG_PATH}/jumpstart_version.yml", 'w' ) do |out|
46
- YAML.dump( {:jumpstart_version_major => @version_major, :jumpstart_version_minor => @version_minor, :jumpstart_version_patch => @version_patch}, out )
47
- end
48
- end
49
-
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
53
- def self.bump(version_type)
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
61
- dump_jumpstart_version_yaml
62
- end
63
-
64
- # Handles calls to JumpStart::Setup.bump_version_major, JumpStart::Setup.bump_version_minor and JumpStart::Setup.bump_version_patch class methods.
65
- def self.method_missing(method, *args)
66
- if method.to_s.match(/bump_version_(major|minor|patch)/)
67
- version_type = method.to_s.sub('bump_', '')
68
- self.send(:bump, "#{version_type}")
69
- else
70
- super
71
- end
72
- end
73
-
74
- end
75
- end
@@ -1,111 +0,0 @@
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