Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
completed spec for three main management methods
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbuddy authored and indirect committed Aug 4, 2010
1 parent aaf9439 commit eeadd44
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 27 deletions.
36 changes: 19 additions & 17 deletions lib/bundler/gem_helper.rb
@@ -1,8 +1,6 @@
module Bundler
class GemHelper

VERSION_REGEXP = /V(ERSION|ersion)\s*=\s*(["'])(.*?)\2/

def self.install_tasks
dir = caller.find{|c| /Rakefile:/}[/^(.*?)\/Rakefile:/, 1]
GemHelper.new(dir).install
Expand Down Expand Up @@ -33,18 +31,6 @@ def install
end
end

protected
def built_gem_path
Dir[File.join(base, "#{name}-*.gem")].sort_by{|f| File.mtime(f)}.last
end

def interpolate_name
gemspecs = Dir[File.join(base, "*.gemspec")]
raise "Unable to determine name from existing gemspec." unless gemspecs.size == 1

File.basename(gemspecs.first)[/^(.*)\.gemspec$/, 1]
end

def build_gem
file_name = nil
sh("gem build #{spec_path}") {
Expand All @@ -65,11 +51,26 @@ def push_gem
guard_already_tagged
tag_version {
git_push
built_gem_path = build_gem
sh("gem push #{built_gem_path}")
rubygem_push(build_gem)
}
end

protected
def rubygem_push(path)
sh("gem push #{path}")
end

def built_gem_path
Dir[File.join(base, "#{name}-*.gem")].sort_by{|f| File.mtime(f)}.last
end

def interpolate_name
gemspecs = Dir[File.join(base, "*.gemspec")]
raise "Unable to determine name from existing gemspec." unless gemspecs.size == 1

File.basename(gemspecs.first)[/^(.*)\.gemspec$/, 1]
end

def git_push
sh "git push --all"
sh "git push --tags"
Expand All @@ -96,7 +97,8 @@ def tag_version
end

def current_version
File.read(version_file_path)[VERSION_REGEXP, 3]
raise("Version file could not be found at #{version_file_path}") unless File.exist?(version_file_path)
File.read(version_file_path)[/V(ERSION|ersion)\s*=\s*(["'])(.*?)\2/, 3]
end

def version_file_path
Expand Down
63 changes: 53 additions & 10 deletions spec/other/gem_helper_spec.rb
Expand Up @@ -2,17 +2,60 @@
require 'bundler/gem_helper'

describe "Bundler::GemHelper tasks" do
it "interpolates the name when there is only one gemspec" do
bundle 'gem test'
app = bundled_app("test")
helper = Bundler::GemHelper.new(app.to_s)
helper.name.should == 'test'
context "determining gemspec" do
it "interpolates the name when there is only one gemspec" do
bundle 'gem test'
app = bundled_app("test")
helper = Bundler::GemHelper.new(app.to_s)
helper.name.should == 'test'
end

it "should fail when there is no gemspec" do
bundle 'gem test'
app = bundled_app("test")
FileUtils.rm(File.join(app.to_s, 'test.gemspec'))
proc { Bundler::GemHelper.new(app.to_s) }.should raise_error(/Unable to determine name/)
end

it "should fail when there are two gemspecs and the name isn't specified" do
bundle 'gem test'
app = bundled_app("test")
File.open(File.join(app.to_s, 'test2.gemspec'), 'w') {|f| f << ''}
proc { Bundler::GemHelper.new(app.to_s) }.should raise_error(/Unable to determine name/)
end
end

it "should fail when there is no gemspec" do
bundle 'gem test'
app = bundled_app("test")
FileUtils.rm(File.join(app.to_s, 'test.gemspec'))
proc { Bundler::GemHelper.new(app.to_s) }.should raise_error(/Unable to determine name/)
context "gem management" do
before(:each) do
bundle 'gem test'
@app = bundled_app("test")
gemspec = File.read("#{@app.to_s}/test.gemspec")
File.open("#{@app.to_s}/test.gemspec", 'w') {|f| f << gemspec.gsub(/TODO/, '')}
@helper = Bundler::GemHelper.new(@app.to_s)
end

it "builds" do
@helper.build_gem
bundled_app('test/pkg/test-0.0.0.gem').should exist
end

it "installs" do
@helper.install_gem
should_be_installed("test 0.0.0")
end

it "shouldn't push if there are uncommitted files" do
proc { @helper.push_gem }.should raise_error(/files that need to be committed/)
end

it "pushes" do
@helper.should_receive(:rubygem_push).with(bundled_app('test/pkg/test-0.0.0.gem').to_s)
Dir.chdir(@app) {
`git init --bare #{gem_repo1}`
`git remote add origin file://#{gem_repo1}`
`git commit -a -m"initial commit"`
}
@helper.push_gem
end
end
end

0 comments on commit eeadd44

Please sign in to comment.