git_helper 2.0.2 → 3.1.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.
@@ -2,23 +2,34 @@ 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
+ let(:diff_refs) { double(:diff_refs, base_sha: :base, head_sha: :head) }
10
+
11
+ let(:merge_request) do
12
+ double(:merge_request,
13
+ diff_refs: diff_refs,
14
+ web_url: Faker::Internet.url,
15
+ merge_commit_sha: Faker::Internet.password
16
+ )
17
+ end
18
+
9
19
  let(:options) do
10
20
  {
11
- local_project: 'emmasax4/git_helper',
12
- local_branch: 'main',
21
+ local_project: Faker::Lorem.word,
22
+ local_branch: Faker::Lorem.word,
13
23
  local_code: local_code,
14
24
  cli: highline_cli
15
25
  }
16
26
  end
17
27
 
18
- subject { GitHelper::GitLabMergeRequest.new(options) }
28
+ subject { described_class.new(options) }
19
29
 
20
30
  before do
21
31
  allow(GitHelper::GitLabClient).to receive(:new).and_return(gitlab_client)
32
+ allow(subject).to receive(:puts)
22
33
  end
23
34
 
24
35
  describe '#create' do
@@ -26,16 +37,16 @@ describe GitHelper::GitLabMergeRequest do
26
37
  allow(subject).to receive(:squash_merge_request).and_return(true)
27
38
  allow(subject).to receive(:remove_source_branch).and_return(false)
28
39
  allow(subject).to receive(:new_mr_body).and_return('')
29
- expect(gitlab_client_client).to receive(:create_merge_request)
30
- subject.create({base_branch: 'base', new_title: 'title'})
40
+ expect(gitlab_client_client).to receive(:create_merge_request).and_return(merge_request)
41
+ subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
31
42
  end
32
43
 
33
44
  it 'should call various other methods' do
34
45
  expect(subject).to receive(:squash_merge_request).and_return(true)
35
46
  expect(subject).to receive(:remove_source_branch).and_return(false)
36
47
  expect(subject).to receive(:new_mr_body).and_return('')
37
- allow(gitlab_client_client).to receive(:create_merge_request)
38
- subject.create({base_branch: 'base', new_title: 'title'})
48
+ allow(gitlab_client_client).to receive(:create_merge_request).and_return(merge_request)
49
+ subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
39
50
  end
40
51
 
41
52
  it 'should catch the raised error if the creation does not work' do
@@ -43,36 +54,36 @@ describe GitHelper::GitLabMergeRequest do
43
54
  allow(subject).to receive(:remove_source_branch).and_return(false)
44
55
  allow(subject).to receive(:new_mr_body).and_return('')
45
56
  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)
57
+ expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
47
58
  end
48
59
  end
49
60
 
50
61
  describe '#merge' do
51
62
  it 'should call the gitlab client to merge' do
52
63
  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
- expect(gitlab_client_client).to receive(:accept_merge_request)
64
+ allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
65
+ expect(gitlab_client_client).to receive(:accept_merge_request).and_return(merge_request)
55
66
  subject.merge
56
67
  end
57
68
 
58
69
  it 'should call various other methods' do
59
70
  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
- allow(gitlab_client_client).to receive(:accept_merge_request)
71
+ expect(subject).to receive(:mr_id).and_return(Faker::Number.number).at_least(:once)
72
+ allow(gitlab_client_client).to receive(:accept_merge_request).and_return(merge_request)
62
73
  subject.merge
63
74
  end
64
75
 
65
76
  it 'should catch the raised error if the merge does not work' do
66
77
  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)
78
+ allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
68
79
  allow(gitlab_client_client).to receive(:accept_merge_request).and_raise(StandardError)
69
80
  expect(subject.merge).to eq(nil)
70
81
  end
71
82
 
72
83
  it 'should try to merge multiple times if the first merge errors' do
73
84
  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
- expect(gitlab_client_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil)).exactly(2).times
85
+ allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
86
+ expect(gitlab_client_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil, merge_error: Faker::Lorem.word)).exactly(2).times
76
87
  expect(subject.merge).to eq(nil)
77
88
  end
78
89
  end
@@ -105,40 +116,45 @@ describe GitHelper::GitLabMergeRequest do
105
116
  end
106
117
 
107
118
  context 'if there is one template option' do
119
+ let(:template) { Faker::Lorem.word }
120
+
108
121
  it 'should call the CLI to ask about a single template' do
109
- allow(subject).to receive(:mr_template_options).and_return(['template1'])
122
+ allow(subject).to receive(:mr_template_options).and_return([template])
110
123
  expect(highline_cli).to receive(:apply_template?).and_return(true)
111
124
  subject.send(:template_name_to_apply)
112
125
  end
113
126
 
114
127
  it 'should return the single template if the user says yes' do
115
- allow(subject).to receive(:mr_template_options).and_return(['template1'])
128
+ allow(subject).to receive(:mr_template_options).and_return([template])
116
129
  allow(highline_cli).to receive(:apply_template?).and_return(true)
117
- expect(subject.send(:template_name_to_apply)).to eq('template1')
130
+ expect(subject.send(:template_name_to_apply)).to eq(template)
118
131
  end
119
132
 
120
133
  it 'should return nil if the user says no' do
121
- allow(subject).to receive(:mr_template_options).and_return(['template1'])
134
+ allow(subject).to receive(:mr_template_options).and_return([template])
122
135
  allow(highline_cli).to receive(:apply_template?).and_return(false)
123
136
  expect(subject.send(:template_name_to_apply)).to eq(nil)
124
137
  end
125
138
  end
126
139
 
127
140
  context 'if there are multiple template options' do
141
+ let(:template1) { Faker::Lorem.word }
142
+ let(:template2) { Faker::Lorem.word }
143
+
128
144
  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')
145
+ allow(subject).to receive(:mr_template_options).and_return([template1, template2])
146
+ expect(highline_cli).to receive(:template_to_apply).and_return(template1)
131
147
  subject.send(:template_name_to_apply)
132
148
  end
133
149
 
134
150
  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')
151
+ allow(subject).to receive(:mr_template_options).and_return([template1, template2])
152
+ allow(highline_cli).to receive(:template_to_apply).and_return(template1)
153
+ expect(subject.send(:template_name_to_apply)).to eq(template1)
138
154
  end
139
155
 
140
156
  it 'should return nil if the user says no' do
141
- allow(subject).to receive(:mr_template_options).and_return(['template1', 'template2'])
157
+ allow(subject).to receive(:mr_template_options).and_return([template1, template2])
142
158
  allow(highline_cli).to receive(:template_to_apply).and_return('None')
143
159
  expect(subject.send(:template_name_to_apply)).to eq(nil)
144
160
  end
@@ -154,13 +170,14 @@ describe GitHelper::GitLabMergeRequest do
154
170
 
155
171
  describe '#mr_id' do
156
172
  it 'should ask the CLI for the code request ID' do
157
- expect(highline_cli).to receive(:code_request_id).and_return(123)
173
+ expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
158
174
  subject.send(:mr_id)
159
175
  end
160
176
 
161
177
  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)
178
+ pr_id = Faker::Number.number
179
+ expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
180
+ expect(subject.send(:mr_id)).to eq(pr_id)
164
181
  end
165
182
  end
166
183
 
@@ -198,12 +215,12 @@ describe GitHelper::GitLabMergeRequest do
198
215
  subject.send(:remove_source_branch)
199
216
  end
200
217
 
201
- it "should return the existing project's setting if it exists" do
218
+ it 'should return the existing projects setting if it exists' do
202
219
  allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: true))
203
220
  expect(subject.send(:remove_source_branch)).to eq(true)
204
221
  end
205
222
 
206
- it "should return the existing project's setting if it exists" do
223
+ it 'should return the existing projects setting if it exists' do
207
224
  allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: false))
208
225
  allow(highline_cli).to receive(:remove_source_branch?).and_return(true)
209
226
  expect(subject.send(:remove_source_branch)).to eq(true)
@@ -219,7 +236,7 @@ describe GitHelper::GitLabMergeRequest do
219
236
 
220
237
  describe '#existing_mr' do
221
238
  it 'should call the gitlab client' do
222
- allow(highline_cli).to receive(:code_request_id).and_return(123)
239
+ allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
223
240
  expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
224
241
  subject.send(:existing_mr)
225
242
  end
@@ -11,6 +11,7 @@ describe GitHelper::NewBranch do
11
11
  before do
12
12
  allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
13
13
  allow(GitHelper::HighlineCli).to receive(:new).and_return(cli)
14
+ allow(subject).to receive(:puts)
14
15
  end
15
16
 
16
17
  it 'should call GitHelper::LocalCode' do
@@ -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
  }
@@ -19,49 +20,50 @@ describe GitHelper::GitHubPullRequest do
19
20
 
20
21
  before do
21
22
  allow(GitHelper::OctokitClient).to receive(:new).and_return(octokit_client)
23
+ allow(subject).to receive(:puts)
22
24
  end
23
25
 
24
26
  describe '#create' do
25
27
  it 'should call the octokit client to create' do
26
28
  allow(subject).to receive(:new_pr_body).and_return('')
27
- expect(octokit_client_client).to receive(:create_pull_request)
28
- subject.create({base_branch: 'base', new_title: 'title'})
29
+ expect(octokit_client_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
30
+ subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
29
31
  end
30
32
 
31
33
  it 'should call various other methods' do
32
34
  expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
33
- allow(octokit_client_client).to receive(:create_pull_request)
34
- subject.create({base_branch: 'base', new_title: 'title'})
35
+ allow(octokit_client_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
36
+ subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
35
37
  end
36
38
 
37
39
  it 'should catch the raised error if the creation does not work' do
38
40
  allow(subject).to receive(:new_pr_body).and_return('')
39
41
  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)
42
+ expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
41
43
  end
42
44
  end
43
45
 
44
46
  describe '#merge' do
45
47
  it 'should call the octokit client to merge' do
46
- allow(subject).to receive(:existing_pr).and_return(double(title: 'title'))
48
+ allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
47
49
  allow(subject).to receive(:merge_method).and_return('rebase')
48
- allow(subject).to receive(:pr_id).and_return(123)
49
- expect(octokit_client_client).to receive(:merge_pull_request)
50
+ allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
51
+ expect(octokit_client_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
50
52
  subject.merge
51
53
  end
52
54
 
53
55
  it 'should call various other methods' do
54
- expect(subject).to receive(:existing_pr).and_return(double(title: 'title')).at_least(:once)
56
+ expect(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word)).at_least(:once)
55
57
  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
- allow(octokit_client_client).to receive(:merge_pull_request)
58
+ expect(subject).to receive(:pr_id).and_return(Faker::Number.number).at_least(:once)
59
+ allow(octokit_client_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
58
60
  subject.merge
59
61
  end
60
62
 
61
63
  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'))
64
+ allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
63
65
  allow(subject).to receive(:merge_method).and_return('rebase')
64
- allow(subject).to receive(:pr_id).and_return(123)
66
+ allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
65
67
  allow(octokit_client_client).to receive(:merge_pull_request).and_raise(StandardError)
66
68
  expect(subject.merge).to eq(nil)
67
69
  end
@@ -95,40 +97,45 @@ describe GitHelper::GitHubPullRequest do
95
97
  end
96
98
 
97
99
  context 'if there is one template option' do
100
+ let(:template) { Faker::Lorem.word }
101
+
98
102
  it 'should call the CLI to ask about a single template' do
99
- allow(subject).to receive(:pr_template_options).and_return(['template1'])
103
+ allow(subject).to receive(:pr_template_options).and_return([template])
100
104
  expect(highline_cli).to receive(:apply_template?).and_return(true)
101
105
  subject.send(:template_name_to_apply)
102
106
  end
103
107
 
104
108
  it 'should return the single template if the user says yes' do
105
- allow(subject).to receive(:pr_template_options).and_return(['template1'])
109
+ allow(subject).to receive(:pr_template_options).and_return([template])
106
110
  allow(highline_cli).to receive(:apply_template?).and_return(true)
107
- expect(subject.send(:template_name_to_apply)).to eq('template1')
111
+ expect(subject.send(:template_name_to_apply)).to eq(template)
108
112
  end
109
113
 
110
114
  it 'should return nil if the user says no' do
111
- allow(subject).to receive(:pr_template_options).and_return(['template1'])
115
+ allow(subject).to receive(:pr_template_options).and_return([template])
112
116
  allow(highline_cli).to receive(:apply_template?).and_return(false)
113
117
  expect(subject.send(:template_name_to_apply)).to eq(nil)
114
118
  end
115
119
  end
116
120
 
117
121
  context 'if there are multiple template options' do
122
+ let(:template1) { Faker::Lorem.word }
123
+ let(:template2) { Faker::Lorem.word }
124
+
118
125
  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')
126
+ allow(subject).to receive(:pr_template_options).and_return([template1, template2])
127
+ expect(highline_cli).to receive(:template_to_apply).and_return(template1)
121
128
  subject.send(:template_name_to_apply)
122
129
  end
123
130
 
124
131
  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')
132
+ allow(subject).to receive(:pr_template_options).and_return([template1, template2])
133
+ allow(highline_cli).to receive(:template_to_apply).and_return(template1)
134
+ expect(subject.send(:template_name_to_apply)).to eq(template1)
128
135
  end
129
136
 
130
137
  it 'should return nil if the user says no' do
131
- allow(subject).to receive(:pr_template_options).and_return(['template1', 'template2'])
138
+ allow(subject).to receive(:pr_template_options).and_return([template1, template2])
132
139
  allow(highline_cli).to receive(:template_to_apply).and_return('None')
133
140
  expect(subject.send(:template_name_to_apply)).to eq(nil)
134
141
  end
@@ -144,13 +151,14 @@ describe GitHelper::GitHubPullRequest do
144
151
 
145
152
  describe '#pr_id' do
146
153
  it 'should ask the CLI for the code request ID' do
147
- expect(highline_cli).to receive(:code_request_id).and_return(123)
154
+ expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
148
155
  subject.send(:pr_id)
149
156
  end
150
157
 
151
158
  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)
159
+ pr_id = Faker::Number.number
160
+ expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
161
+ expect(subject.send(:pr_id)).to eq(pr_id)
154
162
  end
155
163
  end
156
164
 
@@ -172,7 +180,7 @@ describe GitHelper::GitHubPullRequest do
172
180
  expect(subject.send(:merge_method)).to be_a(String)
173
181
  end
174
182
 
175
- context "if there's only one item" do
183
+ context 'if theres only one item' do
176
184
  let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
177
185
 
178
186
  it 'should not ask the CLI anything' do
@@ -231,7 +239,7 @@ describe GitHelper::GitHubPullRequest do
231
239
 
232
240
  describe '#existing_pr' do
233
241
  it 'should call the octokit client' do
234
- allow(highline_cli).to receive(:code_request_id).and_return(123)
242
+ allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
235
243
  expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
236
244
  subject.send(:existing_pr)
237
245
  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.2
4
+ version: 3.1.3
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-10 00:00:00.000000000 Z
11
+ date: 2020-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab
@@ -72,14 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.1'
75
+ version: '2.2'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2.1'
82
+ version: '2.2'
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