cypriss-git_remote_branch 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ TEST_DIR = File.dirname(__FILE__)
5
+
6
+ # Install version 2 the shoulda gem with
7
+ # gem install thoughtbot-shoulda --source http://gems.github.com
8
+ # Shoulda depends on ActiveSupport 2.0, so if you don't have Rails 2.x installed, install ActiveSupport before Shoulda:
9
+ # gem install activesupport
10
+ gem 'thoughtbot-shoulda', '~> 2.0'
11
+ require 'shoulda'
12
+ gem 'mocha', '~> 0.5'
13
+ require 'mocha'
14
+
15
+ # Just load redgreen if not running tests from TextMate
16
+ IN_TM = !ENV['TM_DIRECTORY'].nil? unless defined?(IN_TM)
17
+ begin
18
+ require 'redgreen' unless IN_TM
19
+ rescue LoadError => ex
20
+ puts "Couldn't load optional test dependencies: #{ex.inspect}"
21
+ end
22
+
23
+ require File.join( [TEST_DIR] + %w{ .. lib git_remote_branch} )
24
+
25
+ require "#{TEST_DIR}/helpers/in_dir"
26
+ Dir[TEST_DIR+'/helpers/**/*.rb'].each{|f| require f}
27
+
28
+ class Test::Unit::TestCase
29
+ include MoreAssertions
30
+
31
+ attr_reader :grb
32
+ def setup
33
+ @grb = Object.new
34
+ @grb.send :extend, GitRemoteBranch
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class GitHelperTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ @g = GitHelper.new
8
+ @directories = [@g.remote, @g.local1, @g.local2]
9
+ end
10
+
11
+ def teardown
12
+ @g.cleanup
13
+ end
14
+
15
+ def test_init
16
+ @directories.each do |d|
17
+ assert File.exists?(@g.remote), 'Directory for repo must be created'
18
+ assert File.exists?( File.join(@g.remote, '.git') ), 'Repo must be created'
19
+ end
20
+ end
21
+
22
+ def test_cleanup
23
+ @g.cleanup
24
+
25
+ @directories.each do |d|
26
+ assert_false File.exists?(@g.remote), 'Each repo directory must be destroyed after cleanup'
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,39 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class GitRemoteBranchTest < Test::Unit::TestCase
4
+ context 'help' do
5
+ should 'contain examples for all basic commands' do
6
+ GitRemoteBranch::COMMANDS.keys.each do |k|
7
+ assert_match "grb #{k} branch_name", grb.get_usage
8
+ end
9
+ end
10
+
11
+ should 'contain an example for explain' do
12
+ assert_match 'grb explain', grb.get_usage
13
+ end
14
+
15
+ should 'contain an enumeration of all aliases' do
16
+ GitRemoteBranch::COMMANDS.each_pair do |k,v|
17
+ assert_match "#{k}: #{v[:aliases].join(', ')}", grb.get_usage
18
+ end
19
+ end
20
+ end
21
+
22
+ context "the reverse mapping for aliases" do
23
+ GitRemoteBranch::COMMANDS.each_pair do |cmd, params|
24
+ params[:aliases].each do |alias_|
25
+ should "contain the alias #{alias_}" do
26
+ assert GitRemoteBranch::ALIAS_REVERSE_MAP[alias_]
27
+ end
28
+ end
29
+ end
30
+
31
+ context "upon creation" do
32
+ should "raise an exception when there are duplicates" do
33
+ assert_raise(RuntimeError) do
34
+ GitRemoteBranch.get_reverse_map( GitRemoteBranch::COMMANDS.merge(:new_command => {:aliases => ['create']}) )
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,215 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'test_helper')
2
+ require "#{TEST_DIR}/helpers/constants"
3
+
4
+ class ParamReaderTest < Test::Unit::TestCase
5
+ include ShouldaUnitHelpers
6
+
7
+ context 'read_params' do
8
+ context "when on a valid branch" do
9
+ setup do
10
+ grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
11
+ end
12
+
13
+ context "on a normal valid command without an origin" do
14
+ setup do
15
+ @p = grb.read_params %w{create the_branch}
16
+ end
17
+
18
+ should_set_action_to :create
19
+ should_set_branch_to 'the_branch'
20
+ should_set_origin_to 'origin'
21
+ should_set_current_branch_to 'stubbed_current_branch'
22
+ should_set_explain_to false
23
+ should_set_silent_to false
24
+ end
25
+
26
+ context "on a normal valid command" do
27
+ setup do
28
+ @p = grb.read_params %w{create the_branch the_origin}
29
+ end
30
+
31
+ should_set_action_to :create
32
+ should_set_branch_to 'the_branch'
33
+ should_set_origin_to 'the_origin'
34
+ should_set_current_branch_to 'stubbed_current_branch'
35
+ should_set_explain_to false
36
+ should_set_silent_to false
37
+ end
38
+
39
+ should_explain_with_current_branch 'stubbed_current_branch', "use real current branch"
40
+
41
+ should_return_help_for_parameters %w(help), "on a 'help' command"
42
+ should_return_help_for_parameters %w(create), "on an incomplete command"
43
+ should_return_help_for_parameters %w(decombobulate something), "on an invalid command"
44
+
45
+ context "understands the --silent parameter" do
46
+ context "at the beginning" do
47
+ setup do
48
+ @p = grb.read_params %w{--silent create some_branch some_origin}
49
+ end
50
+ should_set_silent_to true
51
+ should_set_action_to :create
52
+ should_set_branch_to 'some_branch'
53
+ should_set_origin_to 'some_origin'
54
+ end
55
+
56
+ context "at the end" do
57
+ setup do
58
+ @p = grb.read_params %w{create some_branch some_origin --silent}
59
+ end
60
+ should_set_silent_to true
61
+ should_set_action_to :create
62
+ should_set_branch_to 'some_branch'
63
+ should_set_origin_to 'some_origin'
64
+ end
65
+
66
+ context "in the freakin' middle" do
67
+ setup do
68
+ @p = grb.read_params %w{create --silent some_branch some_origin}
69
+ end
70
+ should_set_silent_to true
71
+ should_set_action_to :create
72
+ should_set_branch_to 'some_branch'
73
+ should_set_origin_to 'some_origin'
74
+ end
75
+ end
76
+ end
77
+
78
+ context "when on an invalid branch" do
79
+ setup do
80
+ grb.stubs(:capture_process_output).returns([0, BRANCH_LISTING_WHEN_NOT_ON_BRANCH])
81
+ end
82
+
83
+ GitRemoteBranch::COMMANDS.each_key do |action|
84
+ context "running the '#{action}' command" do
85
+ setup do
86
+ @command = [action.to_s, 'branch_name']
87
+ end
88
+
89
+ context "raising an exception" do
90
+ setup do
91
+ begin
92
+ grb.read_params(@command)
93
+ rescue => @ex
94
+ end
95
+ end
96
+
97
+ should "raise an InvalidBranchError" do
98
+ assert_kind_of GitRemoteBranch::InvalidBranchError, @ex
99
+ end
100
+
101
+ should "give a clear error message" do
102
+ assert_match(/identify.*branch/, @ex.message)
103
+ end
104
+
105
+ should "display git's branch listing" do
106
+ assert_match(/\(no branch\)/, @ex.message)
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ should_explain_with_current_branch 'current_branch', "use a dummy value for the current branch"
113
+
114
+ should_return_help_for_parameters %w(help), "on a 'help' command"
115
+ should_return_help_for_parameters %w(create), "on an incomplete command"
116
+ should_return_help_for_parameters %w(decombobulate something), "on an invalid command"
117
+ end
118
+
119
+ context "when not on a git repository" do
120
+ setup do
121
+ grb.stubs(:capture_process_output).returns([128, WHEN_NOT_ON_GIT_REPOSITORY])
122
+ end
123
+
124
+ should_explain_with_current_branch 'current_branch', "use a dummy value for the current branch"
125
+
126
+ should_return_help_for_parameters %w(help), "on a 'help' command"
127
+ should_return_help_for_parameters %w(create), "on an incomplete command"
128
+ should_return_help_for_parameters %w(decombobulate something), "on an invalid command"
129
+
130
+ GitRemoteBranch::COMMANDS.each_key do |action|
131
+ context "running the '#{action}' command" do
132
+ setup do
133
+ @command = [action.to_s, 'branch_name']
134
+ end
135
+
136
+ context "raising an exception" do
137
+ setup do
138
+ begin
139
+ grb.read_params(@command)
140
+ rescue => @ex
141
+ end
142
+ end
143
+
144
+ should "raise an NotOnGitRepositoryError" do
145
+ assert_kind_of GitRemoteBranch::NotOnGitRepositoryError, @ex
146
+ end
147
+
148
+ should "give a clear error message" do
149
+ assert_match(/fatal/, @ex.message)
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+
157
+ context 'explain_mode!' do
158
+ context "when it receives an array beginning with 'explain'" do
159
+ setup do
160
+ @array = ['explain', 'create', 'some_branch']
161
+ end
162
+
163
+ should "return true" do
164
+ assert grb.explain_mode!(@array)
165
+ end
166
+
167
+ should 'accept symbol arrays as well' do
168
+ assert grb.explain_mode!( @array.map{|e| e.to_sym} )
169
+ end
170
+
171
+ should "remove 'explain' from the argument array" do
172
+ grb.explain_mode!(@array)
173
+ assert_equal ['create', 'some_branch'], @array
174
+ end
175
+ end
176
+
177
+ context "when it receives an array that doesn't begin with 'explain'" do
178
+ setup do
179
+ @array = ['create', 'some_branch']
180
+ end
181
+
182
+ should "return false" do
183
+ assert_false grb.explain_mode!(@array)
184
+ end
185
+
186
+ should "not modify the argument array" do
187
+ grb.explain_mode!(@array)
188
+ assert_equal ['create', 'some_branch'], @array
189
+ end
190
+ end
191
+ end
192
+
193
+ context 'get_action' do
194
+ GitRemoteBranch::COMMANDS.each_pair do |cmd, params|
195
+ should "recognize all #{cmd} aliases" do
196
+ params[:aliases].each do |alias_|
197
+ assert cmd, grb.get_action(alias_)
198
+ end
199
+ end
200
+ end
201
+ should 'return nil on unknown aliases' do
202
+ assert_nil grb.get_action('please_dont_create_an_alias_named_like_this')
203
+ end
204
+ end
205
+
206
+ context 'get_origin' do
207
+ should "default to 'origin' when the param is nil" do
208
+ assert_equal 'origin', grb.get_origin(nil)
209
+ end
210
+ should "return the unchanged param if it's not nil" do
211
+ assert_equal 'someword', grb.get_origin('someword')
212
+ end
213
+ end
214
+
215
+ end
@@ -0,0 +1,56 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'test_helper')
2
+ require "#{TEST_DIR}/helpers/constants"
3
+
4
+ class ParamReaderTest < Test::Unit::TestCase
5
+ include ShouldaUnitHelpers
6
+
7
+ def self.craps_out_in_invalid_situations
8
+ context "when not on a git repository" do
9
+ setup do
10
+ grb.stubs(:capture_process_output).returns([128, WHEN_NOT_ON_GIT_REPOSITORY])
11
+ end
12
+
13
+ should "raise an exception" do
14
+ assert_raise(GitRemoteBranch::NotOnGitRepositoryError) { grb.get_current_branch }
15
+ end
16
+ end
17
+
18
+ context "when on an invalid branch" do
19
+ setup do
20
+ grb.stubs(:capture_process_output).returns([0, BRANCH_LISTING_WHEN_NOT_ON_BRANCH])
21
+ end
22
+
23
+ should "raise an exception" do
24
+ assert_raise(GitRemoteBranch::InvalidBranchError) { grb.get_current_branch }
25
+ end
26
+ end
27
+ end
28
+
29
+ context 'get_current_branch' do
30
+ craps_out_in_invalid_situations
31
+
32
+ context "when on a valid branch" do
33
+ setup do
34
+ grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
35
+ end
36
+
37
+ should "return the current branch name" do
38
+ assert_equal 'stubbed_current_branch', grb.get_current_branch
39
+ end
40
+ end
41
+ end
42
+
43
+ context 'local_branches' do
44
+ craps_out_in_invalid_situations
45
+
46
+ context "when on a valid branch" do
47
+ setup do
48
+ grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
49
+ end
50
+
51
+ should "return all the local branch names" do
52
+ assert_array_content %w{stubbed_current_branch other_user/master rubyforge}, grb.local_branches
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,58 @@
1
+ module CaptureFu
2
+ VERSION = '0.0.1'
3
+
4
+ def capture_output(&block)
5
+ real_out, real_err = $stdout, $stderr
6
+ result = fake_out = fake_err = nil
7
+ begin
8
+ fake_out, fake_err = Helpers::PipeStealer.new, Helpers::PipeStealer.new
9
+ $stdout, $stderr = fake_out, fake_err
10
+ result = yield
11
+ ensure
12
+ $stdout, $stderr = real_out, real_err
13
+ end
14
+ return result, fake_out.captured, fake_err.captured
15
+ end
16
+
17
+ # This first implementation is only intended for batch executions.
18
+ # You can't pipe stuff programmatically to the child process.
19
+ def capture_process_output(command)
20
+
21
+ #capture stderr in the same stream
22
+ command << ' 2>&1' unless Helpers.stderr_already_redirected(command)
23
+
24
+ out = `#{command}`
25
+ return $?.exitstatus, out
26
+ end
27
+
28
+
29
+ private
30
+
31
+ module Helpers
32
+
33
+ def self.stderr_already_redirected(command)
34
+ #Already redirected to stdout (valid for Windows)
35
+ return true if command =~ /2>&1\s*\Z/
36
+
37
+ #Redirected to /dev/null (this is clearly POSIX-dependent)
38
+ return true if command =~ /2>\/dev\/null\s*\Z/
39
+
40
+ return false
41
+ end
42
+
43
+ class PipeStealer < File
44
+ attr_reader :captured
45
+ def initialize
46
+ @captured = ''
47
+ end
48
+ def write(s)
49
+ @captured << s
50
+ end
51
+ def captured
52
+ return nil if @captured.empty?
53
+ @captured.dup
54
+ end
55
+ end
56
+
57
+ end #Helper module
58
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cypriss-git_remote_branch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ platform: ruby
6
+ authors:
7
+ - Mathieu Martin
8
+ - Carl Mercier
9
+ - Jonathan Novak
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-06-11 00:00:00 -07:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: colored
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: "1.1"
26
+ version:
27
+ description: git_remote_branch is a learning tool to ease the interaction with remote branches in simple situations.
28
+ email: jnovak@gmail.com
29
+ executables:
30
+ - grb
31
+ extensions: []
32
+
33
+ extra_rdoc_files:
34
+ - README.rdoc
35
+ files:
36
+ - bin
37
+ - bin/grb
38
+ - CHANGELOG
39
+ - lib
40
+ - lib/constants.rb
41
+ - lib/git_remote_branch.rb
42
+ - lib/monkey_patches.rb
43
+ - lib/param_reader.rb
44
+ - lib/state.rb
45
+ - lib/version.rb
46
+ - LICENSE
47
+ - Rakefile
48
+ - README.rdoc
49
+ - tasks
50
+ - tasks/gem.rake
51
+ - tasks/rdoc.rake
52
+ - tasks/test.rake
53
+ - test
54
+ - test/functional
55
+ - test/functional/grb_test.rb
56
+ - test/helpers
57
+ - test/helpers/array_extensions.rb
58
+ - test/helpers/constants.rb
59
+ - test/helpers/extractable.rb
60
+ - test/helpers/git_helper.rb
61
+ - test/helpers/in_dir.rb
62
+ - test/helpers/more_assertions.rb
63
+ - test/helpers/shoulda_functional_helpers.rb
64
+ - test/helpers/shoulda_unit_helpers.rb
65
+ - test/helpers/temp_dir_helper.rb
66
+ - test/test_helper.rb
67
+ - test/unit
68
+ - test/unit/git_helper_test.rb
69
+ - test/unit/git_remote_branch_test.rb
70
+ - test/unit/param_reader_test.rb
71
+ - test/unit/state_test.rb
72
+ - vendor
73
+ - vendor/capture_fu.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/cypriss/git_remote_branch
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --main
79
+ - README.rdoc
80
+ - --exclude
81
+ - lib
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project: grb
99
+ rubygems_version: 1.2.0
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: git_remote_branch eases the interaction with remote branches
103
+ test_files:
104
+ - test/functional
105
+ - test/functional/grb_test.rb
106
+ - test/helpers
107
+ - test/helpers/array_extensions.rb
108
+ - test/helpers/constants.rb
109
+ - test/helpers/extractable.rb
110
+ - test/helpers/git_helper.rb
111
+ - test/helpers/in_dir.rb
112
+ - test/helpers/more_assertions.rb
113
+ - test/helpers/shoulda_functional_helpers.rb
114
+ - test/helpers/shoulda_unit_helpers.rb
115
+ - test/helpers/temp_dir_helper.rb
116
+ - test/test_helper.rb
117
+ - test/unit
118
+ - test/unit/git_helper_test.rb
119
+ - test/unit/git_remote_branch_test.rb
120
+ - test/unit/param_reader_test.rb
121
+ - test/unit/state_test.rb