Permalink
Browse files

Merge pull request #1637 from knu/gemspec_from_rakefile

Add Bundler::GemHelper.gemspec.
  • Loading branch information...
2 parents 663cc6d + 9fac469 commit 42d2c3e32d9208e21ee681d849a7f25629955150 @sferik sferik committed Jan 20, 2012
Showing with 48 additions and 5 deletions.
  1. +17 −5 lib/bundler/gem_helper.rb
  2. +31 −0 spec/bundler/gem_helper_spec.rb
@@ -6,16 +6,26 @@ module Bundler
class GemHelper
include Rake::DSL if defined? Rake::DSL
- def self.install_tasks(opts = {})
- dir = opts[:dir] || Dir.pwd
- self.new(dir, opts[:name]).install
+ class << self
+ # set when install'd.
+ attr_accessor :instance
+
+ def install_tasks(opts = {})
+ new(opts[:dir], opts[:name]).install
+ end
+
+ def gemspec(&block)
+ gemspec = instance.gemspec
+ block.call(gemspec) if block
+ gemspec
+ end
end
attr_reader :spec_path, :base, :gemspec
- def initialize(base, name = nil)
+ def initialize(base = nil, name = nil)
Bundler.ui = UI::Shell.new(Thor::Base.shell.new)
- @base = base
+ @base = (base ||= Dir.pwd)
gemspecs = name ? [File.join(base, "#{name}.gemspec")] : Dir[File.join(base, "{,*}.gemspec")]
raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1
@spec_path = gemspecs.first
@@ -37,6 +47,8 @@ def install
task 'release' do
release_gem
end
+
+ GemHelper.instance = self
end
def build_gem
@@ -1,4 +1,5 @@
require "spec_helper"
+require 'rake'
require 'bundler/gem_helper'
describe "Bundler::GemHelper tasks" do
@@ -61,6 +62,36 @@ def mock_build_message
Bundler.ui.should be_a(Bundler::UI::Shell)
end
+ describe 'install_tasks' do
+ before(:each) do
+ @saved, Rake.application = Rake.application, Rake::Application.new
+ end
+
+ after(:each) do
+ Rake.application = @saved
+ end
+
+ it "defines Rake tasks" do
+ names = %w[build install release]
+
+ names.each { |name|
+ proc { Rake.application[name] }.should raise_error(/Don't know how to build task/)
+ }
+
+ @helper.install
+
+ names.each { |name|
+ proc { Rake.application[name] }.should_not raise_error
+ Rake.application[name].should be_instance_of Rake::Task
+ }
+ end
+
+ it "provides a way to access the gemspec object" do
+ @helper.install
+ Bundler::GemHelper.gemspec.name.should == 'test'
+ end
+ end
+
describe 'build' do
it "builds" do
mock_build_message

0 comments on commit 42d2c3e

Please sign in to comment.