/
test_release_to_git.rb
271 lines (198 loc) · 7.03 KB
/
test_release_to_git.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
require 'test_helper'
class Jeweler
module Commands
class TestReleaseToGit < Test::Unit::TestCase
rubyforge_command_context "running" do
context "happily" do
setup do
stub(@command).clean_staging_area? { true }
stub(@repo).checkout(anything)
stub(@repo) do
add_tag(anything)
push(anything, anything)
end
stub(@repo).push
stub(@command).release_not_tagged? { true }
@command.run
end
should "checkout master" do
assert_received(@repo) {|repo| repo.checkout('master') }
end
should "push" do
assert_received(@repo) {|repo| repo.push('origin', 'master:master') }
end
end
context "happily with different remote, local branch and remote branch" do
setup do
stub(@command).clean_staging_area? { true }
stub(@command).release_tag { "v1.2.0" }
stub(@repo).checkout(anything)
stub(@repo) do
add_tag(anything)
push(anything, anything)
end
stub(@repo).push
stub(@command).release_not_tagged? { true }
@command.run({:remote => 'upstream', :local_branch => 'feature', :remote_branch => 'v1'})
end
should "checkout master" do
assert_received(@repo) {|repo| repo.checkout('feature') }
end
should "tag version" do
assert_received(@repo) {|repo| repo.add_tag('v1.2.0') }
end
should "push" do
assert_received(@repo) {|repo| repo.push('upstream', 'feature:v1') }
end
end
context "happily with different branch" do
setup do
stub(@command).clean_staging_area? { true }
stub(@command).release_tag { "v3.2.0" }
stub(@repo).checkout(anything)
stub(@repo) do
add_tag(anything)
push(anything, anything)
end
stub(@repo).push
stub(@command).release_not_tagged? { true }
@command.run({:branch => 'v3'})
end
should "checkout master" do
assert_received(@repo) {|repo| repo.checkout('v3') }
end
should "tag version" do
assert_received(@repo) {|repo| repo.add_tag('v3.2.0') }
end
should "push" do
assert_received(@repo) {|repo| repo.push('origin', 'v3:v3') }
end
end
context "with an unclean staging area" do
setup do
stub(@command).clean_staging_area? { false }
stub(@command).system
end
should 'raise error' do
assert_raises RuntimeError, /try commiting/i do
@command.run
end
end
should 'display git status' do
@command.run rescue nil
assert_received(@command) {|command| command.system("git status") }
end
end
context "with a release already tagged" do
setup do
stub(@command).clean_staging_area? { true }
stub(@repo).checkout(anything)
stub(@repo).push
stub(@command).release_not_tagged? { false }
@command.run
end
should "checkout master" do
assert_received(@repo) {|repo| repo.checkout('master') }
end
should "push" do
assert_received(@repo) {|repo| repo.push('origin', 'master:master') }
end
end
end
build_command_context "building from jeweler" do
setup do
@command = Jeweler::Commands::ReleaseToGit.build_for(@jeweler)
end
should "assign gemspec" do
assert_same @gemspec, @command.gemspec
end
should "assign version" do
assert_same @version, @command.version
end
should "assign repo" do
assert_same @repo, @command.repo
end
should "assign output" do
assert_same @output, @command.output
end
should "assign gemspec_helper" do
assert_same @gemspec_helper, @command.gemspec_helper
end
should "assign base_dir" do
assert_same @base_dir, @command.base_dir
end
end
# FIXME this code had its ruby-git stuff replaced with `` and system, which is much harder to test, so re-enable these someday
#context "clean_staging_area?" do
# should "be false if there added files" do
# repo = build_repo :added => %w(README)
# command = Jeweler::Commands::ReleaseToGit.new :repo => repo
# assert ! command.clean_staging_area?
# end
# should "be false if there are changed files" do
# repo = build_repo :changed => %w(README)
# command = Jeweler::Commands::ReleaseToGit.new
# command.repo = repo
# assert ! command.clean_staging_area?
# end
# should "be false if there are deleted files" do
# repo = build_repo :deleted => %w(README)
# command = Jeweler::Commands::ReleaseToGit.new
# command.repo = repo
# assert ! command.clean_staging_area?
# end
# should "be true if nothing added, changed, or deleted" do
# repo = build_repo
# command = Jeweler::Commands::ReleaseToGit.new
# command.repo = repo
# assert command.clean_staging_area?
# end
#end
context "release_tagged? when no tag exists" do
setup do
@repo = Object.new
stub(@repo).tag('v1.2.3') { raise Git::GitTagNameDoesNotExist, tag }
@output = StringIO.new
@command = Jeweler::Commands::ReleaseToGit.new
@command.output = @output
@command.repo = @repo
@command.version = '1.2.3'
end
should_eventually "be true" do
assert @command.release_not_tagged?
end
end
context "release_tagged? when tag exists" do
setup do
@repo = Object.new
stub(@repo) do
tag('v1.2.3') { Object.new }
end
@output = StringIO.new
@command = Jeweler::Commands::ReleaseToGit.new
@command.output = @output
@command.repo = @repo
@command.version = '1.2.3'
end
should_eventually "be false" do
assert @command.release_not_tagged?
end
end
def build_repo(options = {})
status = build_status options
repo = Object.new
stub(repo).status { status }
repo
end
def build_status(options = {})
options = {:added => [], :deleted => [], :changed => []}.merge(options)
status = Object.new
stub(status) do
added { options[:added] }
deleted { options[:deleted] }
changed { options[:changed] }
end
end
end
end
end