sprout 1.1.5.pre → 1.1.7.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprout might be problematic. Click here for more details.

data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.5.pre
1
+ 1.1.7.pre
data/bin/sprout CHANGED
@@ -1,4 +1,9 @@
1
- #!/usr/bin/bash
1
+ #!/usr/bin/env ruby
2
2
 
3
- echo 'Type sprout- and then hit the tab key to see the new sprout binaries.'
3
+ require 'rubygems'
4
+ require 'sprout'
5
+
6
+ generator = Sprout::CommandLine.new
7
+ generator.parse! ARGV
8
+ generator.execute
4
9
 
@@ -0,0 +1,33 @@
1
+ module Sprout
2
+
3
+ class CommandLine < Sprout::Executable::Base
4
+
5
+ ##
6
+ # Get the version of the Sprout gem
7
+ add_param :version, Boolean, :default => false, :hidden_value => true
8
+
9
+ add_param_alias :v, :version
10
+
11
+ ##
12
+ # @return [IO] default $stdout, Replace value in test context.
13
+ attr_accessor :logger
14
+
15
+ def initialize
16
+ super
17
+ @logger = $stdout
18
+ end
19
+
20
+ def parse! options
21
+ if options.empty?
22
+ handle_parse_error Sprout::Errors::UsageError.new("At least one parameter is required.")
23
+ end
24
+ super
25
+ end
26
+
27
+ def execute
28
+ if version
29
+ logger.puts "sprout #{Sprout::VERSION::STRING}"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -503,8 +503,7 @@ module Sprout
503
503
 
504
504
  def add_help_param
505
505
  option_parser.on '--help', 'Display this help message' do
506
- puts option_parser.to_s
507
- exit
506
+ abort option_parser.to_s
508
507
  end
509
508
  end
510
509
 
@@ -47,8 +47,10 @@ module Sprout
47
47
  add_param :extension, String, { :default => '.as' }
48
48
 
49
49
  def manifest
50
+ massage_input
51
+
50
52
  directory bin do
51
- template "#{input.snake_case}", "generator_executable"
53
+ template "#{input.dash_case}", "generator_executable"
52
54
  end
53
55
 
54
56
  directory lib do
@@ -72,10 +74,27 @@ module Sprout
72
74
  directory "generators"
73
75
  end
74
76
  end
75
-
76
- #This should actually be moved to the library generator
77
- #directory vendor
78
77
 
78
+ if !File.exists? 'Gemfile'
79
+ template 'Gemfile', 'generator_gemfile'
80
+ else
81
+ say "[INFO] It seems you already have a Gemfile in this project, please be sure it has the following content:"
82
+ say ''
83
+ say ' gem "sprout", ">= #{Sprout::VERSION::STRING}"'
84
+ say ''
85
+ say ' group :development do'
86
+ say ' gem "shoulda"'
87
+ say ' gem "mocha"'
88
+ say ' end'
89
+ say ''
90
+ end
91
+ end
92
+
93
+ protected
94
+
95
+ def massage_input
96
+ self.input = input.gsub(/_generator$/, '')
97
+ self.input = input.gsub(/Generator$/, '')
79
98
  end
80
99
 
81
100
  end
@@ -1,11 +1,14 @@
1
1
 
2
2
  module Sprout
3
+ ##
4
+ # This is where you describe your new Generator.
3
5
  class <%= input.camel_case %>Generator < Generator::Base
4
6
 
5
7
  ##
6
8
  # This is how you add a parameter to your generator
7
9
  #
8
- # add_param :fwee, String, :default => "fwee"
10
+ # # @return [String] Say fwee!
11
+ # add_param :fwee, String, { :default => "fwee" }
9
12
  #
10
13
  def manifest
11
14
  directory input.snake_case do
@@ -1,9 +1,7 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  require 'rubygems'
4
2
  require 'sprout'
5
3
  require 'generators/<%= input.snake_case %>_generator'
6
4
 
7
5
  generator = <%= input.camel_case %>Generator.new
8
6
  generator.parse! ARGV
9
- generator.execute
7
+ generator.execute
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "sprout", ">= <%= Sprout::VERSION::STRING %>"
4
+
5
+ group :development do
6
+ gem "shoulda"
7
+ gem "mocha"
8
+ end
9
+
@@ -1,33 +1,56 @@
1
- require File.join(File.dirname(__FILE__), "test_helper")
1
+ require 'test_helper'
2
2
 
3
3
  require 'generators/<%= input.snake_case %>_generator'
4
4
 
5
5
  class <%= input.camel_case %>GeneratorTest < Test::Unit::TestCase
6
- include SproutTestCase
6
+ include Sprout::TestHelper
7
7
 
8
8
  context "A new <%= input.camel_case %> generator" do
9
9
 
10
10
  setup do
11
+ # Create a temporary directory the generator can
12
+ # add files to:
11
13
  @temp = File.join(fixtures, 'generators', 'tmp')
12
14
  FileUtils.mkdir_p @temp
15
+
16
+ # Instantiate the generator:
13
17
  @generator = Sprout::<%= input.camel_case %>Generator.new
18
+
19
+ # Tell the generator to use the new temp path:
14
20
  @generator.path = @temp
21
+
22
+ # Hide generator output from terminal:
23
+ # (uncomment to see output)
15
24
  @generator.logger = StringIO.new
16
25
  end
17
26
 
18
27
  teardown do
28
+ # Remove the temp directory after each test method:
19
29
  remove_file @temp
20
30
  end
21
31
 
32
+ # Run all test methods with:
33
+ #
34
+ # ruby -I test/unit test/unit/<%= input.snake_case %>_generator_test.rb
35
+ #
36
+ # Run just this test method with:
37
+ #
38
+ # ruby -I test/unit test/unit/<%= input.snake_case %>_generator_test.rb -n '/generate a new/'
39
+ #
22
40
  should "generate a new <%= input.camel_case %>" do
41
+ # provide example input:
23
42
  @generator.input = "<%= input.camel_case %>"
24
43
  @generator.execute
25
44
 
26
- input_dir = File.join(@temp, "<%= input.snake_case %>")
45
+ input_dir = File.join @temp, "<%= input.snake_case %>"
27
46
  assert_directory input_dir
28
47
 
29
- input_file = File.join(input_dir, "<%= input.camel_case %><%= extension %>")
48
+ input_file = File.join input_dir, "<%= input.camel_case %><%= extension %>"
49
+ # Custom Sprout::TestHelper assertion, optional block
50
+ # yields the file content as a String
30
51
  assert_file input_file do |content|
52
+ # Custom Sprout::TestHelper assertion, update the Regex
53
+ # with your expectation.
31
54
  assert_matches /Your content to assert here/, content
32
55
  end
33
56
  end
@@ -1,16 +1,19 @@
1
1
  require "rubygems"
2
2
  require "bundler"
3
+ Bundler.require :default, :development
3
4
 
4
- Bundler.setup :default, :development
5
-
6
- require 'sprout'
7
5
  # These require statments *must* be in this order:
8
6
  # http://bit.ly/bCC0Ew
9
7
  # Somewhat surprised they're not being required by Bundler...
10
8
  require 'shoulda'
11
9
  require 'mocha'
12
10
 
13
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
14
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..'))
11
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
12
+ $:.unshift lib unless $:.include? lib
13
+
14
+ test = File.expand_path(File.join(File.dirname(__FILE__), '..'))
15
+ $:.unshift test unless $:.include? test
16
+
17
+ require 'sprout'
18
+ require 'sprout/test_helper'
15
19
 
16
- require 'sprout/test/sprout_test_case'
@@ -50,8 +50,8 @@ module Sprout
50
50
  directory fixtures
51
51
  directory unit do
52
52
  template "#{input.snake_case}_test.rb", 'ruby_test_case.rb'
53
+ template 'test_helper.rb', 'ruby_test_helper.rb'
53
54
  end
54
- template 'test_helper.rb', 'ruby_test_helper.rb'
55
55
  end
56
56
 
57
57
  directory bin do
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gem 'sprout', '>= 1.0.0.pre'
3
+ gem 'sprout', '>= <%= Sprout::VERSION::STRING %>'
4
4
 
5
5
  group :development do
6
6
  gem 'rake'
@@ -4,9 +4,14 @@ Bundler.require
4
4
 
5
5
  require 'rake/testtask'
6
6
 
7
+ # Hack this dir onto path for Ruby 1.9.2
8
+ # support:
9
+ test_package = File.expand_path(File.join(File.dirname(__FILE__), 'test'))
10
+ $: << test_package unless $:.include? test_package
11
+
7
12
  namespace :test do
8
13
  Rake::TestTask.new(:units) do |t|
9
- t.libs << "test"
14
+ t.libs << "test/unit"
10
15
  t.test_files = FileList["test/unit/*_test.rb"]
11
16
  t.verbose = true
12
17
  end
@@ -1,7 +1,7 @@
1
- require File.join(File.dirname(__FILE__), '..', 'test_helper')
1
+ require 'test_helper'
2
2
 
3
3
  class <%= input.camel_case %>Test < Test::Unit::TestCase
4
- include SproutTestCase
4
+ include Sprout::TestHelper
5
5
 
6
6
  context "A <%= input.camel_case %>" do
7
7
 
@@ -2,9 +2,20 @@ require "rubygems"
2
2
  require "bundler"
3
3
  Bundler.require :default, :development
4
4
 
5
- lib = File.join(File.dirname(__FILE__), '..', 'lib')
5
+ # These require statments *must* be in this order:
6
+ # http://bit.ly/bCC0Ew
7
+ # Somewhat surprised they're not being required by Bundler...
8
+ require 'shoulda'
9
+ require 'mocha'
10
+
11
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
6
12
  $:.unshift lib unless $:.include? lib
7
13
 
14
+ test = File.expand_path(File.join(File.dirname(__FILE__), '..'))
15
+ $:.unshift test unless $:.include? test
16
+
17
+ require 'sprout'
18
+ require 'sprout/test_helper'
19
+
8
20
  require '<%= input.snake_case %>'
9
- require 'sprout/test/sprout_test_case'
10
21
 
data/lib/sprout.rb CHANGED
@@ -43,6 +43,7 @@ require 'sprout/rdoc_parser'
43
43
  require 'sprout/specification'
44
44
  require 'sprout/executable'
45
45
  require 'sprout/daemon'
46
+ require 'sprout/command_line'
46
47
 
47
48
  # Generators
48
49
  require 'sprout/generator'
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class CommandLineTest < Test::Unit::TestCase
4
+ include Sprout::TestHelper
5
+
6
+ context "a new command line ui" do
7
+
8
+ setup do
9
+ @logger = Sprout::OutputBuffer.new
10
+ @instance = Sprout::CommandLine.new
11
+ @instance.logger = @logger
12
+ end
13
+
14
+ should "display the version number" do
15
+ @instance.parse! ['--version']
16
+ @instance.execute
17
+ assert_matches /sprout #{Sprout::VERSION::STRING}/, @logger.read
18
+ end
19
+
20
+ should "display helper if no options provided" do
21
+ @instance.expects :abort
22
+ @instance.parse! []
23
+ end
24
+ end
25
+ end
26
+
27
+
@@ -42,8 +42,8 @@ class ExecutableOptionParserTest < Test::Unit::TestCase
42
42
  end
43
43
 
44
44
  should "always accept help option" do
45
- @exe.expects :puts
46
- assert_raises SystemExit do
45
+ @exe.expects :abort
46
+ assert_raises Sprout::Errors::MissingArgumentError do
47
47
  @exe.parse! [ '--help' ]
48
48
  end
49
49
  end
@@ -19,6 +19,19 @@ class GeneratorGeneratorTest < Test::Unit::TestCase
19
19
  remove_file @temp
20
20
  end
21
21
 
22
+ ['TestClassGenerator', 'test_class_generator', 'test_class', 'TestClass'].each do |input|
23
+
24
+ should "massage '#{input}' into appropriate value" do
25
+ @generator.input = "TestClassGenerator"
26
+ @generator.execute
27
+
28
+ test_file = File.join(@temp, 'test', 'unit', 'test_class_generator_test.rb')
29
+ assert_file test_file do |content|
30
+ assert_matches /TestClassGeneratorTest/, content
31
+ end
32
+ end
33
+ end
34
+
22
35
  should "generate a new generator" do
23
36
  @generator.input = 'fwee'
24
37
  @generator.execute
@@ -55,14 +55,14 @@ class RubyGeneratorTest < Test::Unit::TestCase
55
55
  test_dir = File.join project_dir, 'test'
56
56
  assert_file test_dir
57
57
 
58
- test_helper = File.join test_dir, 'test_helper.rb'
58
+ unit_dir = File.join test_dir, 'unit'
59
+ assert_file unit_dir
60
+
61
+ test_helper = File.join unit_dir, 'test_helper.rb'
59
62
  assert_file test_helper do |content|
60
63
  assert_matches /require 'some_project'/, content
61
64
  end
62
65
 
63
- unit_dir = File.join test_dir, 'unit'
64
- assert_file unit_dir
65
-
66
66
  test_case = File.join unit_dir, 'some_project_test.rb'
67
67
  assert_file test_case do |content|
68
68
  assert_matches /class SomeProjectTest/, content
@@ -14,7 +14,8 @@ $:.unshift lib unless $:.include? lib
14
14
 
15
15
  require 'sprout'
16
16
 
17
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..'))
17
+ test = File.expand_path(File.join(File.dirname(__FILE__), '..'))
18
+ $:.unshift test unless $:.include? test
18
19
 
19
20
  require 'unit/fake_process_runner'
20
21
  require 'unit/fake_executable_task'
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 5
8
+ - 7
9
9
  - pre
10
- version: 1.1.5.pre
10
+ version: 1.1.7.pre
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luke Bayes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-31 00:00:00 -08:00
18
+ date: 2011-01-03 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -209,6 +209,7 @@ files:
209
209
  - Gemfile
210
210
  - Gemfile.lock
211
211
  - lib/sprout/archive_unpacker.rb
212
+ - lib/sprout/command_line.rb
212
213
  - lib/sprout/concern.rb
213
214
  - lib/sprout/daemon.rb
214
215
  - lib/sprout/dir.rb
@@ -239,6 +240,7 @@ files:
239
240
  - lib/sprout/generators/generator/generator_generator.rb
240
241
  - lib/sprout/generators/generator/templates/generator_class.rb
241
242
  - lib/sprout/generators/generator/templates/generator_executable
243
+ - lib/sprout/generators/generator/templates/generator_gemfile
242
244
  - lib/sprout/generators/generator/templates/generator_template
243
245
  - lib/sprout/generators/generator/templates/generator_test.rb
244
246
  - lib/sprout/generators/generator/templates/generator_test_helper.rb
@@ -358,6 +360,7 @@ files:
358
360
  - test/fixtures/user/mxmlc_crlf
359
361
  - test/unit/archive_unpacker_test.rb
360
362
  - test/unit/boolean_param_test.rb
363
+ - test/unit/command_line_test.rb
361
364
  - test/unit/daemon_test.rb
362
365
  - test/unit/executable_option_parser_test.rb
363
366
  - test/unit/executable_param_test.rb