git_helper 2.0.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,20 +2,21 @@ require 'spec_helper'
2
2
  require 'git_helper'
3
3
 
4
4
  describe GitHelper::GitLabMergeRequest do
5
- let(:local_code) { double(:local_code, read_template: 'template') }
5
+ let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
6
6
  let(:highline_cli) { double(:highline_cli) }
7
7
  let(:gitlab_client_client) { double(:gitlab_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
8
8
  let(:gitlab_client) { double(:gitlab_client, client: gitlab_client_client) }
9
+
9
10
  let(:options) do
10
11
  {
11
- local_project: 'emmasax4/git_helper',
12
- local_branch: 'main',
12
+ local_project: Faker::Lorem.word,
13
+ local_branch: Faker::Lorem.word,
13
14
  local_code: local_code,
14
15
  cli: highline_cli
15
16
  }
16
17
  end
17
18
 
18
- subject { GitHelper::GitLabMergeRequest.new(options) }
19
+ subject { described_class.new(options) }
19
20
 
20
21
  before do
21
22
  allow(GitHelper::GitLabClient).to receive(:new).and_return(gitlab_client)
@@ -27,7 +28,7 @@ describe GitHelper::GitLabMergeRequest do
27
28
  allow(subject).to receive(:remove_source_branch).and_return(false)
28
29
  allow(subject).to receive(:new_mr_body).and_return('')
29
30
  expect(gitlab_client_client).to receive(:create_merge_request)
30
- subject.create({base_branch: 'base', new_title: 'title'})
31
+ subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
31
32
  end
32
33
 
33
34
  it 'should call various other methods' do
@@ -35,7 +36,7 @@ describe GitHelper::GitLabMergeRequest do
35
36
  expect(subject).to receive(:remove_source_branch).and_return(false)
36
37
  expect(subject).to receive(:new_mr_body).and_return('')
37
38
  allow(gitlab_client_client).to receive(:create_merge_request)
38
- subject.create({base_branch: 'base', new_title: 'title'})
39
+ subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
39
40
  end
40
41
 
41
42
  it 'should catch the raised error if the creation does not work' do
@@ -43,35 +44,35 @@ describe GitHelper::GitLabMergeRequest do
43
44
  allow(subject).to receive(:remove_source_branch).and_return(false)
44
45
  allow(subject).to receive(:new_mr_body).and_return('')
45
46
  allow(gitlab_client_client).to receive(:create_merge_request).and_raise(StandardError)
46
- expect(subject.create({base_branch: 'base', new_title: 'title'})).to eq(nil)
47
+ expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
47
48
  end
48
49
  end
49
50
 
50
51
  describe '#merge' do
51
52
  it 'should call the gitlab client to merge' do
52
53
  allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
53
- allow(subject).to receive(:mr_id).and_return(123)
54
+ allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
54
55
  expect(gitlab_client_client).to receive(:accept_merge_request)
55
56
  subject.merge
56
57
  end
57
58
 
58
59
  it 'should call various other methods' do
59
60
  expect(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title')).at_least(:once)
60
- expect(subject).to receive(:mr_id).and_return(123).at_least(:once)
61
+ expect(subject).to receive(:mr_id).and_return(Faker::Number.number).at_least(:once)
61
62
  allow(gitlab_client_client).to receive(:accept_merge_request)
62
63
  subject.merge
63
64
  end
64
65
 
65
66
  it 'should catch the raised error if the merge does not work' do
66
67
  allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
67
- allow(subject).to receive(:mr_id).and_return(123)
68
+ allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
68
69
  allow(gitlab_client_client).to receive(:accept_merge_request).and_raise(StandardError)
69
70
  expect(subject.merge).to eq(nil)
70
71
  end
71
72
 
72
73
  it 'should try to merge multiple times if the first merge errors' do
73
74
  allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
74
- allow(subject).to receive(:mr_id).and_return(123)
75
+ allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
75
76
  expect(gitlab_client_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil)).exactly(2).times
76
77
  expect(subject.merge).to eq(nil)
77
78
  end
@@ -105,40 +106,45 @@ describe GitHelper::GitLabMergeRequest do
105
106
  end
106
107
 
107
108
  context 'if there is one template option' do
109
+ let(:template) { Faker::Lorem.word }
110
+
108
111
  it 'should call the CLI to ask about a single template' do
109
- allow(subject).to receive(:mr_template_options).and_return(['template1'])
112
+ allow(subject).to receive(:mr_template_options).and_return([template])
110
113
  expect(highline_cli).to receive(:apply_template?).and_return(true)
111
114
  subject.send(:template_name_to_apply)
112
115
  end
113
116
 
114
117
  it 'should return the single template if the user says yes' do
115
- allow(subject).to receive(:mr_template_options).and_return(['template1'])
118
+ allow(subject).to receive(:mr_template_options).and_return([template])
116
119
  allow(highline_cli).to receive(:apply_template?).and_return(true)
117
- expect(subject.send(:template_name_to_apply)).to eq('template1')
120
+ expect(subject.send(:template_name_to_apply)).to eq(template)
118
121
  end
119
122
 
120
123
  it 'should return nil if the user says no' do
121
- allow(subject).to receive(:mr_template_options).and_return(['template1'])
124
+ allow(subject).to receive(:mr_template_options).and_return([template])
122
125
  allow(highline_cli).to receive(:apply_template?).and_return(false)
123
126
  expect(subject.send(:template_name_to_apply)).to eq(nil)
124
127
  end
125
128
  end
126
129
 
127
130
  context 'if there are multiple template options' do
131
+ let(:template1) { Faker::Lorem.word }
132
+ let(:template2) { Faker::Lorem.word }
133
+
128
134
  it 'should call the CLI to ask which of multiple templates to apply' do
129
- allow(subject).to receive(:mr_template_options).and_return(['template1', 'template2'])
130
- expect(highline_cli).to receive(:template_to_apply).and_return('template1')
135
+ allow(subject).to receive(:mr_template_options).and_return([template1, template2])
136
+ expect(highline_cli).to receive(:template_to_apply).and_return(template1)
131
137
  subject.send(:template_name_to_apply)
132
138
  end
133
139
 
134
140
  it 'should return the answer template if the user says yes' do
135
- allow(subject).to receive(:mr_template_options).and_return(['template1', 'template2'])
136
- allow(highline_cli).to receive(:template_to_apply).and_return('template1')
137
- expect(subject.send(:template_name_to_apply)).to eq('template1')
141
+ allow(subject).to receive(:mr_template_options).and_return([template1, template2])
142
+ allow(highline_cli).to receive(:template_to_apply).and_return(template1)
143
+ expect(subject.send(:template_name_to_apply)).to eq(template1)
138
144
  end
139
145
 
140
146
  it 'should return nil if the user says no' do
141
- allow(subject).to receive(:mr_template_options).and_return(['template1', 'template2'])
147
+ allow(subject).to receive(:mr_template_options).and_return([template1, template2])
142
148
  allow(highline_cli).to receive(:template_to_apply).and_return('None')
143
149
  expect(subject.send(:template_name_to_apply)).to eq(nil)
144
150
  end
@@ -154,13 +160,14 @@ describe GitHelper::GitLabMergeRequest do
154
160
 
155
161
  describe '#mr_id' do
156
162
  it 'should ask the CLI for the code request ID' do
157
- expect(highline_cli).to receive(:code_request_id).and_return(123)
163
+ expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
158
164
  subject.send(:mr_id)
159
165
  end
160
166
 
161
167
  it 'should equal an integer' do
162
- expect(highline_cli).to receive(:code_request_id).and_return(123)
163
- expect(subject.send(:mr_id)).to eq(123)
168
+ pr_id = Faker::Number.number
169
+ expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
170
+ expect(subject.send(:mr_id)).to eq(pr_id)
164
171
  end
165
172
  end
166
173
 
@@ -198,12 +205,12 @@ describe GitHelper::GitLabMergeRequest do
198
205
  subject.send(:remove_source_branch)
199
206
  end
200
207
 
201
- it "should return the existing project's setting if it exists" do
208
+ it 'should return the existing projects setting if it exists' do
202
209
  allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: true))
203
210
  expect(subject.send(:remove_source_branch)).to eq(true)
204
211
  end
205
212
 
206
- it "should return the existing project's setting if it exists" do
213
+ it 'should return the existing projects setting if it exists' do
207
214
  allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: false))
208
215
  allow(highline_cli).to receive(:remove_source_branch?).and_return(true)
209
216
  expect(subject.send(:remove_source_branch)).to eq(true)
@@ -219,7 +226,7 @@ describe GitHelper::GitLabMergeRequest do
219
226
 
220
227
  describe '#existing_mr' do
221
228
  it 'should call the gitlab client' do
222
- allow(highline_cli).to receive(:code_request_id).and_return(123)
229
+ allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
223
230
  expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
224
231
  subject.send(:existing_mr)
225
232
  end
@@ -2,14 +2,15 @@ require 'spec_helper'
2
2
  require 'git_helper'
3
3
 
4
4
  describe GitHelper::GitHubPullRequest do
5
- let(:local_code) { double(:local_code, read_template: 'template') }
5
+ let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
6
6
  let(:highline_cli) { double(:highline_cli) }
7
7
  let(:octokit_client_client) { double(:octokit_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
8
8
  let(:octokit_client) { double(:octokit_client, client: octokit_client_client) }
9
+
9
10
  let(:options) do
10
11
  {
11
- local_project: 'emmasax4/git_helper',
12
- local_branch: 'main',
12
+ local_project: Faker::Lorem.word,
13
+ local_branch: Faker::Lorem.word,
13
14
  local_code: local_code,
14
15
  cli: highline_cli
15
16
  }
@@ -25,43 +26,43 @@ describe GitHelper::GitHubPullRequest do
25
26
  it 'should call the octokit client to create' do
26
27
  allow(subject).to receive(:new_pr_body).and_return('')
27
28
  expect(octokit_client_client).to receive(:create_pull_request)
28
- subject.create({base_branch: 'base', new_title: 'title'})
29
+ subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
29
30
  end
30
31
 
31
32
  it 'should call various other methods' do
32
33
  expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
33
34
  allow(octokit_client_client).to receive(:create_pull_request)
34
- subject.create({base_branch: 'base', new_title: 'title'})
35
+ subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
35
36
  end
36
37
 
37
38
  it 'should catch the raised error if the creation does not work' do
38
39
  allow(subject).to receive(:new_pr_body).and_return('')
39
40
  allow(octokit_client_client).to receive(:create_pull_request).and_raise(StandardError)
40
- expect(subject.create({base_branch: 'base', new_title: 'title'})).to eq(nil)
41
+ expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
41
42
  end
42
43
  end
43
44
 
44
45
  describe '#merge' do
45
46
  it 'should call the octokit client to merge' do
46
- allow(subject).to receive(:existing_pr).and_return(double(title: 'title'))
47
+ allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
47
48
  allow(subject).to receive(:merge_method).and_return('rebase')
48
- allow(subject).to receive(:pr_id).and_return(123)
49
+ allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
49
50
  expect(octokit_client_client).to receive(:merge_pull_request)
50
51
  subject.merge
51
52
  end
52
53
 
53
54
  it 'should call various other methods' do
54
- expect(subject).to receive(:existing_pr).and_return(double(title: 'title')).at_least(:once)
55
+ expect(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word)).at_least(:once)
55
56
  expect(subject).to receive(:merge_method).and_return('rebase').at_least(:once)
56
- expect(subject).to receive(:pr_id).and_return(123).at_least(:once)
57
+ expect(subject).to receive(:pr_id).and_return(Faker::Number.number).at_least(:once)
57
58
  allow(octokit_client_client).to receive(:merge_pull_request)
58
59
  subject.merge
59
60
  end
60
61
 
61
62
  it 'should catch the raised error if the merge does not work' do
62
- allow(subject).to receive(:existing_pr).and_return(double(title: 'title'))
63
+ allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
63
64
  allow(subject).to receive(:merge_method).and_return('rebase')
64
- allow(subject).to receive(:pr_id).and_return(123)
65
+ allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
65
66
  allow(octokit_client_client).to receive(:merge_pull_request).and_raise(StandardError)
66
67
  expect(subject.merge).to eq(nil)
67
68
  end
@@ -95,40 +96,45 @@ describe GitHelper::GitHubPullRequest do
95
96
  end
96
97
 
97
98
  context 'if there is one template option' do
99
+ let(:template) { Faker::Lorem.word }
100
+
98
101
  it 'should call the CLI to ask about a single template' do
99
- allow(subject).to receive(:pr_template_options).and_return(['template1'])
102
+ allow(subject).to receive(:pr_template_options).and_return([template])
100
103
  expect(highline_cli).to receive(:apply_template?).and_return(true)
101
104
  subject.send(:template_name_to_apply)
102
105
  end
103
106
 
104
107
  it 'should return the single template if the user says yes' do
105
- allow(subject).to receive(:pr_template_options).and_return(['template1'])
108
+ allow(subject).to receive(:pr_template_options).and_return([template])
106
109
  allow(highline_cli).to receive(:apply_template?).and_return(true)
107
- expect(subject.send(:template_name_to_apply)).to eq('template1')
110
+ expect(subject.send(:template_name_to_apply)).to eq(template)
108
111
  end
109
112
 
110
113
  it 'should return nil if the user says no' do
111
- allow(subject).to receive(:pr_template_options).and_return(['template1'])
114
+ allow(subject).to receive(:pr_template_options).and_return([template])
112
115
  allow(highline_cli).to receive(:apply_template?).and_return(false)
113
116
  expect(subject.send(:template_name_to_apply)).to eq(nil)
114
117
  end
115
118
  end
116
119
 
117
120
  context 'if there are multiple template options' do
121
+ let(:template1) { Faker::Lorem.word }
122
+ let(:template2) { Faker::Lorem.word }
123
+
118
124
  it 'should call the CLI to ask which of multiple templates to apply' do
119
- allow(subject).to receive(:pr_template_options).and_return(['template1', 'template2'])
120
- expect(highline_cli).to receive(:template_to_apply).and_return('template1')
125
+ allow(subject).to receive(:pr_template_options).and_return([template1, template2])
126
+ expect(highline_cli).to receive(:template_to_apply).and_return(template1)
121
127
  subject.send(:template_name_to_apply)
122
128
  end
123
129
 
124
130
  it 'should return the answer template if the user says yes' do
125
- allow(subject).to receive(:pr_template_options).and_return(['template1', 'template2'])
126
- allow(highline_cli).to receive(:template_to_apply).and_return('template1')
127
- expect(subject.send(:template_name_to_apply)).to eq('template1')
131
+ allow(subject).to receive(:pr_template_options).and_return([template1, template2])
132
+ allow(highline_cli).to receive(:template_to_apply).and_return(template1)
133
+ expect(subject.send(:template_name_to_apply)).to eq(template1)
128
134
  end
129
135
 
130
136
  it 'should return nil if the user says no' do
131
- allow(subject).to receive(:pr_template_options).and_return(['template1', 'template2'])
137
+ allow(subject).to receive(:pr_template_options).and_return([template1, template2])
132
138
  allow(highline_cli).to receive(:template_to_apply).and_return('None')
133
139
  expect(subject.send(:template_name_to_apply)).to eq(nil)
134
140
  end
@@ -144,13 +150,14 @@ describe GitHelper::GitHubPullRequest do
144
150
 
145
151
  describe '#pr_id' do
146
152
  it 'should ask the CLI for the code request ID' do
147
- expect(highline_cli).to receive(:code_request_id).and_return(123)
153
+ expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
148
154
  subject.send(:pr_id)
149
155
  end
150
156
 
151
157
  it 'should equal an integer' do
152
- expect(highline_cli).to receive(:code_request_id).and_return(123)
153
- expect(subject.send(:pr_id)).to eq(123)
158
+ pr_id = Faker::Number.number
159
+ expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
160
+ expect(subject.send(:pr_id)).to eq(pr_id)
154
161
  end
155
162
  end
156
163
 
@@ -172,7 +179,7 @@ describe GitHelper::GitHubPullRequest do
172
179
  expect(subject.send(:merge_method)).to be_a(String)
173
180
  end
174
181
 
175
- context "if there's only one item" do
182
+ context 'if theres only one item' do
176
183
  let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
177
184
 
178
185
  it 'should not ask the CLI anything' do
@@ -231,7 +238,7 @@ describe GitHelper::GitHubPullRequest do
231
238
 
232
239
  describe '#existing_pr' do
233
240
  it 'should call the octokit client' do
234
- allow(highline_cli).to receive(:code_request_id).and_return(123)
241
+ allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
235
242
  expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
236
243
  subject.send(:existing_pr)
237
244
  end
@@ -1,3 +1,5 @@
1
+ require 'faker'
2
+
1
3
  # This file was generated by the `rspec --init` command. Conventionally, all
2
4
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
5
  # The generated `.rspec` file contains `--require spec_helper` which will cause
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emma Sax
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-02 00:00:00.000000000 Z
11
+ date: 2020-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faker
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: guard-rspec
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -154,6 +168,7 @@ files:
154
168
  - lib/git_helper/octokit_client.rb
155
169
  - lib/git_helper/pull_request.rb
156
170
  - lib/git_helper/version.rb
171
+ - plugins.zip
157
172
  - spec/git_helper/change_remote_spec.rb
158
173
  - spec/git_helper/checkout_default_spec.rb
159
174
  - spec/git_helper/clean_branches_spec.rb
@@ -188,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
203
  - !ruby/object:Gem::Version
189
204
  version: '0'
190
205
  requirements: []
191
- rubygems_version: 3.1.2
206
+ rubygems_version: 3.1.4
192
207
  signing_key:
193
208
  specification_version: 4
194
209
  summary: A set of GitHub and GitLab workflow scripts.