Permalink
Browse files

Added support for absolut paths in project name

  • Loading branch information...
1 parent a47fb58 commit d0e05e69f351a88efaf2190c47616aa3c8f700b9 @invadersmustdie invadersmustdie committed with technicalpickles Jun 2, 2011
Showing with 30 additions and 8 deletions.
  1. +9 −1 lib/jeweler/generator.rb
  2. +20 −6 test/jeweler/test_generator.rb
  3. +1 −1 test/jeweler/test_generator_initialization.rb
View
@@ -57,10 +57,18 @@ class Generator
def initialize(options = {})
self.options = options
+ extracted_directory = nil
self.project_name = options[:project_name]
if self.project_name.nil? || self.project_name.squeeze.strip == ""
raise NoGitHubRepoNameGiven
+ else
+ path = File.split(self.project_name)
+
+ if path.size > 1
+ extracted_directory = File.join(path[0..-1])
+ self.project_name = path.last
+ end
end
self.development_dependencies = []
@@ -82,7 +90,7 @@ def initialize(options = {})
raise ArgumentError, "Unsupported documentation framework (#{documentation_framework})"
end
- self.target_dir = options[:directory] || self.project_name
+ self.target_dir = options[:directory] || extracted_directory || self.project_name
self.summary = options[:summary] || 'TODO: one-line summary of your gem'
self.description = options[:description] || 'TODO: longer description of your gem'
@@ -2,12 +2,14 @@
class TestGenerator < Test::Unit::TestCase
def build_generator(testing_framework = :shoulda, options = {})
- options = options.merge :project_name => 'the-perfect-gem',
- :user_name => 'John Doe',
- :user_email => 'john@example.com',
- :github_username => 'johndoe',
- :github_token => 'yyz',
- :documentation_framework => :rdoc
+ options = {
+ :project_name => 'the-perfect-gem',
+ :user_name => 'John Doe',
+ :user_email => 'john@example.com',
+ :github_username => 'johndoe',
+ :github_token => 'yyz',
+ :documentation_framework => :rdoc
+ }.merge(options)
options[:testing_framework] = testing_framework
Jeweler::Generator.new(options)
@@ -34,6 +36,18 @@ def build_generator(testing_framework = :shoulda, options = {})
assert_equal 'git@github.com:johndoe/the-perfect-gem.git', build_generator.git_remote
end
+ should "extract project name from absolut path" do
+ assert_equal "my-project", build_generator(:shoulda, {:project_name => "/tmp/my-project"}).project_name
+ end
+
+ should "extract project name from relative path" do
+ assert_equal "my-project", build_generator(:shoulda, {:project_name => "../my-project"}).project_name
+ end
+
+ should "extract project name from direct path" do
+ assert_equal "my-project", build_generator(:shoulda, {:project_name => "my-project"}).project_name
+ end
+
def self.should_have_generator_attribute(attribute, value)
should "have #{value} for #{attribute}" do
assert_equal value, build_generator(@framework).send(attribute)
@@ -101,7 +101,7 @@ def build_generator(options = {})
end
should "set target directory to the project name" do
- assert_equal @project_name, @generator.target_dir
+ assert_equal @project_name, File.split(@generator.target_dir).last
end
should "set user's name from git config" do

0 comments on commit d0e05e6

Please sign in to comment.