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