git_helper 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34ec4f36cbe8b3cf3875894ee4670a5ca704ce4f67abeac7df2d5778f48a474f
4
- data.tar.gz: 51721de128e9639c61c321ef0454c141cad5f91f4ec52ef5aa2161e6bb531c32
3
+ metadata.gz: 59ea066ec1e5cc797d676571c908c55fcc6de186590f5f1d1f14bb5f3ebfe1c5
4
+ data.tar.gz: 31c8412273b1e46d5f181e7a01bac5b10858f848293fe287c357f768e41ab90e
5
5
  SHA512:
6
- metadata.gz: 6f2a22415758219d80055e4ebdb0b954f49bdfb27d2023badea8d0f45e2be151e16d0683c351fd1dd890f7ef864ee5e4291d545af369936e1d65ee0ff14195b4
7
- data.tar.gz: e2bdae4669a0331f84ecc50c7f60b1af00e987556ec2644abbe4c0e44cd45185c16820f4d508c451ad4883adf4e19c4a5dac89670bb6b500c2a700ffd0214ac4
6
+ metadata.gz: 16b7f3b1a77e5a2cae432fcddc556425a18ce88ae6a7147814810af49e42ebe61ca1a82daf691165ef62f7315b10442fcf8c3b458440075b8b767090b5fe560b
7
+ data.tar.gz: dd940ec200f5275c5f07b1b91c5e504bc545b177580ab6c059e64d988438001b186ced83af14a2022e14f9526a0d69fe01989eabd7290bf5378de3560ede5968
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git_helper (3.0.0)
4
+ git_helper (3.0.1)
5
5
  gitlab (~> 4.16)
6
6
  gli (~> 2.13)
7
7
  highline (~> 2.0)
@@ -13,9 +13,13 @@ GEM
13
13
  addressable (2.7.0)
14
14
  public_suffix (>= 2.0.2, < 5.0)
15
15
  coderay (1.1.3)
16
+ concurrent-ruby (1.1.7)
16
17
  diff-lcs (1.4.4)
17
- faraday (1.0.1)
18
+ faker (2.14.0)
19
+ i18n (>= 1.6, < 2)
20
+ faraday (1.1.0)
18
21
  multipart-post (>= 1.2, < 3)
22
+ ruby2_keywords
19
23
  ffi (1.13.1)
20
24
  formatador (0.2.5)
21
25
  gitlab (4.16.1)
@@ -40,6 +44,8 @@ GEM
40
44
  httparty (0.18.1)
41
45
  mime-types (~> 3.0)
42
46
  multi_xml (>= 0.5.2)
47
+ i18n (1.8.5)
48
+ concurrent-ruby (~> 1.0)
43
49
  listen (3.2.1)
44
50
  rb-fsevent (~> 0.10, >= 0.10.3)
45
51
  rb-inotify (~> 0.9, >= 0.9.10)
@@ -47,14 +53,14 @@ GEM
47
53
  method_source (1.0.0)
48
54
  mime-types (3.3.1)
49
55
  mime-types-data (~> 3.2015)
50
- mime-types-data (3.2020.0512)
56
+ mime-types-data (3.2020.1104)
51
57
  multi_xml (0.6.0)
52
58
  multipart-post (2.1.1)
53
59
  nenv (0.3.0)
54
60
  notiffany (0.1.3)
55
61
  nenv (~> 0.1)
56
62
  shellany (~> 0.0)
57
- octokit (4.18.0)
63
+ octokit (4.19.0)
58
64
  faraday (>= 0.9)
59
65
  sawyer (~> 0.8.0, >= 0.5.3)
60
66
  pry (0.13.1)
@@ -65,19 +71,20 @@ GEM
65
71
  rb-fsevent (0.10.4)
66
72
  rb-inotify (0.10.1)
67
73
  ffi (~> 1.0)
68
- rspec (3.9.0)
69
- rspec-core (~> 3.9.0)
70
- rspec-expectations (~> 3.9.0)
71
- rspec-mocks (~> 3.9.0)
72
- rspec-core (3.9.3)
73
- rspec-support (~> 3.9.3)
74
- rspec-expectations (3.9.2)
74
+ rspec (3.10.0)
75
+ rspec-core (~> 3.10.0)
76
+ rspec-expectations (~> 3.10.0)
77
+ rspec-mocks (~> 3.10.0)
78
+ rspec-core (3.10.0)
79
+ rspec-support (~> 3.10.0)
80
+ rspec-expectations (3.10.0)
75
81
  diff-lcs (>= 1.2.0, < 2.0)
76
- rspec-support (~> 3.9.0)
77
- rspec-mocks (3.9.1)
82
+ rspec-support (~> 3.10.0)
83
+ rspec-mocks (3.10.0)
78
84
  diff-lcs (>= 1.2.0, < 2.0)
79
- rspec-support (~> 3.9.0)
80
- rspec-support (3.9.3)
85
+ rspec-support (~> 3.10.0)
86
+ rspec-support (3.10.0)
87
+ ruby2_keywords (0.0.2)
81
88
  sawyer (0.8.2)
82
89
  addressable (>= 2.3.5)
83
90
  faraday (> 0.8, < 2.0)
@@ -92,6 +99,7 @@ PLATFORMS
92
99
 
93
100
  DEPENDENCIES
94
101
  bundler (~> 2.1)
102
+ faker
95
103
  git_helper!
96
104
  guard-rspec (~> 4.3)
97
105
  rake (~> 13.0)
data/Guardfile CHANGED
@@ -1,5 +1,5 @@
1
1
  guard :rspec, cmd: 'bundle exec rspec', all_on_start: true, all_after_pass: true do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
5
  end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # git_helper [![Maintainability](https://api.codeclimate.com/v1/badges/d53da11f17c38cc81b5b/maintainability)](https://codeclimate.com/github/emmasax4/git_helper/maintainability) ![Develop](https://github.com/emmasax4/git_helper/workflows/Develop/badge.svg)
1
+ # git_helper [![Maintainability](https://api.codeclimate.com/v1/badges/d53da11f17c38cc81b5b/maintainability)](https://codeclimate.com/github/emmasax4/git_helper/maintainability) ![Default](https://github.com/emmasax4/git_helper/workflows/Default/badge.svg)
2
2
 
3
3
  ## Gem Usage
4
4
 
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
@@ -27,7 +27,7 @@ command 'change-remote' do |c|
27
27
  end
28
28
  end
29
29
 
30
- desc "Checks out the default branch of a repo based on the local remote branches."
30
+ desc 'Checks out the default branch of a repo based on the local remote branches.'
31
31
  command 'checkout-default' do |c|
32
32
  c.action do |global_options, options, args|
33
33
  GitHelper::CheckoutDefault.new.execute
@@ -41,14 +41,14 @@ command 'clean-branches' do |c|
41
41
  end
42
42
  end
43
43
 
44
- desc "Creates an empty commit with a basic commit message."
44
+ desc 'Creates an empty commit with a basic commit message.'
45
45
  command 'empty-commit' do |c|
46
46
  c.action do |global_options, options, args|
47
47
  GitHelper::EmptyCommit.new.execute
48
48
  end
49
49
  end
50
50
 
51
- desc "Reset your local git commits to origin/HEAD."
51
+ desc 'Reset your local git commits to origin/HEAD.'
52
52
  command 'forget-local-commits' do |c|
53
53
  c.action do |global_options, options, args|
54
54
  GitHelper::ForgetLocalCommits.new.execute
@@ -1,4 +1,9 @@
1
- Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'git_helper')) + "/**/*.rb"].each do |file|
1
+ require 'yaml'
2
+ require 'gitlab'
3
+ require 'highline'
4
+ require 'octokit'
5
+
6
+ Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'git_helper')) + '/**/*.rb'].each do |file|
2
7
  require_relative file
3
8
  end
4
9
 
@@ -1,5 +1,3 @@
1
- require 'yaml'
2
-
3
1
  module GitHelper
4
2
  class GitConfigReader
5
3
  def gitlab_token
@@ -1,5 +1,3 @@
1
- require 'gitlab'
2
-
3
1
  module GitHelper
4
2
  class GitLabClient
5
3
  def client
@@ -1,5 +1,3 @@
1
- require 'highline'
2
-
3
1
  module GitHelper
4
2
  class HighlineCli
5
3
  def new_branch_name
@@ -1,27 +1,27 @@
1
1
  module GitHelper
2
2
  class LocalCode
3
3
  def checkout_default
4
- system("git checkout $(git symbolic-ref refs/remotes/origin/HEAD | sed \"s@^refs/remotes/origin/@@\")")
4
+ system('git checkout $(git symbolic-ref refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@")')
5
5
  end
6
6
 
7
7
  def forget_local_commits
8
- system("git pull")
9
- system("git reset --hard origin/HEAD")
8
+ system('git pull')
9
+ system('git reset --hard origin/HEAD')
10
10
  end
11
11
 
12
12
  def empty_commit
13
- system("git commit --allow-empty -m \"Empty commit\"")
13
+ system('git commit --allow-empty -m \"Empty commit\"')
14
14
  end
15
15
 
16
16
  def clean_branches
17
- system("git checkout $(git symbolic-ref refs/remotes/origin/HEAD | sed \"s@^refs/remotes/origin/@@\")")
18
- system("git pull")
19
- system("git fetch -p")
20
- system("git branch -vv | grep \"origin/.*: gone]\" | awk '{print \$1}' | grep -v \"*\" | xargs git branch -D")
17
+ system('git checkout $(git symbolic-ref refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@")')
18
+ system('git pull')
19
+ system('git fetch -p')
20
+ system('git branch -vv | grep "origin/.*: gone]" | awk "{print \$1}" | grep -v "*" | xargs git branch -D')
21
21
  end
22
22
 
23
23
  def new_branch(branch_name)
24
- system("git pull")
24
+ system('git pull')
25
25
  system("git branch --no-track #{branch_name}")
26
26
  system("git checkout #{branch_name}")
27
27
  system("git push --set-upstream origin #{branch_name}")
@@ -1,5 +1,3 @@
1
- require 'octokit'
2
-
3
1
  module GitHelper
4
2
  class OctokitClient
5
3
  def client
@@ -1,3 +1,3 @@
1
1
  module GitHelper
2
- VERSION = '3.0.1'
2
+ VERSION = '3.1.0'
3
3
  end
@@ -2,22 +2,24 @@ require 'spec_helper'
2
2
  require 'git_helper'
3
3
 
4
4
  describe GitHelper::ChangeRemote do
5
- let(:remote1) { 'git@github.com:github-username-old/project-1.git' }
5
+ let(:remote1) { "git@github.com:#{old_owner}/#{project}.git" }
6
+ let(:project) { Faker::Lorem.word }
7
+ let(:cli) { double(:highline_cli, process_directory_remotes?: true) }
8
+ let(:old_owner) { Faker::Internet.username }
9
+ let(:new_owner) { Faker::Internet.username }
10
+ let(:directory_entries) { [ '.', '..', project, Faker::Lorem.word, Faker::Lorem.word ] }
11
+
6
12
  let(:local_code) do
7
13
  double(:local_code,
8
14
  remotes: [remote1],
9
- remote_name: 'origin',
15
+ remote_name: Faker::Lorem.word,
10
16
  ssh_remote?: true,
11
17
  https_remote?: false,
12
- remote_project: 'project-1',
18
+ remote_project: project,
13
19
  remote_source: 'github.com',
14
20
  change_remote: true
15
21
  )
16
22
  end
17
- let(:cli) { double(:highline_cli, process_directory_remotes?: true) }
18
- let(:old_owner) { 'github-username-old' }
19
- let(:new_owner) { 'github-username-new' }
20
- let(:directory_entries) { [ '.', '..', 'project-1', 'project-2', 'project-3' ] }
21
23
 
22
24
  subject { GitHelper::ChangeRemote.new(old_owner, new_owner) }
23
25
 
@@ -28,9 +30,9 @@ describe GitHelper::ChangeRemote do
28
30
 
29
31
  describe '#execute' do
30
32
  before do
31
- allow(Dir).to receive(:pwd).and_return('/Users/firstname/lastname/path/to/project')
33
+ allow(Dir).to receive(:pwd).and_return("/Users/#{Faker::Name.first_name}/#{project}")
32
34
  allow(Dir).to receive(:entries).and_return(directory_entries)
33
- allow(File).to receive(:join).and_return('/Users/firstname/lastname/path/to/project/project-1')
35
+ allow(File).to receive(:join).and_return("/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
34
36
  allow(File).to receive(:directory?).and_return(true)
35
37
  allow(subject).to receive(:process_dir)
36
38
  end
@@ -59,13 +61,13 @@ describe GitHelper::ChangeRemote do
59
61
  it 'should definitely look in the file structure' do
60
62
  expect(Dir).to receive(:chdir)
61
63
  expect(File).to receive(:exist?)
62
- subject.send(:process_dir, '/Users/firstname/lastname/path/to/project', '/Users/firstname/lastname/path/to/project/project-1')
64
+ subject.send(:process_dir, "/Users/#{Faker::Name.first_name}/#{project}", "/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
63
65
  end
64
66
 
65
67
  context 'when the user says to process the directory' do
66
68
  it 'should call to process the git repository at least once' do
67
69
  expect(subject).to receive(:process_git_repository).at_least(:once)
68
- subject.send(:process_dir, '/Users/firstname/lastname/path/to/project', '/Users/firstname/lastname/path/to/project/project-1')
70
+ subject.send(:process_dir, "/Users/#{Faker::Name.first_name}/#{project}", "/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
69
71
  end
70
72
  end
71
73
 
@@ -74,7 +76,7 @@ describe GitHelper::ChangeRemote do
74
76
 
75
77
  it 'should not call to process the directory' do
76
78
  expect(subject).not_to receive(:process_git_repository)
77
- subject.send(:process_dir, '/Users/firstname/lastname/path/to/project', '/Users/firstname/lastname/path/to/project/project-1')
79
+ subject.send(:process_dir, "/Users/#{Faker::Name.first_name}/#{project}", "/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
78
80
  end
79
81
  end
80
82
  end
@@ -97,7 +99,7 @@ describe GitHelper::ChangeRemote do
97
99
  end
98
100
 
99
101
  context 'when the remote does not include the old owner' do
100
- let(:remote1) { 'git@github.com:github-username-new/project-1.git' }
102
+ let(:remote1) { "git@github.com:#{new_owner}/#{project}.git" }
101
103
 
102
104
  it 'should not call to process the remote' do
103
105
  expect(subject).not_to receive(:process_remote)
@@ -136,10 +138,10 @@ describe GitHelper::ChangeRemote do
136
138
  let(:local_code) do
137
139
  double(:local_code,
138
140
  remotes: [remote1],
139
- remote_name: 'origin',
141
+ remote_name: Faker::Lorem.word,
140
142
  ssh_remote?: false,
141
143
  https_remote?: false,
142
- remote_project: 'project-1',
144
+ remote_project: project,
143
145
  remote_source: 'github.com',
144
146
  change_remote: true
145
147
  )
@@ -3,8 +3,10 @@ require 'git_helper'
3
3
 
4
4
  describe GitHelper::CodeRequest do
5
5
  let(:highline_cli) { double(:highline_cli) }
6
- let(:local_code) { double(:local_code, project_name: 'name', branch: 'branch') }
6
+ let(:local_code) { double(:local_code, project_name: Faker::Lorem.word, branch: Faker::Lorem.word) }
7
7
  let(:process_project) { double(:process_project, create: :created, merge: :merged) }
8
+ let(:base_branch) { Faker::Lorem.word }
9
+ let(:title) { Faker::Lorem.sentence }
8
10
 
9
11
  subject { GitHelper::CodeRequest.new }
10
12
 
@@ -15,8 +17,8 @@ describe GitHelper::CodeRequest do
15
17
 
16
18
  describe '#create' do
17
19
  before do
18
- allow(subject).to receive(:base_branch).and_return('base')
19
- allow(subject).to receive(:new_code_request_title).and_return('Title')
20
+ allow(subject).to receive(:base_branch).and_return(base_branch)
21
+ allow(subject).to receive(:new_code_request_title).and_return(title)
20
22
  end
21
23
 
22
24
  it 'should call to process the project' do
@@ -31,8 +33,8 @@ describe GitHelper::CodeRequest do
31
33
  end
32
34
 
33
35
  it 'should call base_branch and new_code_request_title' do
34
- expect(subject).to receive(:base_branch).and_return('base')
35
- expect(subject).to receive(:new_code_request_title).and_return('Title')
36
+ expect(subject).to receive(:base_branch).and_return(base_branch)
37
+ expect(subject).to receive(:new_code_request_title).and_return(title)
36
38
  allow(subject).to receive(:process_project).and_return(process_project)
37
39
  allow(process_project).to receive(:create)
38
40
  subject.create
@@ -132,7 +134,7 @@ describe GitHelper::CodeRequest do
132
134
 
133
135
  context 'when response is neither' do
134
136
  it 'should raise an error' do
135
- allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('huh?')
137
+ allow(highline_cli).to receive(:conflicting_remote_clarification).and_return(Faker::Lorem.word)
136
138
  expect(subject).to receive(:exit)
137
139
  subject.send(:ask_for_clarification)
138
140
  end
@@ -171,28 +173,28 @@ describe GitHelper::CodeRequest do
171
173
  it 'should call the default branch' do
172
174
  expect(subject).to receive(:default_branch)
173
175
  allow(highline_cli).to receive(:base_branch_default?).at_least(:once)
174
- allow(highline_cli).to receive(:base_branch).at_least(:once).and_return('base')
176
+ allow(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
175
177
  subject.send(:base_branch)
176
178
  end
177
179
 
178
180
  it 'should ask the CLI to ask the user' do
179
181
  allow(subject).to receive(:default_branch)
180
182
  expect(highline_cli).to receive(:base_branch_default?).at_least(:once)
181
- allow(highline_cli).to receive(:base_branch).at_least(:once).and_return('base')
183
+ allow(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
182
184
  subject.send(:base_branch)
183
185
  end
184
186
 
185
187
  context 'if the user says no' do
186
- it "definitely asks for the user's base branch" do
188
+ it 'definitely asks for the users base branch' do
187
189
  allow(subject).to receive(:default_branch)
188
190
  expect(highline_cli).to receive(:base_branch_default?).at_least(:once).and_return(false)
189
- expect(highline_cli).to receive(:base_branch).at_least(:once).and_return('base')
191
+ expect(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
190
192
  subject.send(:base_branch)
191
193
  end
192
194
  end
193
195
 
194
196
  context 'if the user says yes' do
195
- it "does not ask for the user's base branch" do
197
+ it 'does not ask for the users base branch' do
196
198
  allow(subject).to receive(:default_branch)
197
199
  expect(highline_cli).to receive(:base_branch_default?).at_least(:once).and_return(true)
198
200
  expect(highline_cli).not_to receive(:base_branch)
@@ -203,7 +205,7 @@ describe GitHelper::CodeRequest do
203
205
 
204
206
  describe '#autogenerated_title' do
205
207
  it 'should generate a title based on the branch' do
206
- expect(subject).to receive(:local_branch).and_return('branch')
208
+ expect(subject).to receive(:local_branch).and_return(Faker::Lorem.word)
207
209
  expect(local_code).to receive(:generate_title)
208
210
  subject.send(:autogenerated_title)
209
211
  end
@@ -213,28 +215,28 @@ describe GitHelper::CodeRequest do
213
215
  it 'should call autogenerated title method' do
214
216
  expect(subject).to receive(:autogenerated_title)
215
217
  allow(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once)
216
- allow(highline_cli).to receive(:title).at_least(:once).and_return('Title')
218
+ allow(highline_cli).to receive(:title).at_least(:once).and_return(title)
217
219
  subject.send(:new_code_request_title)
218
220
  end
219
221
 
220
222
  it 'should ask the CLI to ask the user' do
221
223
  allow(subject).to receive(:autogenerated_title)
222
224
  expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once)
223
- allow(highline_cli).to receive(:title).at_least(:once).and_return('Title')
225
+ allow(highline_cli).to receive(:title).at_least(:once).and_return(title)
224
226
  subject.send(:new_code_request_title)
225
227
  end
226
228
 
227
229
  context 'if the user says no' do
228
- it "definitely asks for the user's title" do
230
+ it 'definitely asks for the users title' do
229
231
  allow(subject).to receive(:autogenerated_title)
230
232
  expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once).and_return(false)
231
- expect(highline_cli).to receive(:title).at_least(:once).and_return('Title')
233
+ expect(highline_cli).to receive(:title).at_least(:once).and_return(title)
232
234
  subject.send(:new_code_request_title)
233
235
  end
234
236
  end
235
237
 
236
238
  context 'if the user says yes to original title' do
237
- it "does not ask for the user's chosen title" do
239
+ it 'does not ask for the users chosen title' do
238
240
  allow(subject).to receive(:autogenerated_title)
239
241
  expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once).and_return(true)
240
242
  expect(highline_cli).not_to receive(:title)
@@ -2,13 +2,14 @@ require 'spec_helper'
2
2
  require 'git_helper'
3
3
 
4
4
  describe GitHelper::GitConfigReader do
5
- let(:github_token) { '1234ASDF1234ASDF' }
6
- let(:gitlab_token) { 'ASDF123ASDF1234' }
5
+ let(:github_token) { Faker::Internet.password(max_length: 10) }
6
+ let(:gitlab_token) { Faker::Internet.password(max_length: 10) }
7
+
7
8
  let(:config_file) {
8
9
  {
9
- github_user: 'github-user-name',
10
+ github_user: Faker::Internet.username,
10
11
  github_token: github_token,
11
- gitlab_user: 'gitlab-user-name',
12
+ gitlab_user: Faker::Internet.username,
12
13
  gitlab_token: gitlab_token
13
14
  }
14
15
  }
@@ -48,13 +49,14 @@ describe GitHelper::GitConfigReader do
48
49
 
49
50
  describe '#git_config_file_path' do
50
51
  it 'should look in the current directory' do
51
- expect(Dir).to receive(:pwd).and_return('/Users/firstnamelastname/path/to/git_helper')
52
+ expect(Dir).to receive(:pwd).and_return("/Users/#{Faker::Name.first_name}/#{Faker::Lorem.word}")
52
53
  subject.send(:git_config_file_path)
53
54
  end
54
55
 
55
56
  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')
57
+ user = Faker::Name.first_name
58
+ allow(Dir).to receive(:pwd).and_return("/Users/#{user}/#{Faker::Lorem.word}")
59
+ expect(subject.send(:git_config_file_path)).to eq("/Users/#{user}/.git_helper/config.yml")
58
60
  end
59
61
  end
60
62
  end
@@ -12,7 +12,7 @@ describe GitHelper::HighlineCli do
12
12
  end
13
13
 
14
14
  describe '#new_branch_name' do
15
- it "should ask the subject's ask method" do
15
+ it 'should ask the subjects ask method' do
16
16
  expect(subject).to receive(:ask).with('New branch name?')
17
17
  subject.new_branch_name
18
18
  end
@@ -23,34 +23,34 @@ describe GitHelper::HighlineCli do
23
23
  end
24
24
 
25
25
  describe '#process_directory_remotes' do
26
- it "should ask the subject's ask method" do
26
+ it 'should ask the subjects ask method' do
27
27
  expect(subject).to receive(:ask).and_return('y')
28
- subject.process_directory_remotes?('directory')
28
+ subject.process_directory_remotes?(Faker::Lorem.word)
29
29
  end
30
30
 
31
31
  it 'should be a boolean at the end' do
32
32
  allow(subject).to receive(:ask).and_return('y')
33
- expect([true, false]).to include(subject.process_directory_remotes?('directory'))
33
+ expect([true, false]).to include(subject.process_directory_remotes?(Faker::Lorem.word))
34
34
  end
35
35
 
36
36
  it 'should come out as a true boolean if somebody responds y' do
37
37
  allow(subject).to receive(:ask).and_return('y')
38
- expect(subject.process_directory_remotes?('directory')).to eq(true)
38
+ expect(subject.process_directory_remotes?(Faker::Lorem.word)).to eq(true)
39
39
  end
40
40
 
41
41
  it 'should come out as a false boolean if somebody responds n' do
42
42
  allow(subject).to receive(:ask).and_return('n')
43
- expect(subject.process_directory_remotes?('directory')).to eq(false)
43
+ expect(subject.process_directory_remotes?(Faker::Lorem.word)).to eq(false)
44
44
  end
45
45
 
46
46
  it 'should come out as true if somebody presses enter' do
47
47
  allow(subject).to receive(:ask).and_return('')
48
- expect(subject.accept_autogenerated_title?('directory')).to eq(true)
48
+ expect(subject.accept_autogenerated_title?(Faker::Lorem.word)).to eq(true)
49
49
  end
50
50
  end
51
51
 
52
52
  describe '#conflicting_remote_clarification' do
53
- it "should ask the subject's ask method" do
53
+ it 'should ask the subjects ask method' do
54
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
55
  subject.conflicting_remote_clarification
56
56
  end
@@ -61,7 +61,7 @@ describe GitHelper::HighlineCli do
61
61
  end
62
62
 
63
63
  describe '#title' do
64
- it "should ask the subject's ask method" do
64
+ it 'should ask the subjects ask method' do
65
65
  expect(subject).to receive(:ask).with('Title?')
66
66
  subject.title
67
67
  end
@@ -72,7 +72,7 @@ describe GitHelper::HighlineCli do
72
72
  end
73
73
 
74
74
  describe '#base_branch' do
75
- it "should ask the subject's ask method" do
75
+ it 'should ask the subjects ask method' do
76
76
  expect(subject).to receive(:ask).with('Base branch?')
77
77
  subject.base_branch
78
78
  end
@@ -83,92 +83,94 @@ describe GitHelper::HighlineCli do
83
83
  end
84
84
 
85
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')
86
+ let(:phrase) { Faker::Lorem.sentence }
87
+
88
+ it 'should ask the subjects ask method' do
89
+ expect(subject).to receive(:ask).with("#{phrase} Request ID?")
90
+ subject.code_request_id(phrase)
89
91
  end
90
92
 
91
93
  it 'should come out a string' do
92
- expect(subject.code_request_id('Example')).to be_a(String)
94
+ expect(subject.code_request_id(phrase)).to be_a(String)
93
95
  end
94
96
  end
95
97
 
96
98
  describe '#accept_autogenerated_title' do
97
- it "should ask the subject's ask method" do
99
+ it 'should ask the subjects ask method' do
98
100
  expect(subject).to receive(:ask).and_return('y')
99
- subject.accept_autogenerated_title?('Title Example')
101
+ subject.accept_autogenerated_title?(Faker::Lorem.sentence)
100
102
  end
101
103
 
102
104
  it 'should be a boolean at the end' do
103
105
  allow(subject).to receive(:ask).and_return('y')
104
- expect([true, false]).to include(subject.accept_autogenerated_title?('Title Example'))
106
+ expect([true, false]).to include(subject.accept_autogenerated_title?(Faker::Lorem.sentence))
105
107
  end
106
108
 
107
109
  it 'should come out as a true boolean if somebody responds y' do
108
110
  allow(subject).to receive(:ask).and_return('y')
109
- expect(subject.accept_autogenerated_title?('Title Example')).to eq(true)
111
+ expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
110
112
  end
111
113
 
112
114
  it 'should come out as a true boolean if somebody responds n' do
113
115
  allow(subject).to receive(:ask).and_return('n')
114
- expect(subject.accept_autogenerated_title?('Title Example')).to eq(false)
116
+ expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(false)
115
117
  end
116
118
 
117
119
  it 'should come out as a true boolean if somebody responds yes' do
118
120
  allow(subject).to receive(:ask).and_return('yes')
119
- expect(subject.accept_autogenerated_title?('Title Example')).to eq(true)
121
+ expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
120
122
  end
121
123
 
122
124
  it 'should come out as a false boolean if somebody responds no' do
123
125
  allow(subject).to receive(:ask).and_return('no')
124
- expect(subject.accept_autogenerated_title?('Title Example')).to eq(false)
126
+ expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(false)
125
127
  end
126
128
 
127
129
  it 'should come out as true if somebody presses enter' do
128
130
  allow(subject).to receive(:ask).and_return('')
129
- expect(subject.accept_autogenerated_title?('Title Example')).to eq(true)
131
+ expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
130
132
  end
131
133
  end
132
134
 
133
135
  describe '#base_branch_default' do
134
- it "should ask the subject's ask method" do
136
+ it 'should ask the subjects ask method' do
135
137
  expect(subject).to receive(:ask).and_return('y')
136
- subject.base_branch_default?('default_branch')
138
+ subject.base_branch_default?(Faker::Lorem.word)
137
139
  end
138
140
 
139
141
  it 'should be a boolean at the end' do
140
142
  allow(subject).to receive(:ask).and_return('y')
141
- expect([true, false]).to include(subject.base_branch_default?('default_branch'))
143
+ expect([true, false]).to include(subject.base_branch_default?(Faker::Lorem.word))
142
144
  end
143
145
 
144
146
  it 'should come out as a true boolean if somebody responds y' do
145
147
  allow(subject).to receive(:ask).and_return('y')
146
- expect(subject.base_branch_default?('default_branch')).to eq(true)
148
+ expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
147
149
  end
148
150
 
149
151
  it 'should come out as a true boolean if somebody responds n' do
150
152
  allow(subject).to receive(:ask).and_return('n')
151
- expect(subject.base_branch_default?('default_branch')).to eq(false)
153
+ expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(false)
152
154
  end
153
155
 
154
156
  it 'should come out as a true boolean if somebody responds yes' do
155
157
  allow(subject).to receive(:ask).and_return('yes')
156
- expect(subject.base_branch_default?('default_branch')).to eq(true)
158
+ expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
157
159
  end
158
160
 
159
161
  it 'should come out as a false boolean if somebody responds no' do
160
162
  allow(subject).to receive(:ask).and_return('no')
161
- expect(subject.base_branch_default?('default_branch')).to eq(false)
163
+ expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(false)
162
164
  end
163
165
 
164
166
  it 'should come out as true if somebody presses enter' do
165
167
  allow(subject).to receive(:ask).and_return('')
166
- expect(subject.base_branch_default?('default_branch')).to eq(true)
168
+ expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
167
169
  end
168
170
  end
169
171
 
170
172
  describe '#merge_method' do
171
- it "should ask the subject's ask_options method" do
173
+ it 'should ask the subjects ask_options method' do
172
174
  expect(subject).to receive(:ask_options).and_return(3)
173
175
  subject.merge_method(['1', '2', '3'])
174
176
  end
@@ -180,7 +182,7 @@ describe GitHelper::HighlineCli do
180
182
  end
181
183
 
182
184
  describe '#template_to_apply' do
183
- it "should ask the subject's ask_options method" do
185
+ it 'should ask the subjects ask_options method' do
184
186
  expect(subject).to receive(:ask_options).and_return(3)
185
187
  subject.template_to_apply(['option1', 'option2', 'option3'], 'example type')
186
188
  end
@@ -194,22 +196,22 @@ describe GitHelper::HighlineCli do
194
196
  describe '#ask' do
195
197
  it 'should ask the highline client ask'do
196
198
  expect(highline_client).to receive(:ask)
197
- subject.send(:ask, 'prompt goes here')
199
+ subject.send(:ask, Faker::Lorem.sentence)
198
200
  end
199
201
 
200
202
  it 'should return a string' do
201
- expect(subject.send(:ask, 'prompt goes here')).to be_a(String)
203
+ expect(subject.send(:ask, Faker::Lorem.sentence)).to be_a(String)
202
204
  end
203
205
  end
204
206
 
205
207
  describe '#ask_options' do
206
208
  it 'should ask the highline client ask'do
207
209
  expect(highline_client).to receive(:ask)
208
- subject.send(:ask_options, 'prompt goes here', ['1', '2', '3'])
210
+ subject.send(:ask_options, Faker::Lorem.sentence, ['1', '2', '3'])
209
211
  end
210
212
 
211
213
  it 'should return an integer' do
212
- expect(subject.send(:ask_options, 'prompt goes here', ['1', '2', '3'])).to be_a(Integer)
214
+ expect(subject.send(:ask_options, Faker::Lorem.sentence, ['1', '2', '3'])).to be_a(Integer)
213
215
  end
214
216
  end
215
217
  end
@@ -4,11 +4,24 @@ require 'git_helper'
4
4
  describe GitHelper::LocalCode do
5
5
  let(:response) { double(:response, readline: true, to_i: 5) }
6
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)' ] }
7
+ let(:project_name) { Faker::Lorem.word }
8
+ let(:owner) { Faker::Name.first_name }
9
+ let(:ssh_remote) { "origin\tgit@github.com:#{owner}/#{project_name}.git (fetch)" }
10
+ let(:https_remote) { "origin\thttps://github.com/#{owner}/#{project_name}.git (fetch)" }
11
+
12
+ let(:github_remotes) do
13
+ [
14
+ "origin\tgit@github.com:#{owner}/#{project_name}.git (fetch)",
15
+ "origin\thttps://github.com/#{owner}/#{project_name}.git (fetch)"
16
+ ]
17
+ end
11
18
 
19
+ let(:gitlab_remotes) do
20
+ [
21
+ "origin\tgit@gitlab.com:#{owner}/#{project_name}.git (fetch)",
22
+ "origin\thttps://gitlab.com/#{owner}/#{project_name}.git (fetch)"
23
+ ]
24
+ end
12
25
 
13
26
  subject { GitHelper::LocalCode.new }
14
27
 
@@ -51,13 +64,13 @@ describe GitHelper::LocalCode do
51
64
  describe '#new_branch' do
52
65
  it 'should make a system call' do
53
66
  expect(subject).to receive(:system).exactly(4).times
54
- subject.new_branch('branch_name')
67
+ subject.new_branch(Faker::Lorem.word)
55
68
  end
56
69
  end
57
70
 
58
71
  describe '#change_remote' do
59
72
  it 'should return a string' do
60
- expect(subject.change_remote('name', 'url')).to be_a(String)
73
+ expect(subject.change_remote(Faker::Lorem.word, Faker::Internet.url)).to be_a(String)
61
74
  end
62
75
  end
63
76
 
@@ -96,11 +109,11 @@ describe GitHelper::LocalCode do
96
109
 
97
110
  describe '#remote_project' do
98
111
  it 'should return just the plain project if ssh' do
99
- expect(subject.remote_project(ssh_remote)).to eq('git_helper')
112
+ expect(subject.remote_project(ssh_remote)).to eq(project_name)
100
113
  end
101
114
 
102
115
  it 'should return just the plain project if https' do
103
- expect(subject.remote_project(https_remote)).to eq('git_helper')
116
+ expect(subject.remote_project(https_remote)).to eq(project_name)
104
117
  end
105
118
  end
106
119
 
@@ -144,8 +157,8 @@ describe GitHelper::LocalCode do
144
157
  end
145
158
 
146
159
  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')
160
+ allow_any_instance_of(String).to receive(:scan).and_return([["#{owner}/#{project_name}"]])
161
+ expect(subject.project_name).to eq("#{owner}/#{project_name}")
149
162
  end
150
163
  end
151
164
 
@@ -190,43 +203,65 @@ describe GitHelper::LocalCode do
190
203
 
191
204
  describe '#generate_title' do
192
205
  it 'should return a title based on the branch' do
193
- branch = 'jira-123-test-branch'
194
- expect(subject.generate_title(branch)).to eq('JIRA-123 Test branch')
206
+ prefix = Faker::Lorem.word
207
+ word1 = Faker::Lorem.word
208
+ word2 = Faker::Lorem.word
209
+ description = [word1, word2].join('-')
210
+ branch = "#{prefix}-123-#{description}"
211
+ expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
195
212
  end
196
213
 
197
214
  it 'should return a title based on the branch' do
198
- branch = 'jira_123_test_branch'
199
- expect(subject.generate_title(branch)).to eq('JIRA-123 Test branch')
215
+ prefix = Faker::Lorem.word
216
+ word1 = Faker::Lorem.word
217
+ word2 = Faker::Lorem.word
218
+ description = [word1, word2].join('_')
219
+ branch = "#{prefix}_123_#{description}"
220
+ expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
200
221
  end
201
222
 
202
223
  it 'should return a title based on the branch' do
203
- branch = 'jira-123_test_branch'
204
- expect(subject.generate_title(branch)).to eq('JIRA-123 Test branch')
224
+ prefix = Faker::Lorem.word
225
+ word1 = Faker::Lorem.word
226
+ word2 = Faker::Lorem.word
227
+ description = [word1, word2].join('_')
228
+ branch = "#{prefix}-123_#{description}"
229
+ expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
205
230
  end
206
231
 
207
232
  it 'should return a title based on the branch' do
208
- branch = 'test_branch'
209
- expect(subject.generate_title(branch)).to eq('Test branch')
233
+ word1 = Faker::Lorem.word
234
+ word2 = Faker::Lorem.word
235
+ branch = [word1, word2].join('_')
236
+ expect(subject.generate_title(branch)).to eq([word1.capitalize, word2].join(' '))
210
237
  end
211
238
 
212
239
  it 'should return a title based on the branch' do
213
- branch = 'test-branch'
214
- expect(subject.generate_title(branch)).to eq('Test branch')
240
+ word1 = Faker::Lorem.word
241
+ word2 = Faker::Lorem.word
242
+ branch = [word1, word2].join('-')
243
+ expect(subject.generate_title(branch)).to eq([word1.capitalize, word2].join(' '))
215
244
  end
216
245
 
217
246
  it 'should return a title based on the branch' do
218
- branch = 'test'
219
- expect(subject.generate_title(branch)).to eq('Test')
247
+ branch = Faker::Lorem.word
248
+ expect(subject.generate_title(branch)).to eq(branch.capitalize)
220
249
  end
221
250
 
222
251
  it 'should return a title based on the branch' do
223
- branch = 'some_other_words_in_this_test_branch'
224
- expect(subject.generate_title(branch)).to eq('Some other words in this test branch')
252
+ word1 = Faker::Lorem.word
253
+ word2 = Faker::Lorem.word
254
+ word3 = Faker::Lorem.word
255
+ branch = [word1, word2, word3].join('_')
256
+ expect(subject.generate_title(branch)).to eq([word1.capitalize, word2, word3].join(' '))
225
257
  end
226
258
 
227
259
  it 'should return a title based on the branch' do
228
- branch = 'some-other-words-in-this-test-branch'
229
- expect(subject.generate_title(branch)).to eq('Some other words in this test branch')
260
+ word1 = Faker::Lorem.word
261
+ word2 = Faker::Lorem.word
262
+ word3 = Faker::Lorem.word
263
+ branch = [word1, word2, word3].join('-')
264
+ expect(subject.generate_title(branch)).to eq([word1.capitalize, word2, word3].join(' '))
230
265
  end
231
266
  end
232
267
  end
@@ -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: 3.0.1
4
+ version: 3.1.0
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-19 00:00:00.000000000 Z
11
+ date: 2020-11-19 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