Skip to content

Commit

Permalink
extend bump command to also take --tag and --release options, rename …
Browse files Browse the repository at this point in the history
…--to option to --version
  • Loading branch information
Sven Fuchs committed Oct 12, 2010
1 parent 68a6d8f commit 0a637f6
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/gem_release/version_file.rb
Expand Up @@ -48,7 +48,7 @@ def content
end

def bumped_content
content.sub(VERSION_PATTERN) { "#{$1}#{new_number}#{$3}"}
content.sub(VERSION_PATTERN) { "#{$1}#{new_number}#{$3}" }
end
end
end
33 changes: 23 additions & 10 deletions lib/rubygems/commands/bump_command.rb
@@ -1,26 +1,31 @@
require 'core_ext/string/camelize'
require 'rubygems/commands/tag_command'
require 'rubygems/commands/release_command'

class Gem::Commands::BumpCommand < Gem::Command
include GemRelease
include GemRelease, Gem::Commands
include Helpers, CommandOptions

attr_reader :arguments, :usage

OPTIONS = { :to => :patch, :push => false }
OPTIONS = { :version => 'patch', :push => false, :tag => false, :release => false }

def initialize
super 'bump', 'Bump the gem version', OPTIONS

option :to, '-t', 'Target version: next [major|minor|patch] or a given version number [x.x.x]'
option :push, '-p', 'Push to origin (defaults to false)'
option :version, '-v', 'Target version: next [major|minor|patch] or a given version number [x.x.x]'
option :push, '-p', 'Push to origin'
option :tag, '-t', 'Create a git tag and push --tags to origin'
option :release, '-r', 'Build gem from a gemspec and push to rubygems.org'
end

def execute
bump
commit
push if options[:push]
push if options[:push] || options[:tag]
release if options[:release]
tag if options[:tag]
end

protected

def bump
Expand All @@ -38,8 +43,16 @@ def push
say "Pushing to origin"
`git push`
end


def release
ReleaseCommand.new.invoke
end

def tag
TagCommand.new.invoke
end

def version
@version ||= VersionFile.new(:target => options[:to])
@version ||= VersionFile.new(:target => options[:version])
end
end
end
83 changes: 69 additions & 14 deletions test/bump_command_test.rb
Expand Up @@ -5,63 +5,118 @@

class BumpCommandTest < Test::Unit::TestCase
include GemRelease

def setup
build_sandbox
stub_command(BootstrapCommand, :say)
stub_command(TagCommand, :say)
stub_command(BumpCommand, :say)
stub_command(ReleaseCommand, :say)
BootstrapCommand.new.send(:write_scaffold)
end

def teardown
@version = nil
teardown_sandbox
end

def version(options = {})
@version ||= VersionFile.new(options)
end

test "gem bump" do
command = BumpCommand.new
command.expects(:`).with("git add #{version.send(:filename)}")
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
command.invoke
end


test "gem bump --version 0.1.0" do
command = BumpCommand.new
command.expects(:`).with("git add #{version.send(:filename)}")
command.expects(:`).with('git commit -m "Bump to 0.1.0"')
command.invoke('--version', '0.1.0')
end

test "gem bump --push" do
command = BumpCommand.new
command.expects(:`).with("git add #{version.send(:filename)}")
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
command.expects(:`).with('git push')
command.invoke('--push')
end


test "gem bump --push --tag" do
command = BumpCommand.new
command.expects(:`).with("git add #{version.send(:filename)}")
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
command.expects(:`).with('git push')
TagCommand.any_instance.stubs(:gem_version).returns('0.0.2')
TagCommand.any_instance.expects(:`).with("git tag -am 'tag v0.0.2' v0.0.2")
TagCommand.any_instance.expects(:`).with('git push --tags origin')
command.invoke('--push', '--tag')
end

test "gem bump --push --release" do
command = BumpCommand.new
command.expects(:`).with("git add #{version.send(:filename)}")
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
command.expects(:`).with('git push')

release_command = ReleaseCommand.new
ReleaseCommand.expects(:new).returns(release_command)
ReleaseCommand.any_instance.expects(:build)
ReleaseCommand.any_instance.expects(:push)
ReleaseCommand.any_instance.expects(:remove)

command.invoke('--push', '--release')
end

test "gem bump --push --tag --release" do
command = BumpCommand.new
command.expects(:`).with("git add #{version.send(:filename)}")
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
command.expects(:`).with('git push')

release_command = ReleaseCommand.new
ReleaseCommand.expects(:new).returns(release_command)
ReleaseCommand.any_instance.expects(:build)
ReleaseCommand.any_instance.expects(:push)
ReleaseCommand.any_instance.expects(:remove)

release_command = TagCommand.new
TagCommand.expects(:new).returns(release_command)
TagCommand.any_instance.expects(:tag)
TagCommand.any_instance.expects(:push)

command.invoke('--push', '--tag', '--release')
end

test "old_number" do
assert_equal '0.0.1', version.old_number
end

test "new_number w/ default target" do
assert_equal '0.0.2', version.new_number
end

test "new_number w/ :patch target" do
assert_equal '0.0.2', version(:target => :patch).new_number
end

test "new_number w/ :minor target" do
assert_equal '0.1.0', version(:target => :minor).new_number
end

test "new_number w/ :major target" do
assert_equal '1.0.0', version(:target => :major).new_number
end

test "new_number w/ given version number" do
assert_equal '1.1.1', version(:target => '1.1.1').new_number
end

test "bumped_content" do
assert_equal "module FooBar\n VERSION = \"0.0.2\"\nend", version.send(:bumped_content)
assert_equal "module FooBar\n VERSION = \"0.0.2\"\nend\n", version.send(:bumped_content)
end
end
end

0 comments on commit 0a637f6

Please sign in to comment.