git_helper 3.6.1 → 3.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,255 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'git_helper'
5
-
6
- describe GitHelper::GitHubPullRequest do
7
- let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
8
- let(:highline_wrapper) { double(:highline_wrapper) }
9
- let(:github_client) { double(:github_client) }
10
-
11
- let(:options) do
12
- {
13
- local_project: Faker::Lorem.word,
14
- local_branch: Faker::Lorem.word,
15
- local_code: local_code,
16
- highline: highline_wrapper
17
- }
18
- end
19
-
20
- subject { GitHelper::GitHubPullRequest.new(options) }
21
-
22
- before do
23
- allow(GitHelper::GitHubClient).to receive(:new).and_return(github_client)
24
- allow(subject).to receive(:puts)
25
- end
26
-
27
- describe '#create' do
28
- it 'should call the GitHub client to create' do
29
- allow(subject).to receive(:new_pr_body).and_return('')
30
- expect(github_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
31
- subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
32
- end
33
-
34
- it 'should call various other methods' do
35
- expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
36
- allow(github_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
37
- subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
38
- end
39
-
40
- it 'should catch the raised error if the creation does not work' do
41
- allow(subject).to receive(:new_pr_body).and_return('')
42
- allow(github_client).to receive(:create_pull_request).and_raise(StandardError)
43
- expect(subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })).to eq(nil)
44
- end
45
- end
46
-
47
- describe '#merge' do
48
- it 'should call the GitHub client to merge' do
49
- allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
50
- allow(subject).to receive(:merge_method).and_return('rebase')
51
- allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
52
- expect(github_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
53
- subject.merge
54
- end
55
-
56
- it 'should call various other methods' do
57
- expect(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word)).at_least(:once)
58
- expect(subject).to receive(:merge_method).and_return('rebase').at_least(:once)
59
- expect(subject).to receive(:pr_id).and_return(Faker::Number.number).at_least(:once)
60
- allow(github_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
61
- subject.merge
62
- end
63
-
64
- it 'should catch the raised error if the merge does not work' do
65
- allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
66
- allow(subject).to receive(:merge_method).and_return('rebase')
67
- allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
68
- allow(github_client).to receive(:merge_pull_request).and_raise(StandardError)
69
- expect(subject.merge).to eq(nil)
70
- end
71
- end
72
-
73
- describe '#new_pr_body' do
74
- it 'should call the local code if the template to apply exists' do
75
- allow(subject).to receive(:template_name_to_apply).and_return('')
76
- expect(local_code).to receive(:read_template)
77
- subject.send(:new_pr_body)
78
- end
79
-
80
- it 'should not call the local code if the template is nil' do
81
- allow(subject).to receive(:template_name_to_apply).and_return(nil)
82
- expect(local_code).not_to receive(:read_template)
83
- subject.send(:new_pr_body)
84
- end
85
-
86
- it 'should return an empty string if the template is nil' do
87
- allow(subject).to receive(:template_name_to_apply).and_return(nil)
88
- expect(subject.send(:new_pr_body)).to eq('')
89
- end
90
- end
91
-
92
- describe '#template_name_to_apply' do
93
- context 'if PR template options are empty' do
94
- it 'should return nil' do
95
- allow(subject).to receive(:pr_template_options).and_return([])
96
- expect(subject.send(:template_name_to_apply)).to eq(nil)
97
- end
98
- end
99
-
100
- context 'if there is one template option' do
101
- let(:template) { Faker::Lorem.word }
102
-
103
- it 'should call the CLI to ask about a single template' do
104
- allow(subject).to receive(:pr_template_options).and_return([template])
105
- expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
106
- subject.send(:template_name_to_apply)
107
- end
108
-
109
- it 'should return the single template if the user says yes' do
110
- allow(subject).to receive(:pr_template_options).and_return([template])
111
- allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
112
- expect(subject.send(:template_name_to_apply)).to eq(template)
113
- end
114
-
115
- it 'should return nil if the user says no' do
116
- allow(subject).to receive(:pr_template_options).and_return([template])
117
- allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
118
- expect(subject.send(:template_name_to_apply)).to eq(nil)
119
- end
120
- end
121
-
122
- context 'if there are multiple template options' do
123
- let(:template1) { Faker::Lorem.word }
124
- let(:template2) { Faker::Lorem.word }
125
-
126
- it 'should call the CLI to ask which of multiple templates to apply' do
127
- allow(subject).to receive(:pr_template_options).and_return([template1, template2])
128
- expect(highline_wrapper).to receive(:ask_options).and_return(template1)
129
- subject.send(:template_name_to_apply)
130
- end
131
-
132
- it 'should return the answer template if the user says yes' do
133
- allow(subject).to receive(:pr_template_options).and_return([template1, template2])
134
- allow(highline_wrapper).to receive(:ask_options).and_return(template1)
135
- expect(subject.send(:template_name_to_apply)).to eq(template1)
136
- end
137
-
138
- it 'should return nil if the user says no' do
139
- allow(subject).to receive(:pr_template_options).and_return([template1, template2])
140
- allow(highline_wrapper).to receive(:ask_options).and_return('None')
141
- expect(subject.send(:template_name_to_apply)).to eq(nil)
142
- end
143
- end
144
- end
145
-
146
- describe '#pr_template_options' do
147
- it 'should call the local code' do
148
- expect(local_code).to receive(:template_options)
149
- subject.send(:pr_template_options)
150
- end
151
- end
152
-
153
- describe '#pr_id' do
154
- it 'should ask the CLI for the code request ID' do
155
- expect(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
156
- subject.send(:pr_id)
157
- end
158
-
159
- it 'should equal an integer' do
160
- pr_id = Faker::Number.number
161
- expect(highline_wrapper).to receive(:ask).and_return(pr_id)
162
- expect(subject.send(:pr_id)).to eq(pr_id)
163
- end
164
- end
165
-
166
- describe '#merge_method' do
167
- let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: true, allow_rebase_merge: true) }
168
-
169
- before do
170
- allow(subject).to receive(:existing_project).and_return(project)
171
- allow(highline_wrapper).to receive(:ask_options)
172
- end
173
-
174
- it 'should ask the CLI for the merge_method' do
175
- expect(highline_wrapper).to receive(:ask_options).and_return('merge')
176
- subject.send(:merge_method)
177
- end
178
-
179
- it 'should be a string' do
180
- allow(highline_wrapper).to receive(:ask_options).and_return('merge')
181
- expect(subject.send(:merge_method)).to be_a(String)
182
- end
183
-
184
- context 'if theres only one item' do
185
- let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
186
-
187
- it 'should not ask the CLI anything' do
188
- expect(highline_wrapper).not_to receive(:merge_method)
189
- subject.send(:merge_method)
190
- end
191
- end
192
- end
193
-
194
- describe '#merge_options' do
195
- let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: true, allow_rebase_merge: true) }
196
-
197
- before do
198
- allow(subject).to receive(:existing_project).and_return(project)
199
- end
200
-
201
- it 'should return an array' do
202
- expect(subject.send(:merge_options)).to be_a(Array)
203
- end
204
-
205
- it 'should have three items' do
206
- expect(subject.send(:merge_options).length).to eq(3)
207
- end
208
-
209
- context 'when two options are present' do
210
- let(:project) { double(:project, allow_merge_commit: false, allow_squash_merge: true, allow_rebase_merge: true) }
211
-
212
- it 'should have two items' do
213
- expect(subject.send(:merge_options).length).to eq(2)
214
- end
215
- end
216
-
217
- context 'when one option is present' do
218
- let(:project) { double(:project, allow_merge_commit: false, allow_squash_merge: false, allow_rebase_merge: true) }
219
-
220
- it 'should have one item' do
221
- expect(subject.send(:merge_options).length).to eq(1)
222
- end
223
- end
224
-
225
- context 'when no options are present' do
226
- let(:project) { double(:project, allow_merge_commit: false, allow_squash_merge: false, allow_rebase_merge: false) }
227
-
228
- it 'should have no items' do
229
- expect(subject.send(:merge_options).length).to eq(0)
230
- end
231
- end
232
- end
233
-
234
- describe '#existing_project' do
235
- it 'should call the GitHub client' do
236
- expect(github_client).to receive(:repository).and_return(:repository)
237
- subject.send(:existing_project)
238
- end
239
- end
240
-
241
- describe '#existing_pr' do
242
- it 'should call the GitHub client' do
243
- allow(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
244
- expect(github_client).to receive(:pull_request).and_return(:pull_request)
245
- subject.send(:existing_pr)
246
- end
247
- end
248
-
249
- describe '#github_client' do
250
- it 'should call the GitHub client' do
251
- expect(GitHelper::GitHubClient).to receive(:new).and_return(github_client)
252
- subject.send(:github_client)
253
- end
254
- end
255
- end
@@ -1,183 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'git_helper'
5
-
6
- describe GitHelper::Setup do
7
- let(:highline_wrapper) { double(:highline_wrapper, ask: Faker::Lorem.word, ask_yes_no: true) }
8
-
9
- before do
10
- allow(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
11
- allow(subject).to receive(:puts)
12
- end
13
-
14
- after do
15
- GitHelper::Setup.instance_variable_set('@highline', nil)
16
- end
17
-
18
- describe '#execute' 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)
30
- allow(File).to receive(:exists?).and_return(true)
31
- expect(highline_wrapper).to receive(:ask_yes_no).and_return(true).at_least(:twice)
32
- allow(subject).to receive(:create_or_update_config_file).and_return(true)
33
- allow(subject).to receive(:create_or_update_plugin_files)
34
- subject.execute
35
- end
36
-
37
- it 'should call to create or update the config file' do
38
- allow(File).to receive(:exists?).and_return(true)
39
- allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
40
- expect(subject).to receive(:create_or_update_config_file).and_return(true)
41
- allow(subject).to receive(:create_or_update_plugin_files)
42
- subject.execute
43
- end
44
-
45
- it 'should skip if the user opts not to continue' do
46
- allow(File).to receive(:exists?).and_return(true)
47
- allow(subject).to receive(:config_file_exists?).and_return(true)
48
- allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
49
- expect(subject).not_to receive(:create_or_update_config_file)
50
- expect(subject).not_to receive(:create_or_update_plugin_files)
51
- subject.execute
52
- end
53
- end
54
-
55
- describe '#create_or_update_config_file' do
56
- it 'should generate the file based on the answers to the questions' do
57
- expect(subject).to receive(:generate_file_contents)
58
- allow(File).to receive(:open).and_return(nil)
59
- subject.send(:create_or_update_config_file)
60
- end
61
-
62
- it 'should open the file for writing' do
63
- allow(subject).to receive(:generate_file_contents)
64
- expect(File).to receive(:open).and_return(nil)
65
- subject.send(:create_or_update_config_file)
66
- end
67
- end
68
-
69
- describe '#config_file_exists?' do
70
- it 'should return true if the file exists' do
71
- allow(File).to receive(:exist?).and_return(true)
72
- expect(subject.send(:config_file_exists?)).to eq(true)
73
- end
74
-
75
- it 'should return false if the file does not exist' do
76
- allow(File).to receive(:exist?).and_return(false)
77
- expect(subject.send(:config_file_exists?)).to eq(false)
78
- end
79
- end
80
-
81
- describe '#ask_question' do
82
- it 'should use highline to ask a question' do
83
- expect(highline_wrapper).to receive(:ask).and_return(Faker::Lorem.word)
84
- subject.send(:ask_question, Faker::Lorem.sentence)
85
- end
86
-
87
- it 'should return the answer if it is given' do
88
- answer = Faker::Lorem.sentence
89
- allow(highline_wrapper).to receive(:ask).and_return(answer)
90
- expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
91
- end
92
- end
93
-
94
- describe '#generate_file_contents' do
95
- it 'should ask two yes/no questions' do
96
- expect(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(false)
97
- subject.send(:generate_file_contents)
98
- end
99
-
100
- it 'should ask two additional questions for each time the user says yes' do
101
- allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true, false)
102
- expect(subject).to receive(:ask_question).exactly(2).times.and_return(Faker::Lorem.word)
103
- subject.send(:generate_file_contents)
104
- end
105
-
106
- it 'should ask four additional questions for each time the user says yes' do
107
- allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true)
108
- expect(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
109
- subject.send(:generate_file_contents)
110
- end
111
-
112
- it 'should return a string no matter what' do
113
- allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true)
114
- allow(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
115
- expect(subject.send(:generate_file_contents)).to be_a(String)
116
- end
117
- end
118
-
119
- describe '#create_or_update_plugin_files' do
120
- let(:plugins) do
121
- [
122
- {
123
- name: 'plugin-file-one'
124
- },
125
- {
126
- name: 'plugin-file-two'
127
- }
128
- ]
129
- end
130
-
131
- let(:plugins_json) do
132
- "[
133
- {
134
- \"name\": \"plugin-file-one\"
135
- },
136
- {
137
- \"name\": \"plugin-file-two\"
138
- }
139
- ]"
140
- end
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
-
147
- it 'should create the directory if it does not exist' do
148
- allow(File).to receive(:exist?).and_return(false)
149
- allow(File).to receive(:open).and_return(nil)
150
- expect(Dir).to receive(:mkdir)
151
- allow(subject).to receive(:`).and_return(plugins_json)
152
- allow(JSON).to receive(:parse).and_return(plugins)
153
- subject.send(:create_or_update_plugin_files)
154
- end
155
-
156
- it 'should not create the directory if it already exists' do
157
- allow(File).to receive(:exist?).and_return(true)
158
- allow(File).to receive(:open).and_return(nil)
159
- expect(Dir).not_to receive(:mkdir)
160
- allow(subject).to receive(:`).and_return(plugins_json)
161
- allow(JSON).to receive(:parse).and_return(plugins)
162
- subject.send(:create_or_update_plugin_files)
163
- end
164
-
165
- it 'should curl the GitHub API' do
166
- allow(Dir).to receive(:mkdir).and_return(true)
167
- allow(File).to receive(:exists?).and_return(true)
168
- allow(File).to receive(:open).and_return(nil)
169
- allow(subject).to receive(:`).and_return(plugins_json)
170
- expect(JSON).to receive(:parse).with(plugins_json).and_return(plugins)
171
- subject.send(:create_or_update_plugin_files)
172
- end
173
-
174
- it 'should go through the loop for each plugin' do
175
- allow(Dir).to receive(:mkdir).and_return(true)
176
- allow(File).to receive(:exists?).and_return(true)
177
- allow(File).to receive(:open).and_return(nil)
178
- expect(subject).to receive(:`).exactly(3).times
179
- allow(JSON).to receive(:parse).and_return(plugins)
180
- subject.send(:create_or_update_plugin_files)
181
- end
182
- end
183
- end
data/spec/spec_helper.rb DELETED
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'faker'
4
- require 'pry'
5
-
6
- # This file was generated by the `rspec --init` command. Conventionally, all
7
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
- # The generated `.rspec` file contains `--require spec_helper` which will cause
9
- # this file to always be loaded, without a need to explicitly require it in any
10
- # files.
11
- #
12
- # Given that it is always loaded, you are encouraged to keep this file as
13
- # light-weight as possible. Requiring heavyweight dependencies from this file
14
- # will add to the boot time of your test suite on EVERY test run, even for an
15
- # individual file that may not need all of that loaded. Instead, consider making
16
- # a separate helper file that requires the additional dependencies and performs
17
- # the additional setup, and require it from the spec files that actually need
18
- # it.
19
- #
20
- # The `.rspec` file also contains a few flags that are not defaults but that
21
- # users commonly want.
22
- #
23
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
- RSpec.configure do |config|
25
- # rspec-expectations config goes here. You can use an alternate
26
- # assertion/expectation library such as wrong or the stdlib/minitest
27
- # assertions if you prefer.
28
- config.expect_with :rspec do |expectations|
29
- # This option will default to `true` in RSpec 4. It makes the `description`
30
- # and `failure_message` of custom matchers include text for helper methods
31
- # defined using `chain`, e.g.:
32
- # be_bigger_than(2).and_smaller_than(4).description
33
- # # => "be bigger than 2 and smaller than 4"
34
- # ...rather than:
35
- # # => "be bigger than 2"
36
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
37
- end
38
-
39
- config.filter_run focus: true
40
- config.run_all_when_everything_filtered = true
41
-
42
- # rspec-mocks config goes here. You can use an alternate test double
43
- # library (such as bogus or mocha) by changing the `mock_with` option here.
44
- config.mock_with :rspec do |mocks|
45
- # Prevents you from mocking or stubbing a method that does not exist on
46
- # a real object. This is generally recommended, and will default to
47
- # `true` in RSpec 4.
48
- mocks.verify_partial_doubles = true
49
- end
50
- end