git_helper 3.1.3 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ require 'git_helper'
4
4
  describe GitHelper::NewBranch do
5
5
  let(:new_branch_name) { 'new-branch-name' }
6
6
  let(:local_code) { double(:local_code, new_branch: :commit) }
7
- let(:cli) { double(:highline_cli, new_branch_name: new_branch_name) }
7
+ let(:cli) { double(:highline_cli, ask: new_branch_name) }
8
8
 
9
9
  subject { GitHelper::NewBranch.new }
10
10
 
@@ -31,7 +31,7 @@ describe GitHelper::NewBranch do
31
31
  end
32
32
 
33
33
  it 'should ask the highline cli what the new branch name should be' do
34
- expect(cli).to receive(:new_branch_name)
34
+ expect(cli).to receive(:ask)
35
35
  subject.execute
36
36
  end
37
37
  end
@@ -101,19 +101,19 @@ describe GitHelper::GitHubPullRequest do
101
101
 
102
102
  it 'should call the CLI to ask about a single template' do
103
103
  allow(subject).to receive(:pr_template_options).and_return([template])
104
- expect(highline_cli).to receive(:apply_template?).and_return(true)
104
+ expect(highline_cli).to receive(:ask_yes_no).and_return(true)
105
105
  subject.send(:template_name_to_apply)
106
106
  end
107
107
 
108
108
  it 'should return the single template if the user says yes' do
109
109
  allow(subject).to receive(:pr_template_options).and_return([template])
110
- allow(highline_cli).to receive(:apply_template?).and_return(true)
110
+ allow(highline_cli).to receive(:ask_yes_no).and_return(true)
111
111
  expect(subject.send(:template_name_to_apply)).to eq(template)
112
112
  end
113
113
 
114
114
  it 'should return nil if the user says no' do
115
115
  allow(subject).to receive(:pr_template_options).and_return([template])
116
- allow(highline_cli).to receive(:apply_template?).and_return(false)
116
+ allow(highline_cli).to receive(:ask_yes_no).and_return(false)
117
117
  expect(subject.send(:template_name_to_apply)).to eq(nil)
118
118
  end
119
119
  end
@@ -124,19 +124,19 @@ describe GitHelper::GitHubPullRequest do
124
124
 
125
125
  it 'should call the CLI to ask which of multiple templates to apply' do
126
126
  allow(subject).to receive(:pr_template_options).and_return([template1, template2])
127
- expect(highline_cli).to receive(:template_to_apply).and_return(template1)
127
+ expect(highline_cli).to receive(:ask_options).and_return(template1)
128
128
  subject.send(:template_name_to_apply)
129
129
  end
130
130
 
131
131
  it 'should return the answer template if the user says yes' do
132
132
  allow(subject).to receive(:pr_template_options).and_return([template1, template2])
133
- allow(highline_cli).to receive(:template_to_apply).and_return(template1)
133
+ allow(highline_cli).to receive(:ask_options).and_return(template1)
134
134
  expect(subject.send(:template_name_to_apply)).to eq(template1)
135
135
  end
136
136
 
137
137
  it 'should return nil if the user says no' do
138
138
  allow(subject).to receive(:pr_template_options).and_return([template1, template2])
139
- allow(highline_cli).to receive(:template_to_apply).and_return('None')
139
+ allow(highline_cli).to receive(:ask_options).and_return('None')
140
140
  expect(subject.send(:template_name_to_apply)).to eq(nil)
141
141
  end
142
142
  end
@@ -151,13 +151,13 @@ describe GitHelper::GitHubPullRequest do
151
151
 
152
152
  describe '#pr_id' do
153
153
  it 'should ask the CLI for the code request ID' do
154
- expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
154
+ expect(highline_cli).to receive(:ask).and_return(Faker::Number.number)
155
155
  subject.send(:pr_id)
156
156
  end
157
157
 
158
158
  it 'should equal an integer' do
159
159
  pr_id = Faker::Number.number
160
- expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
160
+ expect(highline_cli).to receive(:ask).and_return(pr_id)
161
161
  expect(subject.send(:pr_id)).to eq(pr_id)
162
162
  end
163
163
  end
@@ -167,16 +167,16 @@ describe GitHelper::GitHubPullRequest do
167
167
 
168
168
  before do
169
169
  allow(subject).to receive(:existing_project).and_return(project)
170
- allow(highline_cli).to receive(:merge_method)
170
+ allow(highline_cli).to receive(:ask_options)
171
171
  end
172
172
 
173
173
  it 'should ask the CLI for the merge_method' do
174
- expect(highline_cli).to receive(:merge_method).and_return('merge')
174
+ expect(highline_cli).to receive(:ask_options).and_return('merge')
175
175
  subject.send(:merge_method)
176
176
  end
177
177
 
178
178
  it 'should be a string' do
179
- allow(highline_cli).to receive(:merge_method).and_return('merge')
179
+ allow(highline_cli).to receive(:ask_options).and_return('merge')
180
180
  expect(subject.send(:merge_method)).to be_a(String)
181
181
  end
182
182
 
@@ -239,7 +239,7 @@ describe GitHelper::GitHubPullRequest do
239
239
 
240
240
  describe '#existing_pr' do
241
241
  it 'should call the octokit client' do
242
- allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
242
+ allow(highline_cli).to receive(:ask).and_return(Faker::Number.number)
243
243
  expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
244
244
  subject.send(:existing_pr)
245
245
  end
@@ -0,0 +1,175 @@
1
+ require 'spec_helper'
2
+ require 'git_helper'
3
+
4
+ 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
+
8
+ before do
9
+ allow(GitHelper::HighlineCli).to receive(:new).and_return(highline_cli)
10
+ allow(subject).to receive(:puts)
11
+ end
12
+
13
+ after do
14
+ GitHelper::Setup.instance_variable_set("@highline", nil)
15
+ end
16
+
17
+ describe '#execute' do
18
+ it 'should ask a question if the config file exists' do
19
+ allow(File).to receive(:exists?).and_return(true)
20
+ expect(highline_cli).to receive(:ask_yes_no).and_return(true)
21
+ allow(subject).to receive(:create_or_update_config_file).and_return(true)
22
+ allow(subject).to receive(:create_or_update_plugin_files)
23
+ subject.execute
24
+ end
25
+
26
+ it 'should call to create or update the config file' do
27
+ allow(File).to receive(:exists?).and_return(true)
28
+ allow(highline_cli).to receive(:ask_yes_no).and_return(true)
29
+ expect(subject).to receive(:create_or_update_config_file).and_return(true)
30
+ allow(subject).to receive(:create_or_update_plugin_files)
31
+ subject.execute
32
+ end
33
+
34
+ it 'should skip if the user opts not to continue' do
35
+ allow(File).to receive(:exists?).and_return(true)
36
+ allow(highline_cli).to receive(:ask_yes_no).and_return(false)
37
+ expect(subject).not_to receive(:create_or_update_config_file)
38
+ expect(subject).not_to receive(:create_or_update_plugin_files)
39
+ subject.execute
40
+ end
41
+ end
42
+
43
+ describe '#create_or_update_config_file' do
44
+ it 'should generate the file based on the answers to the questions' do
45
+ expect(subject).to receive(:generate_file_contents)
46
+ allow(File).to receive(:open).and_return(nil)
47
+ subject.send(:create_or_update_config_file)
48
+ end
49
+
50
+ it 'should open the file for writing' do
51
+ allow(subject).to receive(:generate_file_contents)
52
+ expect(File).to receive(:open).and_return(nil)
53
+ subject.send(:create_or_update_config_file)
54
+ end
55
+ end
56
+
57
+ describe '#config_file_exists?' do
58
+ it 'should return true if the file exists' do
59
+ allow(File).to receive(:exists?).and_return(true)
60
+ expect(subject.send(:config_file_exists?)).to eq(true)
61
+ end
62
+
63
+ it 'should return false if the file does not exist' do
64
+ allow(File).to receive(:exists?).and_return(false)
65
+ expect(subject.send(:config_file_exists?)).to eq(false)
66
+ end
67
+ end
68
+
69
+ describe '#ask_question' do
70
+ 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
78
+ subject.send(:ask_question, Faker::Lorem.sentence)
79
+ end
80
+
81
+ it 'should return the answer if it is given' do
82
+ answer = Faker::Lorem.sentence
83
+ allow(highline_cli).to receive(:ask).and_return(answer)
84
+ expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
85
+ end
86
+ end
87
+
88
+ describe '#generate_file_contents' do
89
+ it 'should ask two yes/no questions' do
90
+ expect(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(false)
91
+ subject.send(:generate_file_contents)
92
+ end
93
+
94
+ 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)
96
+ expect(subject).to receive(:ask_question).exactly(2).times.and_return(Faker::Lorem.word)
97
+ subject.send(:generate_file_contents)
98
+ end
99
+
100
+ 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)
102
+ expect(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
103
+ subject.send(:generate_file_contents)
104
+ end
105
+
106
+ it 'should return a string no matter what' do
107
+ allow(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(true)
108
+ allow(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
109
+ expect(subject.send(:generate_file_contents)).to be_a(String)
110
+ end
111
+ end
112
+
113
+ describe '#create_or_update_plugin_files' do
114
+ let(:plugins) do
115
+ [
116
+ {
117
+ 'name': 'plugin-file-one'
118
+ },
119
+ {
120
+ 'name': 'plugin-file-two'
121
+ }
122
+ ]
123
+ end
124
+
125
+ let(:plugins_json) do
126
+ "[
127
+ {
128
+ \"name\": \"plugin-file-one\"
129
+ },
130
+ {
131
+ \"name\": \"plugin-file-two\"
132
+ }
133
+ ]"
134
+ end
135
+
136
+ before do
137
+ allow_any_instance_of(GitHelper::GitConfigReader).to receive(:github_token).and_return(Faker::Internet.password)
138
+ allow_any_instance_of(GitHelper::GitConfigReader).to receive(:github_user).and_return(Faker::Internet.username)
139
+ end
140
+
141
+ it 'should create the directory if it does not exist' do
142
+ allow(File).to receive(:exists?).and_return(false)
143
+ allow(File).to receive(:open).and_return(nil)
144
+ expect(Dir).to receive(:mkdir)
145
+ allow(subject).to receive(:`).and_return(plugins_json)
146
+ allow(JSON).to receive(:parse).and_return(plugins)
147
+ subject.send(:create_or_update_plugin_files)
148
+ end
149
+
150
+ it 'should not create the directory if it already exists' do
151
+ allow(File).to receive(:exists?).and_return(true)
152
+ allow(File).to receive(:open).and_return(nil)
153
+ expect(Dir).not_to receive(:mkdir)
154
+ allow(subject).to receive(:`).and_return(plugins_json)
155
+ allow(JSON).to receive(:parse).and_return(plugins)
156
+ subject.send(:create_or_update_plugin_files)
157
+ end
158
+
159
+ it 'should curl the GitHub API' do
160
+ allow(File).to receive(:exists?).and_return(true)
161
+ allow(File).to receive(:open).and_return(nil)
162
+ allow(subject).to receive(:`).and_return(plugins_json)
163
+ expect(JSON).to receive(:parse).with(plugins_json).and_return(plugins)
164
+ subject.send(:create_or_update_plugin_files)
165
+ end
166
+
167
+ it 'should go through the loop for each plugin' do
168
+ allow(File).to receive(:exists?).and_return(true)
169
+ allow(File).to receive(:open).and_return(nil)
170
+ expect(subject).to receive(:`).exactly(3).times
171
+ allow(JSON).to receive(:parse).and_return(plugins)
172
+ subject.send(:create_or_update_plugin_files)
173
+ end
174
+ end
175
+ end
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.1.3
4
+ version: 3.3.1
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-12-10 00:00:00.000000000 Z
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: faker
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '2.15'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '2.15'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -139,7 +139,6 @@ dependencies:
139
139
  description: A set of GitHub and GitLab workflow scripts to provide a smoother development
140
140
  process for your git projects.
141
141
  email:
142
- - emma.sax4@gmail.com
143
142
  executables:
144
143
  - git-helper
145
144
  extensions: []
@@ -167,6 +166,7 @@ files:
167
166
  - lib/git_helper/new_branch.rb
168
167
  - lib/git_helper/octokit_client.rb
169
168
  - lib/git_helper/pull_request.rb
169
+ - lib/git_helper/setup.rb
170
170
  - lib/git_helper/version.rb
171
171
  - plugins.zip
172
172
  - spec/git_helper/change_remote_spec.rb
@@ -183,8 +183,9 @@ files:
183
183
  - spec/git_helper/new_branch_spec.rb
184
184
  - spec/git_helper/octokit_client_spec.rb
185
185
  - spec/git_helper/pull_request_spec.rb
186
+ - spec/git_helper/setup_spec.rb
186
187
  - spec/spec_helper.rb
187
- homepage: https://github.com/emmasax4/git_helper
188
+ homepage: https://github.com/emmahsax/git_helper
188
189
  licenses:
189
190
  - MIT
190
191
  metadata: {}
@@ -203,23 +204,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
204
  - !ruby/object:Gem::Version
204
205
  version: '0'
205
206
  requirements: []
206
- rubygems_version: 3.1.4
207
+ rubygems_version: 3.2.3
207
208
  signing_key:
208
209
  specification_version: 4
209
210
  summary: A set of GitHub and GitLab workflow scripts.
210
211
  test_files:
211
212
  - spec/spec_helper.rb
212
- - spec/git_helper/octokit_client_spec.rb
213
- - spec/git_helper/new_branch_spec.rb
214
- - spec/git_helper/forget_local_commits_spec.rb
215
- - spec/git_helper/clean_branches_spec.rb
216
213
  - spec/git_helper/change_remote_spec.rb
217
214
  - spec/git_helper/checkout_default_spec.rb
218
- - spec/git_helper/pull_request_spec.rb
219
- - spec/git_helper/gitlab_client_spec.rb
215
+ - spec/git_helper/clean_branches_spec.rb
220
216
  - spec/git_helper/code_request_spec.rb
221
217
  - spec/git_helper/empty_commit_spec.rb
222
- - spec/git_helper/highline_cli_spec.rb
218
+ - spec/git_helper/forget_local_commits_spec.rb
223
219
  - spec/git_helper/git_config_reader_spec.rb
224
- - spec/git_helper/merge_request_spec.rb
220
+ - spec/git_helper/gitlab_client_spec.rb
221
+ - spec/git_helper/highline_cli_spec.rb
225
222
  - spec/git_helper/local_code_spec.rb
223
+ - spec/git_helper/merge_request_spec.rb
224
+ - spec/git_helper/new_branch_spec.rb
225
+ - spec/git_helper/octokit_client_spec.rb
226
+ - spec/git_helper/pull_request_spec.rb
227
+ - spec/git_helper/setup_spec.rb