Skip to content
Browse files

+ Added Sow#make_sub_modules. (bhenderson)

+ Hoe.normalize_names now returns test class name separately. (bhenderson)
+ Sow now generates test and impl files with proper namespacing. (bhenderson)

[git-p4: depot-paths = "//src/hoe/dev/": change = 7966]
  • Loading branch information...
1 parent 74afa78 commit b2937f7df735710a0a1ffc6d2ec448a2d38d8645 @zenspider zenspider committed Nov 12, 2012
Showing with 41 additions and 21 deletions.
  1. +1 −1 Manifest.txt
  2. +20 −5 bin/sow
  3. +9 −6 lib/hoe.rb
  4. +1 −0 template/lib/file_name.rb.erb
  5. +2 −1 template/test/{test_file_name.rb.erb → file_name.rb.erb}
  6. +8 −8 test/test_hoe.rb
View
2 Manifest.txt
@@ -31,7 +31,7 @@ template/README.txt.erb
template/Rakefile.erb
template/bin/file_name.erb
template/lib/file_name.rb.erb
-template/test/test_file_name.rb.erb
+template/test/file_name.rb.erb
test/test_hoe.rb
test/test_hoe_debug.rb
test/test_hoe_gemcutter.rb
View
25 bin/sow
@@ -20,6 +20,16 @@ def check_subdir option
end
end
+def make_sub_modules klass
+ last = nil
+ result = ''
+ klass.split('::')[0..-2].each do |part|
+ last = [last, part].compact.join('::')
+ result << "module #{last}; end\n"
+ end
+ result << "\n" unless result.empty?
+end
+
op = OptionParser.new do |opts|
opts.banner = "Usage: sow [options] project_name"
@@ -79,7 +89,7 @@ project = ARGV.shift
abort op.to_s unless project
abort "Project #{project} seems to exist" if test ?d, project
-_, file_name, klass = Hoe.normalize_names project
+_, file_name, klass, test_klass = Hoe.normalize_names project
FileUtils.cp_r template_path, project
@@ -96,7 +106,7 @@ Dir.chdir project do
warn "erb: #{path}"
File.open path, "w" do |io|
- erb = ERB.new file
+ erb = ERB.new file, nil, '<>'
erb.filename = path
io.puts erb.result(binding)
end
@@ -105,12 +115,17 @@ Dir.chdir project do
paths.grep(/file_name|\.erb$/).each do |file|
new_file = file.sub(/file_name/, file_name).sub(/\.erb$/, '')
- # TODO change template to separate a flat filename from a directory
- # filename
- if file =~ /^(bin|test)/ then
+ case file
+ when /^bin/ then
dir, *rest = new_file.split File::SEPARATOR
new_file = File.join dir, rest.join('_')
+ when /^test/ then
+ dir, *rest = new_file.split File::SEPARATOR
+
+ rest.last.sub! /^/, 'test_'
+
+ new_file = File.join dir, *rest
end
FileUtils.mkdir_p File.dirname new_file
View
15 lib/hoe.rb
@@ -327,7 +327,7 @@ def self.load_plugins plugins = Hoe.plugins
end
##
- # Normalize a project name into the project, file, and klass names that
+ # Normalize a project name into the project, file, klass and test names that
# follow Ruby package naming guidelines.
#
# Project names are lowercase with _ separating package parts and -
@@ -337,14 +337,17 @@ def self.load_plugins plugins = Hoe.plugins
# extension parts. net-http-persistent becomes net/http/persistent.
#
# Klass names are CamelCase with :: separating extension parts.
+ #
+ # Test klass names are same as Klass with Test prepended to each part.
def self.normalize_names project # :nodoc:
- project = project.gsub(/([A-Z])/, '_\1').downcase.sub(/^_/, '')
- klass = project.gsub(/(?:^|_)([a-z])/) { $1.upcase }
- klass = klass. gsub(/(?:^|-)([a-z])/) { "::#{$1.upcase}" }
- file_name = project.gsub(/-/, '/')
+ project = project.gsub(/([A-Z])/, '_\1').downcase.sub(/^_/, '')
+ klass = project.gsub(/(?:^|_)([a-z])/) { $1.upcase }
+ klass = klass. gsub(/(?:^|-)([a-z])/) { "::#{$1.upcase}" }
+ test_klass = klass. gsub(/(^|::)([A-Z])/) { "#{$1}Test#{$2}" }
+ file_name = project.gsub(/-/, '/')
- return project, file_name, klass
+ return project, file_name, klass, test_klass
end
##
View
1 template/lib/file_name.rb.erb
@@ -1,3 +1,4 @@
+<%= make_sub_modules klass %>
class <%= klass %>
VERSION = '1.0.0'
end
View
3 template/test/test_file_name.rb.erb → template/test/file_name.rb.erb
@@ -1,7 +1,8 @@
require "test/unit"
require "<%= file_name %>"
-class Test<%= klass %> < Test::Unit::TestCase
+<%= make_sub_modules test_klass %>
+class <%= test_klass %> < Test::Unit::TestCase
def test_sanity
flunk "write tests or I will kneecap you"
end
View
16 test/test_hoe.rb
@@ -388,14 +388,14 @@ def test_read_manifest
end
def test_rename
- # project, file_name, klass = Hoe.normalize_names 'project_name'
-
- assert_equal %w( word word Word), Hoe.normalize_names('word')
- assert_equal %w( word word Word), Hoe.normalize_names('Word')
- assert_equal %w(two_words two_words TwoWords), Hoe.normalize_names('TwoWords')
- assert_equal %w(two_words two_words TwoWords), Hoe.normalize_names('twoWords')
- assert_equal %w(two-words two/words Two::Words), Hoe.normalize_names('two-words')
- assert_equal %w(two_words two_words TwoWords), Hoe.normalize_names('two_words')
+ # project, file_name, klass, test_klass = Hoe.normalize_names 'project_name'
+
+ assert_equal %w( word word Word TestWord), Hoe.normalize_names('word')
+ assert_equal %w( word word Word TestWord), Hoe.normalize_names('Word')
+ assert_equal %w(two_words two_words TwoWords TestTwoWords), Hoe.normalize_names('TwoWords')
+ assert_equal %w(two_words two_words TwoWords TestTwoWords), Hoe.normalize_names('twoWords')
+ assert_equal %w(two-words two/words Two::Words TestTwo::TestWords), Hoe.normalize_names('two-words')
+ assert_equal %w(two_words two_words TwoWords TestTwoWords), Hoe.normalize_names('two_words')
end
def test_nosudo

0 comments on commit b2937f7

Please sign in to comment.
Something went wrong with that request. Please try again.