git_helper 3.3.0 → 3.3.5

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +31 -8
  4. data/Guardfile +3 -1
  5. data/README.md +4 -4
  6. data/Rakefile +2 -0
  7. data/bin/git-helper +18 -13
  8. data/lib/git_helper.rb +6 -2
  9. data/lib/git_helper/change_remote.rb +15 -6
  10. data/lib/git_helper/checkout_default.rb +2 -0
  11. data/lib/git_helper/clean_branches.rb +2 -0
  12. data/lib/git_helper/code_request.rb +33 -19
  13. data/lib/git_helper/empty_commit.rb +2 -0
  14. data/lib/git_helper/forget_local_commits.rb +2 -0
  15. data/lib/git_helper/git_config_reader.rb +11 -5
  16. data/lib/git_helper/gitlab_client.rb +2 -0
  17. data/lib/git_helper/local_code.rb +18 -8
  18. data/lib/git_helper/merge_request.rb +90 -70
  19. data/lib/git_helper/new_branch.rb +4 -2
  20. data/lib/git_helper/octokit_client.rb +2 -0
  21. data/lib/git_helper/pull_request.rb +97 -66
  22. data/lib/git_helper/setup.rb +69 -40
  23. data/lib/git_helper/version.rb +3 -1
  24. data/spec/git_helper/change_remote_spec.rb +24 -24
  25. data/spec/git_helper/checkout_default_spec.rb +2 -0
  26. data/spec/git_helper/clean_branches_spec.rb +2 -0
  27. data/spec/git_helper/code_request_spec.rb +30 -28
  28. data/spec/git_helper/empty_commit_spec.rb +2 -0
  29. data/spec/git_helper/forget_local_commits_spec.rb +2 -0
  30. data/spec/git_helper/git_config_reader_spec.rb +32 -4
  31. data/spec/git_helper/gitlab_client_spec.rb +2 -0
  32. data/spec/git_helper/local_code_spec.rb +2 -0
  33. data/spec/git_helper/merge_request_spec.rb +24 -23
  34. data/spec/git_helper/new_branch_spec.rb +10 -8
  35. data/spec/git_helper/octokit_client_spec.rb +2 -0
  36. data/spec/git_helper/pull_request_spec.rb +20 -18
  37. data/spec/git_helper/setup_spec.rb +39 -26
  38. data/spec/spec_helper.rb +4 -1
  39. metadata +34 -9
  40. data/lib/git_helper/highline_cli.rb +0 -33
  41. data/spec/git_helper/highline_cli_spec.rb +0 -51
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
@@ -1,19 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
4
6
  describe GitHelper::GitLabMergeRequest do
5
7
  let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
6
- let(:highline_cli) { double(:highline_cli) }
8
+ let(:highline_wrapper) { double(:highline_wrapper) }
7
9
  let(:gitlab_client_client) { double(:gitlab_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
8
10
  let(:gitlab_client) { double(:gitlab_client, client: gitlab_client_client) }
9
11
  let(:diff_refs) { double(:diff_refs, base_sha: :base, head_sha: :head) }
10
12
 
11
13
  let(:merge_request) do
12
14
  double(:merge_request,
13
- diff_refs: diff_refs,
14
- web_url: Faker::Internet.url,
15
- merge_commit_sha: Faker::Internet.password
16
- )
15
+ diff_refs: diff_refs,
16
+ web_url: Faker::Internet.url,
17
+ merge_commit_sha: Faker::Internet.password)
17
18
  end
18
19
 
19
20
  let(:options) do
@@ -21,7 +22,7 @@ describe GitHelper::GitLabMergeRequest do
21
22
  local_project: Faker::Lorem.word,
22
23
  local_branch: Faker::Lorem.word,
23
24
  local_code: local_code,
24
- cli: highline_cli
25
+ highline: highline_wrapper
25
26
  }
26
27
  end
27
28
 
@@ -38,7 +39,7 @@ describe GitHelper::GitLabMergeRequest do
38
39
  allow(subject).to receive(:remove_source_branch).and_return(false)
39
40
  allow(subject).to receive(:new_mr_body).and_return('')
40
41
  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})
42
+ subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
42
43
  end
43
44
 
44
45
  it 'should call various other methods' do
@@ -46,7 +47,7 @@ describe GitHelper::GitLabMergeRequest do
46
47
  expect(subject).to receive(:remove_source_branch).and_return(false)
47
48
  expect(subject).to receive(:new_mr_body).and_return('')
48
49
  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})
50
+ subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
50
51
  end
51
52
 
52
53
  it 'should catch the raised error if the creation does not work' do
@@ -54,7 +55,7 @@ describe GitHelper::GitLabMergeRequest do
54
55
  allow(subject).to receive(:remove_source_branch).and_return(false)
55
56
  allow(subject).to receive(:new_mr_body).and_return('')
56
57
  allow(gitlab_client_client).to receive(:create_merge_request).and_raise(StandardError)
57
- expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
58
+ expect(subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })).to eq(nil)
58
59
  end
59
60
  end
60
61
 
@@ -120,19 +121,19 @@ describe GitHelper::GitLabMergeRequest do
120
121
 
121
122
  it 'should call the CLI to ask about a single template' do
122
123
  allow(subject).to receive(:mr_template_options).and_return([template])
123
- expect(highline_cli).to receive(:ask_yes_no).and_return(true)
124
+ expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
124
125
  subject.send(:template_name_to_apply)
125
126
  end
126
127
 
127
128
  it 'should return the single template if the user says yes' do
128
129
  allow(subject).to receive(:mr_template_options).and_return([template])
129
- allow(highline_cli).to receive(:ask_yes_no).and_return(true)
130
+ allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
130
131
  expect(subject.send(:template_name_to_apply)).to eq(template)
131
132
  end
132
133
 
133
134
  it 'should return nil if the user says no' do
134
135
  allow(subject).to receive(:mr_template_options).and_return([template])
135
- allow(highline_cli).to receive(:ask_yes_no).and_return(false)
136
+ allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
136
137
  expect(subject.send(:template_name_to_apply)).to eq(nil)
137
138
  end
138
139
  end
@@ -143,19 +144,19 @@ describe GitHelper::GitLabMergeRequest do
143
144
 
144
145
  it 'should call the CLI to ask which of multiple templates to apply' do
145
146
  allow(subject).to receive(:mr_template_options).and_return([template1, template2])
146
- expect(highline_cli).to receive(:ask_options).and_return(template1)
147
+ expect(highline_wrapper).to receive(:ask_options).and_return(template1)
147
148
  subject.send(:template_name_to_apply)
148
149
  end
149
150
 
150
151
  it 'should return the answer template if the user says yes' do
151
152
  allow(subject).to receive(:mr_template_options).and_return([template1, template2])
152
- allow(highline_cli).to receive(:ask_options).and_return(template1)
153
+ allow(highline_wrapper).to receive(:ask_options).and_return(template1)
153
154
  expect(subject.send(:template_name_to_apply)).to eq(template1)
154
155
  end
155
156
 
156
157
  it 'should return nil if the user says no' do
157
158
  allow(subject).to receive(:mr_template_options).and_return([template1, template2])
158
- allow(highline_cli).to receive(:ask_options).and_return('None')
159
+ allow(highline_wrapper).to receive(:ask_options).and_return('None')
159
160
  expect(subject.send(:template_name_to_apply)).to eq(nil)
160
161
  end
161
162
  end
@@ -170,25 +171,25 @@ describe GitHelper::GitLabMergeRequest do
170
171
 
171
172
  describe '#mr_id' do
172
173
  it 'should ask the CLI for the code request ID' do
173
- expect(highline_cli).to receive(:ask).and_return(Faker::Number.number)
174
+ expect(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
174
175
  subject.send(:mr_id)
175
176
  end
176
177
 
177
178
  it 'should equal an integer' do
178
179
  pr_id = Faker::Number.number
179
- expect(highline_cli).to receive(:ask).and_return(pr_id)
180
+ expect(highline_wrapper).to receive(:ask).and_return(pr_id)
180
181
  expect(subject.send(:mr_id)).to eq(pr_id)
181
182
  end
182
183
  end
183
184
 
184
185
  describe '#squash_merge_request' do
185
186
  it 'should ask the CLI for the code request ID' do
186
- expect(highline_cli).to receive(:ask_yes_no).and_return(true)
187
+ expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
187
188
  subject.send(:squash_merge_request)
188
189
  end
189
190
 
190
191
  it 'should be a boolean' do
191
- expect(highline_cli).to receive(:ask_yes_no).and_return(false)
192
+ expect(highline_wrapper).to receive(:ask_yes_no).and_return(false)
192
193
  expect([true, false]).to include(subject.send(:squash_merge_request))
193
194
  end
194
195
  end
@@ -200,12 +201,12 @@ describe GitHelper::GitLabMergeRequest do
200
201
 
201
202
  context 'when the existing project has no setting' do
202
203
  it 'should ask the CLI for the code request ID' do
203
- expect(highline_cli).to receive(:ask_yes_no).and_return(true)
204
+ expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
204
205
  subject.send(:remove_source_branch)
205
206
  end
206
207
 
207
208
  it 'should be a boolean' do
208
- allow(highline_cli).to receive(:ask_yes_no).and_return(false)
209
+ allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
209
210
  expect([true, false]).to include(subject.send(:remove_source_branch))
210
211
  end
211
212
  end
@@ -222,7 +223,7 @@ describe GitHelper::GitLabMergeRequest do
222
223
 
223
224
  it 'should return the existing projects setting if it exists' do
224
225
  allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: false))
225
- allow(highline_cli).to receive(:ask_yes_no).and_return(true)
226
+ allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
226
227
  expect(subject.send(:remove_source_branch)).to eq(true)
227
228
  end
228
229
  end
@@ -236,7 +237,7 @@ describe GitHelper::GitLabMergeRequest do
236
237
 
237
238
  describe '#existing_mr' do
238
239
  it 'should call the gitlab client' do
239
- allow(highline_cli).to receive(:ask).and_return(Faker::Number.number)
240
+ allow(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
240
241
  expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
241
242
  subject.send(:existing_mr)
242
243
  end
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
4
6
  describe GitHelper::NewBranch do
5
7
  let(:new_branch_name) { 'new-branch-name' }
6
8
  let(:local_code) { double(:local_code, new_branch: :commit) }
7
- let(:cli) { double(:highline_cli, ask: new_branch_name) }
9
+ let(:highline) { double(:highline_wrapper, ask: new_branch_name) }
8
10
 
9
11
  subject { GitHelper::NewBranch.new }
10
12
 
11
13
  before do
12
14
  allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
13
- allow(GitHelper::HighlineCli).to receive(:new).and_return(cli)
15
+ allow(HighlineWrapper).to receive(:new).and_return(highline)
14
16
  allow(subject).to receive(:puts)
15
17
  end
16
18
 
@@ -25,20 +27,20 @@ describe GitHelper::NewBranch do
25
27
  end
26
28
 
27
29
  context 'when no branch name is passed in' do
28
- it 'should call the highline cli' do
29
- expect(GitHelper::HighlineCli).to receive(:new).and_return(cli)
30
+ it 'should call the highline client' do
31
+ expect(HighlineWrapper).to receive(:new).and_return(highline)
30
32
  subject.execute
31
33
  end
32
34
 
33
- it 'should ask the highline cli what the new branch name should be' do
34
- expect(cli).to receive(:ask)
35
+ it 'should ask the highline client what the new branch name should be' do
36
+ expect(highline).to receive(:ask)
35
37
  subject.execute
36
38
  end
37
39
  end
38
40
 
39
41
  context 'when there is a branch name passed in' do
40
- it 'should not create a highline cli' do
41
- expect(GitHelper::HighlineCli).not_to receive(:new)
42
+ it 'should not create a highline_wrapper client' do
43
+ expect(HighlineWrapper).not_to receive(:new)
42
44
  subject.execute(new_branch_name)
43
45
  end
44
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
4
6
  describe GitHelper::GitHubPullRequest do
5
7
  let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
6
- let(:highline_cli) { double(:highline_cli) }
8
+ let(:highline_wrapper) { double(:highline_wrapper) }
7
9
  let(:octokit_client_client) { double(:octokit_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
8
10
  let(:octokit_client) { double(:octokit_client, client: octokit_client_client) }
9
11
 
@@ -12,7 +14,7 @@ describe GitHelper::GitHubPullRequest do
12
14
  local_project: Faker::Lorem.word,
13
15
  local_branch: Faker::Lorem.word,
14
16
  local_code: local_code,
15
- cli: highline_cli
17
+ highline: highline_wrapper
16
18
  }
17
19
  end
18
20
 
@@ -27,19 +29,19 @@ describe GitHelper::GitHubPullRequest do
27
29
  it 'should call the octokit client to create' do
28
30
  allow(subject).to receive(:new_pr_body).and_return('')
29
31
  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})
32
+ subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
31
33
  end
32
34
 
33
35
  it 'should call various other methods' do
34
36
  expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
35
37
  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})
38
+ subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
37
39
  end
38
40
 
39
41
  it 'should catch the raised error if the creation does not work' do
40
42
  allow(subject).to receive(:new_pr_body).and_return('')
41
43
  allow(octokit_client_client).to receive(:create_pull_request).and_raise(StandardError)
42
- expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
44
+ expect(subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })).to eq(nil)
43
45
  end
44
46
  end
45
47
 
@@ -101,19 +103,19 @@ describe GitHelper::GitHubPullRequest do
101
103
 
102
104
  it 'should call the CLI to ask about a single template' do
103
105
  allow(subject).to receive(:pr_template_options).and_return([template])
104
- expect(highline_cli).to receive(:ask_yes_no).and_return(true)
106
+ expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
105
107
  subject.send(:template_name_to_apply)
106
108
  end
107
109
 
108
110
  it 'should return the single template if the user says yes' do
109
111
  allow(subject).to receive(:pr_template_options).and_return([template])
110
- allow(highline_cli).to receive(:ask_yes_no).and_return(true)
112
+ allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
111
113
  expect(subject.send(:template_name_to_apply)).to eq(template)
112
114
  end
113
115
 
114
116
  it 'should return nil if the user says no' do
115
117
  allow(subject).to receive(:pr_template_options).and_return([template])
116
- allow(highline_cli).to receive(:ask_yes_no).and_return(false)
118
+ allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
117
119
  expect(subject.send(:template_name_to_apply)).to eq(nil)
118
120
  end
119
121
  end
@@ -124,19 +126,19 @@ describe GitHelper::GitHubPullRequest do
124
126
 
125
127
  it 'should call the CLI to ask which of multiple templates to apply' do
126
128
  allow(subject).to receive(:pr_template_options).and_return([template1, template2])
127
- expect(highline_cli).to receive(:ask_options).and_return(template1)
129
+ expect(highline_wrapper).to receive(:ask_options).and_return(template1)
128
130
  subject.send(:template_name_to_apply)
129
131
  end
130
132
 
131
133
  it 'should return the answer template if the user says yes' do
132
134
  allow(subject).to receive(:pr_template_options).and_return([template1, template2])
133
- allow(highline_cli).to receive(:ask_options).and_return(template1)
135
+ allow(highline_wrapper).to receive(:ask_options).and_return(template1)
134
136
  expect(subject.send(:template_name_to_apply)).to eq(template1)
135
137
  end
136
138
 
137
139
  it 'should return nil if the user says no' do
138
140
  allow(subject).to receive(:pr_template_options).and_return([template1, template2])
139
- allow(highline_cli).to receive(:ask_options).and_return('None')
141
+ allow(highline_wrapper).to receive(:ask_options).and_return('None')
140
142
  expect(subject.send(:template_name_to_apply)).to eq(nil)
141
143
  end
142
144
  end
@@ -151,13 +153,13 @@ describe GitHelper::GitHubPullRequest do
151
153
 
152
154
  describe '#pr_id' do
153
155
  it 'should ask the CLI for the code request ID' do
154
- expect(highline_cli).to receive(:ask).and_return(Faker::Number.number)
156
+ expect(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
155
157
  subject.send(:pr_id)
156
158
  end
157
159
 
158
160
  it 'should equal an integer' do
159
161
  pr_id = Faker::Number.number
160
- expect(highline_cli).to receive(:ask).and_return(pr_id)
162
+ expect(highline_wrapper).to receive(:ask).and_return(pr_id)
161
163
  expect(subject.send(:pr_id)).to eq(pr_id)
162
164
  end
163
165
  end
@@ -167,16 +169,16 @@ describe GitHelper::GitHubPullRequest do
167
169
 
168
170
  before do
169
171
  allow(subject).to receive(:existing_project).and_return(project)
170
- allow(highline_cli).to receive(:ask_options)
172
+ allow(highline_wrapper).to receive(:ask_options)
171
173
  end
172
174
 
173
175
  it 'should ask the CLI for the merge_method' do
174
- expect(highline_cli).to receive(:ask_options).and_return('merge')
176
+ expect(highline_wrapper).to receive(:ask_options).and_return('merge')
175
177
  subject.send(:merge_method)
176
178
  end
177
179
 
178
180
  it 'should be a string' do
179
- allow(highline_cli).to receive(:ask_options).and_return('merge')
181
+ allow(highline_wrapper).to receive(:ask_options).and_return('merge')
180
182
  expect(subject.send(:merge_method)).to be_a(String)
181
183
  end
182
184
 
@@ -184,7 +186,7 @@ describe GitHelper::GitHubPullRequest do
184
186
  let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
185
187
 
186
188
  it 'should not ask the CLI anything' do
187
- expect(highline_cli).not_to receive(:merge_method)
189
+ expect(highline_wrapper).not_to receive(:merge_method)
188
190
  subject.send(:merge_method)
189
191
  end
190
192
  end
@@ -239,7 +241,7 @@ describe GitHelper::GitHubPullRequest do
239
241
 
240
242
  describe '#existing_pr' do
241
243
  it 'should call the octokit client' do
242
- allow(highline_cli).to receive(:ask).and_return(Faker::Number.number)
244
+ allow(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
243
245
  expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
244
246
  subject.send(:existing_pr)
245
247
  end
@@ -1,23 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
4
6
  describe GitHelper::Setup do
5
- let(:response) { double(:response, readline: true, to_s: Faker::Lorem.sentence) }
6
- let(:highline_cli) { double(:highline_cli, ask: response, ask_yes_no: true) }
7
+ let(:highline_wrapper) { double(:highline_wrapper, ask: Faker::Lorem.word, ask_yes_no: true) }
7
8
 
8
9
  before do
9
- allow(GitHelper::HighlineCli).to receive(:new).and_return(highline_cli)
10
+ allow(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
10
11
  allow(subject).to receive(:puts)
11
12
  end
12
13
 
13
14
  after do
14
- GitHelper::Setup.instance_variable_set("@highline", nil)
15
+ GitHelper::Setup.instance_variable_set('@highline', nil)
15
16
  end
16
17
 
17
18
  describe '#execute' do
18
- it 'should ask a question if the config file exists' do
19
+ it 'only asks the user one question if the config file does not exist' do
20
+ allow(subject).to receive(:config_file_exists?).and_return(false)
21
+ allow(File).to receive(:exists?).and_return(true)
22
+ expect(highline_wrapper).to receive(:ask_yes_no).and_return(true).exactly(:once)
23
+ allow(subject).to receive(:create_or_update_config_file).and_return(true)
24
+ allow(subject).to receive(:create_or_update_plugin_files)
25
+ subject.execute
26
+ end
27
+
28
+ it 'should ask two questions if the config file exists' do
29
+ allow(subject).to receive(:config_file_exists?).and_return(true)
19
30
  allow(File).to receive(:exists?).and_return(true)
20
- expect(highline_cli).to receive(:ask_yes_no).and_return(true)
31
+ expect(highline_wrapper).to receive(:ask_yes_no).and_return(true).at_least(:twice)
21
32
  allow(subject).to receive(:create_or_update_config_file).and_return(true)
22
33
  allow(subject).to receive(:create_or_update_plugin_files)
23
34
  subject.execute
@@ -25,7 +36,7 @@ describe GitHelper::Setup do
25
36
 
26
37
  it 'should call to create or update the config file' do
27
38
  allow(File).to receive(:exists?).and_return(true)
28
- allow(highline_cli).to receive(:ask_yes_no).and_return(true)
39
+ allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
29
40
  expect(subject).to receive(:create_or_update_config_file).and_return(true)
30
41
  allow(subject).to receive(:create_or_update_plugin_files)
31
42
  subject.execute
@@ -33,7 +44,8 @@ describe GitHelper::Setup do
33
44
 
34
45
  it 'should skip if the user opts not to continue' do
35
46
  allow(File).to receive(:exists?).and_return(true)
36
- allow(highline_cli).to receive(:ask_yes_no).and_return(false)
47
+ allow(subject).to receive(:config_file_exists?).and_return(true)
48
+ allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
37
49
  expect(subject).not_to receive(:create_or_update_config_file)
38
50
  expect(subject).not_to receive(:create_or_update_plugin_files)
39
51
  subject.execute
@@ -56,55 +68,49 @@ describe GitHelper::Setup do
56
68
 
57
69
  describe '#config_file_exists?' do
58
70
  it 'should return true if the file exists' do
59
- allow(File).to receive(:exists?).and_return(true)
71
+ allow(File).to receive(:exist?).and_return(true)
60
72
  expect(subject.send(:config_file_exists?)).to eq(true)
61
73
  end
62
74
 
63
75
  it 'should return false if the file does not exist' do
64
- allow(File).to receive(:exists?).and_return(false)
76
+ allow(File).to receive(:exist?).and_return(false)
65
77
  expect(subject.send(:config_file_exists?)).to eq(false)
66
78
  end
67
79
  end
68
80
 
69
81
  describe '#ask_question' do
70
82
  it 'should use highline to ask a question' do
71
- expect(highline_cli).to receive(:ask).and_return(Faker::Lorem.word)
72
- subject.send(:ask_question, Faker::Lorem.sentence)
73
- end
74
-
75
- it 'should recurse if the highline client gets an empty string' do
76
- allow(highline_cli).to receive(:ask).and_return('', Faker::Lorem.word)
77
- expect(subject).to receive(:ask_question).at_least(:twice).and_call_original
83
+ expect(highline_wrapper).to receive(:ask).and_return(Faker::Lorem.word)
78
84
  subject.send(:ask_question, Faker::Lorem.sentence)
79
85
  end
80
86
 
81
87
  it 'should return the answer if it is given' do
82
88
  answer = Faker::Lorem.sentence
83
- allow(highline_cli).to receive(:ask).and_return(answer)
89
+ allow(highline_wrapper).to receive(:ask).and_return(answer)
84
90
  expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
85
91
  end
86
92
  end
87
93
 
88
94
  describe '#generate_file_contents' do
89
95
  it 'should ask two yes/no questions' do
90
- expect(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(false)
96
+ expect(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(false)
91
97
  subject.send(:generate_file_contents)
92
98
  end
93
99
 
94
100
  it 'should ask two additional questions for each time the user says yes' do
95
- allow(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(true, false)
101
+ allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true, false)
96
102
  expect(subject).to receive(:ask_question).exactly(2).times.and_return(Faker::Lorem.word)
97
103
  subject.send(:generate_file_contents)
98
104
  end
99
105
 
100
106
  it 'should ask four additional questions for each time the user says yes' do
101
- allow(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(true)
107
+ allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true)
102
108
  expect(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
103
109
  subject.send(:generate_file_contents)
104
110
  end
105
111
 
106
112
  it 'should return a string no matter what' do
107
- allow(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(true)
113
+ allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true)
108
114
  allow(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
109
115
  expect(subject.send(:generate_file_contents)).to be_a(String)
110
116
  end
@@ -114,10 +120,10 @@ describe GitHelper::Setup do
114
120
  let(:plugins) do
115
121
  [
116
122
  {
117
- 'name': 'plugin-file-one'
123
+ name: 'plugin-file-one'
118
124
  },
119
125
  {
120
- 'name': 'plugin-file-two'
126
+ name: 'plugin-file-two'
121
127
  }
122
128
  ]
123
129
  end
@@ -133,8 +139,13 @@ describe GitHelper::Setup do
133
139
  ]"
134
140
  end
135
141
 
142
+ before do
143
+ allow_any_instance_of(GitHelper::GitConfigReader).to receive(:github_token).and_return(Faker::Internet.password)
144
+ allow_any_instance_of(GitHelper::GitConfigReader).to receive(:github_user).and_return(Faker::Internet.username)
145
+ end
146
+
136
147
  it 'should create the directory if it does not exist' do
137
- allow(File).to receive(:exists?).and_return(false)
148
+ allow(File).to receive(:exist?).and_return(false)
138
149
  allow(File).to receive(:open).and_return(nil)
139
150
  expect(Dir).to receive(:mkdir)
140
151
  allow(subject).to receive(:`).and_return(plugins_json)
@@ -143,7 +154,7 @@ describe GitHelper::Setup do
143
154
  end
144
155
 
145
156
  it 'should not create the directory if it already exists' do
146
- allow(File).to receive(:exists?).and_return(true)
157
+ allow(File).to receive(:exist?).and_return(true)
147
158
  allow(File).to receive(:open).and_return(nil)
148
159
  expect(Dir).not_to receive(:mkdir)
149
160
  allow(subject).to receive(:`).and_return(plugins_json)
@@ -152,6 +163,7 @@ describe GitHelper::Setup do
152
163
  end
153
164
 
154
165
  it 'should curl the GitHub API' do
166
+ allow(Dir).to receive(:mkdir).and_return(true)
155
167
  allow(File).to receive(:exists?).and_return(true)
156
168
  allow(File).to receive(:open).and_return(nil)
157
169
  allow(subject).to receive(:`).and_return(plugins_json)
@@ -160,6 +172,7 @@ describe GitHelper::Setup do
160
172
  end
161
173
 
162
174
  it 'should go through the loop for each plugin' do
175
+ allow(Dir).to receive(:mkdir).and_return(true)
163
176
  allow(File).to receive(:exists?).and_return(true)
164
177
  allow(File).to receive(:open).and_return(nil)
165
178
  expect(subject).to receive(:`).exactly(3).times