diff --git a/lib/gem_release/version_file.rb b/lib/gem_release/version_file.rb index 235c823..338a928 100644 --- a/lib/gem_release/version_file.rb +++ b/lib/gem_release/version_file.rb @@ -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 diff --git a/lib/rubygems/commands/bump_command.rb b/lib/rubygems/commands/bump_command.rb index 553f5eb..27f51e7 100644 --- a/lib/rubygems/commands/bump_command.rb +++ b/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 @@ -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 \ No newline at end of file +end diff --git a/test/bump_command_test.rb b/test/bump_command_test.rb index d45ff64..101ad72 100644 --- a/test/bump_command_test.rb +++ b/test/bump_command_test.rb @@ -5,30 +5,39 @@ 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)}") @@ -36,32 +45,78 @@ def version(options = {}) 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 \ No newline at end of file +end