git_helper 1.3.0 → 3.0.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +17 -13
- data/README.md +37 -44
- data/Rakefile +1 -37
- data/bin/git-helper +10 -28
- data/lib/git_helper.rb +3 -5
- data/lib/git_helper/change_remote.rb +53 -40
- data/lib/git_helper/checkout_default.rb +1 -1
- data/lib/git_helper/clean_branches.rb +1 -4
- data/lib/git_helper/code_request.rb +95 -0
- data/lib/git_helper/empty_commit.rb +1 -1
- data/lib/git_helper/forget_local_commits.rb +7 -0
- data/lib/git_helper/git_config_reader.rb +1 -1
- data/lib/git_helper/gitlab_client.rb +0 -1
- data/lib/git_helper/highline_cli.rb +21 -17
- data/lib/git_helper/local_code.rb +67 -19
- data/lib/git_helper/merge_request.rb +55 -73
- data/lib/git_helper/new_branch.rb +2 -13
- data/lib/git_helper/octokit_client.rb +0 -1
- data/lib/git_helper/pull_request.rb +44 -67
- data/lib/git_helper/version.rb +1 -1
- data/plugins.zip +0 -0
- data/spec/git_helper/change_remote_spec.rb +173 -0
- data/spec/git_helper/checkout_default_spec.rb +19 -0
- data/spec/git_helper/clean_branches_spec.rb +19 -0
- data/spec/git_helper/code_request_spec.rb +259 -0
- data/spec/git_helper/empty_commit_spec.rb +19 -0
- data/spec/git_helper/forget_local_commits_spec.rb +19 -0
- data/spec/git_helper/git_config_reader_spec.rb +60 -0
- data/spec/git_helper/gitlab_client_spec.rb +26 -0
- data/spec/git_helper/highline_cli_spec.rb +215 -0
- data/spec/git_helper/local_code_spec.rb +231 -0
- data/spec/git_helper/merge_request_spec.rb +234 -0
- data/spec/git_helper/new_branch_spec.rb +44 -0
- data/spec/git_helper/octokit_client_spec.rb +26 -0
- data/spec/git_helper/pull_request_spec.rb +246 -0
- data/spec/spec_helper.rb +0 -7
- metadata +41 -24
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
3
|
+
|
4
|
+
describe GitHelper::EmptyCommit do
|
5
|
+
let(:local_code) { double(:local_code, empty_commit: :commit) }
|
6
|
+
|
7
|
+
subject { GitHelper::EmptyCommit.new }
|
8
|
+
|
9
|
+
it 'should call GitHelper::LocalCode' do
|
10
|
+
expect(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
11
|
+
subject.execute
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should call the empty_commit method from the local code class' do
|
15
|
+
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
16
|
+
expect(local_code).to receive(:empty_commit)
|
17
|
+
subject.execute
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
3
|
+
|
4
|
+
describe GitHelper::ForgetLocalCommits do
|
5
|
+
let(:local_code) { double(:local_code, forget_local_commits: :commit) }
|
6
|
+
|
7
|
+
subject { GitHelper::ForgetLocalCommits.new }
|
8
|
+
|
9
|
+
it 'should call GitHelper::LocalCode' do
|
10
|
+
expect(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
11
|
+
subject.execute
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should call the forget_local_commits method from the local code class' do
|
15
|
+
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
16
|
+
expect(local_code).to receive(:forget_local_commits)
|
17
|
+
subject.execute
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
3
|
+
|
4
|
+
describe GitHelper::GitConfigReader do
|
5
|
+
let(:github_token) { '1234ASDF1234ASDF' }
|
6
|
+
let(:gitlab_token) { 'ASDF123ASDF1234' }
|
7
|
+
let(:config_file) {
|
8
|
+
{
|
9
|
+
github_user: 'github-user-name',
|
10
|
+
github_token: github_token,
|
11
|
+
gitlab_user: 'gitlab-user-name',
|
12
|
+
gitlab_token: gitlab_token
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
subject { GitHelper::GitConfigReader.new }
|
17
|
+
|
18
|
+
describe '#gitlab_token' do
|
19
|
+
it 'should locate the gitlab_token' do
|
20
|
+
expect(subject).to receive(:config_file).and_return(config_file)
|
21
|
+
expect(subject.gitlab_token).to eq(gitlab_token)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should call the config file' do
|
25
|
+
expect(subject).to receive(:config_file).and_return(config_file)
|
26
|
+
subject.gitlab_token
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#github_token' do
|
31
|
+
it 'should locate the github_token' do
|
32
|
+
expect(subject).to receive(:config_file).and_return(config_file)
|
33
|
+
expect(subject.github_token).to eq(github_token)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should call the config file' do
|
37
|
+
expect(subject).to receive(:config_file).and_return(config_file)
|
38
|
+
subject.github_token
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#config_file' do
|
43
|
+
it 'should yaml load the file path' do
|
44
|
+
expect(YAML).to receive(:load_file)
|
45
|
+
subject.send(:config_file)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#git_config_file_path' do
|
50
|
+
it 'should look in the current directory' do
|
51
|
+
expect(Dir).to receive(:pwd).and_return('/Users/firstnamelastname/path/to/git_helper')
|
52
|
+
subject.send(:git_config_file_path)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should return the base path with the git config file at the end' do
|
56
|
+
allow(Dir).to receive(:pwd).and_return('/Users/firstnamelastname/path/to/git_helper')
|
57
|
+
expect(subject.send(:git_config_file_path)).to eq('/Users/firstnamelastname/.git_helper/config.yml')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
3
|
+
|
4
|
+
describe GitHelper::GitLabClient do
|
5
|
+
let(:git_config_reader) { double(:git_config_reader, gitlab_token: :token) }
|
6
|
+
|
7
|
+
subject { GitHelper::GitLabClient.new }
|
8
|
+
|
9
|
+
before do
|
10
|
+
allow(GitHelper::GitConfigReader).to receive(:new).and_return(git_config_reader)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#client' do
|
14
|
+
it 'should call the GitLab client to make a new client' do
|
15
|
+
expect(Gitlab).to receive(:client)
|
16
|
+
subject.client
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#git_config_reader' do
|
21
|
+
it 'should make a new git config reader' do
|
22
|
+
expect(GitHelper::GitConfigReader).to receive(:new)
|
23
|
+
subject.send(:git_config_reader)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
3
|
+
|
4
|
+
describe GitHelper::HighlineCli do
|
5
|
+
let(:response) { double(:response, readline: true, to_i: 5) }
|
6
|
+
let(:highline_client) { double(:highline_cli, ask: response) }
|
7
|
+
|
8
|
+
subject { GitHelper::HighlineCli.new }
|
9
|
+
|
10
|
+
before do
|
11
|
+
allow(HighLine).to receive(:new).and_return(highline_client)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#new_branch_name' do
|
15
|
+
it "should ask the subject's ask method" do
|
16
|
+
expect(subject).to receive(:ask).with('New branch name?')
|
17
|
+
subject.new_branch_name
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should come out a string' do
|
21
|
+
expect(subject.new_branch_name).to be_a(String)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#process_directory_remotes' do
|
26
|
+
it "should ask the subject's ask method" do
|
27
|
+
expect(subject).to receive(:ask).and_return('y')
|
28
|
+
subject.process_directory_remotes?('directory')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should be a boolean at the end' do
|
32
|
+
allow(subject).to receive(:ask).and_return('y')
|
33
|
+
expect([true, false]).to include(subject.process_directory_remotes?('directory'))
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should come out as a true boolean if somebody responds y' do
|
37
|
+
allow(subject).to receive(:ask).and_return('y')
|
38
|
+
expect(subject.process_directory_remotes?('directory')).to eq(true)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should come out as a false boolean if somebody responds n' do
|
42
|
+
allow(subject).to receive(:ask).and_return('n')
|
43
|
+
expect(subject.process_directory_remotes?('directory')).to eq(false)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should come out as true if somebody presses enter' do
|
47
|
+
allow(subject).to receive(:ask).and_return('')
|
48
|
+
expect(subject.accept_autogenerated_title?('directory')).to eq(true)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#conflicting_remote_clarification' do
|
53
|
+
it "should ask the subject's ask method" do
|
54
|
+
expect(subject).to receive(:ask).with('Found git remotes for both GitHub and GitLab. Would you like to proceed with GitLab or GitHub? (github/gitlab)').and_return('gitlab')
|
55
|
+
subject.conflicting_remote_clarification
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should come out a string' do
|
59
|
+
expect(subject.conflicting_remote_clarification).to be_a(String)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#title' do
|
64
|
+
it "should ask the subject's ask method" do
|
65
|
+
expect(subject).to receive(:ask).with('Title?')
|
66
|
+
subject.title
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should come out a string' do
|
70
|
+
expect(subject.title).to be_a(String)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#base_branch' do
|
75
|
+
it "should ask the subject's ask method" do
|
76
|
+
expect(subject).to receive(:ask).with('Base branch?')
|
77
|
+
subject.base_branch
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should come out a string' do
|
81
|
+
expect(subject.base_branch).to be_a(String)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#code_request_id' do
|
86
|
+
it "should ask the subject's ask method" do
|
87
|
+
expect(subject).to receive(:ask).with('Example Request ID?')
|
88
|
+
subject.code_request_id('Example')
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should come out a string' do
|
92
|
+
expect(subject.code_request_id('Example')).to be_a(String)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#accept_autogenerated_title' do
|
97
|
+
it "should ask the subject's ask method" do
|
98
|
+
expect(subject).to receive(:ask).and_return('y')
|
99
|
+
subject.accept_autogenerated_title?('Title Example')
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should be a boolean at the end' do
|
103
|
+
allow(subject).to receive(:ask).and_return('y')
|
104
|
+
expect([true, false]).to include(subject.accept_autogenerated_title?('Title Example'))
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should come out as a true boolean if somebody responds y' do
|
108
|
+
allow(subject).to receive(:ask).and_return('y')
|
109
|
+
expect(subject.accept_autogenerated_title?('Title Example')).to eq(true)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should come out as a true boolean if somebody responds n' do
|
113
|
+
allow(subject).to receive(:ask).and_return('n')
|
114
|
+
expect(subject.accept_autogenerated_title?('Title Example')).to eq(false)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should come out as a true boolean if somebody responds yes' do
|
118
|
+
allow(subject).to receive(:ask).and_return('yes')
|
119
|
+
expect(subject.accept_autogenerated_title?('Title Example')).to eq(true)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should come out as a false boolean if somebody responds no' do
|
123
|
+
allow(subject).to receive(:ask).and_return('no')
|
124
|
+
expect(subject.accept_autogenerated_title?('Title Example')).to eq(false)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should come out as true if somebody presses enter' do
|
128
|
+
allow(subject).to receive(:ask).and_return('')
|
129
|
+
expect(subject.accept_autogenerated_title?('Title Example')).to eq(true)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#base_branch_default' do
|
134
|
+
it "should ask the subject's ask method" do
|
135
|
+
expect(subject).to receive(:ask).and_return('y')
|
136
|
+
subject.base_branch_default?('default_branch')
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should be a boolean at the end' do
|
140
|
+
allow(subject).to receive(:ask).and_return('y')
|
141
|
+
expect([true, false]).to include(subject.base_branch_default?('default_branch'))
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should come out as a true boolean if somebody responds y' do
|
145
|
+
allow(subject).to receive(:ask).and_return('y')
|
146
|
+
expect(subject.base_branch_default?('default_branch')).to eq(true)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should come out as a true boolean if somebody responds n' do
|
150
|
+
allow(subject).to receive(:ask).and_return('n')
|
151
|
+
expect(subject.base_branch_default?('default_branch')).to eq(false)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should come out as a true boolean if somebody responds yes' do
|
155
|
+
allow(subject).to receive(:ask).and_return('yes')
|
156
|
+
expect(subject.base_branch_default?('default_branch')).to eq(true)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should come out as a false boolean if somebody responds no' do
|
160
|
+
allow(subject).to receive(:ask).and_return('no')
|
161
|
+
expect(subject.base_branch_default?('default_branch')).to eq(false)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should come out as true if somebody presses enter' do
|
165
|
+
allow(subject).to receive(:ask).and_return('')
|
166
|
+
expect(subject.base_branch_default?('default_branch')).to eq(true)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe '#merge_method' do
|
171
|
+
it "should ask the subject's ask_options method" do
|
172
|
+
expect(subject).to receive(:ask_options).and_return(3)
|
173
|
+
subject.merge_method(['1', '2', '3'])
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should return a string' do
|
177
|
+
allow(subject).to receive(:ask_options).and_return(2)
|
178
|
+
expect(subject.merge_method(['1', '2', '3'])).to be_a(String)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe '#template_to_apply' do
|
183
|
+
it "should ask the subject's ask_options method" do
|
184
|
+
expect(subject).to receive(:ask_options).and_return(3)
|
185
|
+
subject.template_to_apply(['option1', 'option2', 'option3'], 'example type')
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should return a string' do
|
189
|
+
allow(subject).to receive(:ask_options).and_return(3)
|
190
|
+
expect(subject.template_to_apply(['option1', 'option2', 'option3'], 'example type')).to eq('None')
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#ask' do
|
195
|
+
it 'should ask the highline client ask'do
|
196
|
+
expect(highline_client).to receive(:ask)
|
197
|
+
subject.send(:ask, 'prompt goes here')
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'should return a string' do
|
201
|
+
expect(subject.send(:ask, 'prompt goes here')).to be_a(String)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe '#ask_options' do
|
206
|
+
it 'should ask the highline client ask'do
|
207
|
+
expect(highline_client).to receive(:ask)
|
208
|
+
subject.send(:ask_options, 'prompt goes here', ['1', '2', '3'])
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should return an integer' do
|
212
|
+
expect(subject.send(:ask_options, 'prompt goes here', ['1', '2', '3'])).to be_a(Integer)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
3
|
+
|
4
|
+
describe GitHelper::LocalCode do
|
5
|
+
let(:response) { double(:response, readline: true, to_i: 5) }
|
6
|
+
let(:local_codeent) { double(:local_code, ask: response) }
|
7
|
+
let(:ssh_remote) { 'origin\tgit@github.com:emmasax4/git_helper.git (fetch)' }
|
8
|
+
let(:https_remote) { 'origin\thttps://github.com/emmasax4/git_helper.git (fetch)' }
|
9
|
+
let(:github_remotes) { ['origin\tgit@github.com:emmasax4/git_helper.git (fetch)', 'origin\thttps://github.com/emmasax4/git_helper.git (fetch)' ] }
|
10
|
+
let(:gitlab_remotes) { ['origin\tgit@gitlab.com:emmasax4/git_helper.git (fetch)', 'origin\thttps://gitlab.com/emmasax4/git_helper.git (fetch)' ] }
|
11
|
+
|
12
|
+
|
13
|
+
subject { GitHelper::LocalCode.new }
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow(subject).to receive(:system).and_return(nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#checkout_default' do
|
20
|
+
it 'should make a system call' do
|
21
|
+
expect(subject).to receive(:system)
|
22
|
+
subject.checkout_default
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#forget_local_commits' do
|
27
|
+
it 'should make a system call' do
|
28
|
+
expect(subject).to receive(:system).exactly(2).times
|
29
|
+
subject.forget_local_commits
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return nil' do
|
33
|
+
expect(subject.forget_local_commits).to eq(nil)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#empty_commit' do
|
38
|
+
it 'should make a system call' do
|
39
|
+
expect(subject).to receive(:system)
|
40
|
+
subject.empty_commit
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#clean_branches' do
|
45
|
+
it 'should make a system call' do
|
46
|
+
expect(subject).to receive(:system).exactly(4).times
|
47
|
+
subject.clean_branches
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#new_branch' do
|
52
|
+
it 'should make a system call' do
|
53
|
+
expect(subject).to receive(:system).exactly(4).times
|
54
|
+
subject.new_branch('branch_name')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#change_remote' do
|
59
|
+
it 'should return a string' do
|
60
|
+
expect(subject.change_remote('name', 'url')).to be_a(String)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#remotes' do
|
65
|
+
it 'should return an array of strings' do
|
66
|
+
expect(subject.remotes).to be_a(Array)
|
67
|
+
expect(subject.remotes.first).to be_a(String)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#remote_name' do
|
72
|
+
it 'should be a string' do
|
73
|
+
expect(subject.remote_name(ssh_remote)).to be_a(String)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#ssh_remote' do
|
78
|
+
it 'should come out true if ssh' do
|
79
|
+
expect(subject.ssh_remote?(ssh_remote)).to eq(true)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should come out false if https' do
|
83
|
+
expect(subject.ssh_remote?(https_remote)).to eq(false)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#https_remote' do
|
88
|
+
it 'should come out false if ssh' do
|
89
|
+
expect(subject.https_remote?(ssh_remote)).to eq(false)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should come out true if https' do
|
93
|
+
expect(subject.https_remote?(https_remote)).to eq(true)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#remote_project' do
|
98
|
+
it 'should return just the plain project if ssh' do
|
99
|
+
expect(subject.remote_project(ssh_remote)).to eq('git_helper')
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should return just the plain project if https' do
|
103
|
+
expect(subject.remote_project(https_remote)).to eq('git_helper')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#remote_source' do
|
108
|
+
it 'should return just the plain project if ssh' do
|
109
|
+
expect(subject.remote_source(ssh_remote)).to eq('github.com')
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should return just the plain project if https' do
|
113
|
+
expect(subject.remote_source(https_remote)).to eq('github.com')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#github_repo' do
|
118
|
+
it 'should return true if github' do
|
119
|
+
allow(subject).to receive(:remotes).and_return(github_remotes)
|
120
|
+
expect(subject.github_repo?).to eq(true)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should return false if gitlab' do
|
124
|
+
allow(subject).to receive(:remotes).and_return(gitlab_remotes)
|
125
|
+
expect(subject.github_repo?).to eq(false)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#gitlab_project' do
|
130
|
+
it 'should return true if gitlab' do
|
131
|
+
allow(subject).to receive(:remotes).and_return(gitlab_remotes)
|
132
|
+
expect(subject.gitlab_project?).to eq(true)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should return false if github' do
|
136
|
+
allow(subject).to receive(:remotes).and_return(github_remotes)
|
137
|
+
expect(subject.gitlab_project?).to eq(false)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#project_name' do
|
142
|
+
it 'should return a string' do
|
143
|
+
expect(subject.project_name).to be_a(String)
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should equal this project name' do
|
147
|
+
allow_any_instance_of(String).to receive(:scan).and_return([['emmasax4/git_helper']])
|
148
|
+
expect(subject.project_name).to eq('emmasax4/git_helper')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#branch' do
|
153
|
+
it 'should return a string' do
|
154
|
+
expect(subject.branch).to be_a(String)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#default_branch' do
|
159
|
+
it 'should return a string' do
|
160
|
+
expect(subject.default_branch).to be_a(String)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#template_options' do
|
165
|
+
let(:template_identifiers) do
|
166
|
+
{
|
167
|
+
nested_directory_name: 'PULL_REQUEST_TEMPLATE',
|
168
|
+
non_nested_file_name: 'pull_request_template'
|
169
|
+
}
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should return an array' do
|
173
|
+
expect(subject.template_options(template_identifiers)).to be_a(Array)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should call Dir.glob and File.join' do
|
177
|
+
expect(Dir).to receive(:glob).and_return(['.github/pull_request_template.md']).at_least(:once)
|
178
|
+
expect(File).to receive(:join).at_least(:once)
|
179
|
+
subject.template_options(template_identifiers)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe '#read_template' do
|
184
|
+
it 'should call File.open' do
|
185
|
+
expect(File).to receive(:open).and_return(double(read: true))
|
186
|
+
subject.read_template('.gitignore')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe '#generate_title' do
|
191
|
+
it 'should return a title based on the branch' do
|
192
|
+
branch = 'jira-123-test-branch'
|
193
|
+
expect(subject.generate_title(branch)).to eq('JIRA-123 Test branch')
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'should return a title based on the branch' do
|
197
|
+
branch = 'jira_123_test_branch'
|
198
|
+
expect(subject.generate_title(branch)).to eq('JIRA-123 Test branch')
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should return a title based on the branch' do
|
202
|
+
branch = 'jira-123_test_branch'
|
203
|
+
expect(subject.generate_title(branch)).to eq('JIRA-123 Test branch')
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should return a title based on the branch' do
|
207
|
+
branch = 'test_branch'
|
208
|
+
expect(subject.generate_title(branch)).to eq('Test branch')
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should return a title based on the branch' do
|
212
|
+
branch = 'test-branch'
|
213
|
+
expect(subject.generate_title(branch)).to eq('Test branch')
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'should return a title based on the branch' do
|
217
|
+
branch = 'test'
|
218
|
+
expect(subject.generate_title(branch)).to eq('Test')
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should return a title based on the branch' do
|
222
|
+
branch = 'some_other_words_in_this_test_branch'
|
223
|
+
expect(subject.generate_title(branch)).to eq('Some other words in this test branch')
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'should return a title based on the branch' do
|
227
|
+
branch = 'some-other-words-in-this-test-branch'
|
228
|
+
expect(subject.generate_title(branch)).to eq('Some other words in this test branch')
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|