Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Introducing "git-start <card_type>" to replace git-bug, git-chore, an…

…d git-feature.

* Changing API of Commands::Base to not take STDIN/STDOUT in the constructor

[contributes #1]
  • Loading branch information...
commit e5f0131706209a61d87eccc93337d8091e2fceba 1 parent a7cb194
@zdennis authored
View
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
7 bin/git-bug
@@ -1,7 +0,0 @@
-#!/usr/bin/env ruby
-
-$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
-
-require 'commands/bug'
-
-exit Commands::Bug.new(STDIN, STDOUT, *ARGV).run!
View
7 bin/git-chore
@@ -1,7 +0,0 @@
-#!/usr/bin/env ruby
-
-$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
-
-require 'commands/chore'
-
-exit Commands::Chore.new(STDIN, STDOUT, *ARGV).run!
View
7 bin/git-feature
@@ -1,7 +0,0 @@
-#!/usr/bin/env ruby
-
-$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
-
-require 'commands/feature'
-
-exit Commands::Feature.new(STDIN, STDOUT, *ARGV).run!
View
2  bin/git-finish
@@ -4,4 +4,4 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'commands/finish'
-exit Commands::Finish.new(STDIN, STDOUT, *ARGV).run!
+exit Commands::Finish.new(*ARGV).with(STDIN, STDOUT).run!
View
2  bin/git-info
@@ -4,4 +4,4 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'commands/info'
-exit Commands::Info.new(STDIN, STDOUT, *ARGV).run!
+exit Commands::Info.new(*ARGV).with(STDIN, STDOUT).run!
View
2  bin/git-pick
@@ -5,4 +5,4 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'commands/feature'
STDOUT.puts "DEPRECATION WARNING: git pick has been deprecated. Please use git feature instead."
-exit Commands::Feature.new(STDIN, STDOUT, *ARGV).run!
+exit Commands::Feature.new(*ARGV).with(STDIN, STDOUT).run!
View
8 bin/git-start
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
+
+require 'commands/start'
+
+args = ARGV
+exit Commands::Start.for(*ARGV).with(STDIN, STDOUT).run!
View
20 features/start.feature
@@ -22,15 +22,15 @@ Feature: git start
And the exit status should be 1
Examples:
- | command |
- | git-bug |
- | git-chore |
- | git-feature |
+ | command |
+ | git-start bug |
+ | git-start chore |
+ | git-start feature |
Scenario: Starting the next feature when it is unestimated
Given I have an unestimated Pivotal Tracker feature
And I have configured the Git repos for Pivotal
- When I run `git-feature -D`
+ When I run `git-start feature -D`
Then the output should contain:
"""
Stories in the started state must be estimated.
@@ -41,7 +41,7 @@ Feature: git start
Scenario: Starting the next chore when it is unestimated
Given I have an unestimated Pivotal Tracker chore
And I have configured the Git repos for Pivotal
- When I run `git-chore -D`
+ When I run `git-start chore -D`
Then the output should contain "Switched to a new branch 'CURRENT_CARD-chore'"
And I should be on the "CURRENT_CARD-chore" branch
And card CURRENT_CARD is marked is started in Pivotal Tracker
@@ -50,7 +50,7 @@ Feature: git start
Scenario: Starting the next bug when it is unestimated
Given I have an unestimated Pivotal Tracker bug
And I have configured the Git repos for Pivotal
- When I run `git-bug -D`
+ When I run `git-start bug -D`
Then the output should contain "Switched to a new branch 'CURRENT_CARD-bugfix'"
And I should be on the "CURRENT_CARD-bugfix" branch
And card CURRENT_CARD is marked is started in Pivotal Tracker
@@ -58,7 +58,7 @@ Feature: git start
Scenario Outline: Starting the next estimated card interactively (without -D option)
Given I have a Pivotal Tracker <card_type>
And I have configured the Git repos for Pivotal
- When I run `git-<card_type>` interactively
+ When I run `git-start <card_type>` interactively
And I type "a_purple_<card_type>"
Then the output should contain "Switched to a new branch 'CURRENT_CARD-a_purple_<card_type>'"
And I should be on the "CURRENT_CARD-a_purple_<card_type>" branch
@@ -73,7 +73,7 @@ Feature: git start
Scenario Outline: Starting the next estimated card using configured defaults (with -D option)
Given I have a Pivotal Tracker <card_type>
And I have configured the Git repos for Pivotal
- When I run `git-<card_type> -D`
+ When I run `git-start <card_type> -D`
Then the output should contain "Switched to a new branch 'CURRENT_CARD-<card_type><branch_suffix>'"
And I should be on the "CURRENT_CARD-<card_type><branch_suffix>" branch
And card CURRENT_CARD is marked is started in Pivotal Tracker
@@ -87,7 +87,7 @@ Feature: git start
Scenario Outline: Supplying Pivotal configuration via command line arguments
Given I have a Pivotal Tracker <card_type>
And I have configured the Git repos for Pivotal with bogus information
- When I run `git-<card_type> -k PIVOTAL_API_KEY -p PIVOTAL_TEST_PROJECT -n "PIVOTAL_USER" -D`
+ When I run `git-start <card_type> -k PIVOTAL_API_KEY -p PIVOTAL_TEST_PROJECT -n "PIVOTAL_USER" -D`
Then the output should contain "Switched to a new branch 'CURRENT_CARD-<card_type><branch_suffix>'"
And I should be on the "CURRENT_CARD-<card_type><branch_suffix>" branch
And card CURRENT_CARD is marked is started in Pivotal Tracker
View
14 lib/commands/base.rb
@@ -7,14 +7,22 @@ class Base
attr_accessor :input, :output, :options
- def initialize(input=STDIN, output=STDOUT, *args)
- @input = input
- @output = output
+ def initialize(*args)
+ @input = STDIN
+ @output = STDOUT
+
@options = {}
parse_gitconfig
parse_argv(*args)
end
+
+ def with(input, output)
+ tap do
+ @input = input
+ @output = output
+ end
+ end
def put(string, newline=true)
@output.print(newline ? string + "\n" : string) unless options[:quiet]
View
24 lib/commands/start.rb
@@ -0,0 +1,24 @@
+require 'commands/bug'
+require 'commands/chore'
+require 'commands/feature'
+
+module Commands
+ class Start
+ COMMAND_MAP = {
+ "bug" => Commands::Bug,
+ "chore" => Commands::Chore,
+ "feature" => Commands::Feature
+ }
+
+ def self.for(*args)
+ card_type = args.first
+ if klass=COMMAND_MAP[card_type]
+ args.shift
+ COMMAND_MAP[card_type].new(*args)
+ else
+ COMMAND_MAP[card_type] || raise(ArgumentError,"Unknown command type requested: #{card_type}")
+ end
+ end
+ end
+
+end
View
1  lib/git-pivotal.rb
@@ -7,3 +7,4 @@
require File.join('commands', 'chore')
require File.join('commands', 'finish')
require File.join('commands', 'info')
+require File.join('commands', 'start')
View
38 spec/commands/base_spec.rb
@@ -11,27 +11,27 @@
end
it "should set the api key with the -k option" do
- @pick = Commands::Base.new(@input, @output,"-k", "1234")
+ @pick = Commands::Base.new("-k", "1234").with(@input, @output)
@pick.options[:api_token].should == "1234"
end
it "should set the api key with the --api-token= option" do
- @pick = Commands::Base.new(@input, @output,"--api-key=1234")
+ @pick = Commands::Base.new("--api-key=1234").with(@input, @output)
@pick.options[:api_token].should == "1234"
end
it "should set the project id with the -p option" do
- @pick = Commands::Base.new(@input, @output,"-p", "1")
+ @pick = Commands::Base.new("-p", "1").with(@input, @output)
@pick.options[:project_id].should == "1"
end
it "should set the project id with the --project-id= option" do
- @pick = Commands::Base.new(@input, @output,"--project-id=1")
+ @pick = Commands::Base.new("--project-id=1").with(@input, @output)
@pick.options[:project_id].should == "1"
end
it "should set the full name with the -n option" do
- @pick = Commands::Base.new(@input, @output,"-n", "Jeff Tucker")
+ @pick = Commands::Base.new("-n", "Jeff Tucker").with(@input, @output)
@pick.options[:full_name].should == "Jeff Tucker"
end
@@ -41,32 +41,32 @@
end
it "should set the quiet flag with the -q option" do
- @pick = Commands::Base.new(@input, @output,"-q")
+ @pick = Commands::Base.new("-q").with(@input, @output)
@pick.options[:quiet].should be_true
end
it "should set the quiet flag with the --quiet option" do
- @pick = Commands::Base.new(@input, @output,"--quiet")
+ @pick = Commands::Base.new("--quiet").with(@input, @output)
@pick.options[:quiet].should be_true
end
it "should set the verbose flag with the -v option" do
- @pick = Commands::Base.new(@input, @output,"-v")
+ @pick = Commands::Base.new("-v").with(@input, @output)
@pick.options[:verbose].should be_true
end
it "should set the verbose flag with the --verbose option" do
- @pick = Commands::Base.new(@input, @output,"--verbose")
+ @pick = Commands::Base.new("--verbose").with(@input, @output)
@pick.options[:verbose].should be_true
end
it "should unset the verbose flag with the --no-verbose option" do
- @pick = Commands::Base.new(@input, @output,"--no-verbose")
+ @pick = Commands::Base.new("--no-verbose").with(@input, @output)
@pick.options[:verbose].should be_false
end
it "should set the integration branch with the -b option" do
- @pick = Commands::Base.new(@input, @output, "-b", "integration")
+ @pick = Commands::Base.new("-b", "integration").with(@input, @output)
@pick.send(:integration_branch).should == "integration"
end
@@ -77,7 +77,7 @@
end
it "should set the integration branch with the --integration-branch= option" do
- @pick = Commands::Base.new(@input, @output, "--integration-branch=integration")
+ @pick = Commands::Base.new("--integration-branch=integration").with(@input, @output)
@pick.send(:integration_branch).should == "integration"
end
@@ -89,19 +89,19 @@
it "should print a message if the API token is missing" do
@output.expects(:print).with("Pivotal Tracker API Token and Project ID are required\n")
- @pick = Commands::Base.new(@input, @output, "-p", "1")
+ @pick = Commands::Base.new("-p", "1").with(@input, @output)
@pick.run!
end
it "should print a message if the project ID is missing" do
@output.expects(:print).with("Pivotal Tracker API Token and Project ID are required\n")
- @pick = Commands::Base.new(@input, @output, "-k", "1")
+ @pick = Commands::Base.new("-k", "1").with(@input, @output)
@pick.run!
end
it "should set the append name flag with the -a option" do
- @pick = Commands::Base.new(@input, @output,"-a")
+ @pick = Commands::Base.new("-a").with(@input, @output)
@pick.options[:append_name].should be_true
end
@@ -112,7 +112,7 @@
end
it "should set the append name flag with the --append-name" do
- @pick = Commands::Base.new(@input, @output, "--append-name")
+ @pick = Commands::Base.new("--append-name").with(@input, @output)
@pick.options[:append_name].should be_true
end
@@ -122,17 +122,17 @@
end
it "should set use_ssl to true with --use-ssl" do
- @pick = Commands::Base.new(@input, @output, "--use-ssl")
+ @pick = Commands::Base.new("--use-ssl").with(@input, @output)
@pick.options[:use_ssl].should be_true
end
it "should set use_ssl to true with -S" do
- @pick = Commands::Base.new(@input, @output, "-S")
+ @pick = Commands::Base.new("-S").with(@input, @output)
@pick.options[:use_ssl].should be_true
end
it "should set use_ssl to false by default" do
- @pick = Commands::Base.new(@input, @output, "")
+ @pick = Commands::Base.new("").with(@input, @output)
@pick.options[:use_ssl].should be_false
end
View
24 spec/commands/start_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe Commands::Start do
+
+ describe '.for' do
+ it "returns the Command::Bug when the first argument is bug" do
+ Commands::Start.for("bug").should be_instance_of(Commands::Bug)
+ end
+
+ it "returns the Command::Chore when the first argument is chore" do
+ Commands::Start.for("chore").should be_instance_of(Commands::Chore)
+ end
+
+ it "returns the Command::Feature when the first argument is feature" do
+ Commands::Start.for("feature").should be_instance_of(Commands::Feature)
+ end
+
+ it "raises when the command is unknown card type" do
+ expect { Commands::Start.for("unknown") }.should raise_error(ArgumentError, "Unknown command type requested: unknown")
+ end
+
+ end
+
+end
View
18 spec/spec_helper.rb
@@ -1,16 +1,24 @@
-require 'rspec'
require 'mocha'
require 'builder'
+# This file was generated by the `rspec --init` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# Require this file using `require "spec_helper.rb"` to ensure that it is only
+# loaded once.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+RSpec.configure do |config|
+ config.mock_with :mocha
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+end
+
specdir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
require File.join(specdir, 'lib','git-pivotal')
require File.join(File.dirname(__FILE__), 'factories')
-RSpec.configure do |config|
- config.mock_with :mocha
-end
-
def stub_connection_to_pivotal
RestClient::Resource.any_instance.stubs(:get).returns("")
end
Please sign in to comment.
Something went wrong with that request. Please try again.