simple-git-pair 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ ## 0.0.1
2
+ - Initial release
3
+
4
+ ## 0.0.2
5
+ - Added rspec suite
6
+ - Fixed ugly output if unknown pair is specified
7
+
8
+ ## 0.0.3
9
+ - Added integration test suite
10
+ - git pair init command
11
+ - Improved documentation
12
+
13
+ ## 0.0.4
14
+ - Interactive creation of a sample config
data/bin/git-pair CHANGED
@@ -1,4 +1,38 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'commander/import'
2
4
  require 'simple-git-pair'
3
5
 
4
- SimpleGitPair::Cli.new(ARGV).run!
6
+ BINARY_NAME = "git pair"
7
+
8
+ #TODO: figure out a better way to output usage first
9
+ program :name, "\n Usage:\n #{BINARY_NAME} <initials>"
10
+ program :version, SimpleGitPair::VERSION
11
+ program :description, SimpleGitPair::SUMMARY
12
+ program :int_message, "Good bye"
13
+ program :help, 'Example', 'git pair nt ae Changes your git user.name to "Nicola Tesla & Alfred Einstein"'
14
+ program :help_formatter, :compact
15
+
16
+ default_command :change
17
+ 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"
21
+ c.action do |args, options|
22
+ if args.empty?
23
+ commands['help'].run
24
+ else
25
+ SimpleGitPair::Command::Change.new(args).run!
26
+ end
27
+ end
28
+ end
29
+
30
+ 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"
34
+ c.action do |args, options|
35
+ SimpleGitPair::Command::Init.new.run!
36
+ end
37
+ end
38
+
@@ -0,0 +1,34 @@
1
+ Given /^there is a local repo$/ do
2
+ @git_repo = 'my-repo'
3
+ step %Q{a directory named "#{@git_repo}"}
4
+ step %Q{I cd to "#{@git_repo}"}
5
+ step 'I run `git init`'
6
+ end
7
+
8
+ Given /^there is no pairs file$/ do
9
+ step %Q{I remove the file "#{@pairs_file}"} if File.exists? @pairs_file
10
+ end
11
+
12
+ Then /^it creates a sample pairs file$/ do
13
+ step %Q{a file named "#{@pairs_file}" should exist}
14
+ end
15
+
16
+ When /^the git username should be "(.*?)"$/ do |username|
17
+ step "I run `git config user.name`"
18
+ step %Q{the output should contain "#{username}"}
19
+ end
20
+
21
+ When /^I commit some changes$/ do
22
+ step 'I append to "some_file" with "some_changes"'
23
+ step 'I run `git add .`'
24
+ step 'I run `git commit -m "some changes"`'
25
+ end
26
+
27
+ Then /^I should see "(.*?)" on the commit$/ do |username|
28
+ step 'I run `git --no-pager log`'
29
+ step %Q{the output should contain "Author: #{username}"}
30
+ end
31
+
32
+ Then /^it should offer to create a sample config$/ do
33
+ step %Q{the output should contain "Create a sample one?"}
34
+ end
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ require 'aruba/cucumber'
3
+ PROJECT_ROOT = "#{File.dirname(__FILE__)}/../.."
4
+ CUKE_TMP_DIR = File.join PROJECT_ROOT, 'features', 'tmp'
5
+
6
+ Before do
7
+ @dirs = [CUKE_TMP_DIR]
8
+ @real_home = ENV['HOME']
9
+ ENV['HOME'] = CUKE_TMP_DIR
10
+ @pairs_file = File.join ENV['HOME'], ".git_pairs"
11
+ FileUtils.rm_rf CUKE_TMP_DIR if File.exists? CUKE_TMP_DIR
12
+ end
13
+
14
+ After do |scenario|
15
+ FileUtils.rm_rf CUKE_TMP_DIR if File.exists? CUKE_TMP_DIR
16
+ ENV['HOME'] = @real_home
17
+ end
@@ -1,2 +1,4 @@
1
1
  require 'simple-git-pair/helper'
2
- require 'simple-git-pair/cli'
2
+ require 'simple-git-pair/command/base'
3
+ require 'simple-git-pair/command/init'
4
+ require 'simple-git-pair/command/change'
@@ -0,0 +1,15 @@
1
+ module SimpleGitPair
2
+ module Command
3
+ class Base
4
+ attr_accessor :opts
5
+
6
+ def initialize(opts = {})
7
+ self.opts = opts
8
+ end
9
+
10
+ def run!
11
+ raise "Could you implement run! method on #{self.class}?"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ require 'simple-git-pair/command/base'
2
+ require 'simple-git-pair/helper'
3
+
4
+ module SimpleGitPair
5
+ module Command
6
+ class Change < Base
7
+ def run!
8
+ exit 1 unless ensure_pairs_file_exists
9
+
10
+ begin
11
+ system "git config user.name '#{(Helper.names_for opts).join ' & '}'"
12
+ rescue Helper::NotFoundException => ex
13
+ puts ex.message
14
+ exit 1
15
+ end
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
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ require 'simple-git-pair/command/base'
2
+ require 'simple-git-pair/helper'
3
+
4
+ module SimpleGitPair
5
+ module Command
6
+ class Init < Base
7
+ def run!
8
+ if Helper.pairs_file_exists?
9
+ Helper.say_pairs_file_exists
10
+ else
11
+ Helper.create_pairs_file
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,4 @@
1
- require 'yaml'
1
+ require 'yaml' # need to explicitly require yaml for ruby 1.8.7
2
2
  require 'simple-git-pair/version'
3
3
 
4
4
  module SimpleGitPair
@@ -8,32 +8,17 @@ module SimpleGitPair
8
8
 
9
9
  class << self
10
10
  PAIRS_FILE_NAME = '.git_pairs'
11
- PAIRS_FILE_PATH = File.expand_path("~/#{PAIRS_FILE_NAME}")
12
-
13
- def show_help
14
- puts <<-EOS
15
-
16
- #{SUMMARY}
17
- Usage: git-pair <initial1> <initial2>
18
-
19
- Commands:
20
- init - creates sample #{PAIRS_FILE_NAME} config
21
- EOS
22
- end
11
+ PAIRS_FILE_PATH = File.join ENV['HOME'], PAIRS_FILE_NAME
23
12
 
24
13
  def complain_about_pairs_file
25
14
  puts <<-EOS
26
-
27
- Please create #{PAIRS_FILE_NAME} file in your home directory in yaml format:
28
- ae: Alfred Einstein
29
- nt: Nikola Tesla
15
+ Couldn't find #{PAIRS_FILE_PATH}
16
+ Please run: git pair init
30
17
  EOS
31
18
  end
32
19
 
33
20
  def say_pairs_file_exists
34
- puts <<-EOS
35
- #{PAIRS_FILE_PATH} already exists. You're good to go.
36
- EOS
21
+ puts "#{PAIRS_FILE_PATH} already exists. You're good to go."
37
22
  end
38
23
 
39
24
  def names_for args
@@ -1,4 +1,4 @@
1
1
  module SimpleGitPair
2
2
  SUMMARY = "Simple way to add your pair to a git commit message"
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
@@ -1,42 +1,18 @@
1
- require 'simple-git-pair/cli'
1
+ require 'simple-git-pair/command/change'
2
2
 
3
- describe SimpleGitPair::Cli do
3
+ describe SimpleGitPair::Command::Change do
4
4
  before { Object.stub(:system) }
5
5
  let(:opts) { [] }
6
- let(:cli) { described_class.new opts }
6
+ let(:command) { described_class.new opts }
7
7
 
8
8
  describe "#run!" do
9
- subject { cli.run! }
10
-
11
- context "there is no option passed in" do
12
- let(:opts) { [] }
13
- it "shows help" do
14
- SimpleGitPair::Helper.should_receive :show_help
15
- expect { subject }.to raise_error SystemExit
16
- end
17
- end
18
-
19
- context "with --help or -h option" do
20
- let(:opts) { ['--help', '-h'] }
21
- it "shows help" do
22
- SimpleGitPair::Helper.should_receive :show_help
23
- expect { subject }.to raise_error SystemExit
24
- end
25
- end
26
-
27
- context "'init' command" do
28
- let(:opts) { ['init'] }
29
- it "runs init cmd" do
30
- cli.should_receive :init_cmd
31
- expect { subject }.to raise_error SystemExit
32
- end
33
- end
9
+ subject { command.run! }
34
10
 
35
11
  context "there is NO pairs file" do
36
- before { SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return false }
37
12
  let(:opts) { ["some_initials"] }
13
+
14
+ before { command.stub(:ensure_pairs_file_exists).and_return false }
38
15
  it "complains and exit" do
39
- SimpleGitPair::Helper.should_receive :complain_about_pairs_file
40
16
  expect { subject }.to raise_error SystemExit
41
17
  end
42
18
  end
@@ -46,11 +22,11 @@ describe SimpleGitPair::Cli do
46
22
  before {
47
23
  SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return true
48
24
  SimpleGitPair::Helper.stub(:names_for).and_return ["Super Mario", "Pac Man"]
49
- cli.stub! :system
25
+ command.stub! :system
50
26
  }
51
27
  let(:opts) { ['sm', 'pm'] }
52
28
  it "changes only username to pair name" do
53
- cli.should_receive(:system).with("git config user.name 'Super Mario & Pac Man'")
29
+ command.should_receive(:system).with("git config user.name 'Super Mario & Pac Man'")
54
30
  subject
55
31
  end
56
32
  end
@@ -59,11 +35,11 @@ describe SimpleGitPair::Cli do
59
35
  before {
60
36
  SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return true
61
37
  SimpleGitPair::Helper.stub(:names_for).and_return ["Pac Man"]
62
- cli.stub! :system
38
+ command.stub! :system
63
39
  }
64
40
  let(:opts) { ['pm'] }
65
41
  it "changes only username to single name" do
66
- cli.should_receive(:system).with("git config user.name 'Pac Man'")
42
+ command.should_receive(:system).with("git config user.name 'Pac Man'")
67
43
  subject
68
44
  end
69
45
  end
@@ -74,31 +50,35 @@ describe SimpleGitPair::Cli do
74
50
  before {
75
51
  SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return true
76
52
  SimpleGitPair::Helper.stub(:names_for).and_raise ex
77
- cli.stub! :system
78
- cli.should_receive(:puts).with(ex.message)
53
+ command.stub! :system
54
+ command.should_receive(:puts).with(ex.message)
79
55
  }
80
56
  it { expect { subject }.to raise_error SystemExit }
81
57
  end
82
58
  end
59
+ end
83
60
 
84
- describe "#init_cmd" do
85
- subject { cli.send :init_cmd }
61
+ describe "#ensure_pairs_file_exists" do
62
+ subject { command.send :ensure_pairs_file_exists }
86
63
 
87
- context "pairs file already exists" do
88
- before { SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return true }
89
- it "complains and exit" do
90
- SimpleGitPair::Helper.should_receive :say_pairs_file_exists
91
- subject.should be_false
92
- end
93
- end
64
+ context "there is NO pairs file" do
65
+ before { SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return false }
94
66
 
95
- context "there is no pairs file" do
96
- before { SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return false }
97
- it "creates a pairs file" do
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
98
70
  SimpleGitPair::Helper.should_receive(:create_pairs_file).and_return true
99
71
  subject.should be_true
100
72
  end
101
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
102
82
  end
103
83
  end
104
84
  end
@@ -0,0 +1,23 @@
1
+ require 'simple-git-pair/command/init'
2
+
3
+ describe SimpleGitPair::Command::Init do
4
+ describe "#run!" do
5
+ subject { described_class.new.run! }
6
+
7
+ context "pairs file already exists" do
8
+ before { SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return true }
9
+ it "complains and exit" do
10
+ SimpleGitPair::Helper.should_receive :say_pairs_file_exists
11
+ subject
12
+ end
13
+ end
14
+
15
+ context "there is no pairs file" do
16
+ before { SimpleGitPair::Helper.stub(:pairs_file_exists?).and_return false }
17
+ it "creates a pairs file" do
18
+ SimpleGitPair::Helper.should_receive(:create_pairs_file).and_return true
19
+ subject
20
+ end
21
+ end
22
+ end
23
+ 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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,44 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-02 00:00:00.000000000 Z
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: commander
16
+ requirement: &70286427233280 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70286427233280
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rspec
16
- requirement: &70241657198260 !ruby/object:Gem::Requirement
27
+ requirement: &70286427232800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70286427232800
36
+ - !ruby/object:Gem::Dependency
37
+ name: aruba
38
+ requirement: &70286427232220 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70286427232220
47
+ - !ruby/object:Gem::Dependency
48
+ name: cucumber
49
+ requirement: &70286427231460 !ruby/object:Gem::Requirement
17
50
  none: false
18
51
  requirements:
19
52
  - - ! '>='
@@ -21,10 +54,10 @@ dependencies:
21
54
  version: '0'
22
55
  type: :development
23
56
  prerelease: false
24
- version_requirements: *70241657198260
57
+ version_requirements: *70286427231460
25
58
  - !ruby/object:Gem::Dependency
26
59
  name: rake
27
- requirement: &70241657197660 !ruby/object:Gem::Requirement
60
+ requirement: &70286427231020 !ruby/object:Gem::Requirement
28
61
  none: false
29
62
  requirements:
30
63
  - - ! '>='
@@ -32,10 +65,10 @@ dependencies:
32
65
  version: '0'
33
66
  type: :development
34
67
  prerelease: false
35
- version_requirements: *70241657197660
68
+ version_requirements: *70286427231020
36
69
  - !ruby/object:Gem::Dependency
37
70
  name: debugger
38
- requirement: &70241657197160 !ruby/object:Gem::Requirement
71
+ requirement: &70286427230240 !ruby/object:Gem::Requirement
39
72
  none: false
40
73
  requirements:
41
74
  - - ! '>='
@@ -43,9 +76,8 @@ dependencies:
43
76
  version: '0'
44
77
  type: :development
45
78
  prerelease: false
46
- version_requirements: *70241657197160
47
- description: Changes only user.name setting in git config, so github
48
- can still understand under which account a code was committed
79
+ version_requirements: *70286427230240
80
+ description: Simple way to add your pair to a git commit message
49
81
  email:
50
82
  - a.tamoykin@gmail.com
51
83
  executables:
@@ -53,15 +85,21 @@ executables:
53
85
  extensions: []
54
86
  extra_rdoc_files: []
55
87
  files:
56
- - lib/simple-git-pair/cli.rb
88
+ - lib/simple-git-pair/command/base.rb
89
+ - lib/simple-git-pair/command/change.rb
90
+ - lib/simple-git-pair/command/init.rb
57
91
  - lib/simple-git-pair/helper.rb
58
92
  - lib/simple-git-pair/version.rb
59
93
  - lib/simple-git-pair.rb
60
94
  - bin/git-pair
95
+ - CHANGELOG.md
61
96
  - README.md
62
- - spec/lib/simple-git-pair/cli_spec.rb
97
+ - spec/lib/simple-git-pair/command/change_spec.rb
98
+ - spec/lib/simple-git-pair/command/init_spec.rb
63
99
  - spec/lib/simple-git-pair/helper_spec.rb
64
100
  - spec/spec_helper.rb
101
+ - features/step_definitions/pair_steps.rb
102
+ - features/support/env.rb
65
103
  homepage: http://github.com/fsproru/simple-git-pair
66
104
  licenses: []
67
105
  post_install_message:
@@ -87,6 +125,9 @@ signing_key:
87
125
  specification_version: 3
88
126
  summary: Simple way to add your pair to a git commit message
89
127
  test_files:
90
- - spec/lib/simple-git-pair/cli_spec.rb
128
+ - spec/lib/simple-git-pair/command/change_spec.rb
129
+ - spec/lib/simple-git-pair/command/init_spec.rb
91
130
  - spec/lib/simple-git-pair/helper_spec.rb
92
131
  - spec/spec_helper.rb
132
+ - features/step_definitions/pair_steps.rb
133
+ - features/support/env.rb
@@ -1,46 +0,0 @@
1
- require 'simple-git-pair/helper'
2
-
3
- module SimpleGitPair
4
- class Cli
5
- attr_accessor :opts
6
-
7
- def initialize(opts = {})
8
- self.opts = opts
9
- end
10
-
11
- def run!
12
- if opts.delete "--help" or opts.delete "-h" or opts.empty?
13
- Helper.show_help
14
- exit 0
15
- end
16
-
17
- if opts.delete "init"
18
- exit(init_cmd ? 0 : 1)
19
- end
20
-
21
- unless Helper.pairs_file_exists?
22
- Helper.complain_about_pairs_file
23
- exit 1
24
- end
25
-
26
- begin
27
- system "git config user.name '#{(Helper.names_for ARGV).join ' & '}'"
28
- rescue Helper::NotFoundException => ex
29
- puts ex.message
30
- exit 1
31
- end
32
-
33
- system "git config user.name" # output current username
34
- end
35
-
36
- private
37
-
38
- def init_cmd
39
- if Helper.pairs_file_exists?
40
- Helper.say_pairs_file_exists
41
- else
42
- Helper.create_pairs_file
43
- end
44
- end
45
- end
46
- end