summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Davis <ryand@zenspider.com>2012-11-12 16:35:30 -0800
committerRyan Davis <ryand@zenspider.com>2012-11-12 16:35:30 -0800
commitb2937f7df735710a0a1ffc6d2ec448a2d38d8645 (patch)
tree867498333e4034a12207c40c03a9a32231c3da58
parent74afa78b07b272e3187a7905505f5e7608ed020a (diff)
downloadhoe-b2937f7df735710a0a1ffc6d2ec448a2d38d8645.tar.gz
+ 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]
-rw-r--r--Manifest.txt2
-rwxr-xr-xbin/sow25
-rw-r--r--lib/hoe.rb15
-rw-r--r--template/lib/file_name.rb.erb1
-rw-r--r--template/test/file_name.rb.erb (renamed from template/test/test_file_name.rb.erb)3
-rw-r--r--test/test_hoe.rb16
6 files changed, 41 insertions, 21 deletions
diff --git a/Manifest.txt b/Manifest.txt
index df3cd68..487f500 100644
--- a/Manifest.txt
+++ b/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
diff --git a/bin/sow b/bin/sow
index 1a66544..7e2939c 100755
--- a/bin/sow
+++ b/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
diff --git a/lib/hoe.rb b/lib/hoe.rb
index 9b49e42..6e009f1 100644
--- a/lib/hoe.rb
+++ b/lib/hoe.rb
@@ -327,7 +327,7 @@ class Hoe
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 @@ class Hoe
# 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
##
diff --git a/template/lib/file_name.rb.erb b/template/lib/file_name.rb.erb
index 2c5cda5..37e61d6 100644
--- a/template/lib/file_name.rb.erb
+++ b/template/lib/file_name.rb.erb
@@ -1,3 +1,4 @@
+<%= make_sub_modules klass %>
class <%= klass %>
VERSION = '1.0.0'
end
diff --git a/template/test/test_file_name.rb.erb b/template/test/file_name.rb.erb
index 44fb2fa..e4d2eb8 100644
--- a/template/test/test_file_name.rb.erb
+++ b/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
diff --git a/test/test_hoe.rb b/test/test_hoe.rb
index c078864..ef958d2 100644
--- a/test/test_hoe.rb
+++ b/test/test_hoe.rb
@@ -388,14 +388,14 @@ class TestHoe < MiniTest::Unit::TestCase
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