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 +1 -1
- data/bin/sprout +7 -2
- data/lib/sprout/command_line.rb +33 -0
- data/lib/sprout/executable/base.rb +1 -2
- data/lib/sprout/generators/generator/generator_generator.rb +23 -4
- data/lib/sprout/generators/generator/templates/generator_class.rb +4 -1
- data/lib/sprout/generators/generator/templates/generator_executable +1 -3
- data/lib/sprout/generators/generator/templates/generator_gemfile +9 -0
- data/lib/sprout/generators/generator/templates/generator_test.rb +27 -4
- data/lib/sprout/generators/generator/templates/generator_test_helper.rb +9 -6
- data/lib/sprout/generators/ruby/ruby_generator.rb +1 -1
- data/lib/sprout/generators/ruby/templates/ruby_gemfile +1 -1
- data/lib/sprout/generators/ruby/templates/ruby_rakefile +6 -1
- data/lib/sprout/generators/ruby/templates/ruby_test_case.rb +2 -2
- data/lib/sprout/generators/ruby/templates/ruby_test_helper.rb +13 -2
- data/lib/sprout.rb +1 -0
- data/test/unit/command_line_test.rb +27 -0
- data/test/unit/executable_option_parser_test.rb +2 -2
- data/test/unit/generator_generator_test.rb +13 -0
- data/test/unit/ruby_generator_test.rb +4 -4
- data/test/unit/test_helper.rb +2 -1
- metadata +6 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.7.pre
|
data/bin/sprout
CHANGED
@@ -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
|
@@ -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.
|
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
|
-
#
|
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,33 +1,56 @@
|
|
1
|
-
require
|
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
|
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
|
45
|
+
input_dir = File.join @temp, "<%= input.snake_case %>"
|
27
46
|
assert_directory input_dir
|
28
47
|
|
29
|
-
input_file = File.join
|
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
|
-
|
14
|
-
$:.unshift
|
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
|
@@ -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
|
@@ -2,9 +2,20 @@ require "rubygems"
|
|
2
2
|
require "bundler"
|
3
3
|
Bundler.require :default, :development
|
4
4
|
|
5
|
-
|
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
@@ -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 :
|
46
|
-
assert_raises
|
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
|
-
|
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
|
data/test/unit/test_helper.rb
CHANGED
@@ -14,7 +14,8 @@ $:.unshift lib unless $:.include? lib
|
|
14
14
|
|
15
15
|
require 'sprout'
|
16
16
|
|
17
|
-
|
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
|
-
-
|
8
|
+
- 7
|
9
9
|
- pre
|
10
|
-
version: 1.1.
|
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:
|
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
|