livebuzz-gitx 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +31 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +84 -0
- data/Rakefile +5 -0
- data/bin/git-buildtag +6 -0
- data/bin/git-cleanup +7 -0
- data/bin/git-integrate +6 -0
- data/bin/git-nuke +6 -0
- data/bin/git-release +6 -0
- data/bin/git-review +6 -0
- data/bin/git-reviewrequest +8 -0
- data/bin/git-share +6 -0
- data/bin/git-start +6 -0
- data/bin/git-track +6 -0
- data/bin/git-update +6 -0
- data/lib/livebuzz/gitx/cli/base_command.rb +58 -0
- data/lib/livebuzz/gitx/cli/buildtag_command.rb +41 -0
- data/lib/livebuzz/gitx/cli/cleanup_command.rb +47 -0
- data/lib/livebuzz/gitx/cli/integrate_command.rb +95 -0
- data/lib/livebuzz/gitx/cli/nuke_command.rb +64 -0
- data/lib/livebuzz/gitx/cli/release_command.rb +41 -0
- data/lib/livebuzz/gitx/cli/review_command.rb +101 -0
- data/lib/livebuzz/gitx/cli/share_command.rb +17 -0
- data/lib/livebuzz/gitx/cli/start_command.rb +39 -0
- data/lib/livebuzz/gitx/cli/track_command.rb +16 -0
- data/lib/livebuzz/gitx/cli/update_command.rb +37 -0
- data/lib/livebuzz/gitx/configuration.rb +47 -0
- data/lib/livebuzz/gitx/extensions/string.rb +12 -0
- data/lib/livebuzz/gitx/extensions/thor.rb +39 -0
- data/lib/livebuzz/gitx/github.rb +177 -0
- data/lib/livebuzz/gitx/version.rb +5 -0
- data/lib/livebuzz/gitx.rb +10 -0
- data/livebuzz-gitx.gemspec +37 -0
- data/spec/fixtures/vcr_cassettes/pull_request_does_exist_with_failure_status.yml +135 -0
- data/spec/fixtures/vcr_cassettes/pull_request_does_exist_with_success_status.yml +149 -0
- data/spec/fixtures/vcr_cassettes/pull_request_does_not_exist.yml +133 -0
- data/spec/livebuzz/gitx/cli/base_command_spec.rb +41 -0
- data/spec/livebuzz/gitx/cli/buildtag_command_spec.rb +70 -0
- data/spec/livebuzz/gitx/cli/cleanup_command_spec.rb +37 -0
- data/spec/livebuzz/gitx/cli/integrate_command_spec.rb +272 -0
- data/spec/livebuzz/gitx/cli/nuke_command_spec.rb +165 -0
- data/spec/livebuzz/gitx/cli/release_command_spec.rb +148 -0
- data/spec/livebuzz/gitx/cli/review_command_spec.rb +307 -0
- data/spec/livebuzz/gitx/cli/share_command_spec.rb +32 -0
- data/spec/livebuzz/gitx/cli/start_command_spec.rb +96 -0
- data/spec/livebuzz/gitx/cli/track_command_spec.rb +31 -0
- data/spec/livebuzz/gitx/cli/update_command_spec.rb +79 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/support/global_config.rb +24 -0
- data/spec/support/home_env.rb +11 -0
- data/spec/support/matchers/meet_expectations_matcher.rb +7 -0
- data/spec/support/pry.rb +1 -0
- data/spec/support/stub_execution.rb +14 -0
- data/spec/support/timecop.rb +9 -0
- data/spec/support/vcr.rb +6 -0
- data/spec/support/webmock.rb +1 -0
- metadata +350 -0
@@ -0,0 +1,307 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'livebuzz/gitx/cli/review_command'
|
3
|
+
|
4
|
+
describe LiveBuzz::Gitx::Cli::ReviewCommand do
|
5
|
+
let(:args) { [] }
|
6
|
+
let(:options) { {} }
|
7
|
+
let(:config) do
|
8
|
+
{
|
9
|
+
pretend: true
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:cli) { described_class.new(args, options, config) }
|
13
|
+
let(:repo) { double('fake repo', config: repo_config) }
|
14
|
+
let(:repo_config) do
|
15
|
+
{
|
16
|
+
'remote.origin.url' => 'https://github.com/livebuzzevents/livebuzz-gitx'
|
17
|
+
}
|
18
|
+
end
|
19
|
+
let(:branch) { double('fake branch', name: 'feature-branch') }
|
20
|
+
|
21
|
+
before do
|
22
|
+
allow(cli).to receive(:repo).and_return(repo)
|
23
|
+
allow(cli).to receive(:current_branch).and_return(branch)
|
24
|
+
allow(cli).to receive(:ask_editor).and_return('description')
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#review' do
|
28
|
+
context 'when pull request does not exist' do
|
29
|
+
let(:authorization_token) { '123123' }
|
30
|
+
let(:changelog) { '* made some fixes' }
|
31
|
+
let(:fake_update_command) { double('fake update command', update: nil) }
|
32
|
+
let(:new_pull_request) do
|
33
|
+
{
|
34
|
+
html_url: "https://path/to/html/pull/request",
|
35
|
+
issue_url: "https://api/path/to/issue/url",
|
36
|
+
number: 10,
|
37
|
+
head: {
|
38
|
+
ref: "branch_name"
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
before do
|
43
|
+
expect(LiveBuzz::Gitx::Cli::UpdateCommand).to receive(:new).and_return(fake_update_command)
|
44
|
+
|
45
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
46
|
+
expect(cli).to receive(:run_cmd).with("git log master...feature-branch --reverse --no-merges --pretty=format:'* %s%n%b'").and_return("* old commit\n\n* new commit").ordered
|
47
|
+
expect(cli).to receive(:ask_editor).with("### Changelog\n* old commit\n\n* new commit\n#{LiveBuzz::Gitx::Github::PULL_REQUEST_FOOTER}", anything).and_return('description')
|
48
|
+
|
49
|
+
stub_request(:post, 'https://api.github.com/repos/livebuzzevents/livebuzz-gitx/pulls').to_return(:status => 201, :body => new_pull_request.to_json, :headers => {'Content-Type' => 'application/json'})
|
50
|
+
|
51
|
+
VCR.use_cassette('pull_request_does_not_exist') do
|
52
|
+
cli.review
|
53
|
+
end
|
54
|
+
end
|
55
|
+
it 'creates github pull request' do
|
56
|
+
should meet_expectations
|
57
|
+
end
|
58
|
+
it 'runs expected commands' do
|
59
|
+
should meet_expectations
|
60
|
+
end
|
61
|
+
end
|
62
|
+
context 'when authorization_token is missing' do
|
63
|
+
let(:authorization_token) { nil }
|
64
|
+
it do
|
65
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
66
|
+
expect { cli.review }.to raise_error(/token not found/)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
context 'when pull request already exists' do
|
70
|
+
let(:authorization_token) { '123123' }
|
71
|
+
before do
|
72
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
73
|
+
expect(cli).to_not receive(:create_pull_request)
|
74
|
+
|
75
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
76
|
+
cli.review
|
77
|
+
end
|
78
|
+
end
|
79
|
+
it 'does not create new pull request' do
|
80
|
+
should meet_expectations
|
81
|
+
end
|
82
|
+
end
|
83
|
+
context 'when --assignee option passed' do
|
84
|
+
let(:options) do
|
85
|
+
{
|
86
|
+
assignee: 'johndoe'
|
87
|
+
}
|
88
|
+
end
|
89
|
+
let(:authorization_token) { '123123' }
|
90
|
+
before do
|
91
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
92
|
+
|
93
|
+
stub_request(:patch, /.*api.github.com.*/).to_return(:status => 200)
|
94
|
+
|
95
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
96
|
+
cli.review
|
97
|
+
end
|
98
|
+
end
|
99
|
+
it 'updates github pull request' do
|
100
|
+
expect(WebMock).to have_requested(:patch, "https://api.github.com/repos/livebuzzevents/livebuzz-gitx/issues/10")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
context 'when --open flag passed' do
|
104
|
+
let(:options) do
|
105
|
+
{
|
106
|
+
open: true
|
107
|
+
}
|
108
|
+
end
|
109
|
+
let(:authorization_token) { '123123' }
|
110
|
+
before do
|
111
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
112
|
+
expect(cli).to receive(:run_cmd).with("open https://path/to/html/pull/request").ordered
|
113
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
114
|
+
cli.review
|
115
|
+
end
|
116
|
+
end
|
117
|
+
it 'runs open command with pull request url' do
|
118
|
+
should meet_expectations
|
119
|
+
end
|
120
|
+
end
|
121
|
+
context 'when --bump flag is passed' do
|
122
|
+
let(:options) do
|
123
|
+
{
|
124
|
+
bump: true
|
125
|
+
}
|
126
|
+
end
|
127
|
+
let(:authorization_token) { '123123' }
|
128
|
+
let(:reference) { double('fake reference', target_id: 'e12da4') }
|
129
|
+
before do
|
130
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
131
|
+
expect(cli).to receive(:ask_editor).and_return('comment description')
|
132
|
+
allow(repo).to receive(:head).and_return(reference)
|
133
|
+
stub_request(:post, /.*api.github.com.*/).to_return(:status => 201)
|
134
|
+
|
135
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
136
|
+
cli.review
|
137
|
+
end
|
138
|
+
end
|
139
|
+
it 'posts comment to github' do
|
140
|
+
expect(WebMock).to have_requested(:post, "https://api.github.com/repos/livebuzzevents/livebuzz-gitx/issues/10/comments").
|
141
|
+
with(body: {body: "[gitx] review bump :tada:\n\ncomment description"})
|
142
|
+
end
|
143
|
+
it 'creates pending build status for latest commit' do
|
144
|
+
expect(WebMock).to have_requested(:post, 'https://api.github.com/repos/livebuzzevents/livebuzz-gitx/statuses/e12da4').
|
145
|
+
with(body: {state: 'pending', context: 'peer_review', description: 'Peer review in progress'})
|
146
|
+
end
|
147
|
+
end
|
148
|
+
context 'when --reject flag is passed' do
|
149
|
+
let(:options) do
|
150
|
+
{
|
151
|
+
reject: true
|
152
|
+
}
|
153
|
+
end
|
154
|
+
let(:authorization_token) { '123123' }
|
155
|
+
let(:reference) { double('fake reference', target_id: 'e12da4') }
|
156
|
+
before do
|
157
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
158
|
+
expect(cli).to receive(:ask_editor).and_return('comment body')
|
159
|
+
allow(repo).to receive(:head).and_return(reference)
|
160
|
+
stub_request(:post, /.*api.github.com.*/).to_return(:status => 201)
|
161
|
+
|
162
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
163
|
+
cli.review
|
164
|
+
end
|
165
|
+
end
|
166
|
+
it 'posts comment to github' do
|
167
|
+
expect(WebMock).to have_requested(:post, "https://api.github.com/repos/livebuzzevents/livebuzz-gitx/issues/10/comments").
|
168
|
+
with(body: {body: "[gitx] review rejected\n\ncomment body"})
|
169
|
+
end
|
170
|
+
it 'creates failure build status for latest commit' do
|
171
|
+
expect(WebMock).to have_requested(:post, 'https://api.github.com/repos/livebuzzevents/livebuzz-gitx/statuses/e12da4').
|
172
|
+
with(body: {state: 'failure', context: 'peer_review', description: 'Peer review rejected'})
|
173
|
+
end
|
174
|
+
end
|
175
|
+
context 'when --approve flag is passed' do
|
176
|
+
let(:options) do
|
177
|
+
{
|
178
|
+
approve: true
|
179
|
+
}
|
180
|
+
end
|
181
|
+
let(:authorization_token) { '123123' }
|
182
|
+
let(:reference) { double('fake reference', target_id: 'e12da4') }
|
183
|
+
before do
|
184
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
185
|
+
expect(cli).to receive(:ask_editor).and_return('comment body')
|
186
|
+
allow(repo).to receive(:head).and_return(reference)
|
187
|
+
stub_request(:post, /.*api.github.com.*/).to_return(:status => 201)
|
188
|
+
|
189
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
190
|
+
cli.review
|
191
|
+
end
|
192
|
+
end
|
193
|
+
it 'posts comment to github' do
|
194
|
+
expect(WebMock).to have_requested(:post, "https://api.github.com/repos/livebuzzevents/livebuzz-gitx/issues/10/comments").
|
195
|
+
with(body: {body: "[gitx] review approved :shipit:\n\ncomment body"})
|
196
|
+
end
|
197
|
+
it 'creates success build status for latest commit' do
|
198
|
+
expect(WebMock).to have_requested(:post, 'https://api.github.com/repos/livebuzzevents/livebuzz-gitx/statuses/e12da4').
|
199
|
+
with(body: {state: 'success', context: 'peer_review', description: 'Peer review approved'})
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe '#authorization_token' do
|
205
|
+
context 'when github.user is not configured' do
|
206
|
+
it 'raises error' do
|
207
|
+
expect do
|
208
|
+
cli.send(:authorization_token)
|
209
|
+
end.to raise_error(/Github user not configured/)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
context 'when global config token is nil' do
|
213
|
+
let(:repo_config) do
|
214
|
+
{
|
215
|
+
'remote.origin.url' => 'https://github.com/livebuzzevents/livebuzz-gitx',
|
216
|
+
'github.user' => 'ryan@codecrate.com'
|
217
|
+
}
|
218
|
+
end
|
219
|
+
let(:github_password) { 'secretz' }
|
220
|
+
let(:authorization_token) { '123981239123' }
|
221
|
+
before do
|
222
|
+
stub_request(:post, "https://ryan@codecrate.com:secretz@api.github.com/authorizations").
|
223
|
+
to_return(:status => 200, :body => JSON.dump(token: authorization_token), :headers => {'Content-Type' => 'application/json'})
|
224
|
+
|
225
|
+
expect(cli).to receive(:ask).with('Github password for ryan@codecrate.com: ', {:echo => false}).and_return(github_password)
|
226
|
+
expect(cli).to receive(:ask).with('Github two factor authorization token (if enabled): ', {:echo => false}).and_return(nil)
|
227
|
+
|
228
|
+
@auth_token = cli.send(:authorization_token)
|
229
|
+
end
|
230
|
+
it 'stores authorization_token in global config' do
|
231
|
+
expect(global_config).to include('token' => authorization_token)
|
232
|
+
end
|
233
|
+
it { expect(@auth_token).to eq authorization_token }
|
234
|
+
end
|
235
|
+
context 'when global authorization_token is nil and first request fails' do
|
236
|
+
let(:repo_config) do
|
237
|
+
{
|
238
|
+
'remote.origin.url' => 'https://github.com/livebuzzevents/livebuzz-gitx',
|
239
|
+
'github.user' => 'ryan@codecrate.com'
|
240
|
+
}
|
241
|
+
end
|
242
|
+
let(:github_password) { 'secretz' }
|
243
|
+
let(:authorization_token) { '123981239123' }
|
244
|
+
before do
|
245
|
+
stub_request(:post, "https://ryan@codecrate.com:secretz@api.github.com/authorizations").
|
246
|
+
to_return(:status => 401, :body => JSON.dump(token: authorization_token), :headers => {'Content-Type' => 'application/json'}).
|
247
|
+
then.
|
248
|
+
to_return(:status => 200, :body => JSON.dump(token: authorization_token), :headers => {'Content-Type' => 'application/json'})
|
249
|
+
|
250
|
+
expect(cli).to receive(:ask).with('Github password for ryan@codecrate.com: ', {:echo => false}).and_return(github_password).twice
|
251
|
+
expect(cli).to receive(:ask).with('Github two factor authorization token (if enabled): ', {:echo => false}).and_return(nil).twice
|
252
|
+
|
253
|
+
@auth_token = cli.send(:authorization_token)
|
254
|
+
end
|
255
|
+
it 'stores authorization_token in global config' do
|
256
|
+
expect(global_config).to include('token' => authorization_token)
|
257
|
+
end
|
258
|
+
it { expect(@auth_token).to eq authorization_token }
|
259
|
+
end
|
260
|
+
context 'when the global config has an existing token' do
|
261
|
+
let(:authorization_token) { '123981239123' }
|
262
|
+
let(:repo_config) do
|
263
|
+
{
|
264
|
+
'remote.origin.url' => 'https://github.com/livebuzzevents/livebuzz-gitx',
|
265
|
+
'github.user' => 'ryan@codecrate.com'
|
266
|
+
}
|
267
|
+
end
|
268
|
+
let(:config) do
|
269
|
+
{
|
270
|
+
'token' => authorization_token
|
271
|
+
}
|
272
|
+
end
|
273
|
+
before do
|
274
|
+
File.open(global_config_file, 'w') do |file|
|
275
|
+
file.write(config.to_yaml)
|
276
|
+
end
|
277
|
+
@auth_token = cli.send(:authorization_token)
|
278
|
+
end
|
279
|
+
it { expect(@auth_token).to eq authorization_token }
|
280
|
+
end
|
281
|
+
context 'when two factor authorization token given' do
|
282
|
+
let(:repo_config) do
|
283
|
+
{
|
284
|
+
'remote.origin.url' => 'https://github.com/livebuzzevents/livebuzz-gitx',
|
285
|
+
'github.user' => 'ryan@codecrate.com'
|
286
|
+
}
|
287
|
+
end
|
288
|
+
let(:github_password) { 'secretz' }
|
289
|
+
let(:authorization_token) { '123981239123' }
|
290
|
+
let(:two_factor_auth_token) { '456456' }
|
291
|
+
before do
|
292
|
+
stub_request(:post, "https://ryan@codecrate.com:secretz@api.github.com/authorizations").
|
293
|
+
with(headers: {'X-GitHub-OTP' => two_factor_auth_token}).
|
294
|
+
to_return(:status => 200, :body => JSON.dump(token: authorization_token), :headers => {'Content-Type' => 'application/json'})
|
295
|
+
|
296
|
+
expect(cli).to receive(:ask).with('Github password for ryan@codecrate.com: ', {:echo => false}).and_return(github_password)
|
297
|
+
expect(cli).to receive(:ask).with('Github two factor authorization token (if enabled): ', {:echo => false}).and_return(two_factor_auth_token)
|
298
|
+
|
299
|
+
@auth_token = cli.send(:authorization_token)
|
300
|
+
end
|
301
|
+
it 'stores authorization_token in global config' do
|
302
|
+
expect(global_config).to include('token' => authorization_token)
|
303
|
+
end
|
304
|
+
it { expect(@auth_token).to eq authorization_token }
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'livebuzz/gitx/cli/share_command'
|
3
|
+
|
4
|
+
describe LiveBuzz::Gitx::Cli::ShareCommand do
|
5
|
+
let(:args) { [] }
|
6
|
+
let(:options) { {} }
|
7
|
+
let(:config) do
|
8
|
+
{
|
9
|
+
pretend: true
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:cli) { LiveBuzz::Gitx::Cli::ShareCommand.new(args, options, config) }
|
13
|
+
let(:branch) { double('fake branch', name: 'feature-branch') }
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow(cli).to receive(:current_branch).and_return(branch)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#share' do
|
20
|
+
before do
|
21
|
+
allow(cli).to receive(:say)
|
22
|
+
|
23
|
+
expect(cli).to receive(:run_cmd).with('git push origin feature-branch').ordered
|
24
|
+
expect(cli).to receive(:run_cmd).with('git branch --set-upstream-to origin/feature-branch').ordered
|
25
|
+
|
26
|
+
cli.share
|
27
|
+
end
|
28
|
+
it 'runs expected commands' do
|
29
|
+
should meet_expectations
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'livebuzz/gitx/cli/start_command'
|
3
|
+
|
4
|
+
describe LiveBuzz::Gitx::Cli::StartCommand do
|
5
|
+
let(:args) { [] }
|
6
|
+
let(:options) { {} }
|
7
|
+
let(:config) do
|
8
|
+
{
|
9
|
+
pretend: true
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:cli) { LiveBuzz::Gitx::Cli::StartCommand.new(args, options, config) }
|
13
|
+
let(:repo) { cli.send(:repo) }
|
14
|
+
|
15
|
+
describe '#start' do
|
16
|
+
context 'when user inputs branch that is valid' do
|
17
|
+
before do
|
18
|
+
expect(cli).to receive(:checkout_branch).with('master').ordered
|
19
|
+
expect(cli).to receive(:run_cmd).with('git pull').ordered
|
20
|
+
expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
|
21
|
+
expect(cli).to receive(:checkout_branch).with('new-branch').ordered
|
22
|
+
|
23
|
+
cli.start 'new-branch'
|
24
|
+
end
|
25
|
+
it do
|
26
|
+
should meet_expectations
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context 'when user does not input a branch name' do
|
30
|
+
before do
|
31
|
+
expect(cli).to receive(:ask).and_return('new-branch')
|
32
|
+
|
33
|
+
expect(cli).to receive(:checkout_branch).with('master').ordered
|
34
|
+
expect(cli).to receive(:run_cmd).with('git pull').ordered
|
35
|
+
expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
|
36
|
+
expect(cli).to receive(:checkout_branch).with('new-branch').ordered
|
37
|
+
|
38
|
+
cli.start
|
39
|
+
end
|
40
|
+
it 'prompts user to enter a new branch name' do
|
41
|
+
should meet_expectations
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context 'when user inputs an invalid branch name' do
|
45
|
+
before do
|
46
|
+
expect(cli).to receive(:ask).and_return('new-branch')
|
47
|
+
|
48
|
+
expect(cli).to receive(:checkout_branch).with('master').ordered
|
49
|
+
expect(cli).to receive(:run_cmd).with('git pull').ordered
|
50
|
+
expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
|
51
|
+
expect(cli).to receive(:checkout_branch).with('new-branch').ordered
|
52
|
+
|
53
|
+
cli.start 'a bad_branch-name?'
|
54
|
+
end
|
55
|
+
it 'prompts user to enter a new branch name' do
|
56
|
+
should meet_expectations
|
57
|
+
end
|
58
|
+
end
|
59
|
+
context 'when branch already exists in local repo' do
|
60
|
+
let(:branches) { double(each_name: ['bar']) }
|
61
|
+
before do
|
62
|
+
expect(repo).to receive(:branches).and_return(branches)
|
63
|
+
|
64
|
+
expect(cli).to receive(:ask).and_return('new-branch')
|
65
|
+
|
66
|
+
expect(cli).to receive(:checkout_branch).with('master').ordered
|
67
|
+
expect(cli).to receive(:run_cmd).with('git pull').ordered
|
68
|
+
expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
|
69
|
+
expect(cli).to receive(:checkout_branch).with('new-branch').ordered
|
70
|
+
|
71
|
+
cli.start 'bar'
|
72
|
+
end
|
73
|
+
it 'prompts user to enter a new branch name' do
|
74
|
+
should meet_expectations
|
75
|
+
end
|
76
|
+
end
|
77
|
+
context 'when branch already exists in remote repo' do
|
78
|
+
let(:branches) { double(each_name: ['origin/bar']) }
|
79
|
+
before do
|
80
|
+
expect(repo).to receive(:branches).and_return(branches)
|
81
|
+
|
82
|
+
expect(cli).to receive(:ask).and_return('new-branch')
|
83
|
+
|
84
|
+
expect(cli).to receive(:checkout_branch).with('master').ordered
|
85
|
+
expect(cli).to receive(:run_cmd).with('git pull').ordered
|
86
|
+
expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
|
87
|
+
expect(cli).to receive(:checkout_branch).with('new-branch').ordered
|
88
|
+
|
89
|
+
cli.start 'bar'
|
90
|
+
end
|
91
|
+
it 'prompts user to enter a new branch name' do
|
92
|
+
should meet_expectations
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'livebuzz/gitx/cli/track_command'
|
3
|
+
|
4
|
+
describe LiveBuzz::Gitx::Cli::TrackCommand do
|
5
|
+
let(:args) { [] }
|
6
|
+
let(:options) { {} }
|
7
|
+
let(:config) do
|
8
|
+
{
|
9
|
+
pretend: true
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:cli) { LiveBuzz::Gitx::Cli::TrackCommand.new(args, options, config) }
|
13
|
+
let(:branch) { double('fake branch', name: 'feature-branch') }
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow(cli).to receive(:current_branch).and_return(branch)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#track' do
|
20
|
+
before do
|
21
|
+
allow(cli).to receive(:say)
|
22
|
+
|
23
|
+
expect(cli).to receive(:run_cmd).with('git branch --set-upstream-to origin/feature-branch').ordered
|
24
|
+
|
25
|
+
cli.track
|
26
|
+
end
|
27
|
+
it 'runs expected commands' do
|
28
|
+
should meet_expectations
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'livebuzz/gitx/cli/update_command'
|
3
|
+
|
4
|
+
describe LiveBuzz::Gitx::Cli::UpdateCommand do
|
5
|
+
let(:args) { [] }
|
6
|
+
let(:options) { {} }
|
7
|
+
let(:config) do
|
8
|
+
{
|
9
|
+
pretend: true
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:cli) { LiveBuzz::Gitx::Cli::UpdateCommand.new(args, options, config) }
|
13
|
+
let(:branch) { double('fake branch', name: 'feature-branch') }
|
14
|
+
let(:repo) { cli.send(:repo) }
|
15
|
+
let(:remote_branch_names) { ['origin/feature-branch'] }
|
16
|
+
|
17
|
+
before do
|
18
|
+
allow(cli).to receive(:current_branch).and_return(branch)
|
19
|
+
branches = double('fake branches')
|
20
|
+
allow(branches).to receive(:each_name).with(:remote).and_return(remote_branch_names)
|
21
|
+
allow(repo).to receive(:branches).and_return(branches)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#update' do
|
25
|
+
context 'when no merge conflicts occur' do
|
26
|
+
before do
|
27
|
+
allow(cli).to receive(:say)
|
28
|
+
|
29
|
+
expect(cli).to receive(:run_cmd).with('git pull origin feature-branch').ordered
|
30
|
+
expect(cli).to receive(:run_cmd).with('git pull origin master').ordered
|
31
|
+
expect(cli).to receive(:run_cmd).with('git push origin HEAD').ordered
|
32
|
+
|
33
|
+
cli.update
|
34
|
+
end
|
35
|
+
it 'runs expected commands' do
|
36
|
+
should meet_expectations
|
37
|
+
end
|
38
|
+
end
|
39
|
+
context 'when merge conflicts occur when pulling remote feature-branch' do
|
40
|
+
before do
|
41
|
+
allow(cli).to receive(:say)
|
42
|
+
|
43
|
+
expect(cli).to receive(:run_cmd).with('git pull origin feature-branch').and_raise('merge error').ordered
|
44
|
+
|
45
|
+
expect { cli.update }.to raise_error(LiveBuzz::Gitx::Cli::BaseCommand::MergeError, 'Merge Conflict Occurred. Please fix merge conflict and rerun the update command')
|
46
|
+
end
|
47
|
+
it 'raises error' do
|
48
|
+
should meet_expectations
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context 'when merge conflicts occur when pulling remote master branch' do
|
52
|
+
before do
|
53
|
+
allow(cli).to receive(:say)
|
54
|
+
|
55
|
+
expect(cli).to receive(:run_cmd).with('git pull origin feature-branch').ordered
|
56
|
+
expect(cli).to receive(:run_cmd).with('git pull origin master').and_raise('merge error occurred').ordered
|
57
|
+
|
58
|
+
expect { cli.update }.to raise_error(LiveBuzz::Gitx::Cli::BaseCommand::MergeError, 'Merge Conflict Occurred. Please fix merge conflict and rerun the update command')
|
59
|
+
end
|
60
|
+
it 'raises error' do
|
61
|
+
should meet_expectations
|
62
|
+
end
|
63
|
+
end
|
64
|
+
context 'when feature-branch does not exist remotely' do
|
65
|
+
let(:remote_branch_names) { [] }
|
66
|
+
before do
|
67
|
+
allow(cli).to receive(:say)
|
68
|
+
|
69
|
+
expect(cli).not_to receive(:run_cmd).with('git pull origin feature-branch')
|
70
|
+
expect(cli).to receive(:run_cmd).with('git pull origin master').ordered
|
71
|
+
|
72
|
+
cli.update
|
73
|
+
end
|
74
|
+
it 'skips pulling from feature branch' do
|
75
|
+
should meet_expectations
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear! do
|
3
|
+
::SimpleCov.add_filter 'spec'
|
4
|
+
::SimpleCov.add_filter 'lib/livebuzz/gitx/extensions'
|
5
|
+
end
|
6
|
+
require 'rubygems'
|
7
|
+
require 'bundler/setup'
|
8
|
+
|
9
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
10
|
+
# in spec/support/ and its subdirectories.
|
11
|
+
Dir[File.join(__dir__, "support/**/*.rb")].each { |f| require f }
|
12
|
+
|
13
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
14
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
15
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
16
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
17
|
+
#
|
18
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
19
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
20
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
21
|
+
# individual file that may not need all of that loaded. Instead, make a
|
22
|
+
# separate helper file that requires this one and then use it only in the specs
|
23
|
+
# that actually need it.
|
24
|
+
#
|
25
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
26
|
+
# users commonly want.
|
27
|
+
#
|
28
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
29
|
+
RSpec.configure do |config|
|
30
|
+
# These two settings work together to allow you to limit a spec run
|
31
|
+
# to individual examples or groups you care about by tagging them with
|
32
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
33
|
+
# get run.
|
34
|
+
config.filter_run :focus
|
35
|
+
config.run_all_when_everything_filtered = true
|
36
|
+
|
37
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
38
|
+
# file, and it's useful to allow more verbose output when running an
|
39
|
+
# individual spec file.
|
40
|
+
if config.files_to_run.one?
|
41
|
+
# Use the documentation formatter for detailed output,
|
42
|
+
# unless a formatter has already been configured
|
43
|
+
# (e.g. via a command-line flag).
|
44
|
+
config.default_formatter = 'doc'
|
45
|
+
end
|
46
|
+
|
47
|
+
# Print the 10 slowest examples and example groups at the
|
48
|
+
# end of the spec run, to help surface which specs are running
|
49
|
+
# particularly slow.
|
50
|
+
# config.profile_examples = 10
|
51
|
+
|
52
|
+
# Run specs in random order to surface order dependencies. If you find an
|
53
|
+
# order dependency and want to debug it, you can fix the order by providing
|
54
|
+
# the seed, which is printed after each run.
|
55
|
+
# --seed 1234
|
56
|
+
config.order = :random
|
57
|
+
|
58
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
59
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
60
|
+
# test failures related to randomization by passing the same `--seed` value
|
61
|
+
# as the one that triggered the failure.
|
62
|
+
Kernel.srand config.seed
|
63
|
+
|
64
|
+
# rspec-expectations config goes here. You can use an alternate
|
65
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
66
|
+
# assertions if you prefer.
|
67
|
+
config.expect_with :rspec do |expectations|
|
68
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
69
|
+
# For more details, see:
|
70
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
71
|
+
expectations.syntax = :expect
|
72
|
+
end
|
73
|
+
|
74
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
75
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
76
|
+
config.mock_with :rspec do |mocks|
|
77
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
78
|
+
# For more details, see:
|
79
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
80
|
+
mocks.syntax = :expect
|
81
|
+
|
82
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
83
|
+
# a real object. This is generally recommended.
|
84
|
+
mocks.verify_partial_doubles = true
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# helper for reading global config file
|
2
|
+
module GlobalConfig
|
3
|
+
def global_config_file
|
4
|
+
config_file = File.join(temp_dir, '.config/gitx/github.yml')
|
5
|
+
config_dir = File.dirname(config_file)
|
6
|
+
FileUtils.mkdir_p(config_dir) unless File.exists?(config_dir)
|
7
|
+
config_file
|
8
|
+
end
|
9
|
+
def global_config
|
10
|
+
YAML.load_file(global_config_file)
|
11
|
+
end
|
12
|
+
def temp_dir
|
13
|
+
tmp_dir = File.join(__dir__, '../tmp')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.include GlobalConfig
|
19
|
+
|
20
|
+
config.before do
|
21
|
+
FileUtils.rm_rf(temp_dir)
|
22
|
+
FileUtils.mkdir_p(temp_dir)
|
23
|
+
end
|
24
|
+
end
|
data/spec/support/pry.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'pry'
|