abak-flow 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,353 +0,0 @@
1
- # coding: utf-8
2
- require "spec_helper"
3
-
4
- describe Abak::Flow::PullRequest do
5
- describe "Interface" do
6
- subject { described_class.new }
7
-
8
- it { should respond_to :valid? }
9
- it { should respond_to :invalid? }
10
- it { should respond_to :publish }
11
- it { should respond_to :publish! }
12
-
13
- it { should respond_to :recommendations }
14
- it { should respond_to :github_link }
15
- it { should respond_to :exception }
16
- end
17
-
18
- describe "Initialize process" do
19
- let(:attributes) { {target: "develop", title: "Fix some problem", body: "Check this request"} }
20
- let(:request) { described_class.new attributes }
21
-
22
- before do
23
- Abak::Flow::System.any_instance.stub(:ready).and_return true
24
- Abak::Flow::System.any_instance.stub(:recommendations).and_return []
25
- end
26
-
27
- subject { request }
28
- its(:options) { should_not be_nil }
29
-
30
- describe "#recommendations" do
31
- subject { request.recommendations }
32
-
33
- its(:first) { should be_empty }
34
- its(:last) { should be_empty }
35
- end
36
- end
37
-
38
- describe "#title" do
39
- before { Abak::Flow::Branches.stub(:current_branch).and_return branch }
40
-
41
- context "when have only branch name" do
42
- let(:branch) { double("Branch", tracker_task: "hello") }
43
- subject { described_class.new }
44
-
45
- its(:title) { should eq "hello" }
46
- end
47
-
48
- context "when have only option task" do
49
- let(:branch) { double("Branch", tracker_task: nil) }
50
- subject { described_class.new(title: "megusta") }
51
-
52
- its(:title) { should eq "megusta" }
53
- end
54
-
55
- context "when have option task and branch name" do
56
- let(:branch) { double("Branch", tracker_task: "tako") }
57
- subject { described_class.new(title: "burito") }
58
-
59
- its(:title) { should eq "tako :: burito" }
60
- end
61
- end
62
-
63
- describe "#comment" do
64
- before { Abak::Flow::Branches.stub(:current_branch).and_return branch }
65
-
66
- describe "when have nothing" do
67
- let(:branch) { double("Branch", tracker_task: nil, task?: false) }
68
-
69
- before { Abak::Flow::Messages.any_instance.should_receive(:t).with(:forgot_task).and_return "I forgot my task" }
70
- subject { described_class.new }
71
-
72
- its(:comment) { should eq "I forgot my task" }
73
- end
74
-
75
- describe "when have only branch name" do
76
- let(:branch) { double("Branch", tracker_task: "hello", task?: true) }
77
-
78
- before { described_class.any_instance.stub(:default_comment).and_return "Default comment" }
79
- subject { described_class.new }
80
-
81
- its(:comment) { should eq "Default comment" }
82
- end
83
-
84
- describe "when have only option comment" do
85
- let(:branch) { double("Branch", tracker_task: "hello", task?: false) }
86
-
87
- subject { described_class.new(comment: "megusta") }
88
-
89
- its(:comment) { should eq "megusta" }
90
- end
91
-
92
- describe "when have option comment and branch name" do
93
- let(:branch) { double("Branch", tracker_task: "tako", task?: true) }
94
-
95
- before { described_class.any_instance.stub(:default_comment).and_return "Default comment" }
96
- subject { described_class.new(comment: "burito") }
97
-
98
- its(:comment) { should include "Default comment" }
99
- its(:comment) { should include "burito" }
100
- end
101
- end
102
-
103
- describe "#branch" do
104
- before { Abak::Flow::Branches.stub(:current_branch).and_return branch }
105
-
106
- describe "when have only option branch" do
107
- let(:branch) { double("Branch", tracker_task: nil) }
108
- subject { described_class.new(branch: "tako") }
109
-
110
- its(:branch) { should eq "tako" }
111
- end
112
-
113
- describe "when have only feature branch" do
114
- let(:branch) { double("Branch", tracker_task: "tako", hotfix?: false, feature?: true) }
115
-
116
- subject { described_class.new }
117
-
118
- its(:branch) { should eq "develop" }
119
- end
120
-
121
- describe "when have only hotfix branch" do
122
- let(:branch) { double("Branch", tracker_task: "tako", feature?: false, hotfix?: true) }
123
-
124
- subject { described_class.new }
125
-
126
- its(:branch) { should eq "master" }
127
- end
128
-
129
- describe "when have hotfix branch and option branch" do
130
- let(:branch) { double("Branch", tracker_task: "tako", feature?: false, hotfix?: true) }
131
-
132
- subject { described_class.new(branch: "pewpew") }
133
-
134
- its(:branch) { should eq "pewpew" }
135
- end
136
- end
137
-
138
-
139
- describe "Publishing process" do
140
- let(:pull_request) { Abak::Flow::PullRequest.new }
141
-
142
- subject { pull_request }
143
-
144
- describe "when something goes wrong" do
145
- describe "when system is not ready" do
146
- before { Abak::Flow::System.any_instance.stub(:ready).and_return false }
147
- before { pull_request.stub(:invalid?).and_return true }
148
-
149
- its(:publish) { should be_false }
150
-
151
- describe "#exception" do
152
- before { pull_request.publish }
153
-
154
- its(:exception) { should_not be_nil }
155
- end
156
- end
157
-
158
- describe "when pull request is invalid" do
159
- before { Abak::Flow::System.any_instance.stub(:ready).and_return true }
160
- before { pull_request.stub(:invalid?).and_return true }
161
-
162
- its(:publish) { should be_false }
163
- end
164
-
165
- describe "when something raise exception" do
166
- before do
167
- Abak::Flow::System.any_instance.stub(:ready).and_return true
168
- pull_request.stub(:invalid?).and_return false
169
- pull_request.stub(:publish_pull_request).and_raise Exception
170
- end
171
-
172
- it { expect { pull_request.publish }.not_to raise_error }
173
-
174
- describe "#exception" do
175
- before { pull_request.publish }
176
-
177
- its(:exception) { should_not be_nil }
178
- end
179
- end
180
- end
181
-
182
- describe "when all right" do
183
- before do
184
- Abak::Flow::System.any_instance.stub(:ready).and_return true
185
- pull_request.stub(:invalid?).and_return false
186
- pull_request.stub(:publish_pull_request).and_return double("Result").as_null_object
187
- end
188
-
189
- its(:publish) { should be_true }
190
- end
191
-
192
- describe "when use bang! method" do
193
- describe "when something goes wrong" do
194
- describe "when we raise exception" do
195
- before { Abak::Flow::System.any_instance.stub(:ready).and_return false }
196
-
197
- it { expect { pull_request.publish! }.to raise_error Exception }
198
- end
199
-
200
- describe "when something raise exception" do
201
- before { Abak::Flow::System.any_instance.stub(:ready).and_return false }
202
- before { pull_request.stub(:publish_pull_request).and_raise Exception }
203
-
204
- it { expect { pull_request.publish! }.to raise_error Exception }
205
- end
206
- end
207
-
208
- describe "when all right" do
209
- before do
210
- Abak::Flow::System.any_instance.stub(:ready).and_return true
211
- pull_request.stub(:invalid?).and_return false
212
- pull_request.stub(:publish_pull_request).and_return double("Result").as_null_object
213
- end
214
-
215
- it { expect { pull_request.publish! }.not_to raise_error }
216
- end
217
- end
218
-
219
- describe "#github_link" do
220
- describe "when request not published" do
221
- its(:github_link) { should be_nil }
222
- end
223
-
224
- describe "when request successfully published" do
225
- before do
226
- Abak::Flow::System.any_instance.stub(:ready).and_return true
227
- pull_request.stub(:invalid?).and_return false
228
- pull_request.stub(:publish_pull_request).and_return double("Result", href: "wow").as_null_object
229
-
230
- pull_request.publish
231
- end
232
-
233
- its(:github_link) { should eq "wow" }
234
- end
235
- end
236
- end
237
-
238
- # describe "Validation process" do
239
- # describe "when system is not ready" do
240
- # before do
241
- # Abak::Flow::PullRequest::System.ready = false
242
- # Abak::Flow::PullRequest::System.recommendations = %w[one two three]
243
- # end
244
- #
245
- # subject { Abak::Flow::PullRequest.new }
246
- #
247
- # describe "when pull request is valid" do
248
- # it "should not be valid pull request" do
249
- # subject.stub(:requirements_satisfied?, true) do
250
- # subject.valid?.must_equal false
251
- # end
252
- # end
253
- #
254
- # it "should be invalid request" do
255
- # subject.stub(:requirements_satisfied?, true) do
256
- # subject.invalid?.must_equal true
257
- # end
258
- # end
259
- #
260
- # it "should have system recommendations" do
261
- # subject.stub(:requirements_satisfied?, true) do
262
- # subject.valid?
263
- # subject.recommendations[0].wont_be_empty
264
- # end
265
- # end
266
- # end
267
- #
268
- # describe "when pull request is invalid" do
269
- # it "should have only system recommendations" do
270
- # subject.stub(:requirements_satisfied?, false) do
271
- # subject.valid?
272
- # subject.recommendations[0].wont_be_empty
273
- # subject.recommendations[1].must_be_empty
274
- # end
275
- # end
276
- # end
277
- # end
278
- #
279
- # describe "when system is ready" do
280
- # before do
281
- # Abak::Flow::PullRequest::System.ready = true
282
- # Abak::Flow::PullRequest::System.recommendations = []
283
- # end
284
- #
285
- # subject { Abak::Flow::PullRequest.new }
286
- #
287
- # describe "when pull request is valid" do
288
- # it "should be valid pull request" do
289
- # subject.stub(:requirements_satisfied?, true) do
290
- # subject.valid?.must_equal true
291
- # end
292
- # end
293
- #
294
- # it "should not be invalid request" do
295
- # subject.stub(:requirements_satisfied?, true) do
296
- # subject.invalid?.must_equal false
297
- # end
298
- # end
299
- #
300
- # it "should not have system recommendations" do
301
- # subject.stub(:requirements_satisfied?, true) do
302
- # subject.valid?
303
- # subject.recommendations[0].must_be_empty
304
- # end
305
- # end
306
- # end
307
- #
308
- # describe "when pull request is invalid" do
309
- # describe "when title not specified" do
310
- # let(:branch) { CurrentBranchMock.new(nil, "hotfix") }
311
- # before { Abak::Flow::PullRequest::Branches.current_branch = branch }
312
- #
313
- # it "should not satisfy requirements" do
314
- # subject.send(:requirements_satisfied?).must_equal false
315
- # end
316
- #
317
- # it "should have recommendations" do
318
- # subject.valid?
319
- # subject.recommendations[1].wont_be_empty
320
- # end
321
- # end
322
- #
323
- # describe "when branch not specified" do
324
- # let(:branch) { CurrentBranchMock.new("SG-001", "pewpew") }
325
- # before { Abak::Flow::PullRequest::Branches.current_branch = branch }
326
- #
327
- # it "should not satisfy requirements" do
328
- # subject.send(:requirements_satisfied?).must_equal false
329
- # end
330
- #
331
- # it "should have recommendations" do
332
- # subject.valid?
333
- # subject.recommendations[1].wont_be_empty
334
- # end
335
- # end
336
- #
337
- # describe "when branch and title not specified" do
338
- # let(:branch) { CurrentBranchMock.new(nil, "pewpew") }
339
- # before { Abak::Flow::PullRequest::Branches.current_branch = branch }
340
- #
341
- # it "should not satisfy requirements" do
342
- # subject.send(:requirements_satisfied?).must_equal false
343
- # end
344
- #
345
- # it "should have recommendations" do
346
- # subject.valid?
347
- # subject.recommendations[1].wont_be_empty
348
- # end
349
- # end
350
- # end
351
- # end
352
- # end
353
- end
@@ -1,97 +0,0 @@
1
- # coding: utf-8
2
- require "spec_helper"
3
-
4
- describe Abak::Flow::System do
5
- let(:instance) { described_class.clone.instance }
6
- let(:remotes) { {origin: "origin_repo", upstream: "upstream_repo"} }
7
- let(:params) { double("Params", oauth_user: "User", oauth_token: "Token", proxy_server: "http://proxy.com", locale: "en") }
8
- let(:empty_params) { double("Params", oauth_user: nil, oauth_token: nil, proxy_server: nil, locale: nil) }
9
-
10
- describe "#ready?" do
11
- subject { instance.ready? }
12
-
13
- context "when all requirements is not set" do
14
- before do
15
- Abak::Flow::Project.any_instance.stub(:remotes).and_return({})
16
- Abak::Flow::Configuration.any_instance.stub(:params).and_return empty_params
17
- end
18
-
19
- it { should be_false }
20
- end
21
-
22
- context "when upstream is not set" do
23
- before do
24
- Abak::Flow::Project.any_instance.stub(:remotes).and_return({origin: "not_nil"})
25
- Abak::Flow::Configuration.any_instance.stub(:params).and_return params
26
- end
27
-
28
- it { should be_false }
29
- end
30
-
31
- context "when origin is not set" do
32
- before do
33
- Abak::Flow::Project.any_instance.stub(:remotes).and_return({upstream: "not_nil"})
34
- Abak::Flow::Configuration.any_instance.stub(:params).and_return params
35
- end
36
-
37
- it { should be_false }
38
- end
39
-
40
- context "when all config params is not set" do
41
- before do
42
- Abak::Flow::Project.any_instance.stub(:remotes).and_return remotes
43
- Abak::Flow::Configuration.any_instance.stub(:params).and_return empty_params
44
- end
45
-
46
- it { should be_false }
47
- end
48
-
49
- context "when proxy server config is not set" do
50
- before do
51
- params.stub(:proxy).and_return nil
52
-
53
- Abak::Flow::Project.any_instance.stub(:remotes).and_return remotes
54
- Abak::Flow::Configuration.any_instance.stub(:params).and_return params
55
- end
56
-
57
- it { should be_true }
58
- end
59
-
60
- context "when all config params is set" do
61
- before do
62
- Abak::Flow::Project.any_instance.stub(:remotes).and_return remotes
63
- Abak::Flow::Configuration.any_instance.stub(:params).and_return params
64
- end
65
-
66
- it { should be_true }
67
- end
68
- end
69
-
70
- describe "#information" do
71
- context "when proxy is set" do
72
- before do
73
- Abak::Flow::Project.any_instance.stub(:remotes).and_return remotes
74
- Abak::Flow::Configuration.any_instance.stub(:params).and_return params
75
- end
76
-
77
- before { instance.ready? }
78
- subject { instance.information }
79
-
80
- it { should_not be_empty }
81
- end
82
-
83
- context "when proxy is not set" do
84
- before do
85
- params.stub(:proxy_server).and_return nil
86
-
87
- Abak::Flow::Project.any_instance.stub(:remotes).and_return remotes
88
- Abak::Flow::Configuration.any_instance.stub(:params).and_return params
89
- end
90
-
91
- before { instance.ready? }
92
- subject { instance.information }
93
-
94
- it { should be_empty }
95
- end
96
- end
97
- end