simple-git-pair 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Build Status](https://secure.travis-ci.org/fsproru/simple-git-pair.png)](http://travis-ci.org/fsproru/simple-git-pair)
2
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/fsproru/simple-git-pair)
2
3
 
3
4
  ## TL;DR
4
5
  Simple way to add your pair to a git commit message.
data/bin/git-pair CHANGED
@@ -3,10 +3,8 @@ require 'rubygems'
3
3
  require 'commander/import'
4
4
  require 'simple-git-pair'
5
5
 
6
- BINARY_NAME = "git pair"
7
-
8
6
  #TODO: figure out a better way to output usage first
9
- program :name, "\n Usage:\n #{BINARY_NAME} <initials>"
7
+ program :name, "\n Usage:\n #{SimpleGitPair::BINARY_NAME} <initials>"
10
8
  program :version, SimpleGitPair::VERSION
11
9
  program :description, SimpleGitPair::SUMMARY
12
10
  program :int_message, "Good bye"
@@ -15,9 +13,9 @@ program :help_formatter, :compact
15
13
 
16
14
  default_command :change
17
15
  command :change do |c|
18
- c.description = "Changes your git user.name"
19
- c.syntax = "git pair change <initials>"
20
- c.example 'Nicola Tesla & Alfred Einstein', "#{BINARY_NAME} change nt ae"
16
+ c.description = "Change your git user.name"
17
+ c.syntax = "#{SimpleGitPair::BINARY_NAME} change <initials>"
18
+ c.example 'Nicola Tesla & Alfred Einstein', "#{SimpleGitPair::BINARY_NAME} change nt ae"
21
19
  c.action do |args, options|
22
20
  if args.empty?
23
21
  commands['help'].run
@@ -28,11 +26,19 @@ command :change do |c|
28
26
  end
29
27
 
30
28
  command :init do |c|
31
- c.syntax = "#{BINARY_NAME} init"
32
- c.description = "Creates a sample config file"
33
- c.example "Creates .git_pairs in your home directory", "#{BINARY_NAME} init"
29
+ c.description = "Create a sample config file"
30
+ c.syntax = "#{SimpleGitPair::BINARY_NAME} init"
31
+ c.example "Creates .git_pairs in your home directory", "#{SimpleGitPair::BINARY_NAME} init"
34
32
  c.action do |args, options|
35
33
  SimpleGitPair::Command::Init.new.run!
36
34
  end
37
35
  end
38
36
 
37
+ command :add do |c|
38
+ c.description = "Add new pair to a list"
39
+ c.syntax = SimpleGitPair::Command::Add::USAGE
40
+ c.example "Adds New Guy to pairs list", "#{SimpleGitPair::BINARY_NAME} add ng New Guy"
41
+ c.action do |args, options|
42
+ SimpleGitPair::Command::Add.new(args).run!
43
+ end
44
+ end
@@ -5,8 +5,14 @@ Given /^there is a local repo$/ do
5
5
  step 'I run `git init`'
6
6
  end
7
7
 
8
- Given /^there is no pairs file$/ do
9
- step %Q{I remove the file "#{@pairs_file}"} if File.exists? @pairs_file
8
+ Given /^there is (no|a) pairs file$/ do |yes_no|
9
+ file_should_exist = yes_no == "a" ? true : false
10
+
11
+ if file_should_exist
12
+ `git pair init`
13
+ else
14
+ step %Q{I remove the file "#{@pairs_file}"} if File.exists? @pairs_file
15
+ end
10
16
  end
11
17
 
12
18
  Then /^it creates a sample pairs file$/ do
@@ -2,3 +2,4 @@ require 'simple-git-pair/helper'
2
2
  require 'simple-git-pair/command/base'
3
3
  require 'simple-git-pair/command/init'
4
4
  require 'simple-git-pair/command/change'
5
+ require 'simple-git-pair/command/add'
@@ -0,0 +1,56 @@
1
+ require 'simple-git-pair/command/base'
2
+ require 'rainbow'
3
+
4
+ module SimpleGitPair
5
+ module Command
6
+ class Add < Base
7
+ USAGE = "#{BINARY_NAME} add <initials> <Full Name>"
8
+
9
+ def run!
10
+ exit 1 unless ensure_pairs_file_exists
11
+
12
+ initials, fullname, valid_opts, errors = validate_opts
13
+ unless valid_opts
14
+ puts errors.join "\n"
15
+ puts "Usage: #{USAGE}"
16
+ exit 1
17
+ end
18
+
19
+ pairs = Helper.read_pairs
20
+ existent_user = pairs[initials]
21
+ message = ""
22
+
23
+ if existent_user
24
+ unless agree("#{initials} has alredy taken by #{existent_user}. Override it with #{fullname}? (yes/no)")
25
+ puts "#{fullname} was not added"
26
+ exit 1
27
+ end
28
+
29
+ message = "Updated #{initials} to be #{fullname}"
30
+ else
31
+ message = "Added #{fullname}"
32
+ end
33
+
34
+ pairs[initials] = fullname
35
+ Helper.save_pairs pairs
36
+ puts message.color(:green)
37
+ end
38
+
39
+ private
40
+
41
+ ##
42
+ # Validate and return options
43
+ #
44
+ # Returns: array
45
+ # [initials, fullname, status, errors]
46
+ def validate_opts
47
+ initials = opts.shift
48
+ fullname = opts.join " "
49
+ errors = []
50
+ errors << "Initials should contain no spaces" if /\s/.match initials
51
+ errors << "Please provide a Full Name" if fullname == ""
52
+ [ initials, fullname, errors.empty?, errors ]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,5 @@
1
+ require 'simple-git-pair/helper'
2
+
1
3
  module SimpleGitPair
2
4
  module Command
3
5
  class Base
@@ -10,6 +12,24 @@ module SimpleGitPair
10
12
  def run!
11
13
  raise "Could you implement run! method on #{self.class}?"
12
14
  end
15
+
16
+ private
17
+
18
+ # Interactively creates a sample pairs file if pairs file doesn't exist
19
+ def ensure_pairs_file_exists
20
+ file_exists = Helper.pairs_file_exists?
21
+
22
+ unless file_exists
23
+ if agree("Can't find a config file. Create a sample one? (yes/no)")
24
+ file_exists = Helper.create_pairs_file
25
+ else
26
+ Helper.complain_about_pairs_file
27
+ file_exists = false
28
+ end
29
+ end
30
+
31
+ file_exists
32
+ end
13
33
  end
14
34
  end
15
35
  end
@@ -1,5 +1,5 @@
1
1
  require 'simple-git-pair/command/base'
2
- require 'simple-git-pair/helper'
2
+ require 'rainbow'
3
3
 
4
4
  module SimpleGitPair
5
5
  module Command
@@ -14,25 +14,7 @@ module SimpleGitPair
14
14
  exit 1
15
15
  end
16
16
 
17
- system "git config user.name" # output current username
18
- end
19
-
20
- private
21
-
22
- # Interactively creates a sample pairs file if pairs file doesn't exist
23
- def ensure_pairs_file_exists
24
- file_exists = Helper.pairs_file_exists?
25
-
26
- unless file_exists
27
- if agree("Can't find a config file. Create a sample one? (yes/no)")
28
- file_exists = Helper.create_pairs_file
29
- else
30
- Helper.complain_about_pairs_file
31
- file_exists = false
32
- end
33
- end
34
-
35
- file_exists
17
+ puts `git config user.name`.chomp.color(:green)
36
18
  end
37
19
  end
38
20
  end
@@ -1,5 +1,4 @@
1
1
  require 'simple-git-pair/command/base'
2
- require 'simple-git-pair/helper'
3
2
 
4
3
  module SimpleGitPair
5
4
  module Command
@@ -18,11 +18,11 @@ Please run: git pair init
18
18
  end
19
19
 
20
20
  def say_pairs_file_exists
21
- puts "#{PAIRS_FILE_PATH} already exists. You're good to go."
21
+ puts "#{PAIRS_FILE_PATH} already exists. You're good to go.".color(:green)
22
22
  end
23
23
 
24
24
  def names_for args
25
- pairs = YAML.load_file PAIRS_FILE_PATH
25
+ pairs = read_pairs
26
26
 
27
27
  names = []
28
28
  args.each do |opt|
@@ -40,6 +40,16 @@ Please run: git pair init
40
40
  def create_pairs_file
41
41
  File.open(PAIRS_FILE_PATH, "w") { |f| f.write "nt: Nikola Tesla\nae: Alfred Einstein" }
42
42
  end
43
+
44
+ def save_pairs hash
45
+ File.open(PAIRS_FILE_PATH, 'w' ) do |file|
46
+ YAML.dump( hash, file )
47
+ end
48
+ end
49
+
50
+ def read_pairs
51
+ YAML.load_file PAIRS_FILE_PATH
52
+ end
43
53
  end
44
54
  end
45
55
  end
@@ -1,4 +1,5 @@
1
1
  module SimpleGitPair
2
- SUMMARY = "Simple way to add your pair to a git commit message"
3
- VERSION = '0.0.4'
2
+ SUMMARY = "Simple way to add your pair to a git commit message"
3
+ BINARY_NAME = "git pair"
4
+ VERSION = '0.1.0'
4
5
  end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+ require 'simple-git-pair/command/add'
3
+
4
+ describe SimpleGitPair::Command::Add do
5
+ let(:opts) { [] }
6
+ let(:command) { described_class.new opts }
7
+
8
+ describe "#run!" do
9
+ subject { command.run! }
10
+ before { command.stub :puts }
11
+
12
+ it_should_behave_like "command that ensures that pairs file exists"
13
+
14
+ context "there is a pairs file" do
15
+ context "and there is already a pair with the same initials" do
16
+ let(:opts) { ["ng", "New", "Guy"] }
17
+ before { SimpleGitPair::Helper.stub(:read_pairs).and_return({"ng" => "Already Exists"}) }
18
+
19
+ context "and user agrees to override" do
20
+ before { command.stub(:agree).and_return true }
21
+ it "overrides the pair" do
22
+ SimpleGitPair::Helper.should_receive(:save_pairs).with({"ng" => "New Guy"})
23
+ subject
24
+ end
25
+ end
26
+
27
+ context "and user dissagrees to override" do
28
+ before { command.stub(:agree).and_return false }
29
+ it "doesn't override and exits" do
30
+ SimpleGitPair::Helper.should_not_receive :save_pairs
31
+ expect {subject}.to raise_error SystemExit
32
+ end
33
+ end
34
+ end
35
+
36
+ context "and there is NO pair with same initials" do
37
+ let(:opts) { ["ng", "New", "Guy"] }
38
+ before { SimpleGitPair::Helper.stub(:read_pairs).and_return({"og" => "Old Guy"}) }
39
+
40
+ it "adds a pair" do
41
+ SimpleGitPair::Helper.should_receive(:save_pairs).with({"og" => "Old Guy", "ng" => "New Guy"})
42
+ subject
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "#validate_opts" do
49
+ subject { command.send :validate_opts }
50
+
51
+ context "initials have spaces" do
52
+ let(:opts) { ["n g", "New_Guy"] }
53
+ it "returns error status and msg" do
54
+ initials, fullname, valid_opts, errors = subject
55
+ valid_opts.should be_false
56
+ errors.should_not be_empty
57
+ end
58
+ end
59
+
60
+ context "full name is not passed in" do
61
+ let(:opts) { ["ng"] }
62
+ it "returns error status and msg" do
63
+ initials, fullname, valid_opts, errors = subject
64
+ valid_opts.should be_false
65
+ errors.should_not be_empty
66
+ end
67
+ end
68
+
69
+ context "initals and fullname are fine" do
70
+ let(:opts) { ["ng", "New", "Awesome", "Guy"] }
71
+
72
+ it { expect {subject}.to_not raise_error RuntimeError }
73
+
74
+ it "treats all options after intials as a fullname" do
75
+ intials, fullname = subject
76
+ fullname.should == "New Awesome Guy"
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,34 @@
1
+ require 'simple-git-pair/command/base'
2
+
3
+ describe SimpleGitPair::Command::Base do
4
+ let(:command) { described_class.new [] }
5
+
6
+ describe "#run!" do
7
+ subject { command.run! }
8
+ it { expect { subject }.to raise_error RuntimeError }
9
+ end
10
+
11
+ describe "#ensure_pairs_file_exists" do
12
+ subject { command.send :ensure_pairs_file_exists }
13
+
14
+ context "there is NO pairs file" do
15
+ before { SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return false }
16
+
17
+ context "and user agrees to create it" do
18
+ before { command.stub(:agree).and_return true }
19
+ it "creates a pairs file and returns true" do
20
+ SimpleGitPair::Helper.should_receive(:create_pairs_file).and_return true
21
+ subject.should be_true
22
+ end
23
+ end
24
+
25
+ context "and user disagrees to create it" do
26
+ before { command.stub(:agree).and_return false }
27
+ it "complains and return false" do
28
+ SimpleGitPair::Helper.should_receive :complain_about_pairs_file
29
+ subject.should be_false
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,21 +1,15 @@
1
+ require 'spec_helper'
1
2
  require 'simple-git-pair/command/change'
2
3
 
3
4
  describe SimpleGitPair::Command::Change do
4
- before { Object.stub(:system) }
5
5
  let(:opts) { [] }
6
6
  let(:command) { described_class.new opts }
7
7
 
8
8
  describe "#run!" do
9
+ before { command.stub :puts }
9
10
  subject { command.run! }
10
11
 
11
- context "there is NO pairs file" do
12
- let(:opts) { ["some_initials"] }
13
-
14
- before { command.stub(:ensure_pairs_file_exists).and_return false }
15
- it "complains and exit" do
16
- expect { subject }.to raise_error SystemExit
17
- end
18
- end
12
+ it_should_behave_like "command that ensures that pairs file exists"
19
13
 
20
14
  context "there is a pairs file" do
21
15
  context "and multiple initials are passed in" do
@@ -57,28 +51,4 @@ describe SimpleGitPair::Command::Change do
57
51
  end
58
52
  end
59
53
  end
60
-
61
- describe "#ensure_pairs_file_exists" do
62
- subject { command.send :ensure_pairs_file_exists }
63
-
64
- context "there is NO pairs file" do
65
- before { SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return false }
66
-
67
- context "and user agrees to create it" do
68
- before { command.stub(:agree).and_return true }
69
- it "creates a pairs file and returns true" do
70
- SimpleGitPair::Helper.should_receive(:create_pairs_file).and_return true
71
- subject.should be_true
72
- end
73
- end
74
-
75
- context "and user disagrees to create it" do
76
- before { command.stub(:agree).and_return false }
77
- it "complains and return false" do
78
- SimpleGitPair::Helper.should_receive :complain_about_pairs_file
79
- subject.should be_false
80
- end
81
- end
82
- end
83
- end
84
54
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
2
 
3
- Rspec.configure do |config|
3
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
4
+
5
+ RSpec.configure do |config|
4
6
  config.color_enabled = true
5
7
  end
@@ -0,0 +1,8 @@
1
+ shared_examples_for "command that ensures that pairs file exists" do
2
+ context "there is NO pairs file" do
3
+ before { command.stub(:ensure_pairs_file_exists).and_return false }
4
+ it "complains and exit" do
5
+ expect { subject }.to raise_error SystemExit
6
+ end
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-git-pair
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-10 00:00:00.000000000 Z
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander
16
- requirement: &70286427233280 !ruby/object:Gem::Requirement
16
+ requirement: &70239044165920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70286427233280
24
+ version_requirements: *70239044165920
25
+ - !ruby/object:Gem::Dependency
26
+ name: rainbow
27
+ requirement: &70239044181500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70239044181500
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rspec
27
- requirement: &70286427232800 !ruby/object:Gem::Requirement
38
+ requirement: &70239044180880 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70286427232800
46
+ version_requirements: *70239044180880
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: aruba
38
- requirement: &70286427232220 !ruby/object:Gem::Requirement
49
+ requirement: &70239044180280 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70286427232220
57
+ version_requirements: *70239044180280
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: cucumber
49
- requirement: &70286427231460 !ruby/object:Gem::Requirement
60
+ requirement: &70239044179400 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70286427231460
68
+ version_requirements: *70239044179400
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: rake
60
- requirement: &70286427231020 !ruby/object:Gem::Requirement
71
+ requirement: &70239044178820 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70286427231020
79
+ version_requirements: *70239044178820
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: debugger
71
- requirement: &70286427230240 !ruby/object:Gem::Requirement
82
+ requirement: &70239044178320 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,7 +87,7 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70286427230240
90
+ version_requirements: *70239044178320
80
91
  description: Simple way to add your pair to a git commit message
81
92
  email:
82
93
  - a.tamoykin@gmail.com
@@ -85,6 +96,7 @@ executables:
85
96
  extensions: []
86
97
  extra_rdoc_files: []
87
98
  files:
99
+ - lib/simple-git-pair/command/add.rb
88
100
  - lib/simple-git-pair/command/base.rb
89
101
  - lib/simple-git-pair/command/change.rb
90
102
  - lib/simple-git-pair/command/init.rb
@@ -94,15 +106,18 @@ files:
94
106
  - bin/git-pair
95
107
  - CHANGELOG.md
96
108
  - README.md
109
+ - spec/lib/simple-git-pair/command/add_spec.rb
110
+ - spec/lib/simple-git-pair/command/base_spec.rb
97
111
  - spec/lib/simple-git-pair/command/change_spec.rb
98
112
  - spec/lib/simple-git-pair/command/init_spec.rb
99
113
  - spec/lib/simple-git-pair/helper_spec.rb
100
114
  - spec/spec_helper.rb
115
+ - spec/support/shared_examples/command_examples.rb
101
116
  - features/step_definitions/pair_steps.rb
102
117
  - features/support/env.rb
103
118
  homepage: http://github.com/fsproru/simple-git-pair
104
119
  licenses: []
105
- post_install_message:
120
+ post_install_message: ! 'Pair up! Run: git pair'
106
121
  rdoc_options: []
107
122
  require_paths:
108
123
  - lib
@@ -125,9 +140,12 @@ signing_key:
125
140
  specification_version: 3
126
141
  summary: Simple way to add your pair to a git commit message
127
142
  test_files:
143
+ - spec/lib/simple-git-pair/command/add_spec.rb
144
+ - spec/lib/simple-git-pair/command/base_spec.rb
128
145
  - spec/lib/simple-git-pair/command/change_spec.rb
129
146
  - spec/lib/simple-git-pair/command/init_spec.rb
130
147
  - spec/lib/simple-git-pair/helper_spec.rb
131
148
  - spec/spec_helper.rb
149
+ - spec/support/shared_examples/command_examples.rb
132
150
  - features/step_definitions/pair_steps.rb
133
151
  - features/support/env.rb