22
33require "test_helper"
44require "English"
5+ require "open3"
56
67module Cibuildgem
78 class CLITest < Minitest ::Test
@@ -129,14 +130,20 @@ def test_ci_template_when_passed_a_test_command_and_workdir
129130 FileUtils . rm_rf ( "test/fixtures/dummy_gem/.github" )
130131 end
131132
132- def test_release
133+ def test_release_succeeds
133134 FileUtils . touch ( "tmp/foo.gem" )
134135 FileUtils . touch ( "tmp/bar.gem" )
135136 FileUtils . touch ( "tmp/some_file" )
136137
138+ status = Struct . new ( :success? )
137139 gem_pushed = [ ]
140+ callable = proc do |gem_name |
141+ gem_pushed << gem_name
138142
139- Kernel . stub ( :system , -> ( gem , _ ) { gem_pushed << gem } ) do
143+ [ "" , status . new ( true ) ]
144+ end
145+
146+ Open3 . stub ( :capture2e , callable ) do
140147 CLI . start ( [ "release" , "--glob" , "tmp/*" ] )
141148 end
142149
@@ -147,6 +154,59 @@ def test_release
147154 FileUtils . rm_rf ( "tmp/some_file" )
148155 end
149156
157+ def test_release_when_gem_was_already_pushed
158+ FileUtils . touch ( "tmp/foo.gem" )
159+ FileUtils . touch ( "tmp/bar.gem" )
160+ FileUtils . touch ( "tmp/some_file" )
161+
162+ status = Struct . new ( :success? )
163+ gem_pushed = [ ]
164+ callable = proc do |gem_name |
165+ gem_pushed << gem_name
166+
167+ if gem_name == "gem push tmp/bar.gem"
168+ [ "Repushing of gem versions is not allowed" , status . new ( false ) ]
169+ else
170+ [ "" , status . new ( true ) ]
171+ end
172+ end
173+
174+ Open3 . stub ( :capture2e , callable ) do
175+ out , _ = capture_subprocess_io do
176+ CLI . start ( [ "release" , "--glob" , "tmp/*" ] )
177+ end
178+
179+ assert_equal ( "Gem tmp/bar.gem already exists on RubyGems.org, skipping...\n " , out )
180+ end
181+
182+ assert_equal ( [ "gem push tmp/bar.gem" , "gem push tmp/foo.gem" ] , gem_pushed . sort )
183+ ensure
184+ FileUtils . rm_rf ( "tmp/foo.gem" )
185+ FileUtils . rm_rf ( "tmp/bar.gem" )
186+ FileUtils . rm_rf ( "tmp/some_file" )
187+ end
188+
189+ def test_release_fails
190+ FileUtils . touch ( "tmp/foo.gem" )
191+ FileUtils . touch ( "tmp/bar.gem" )
192+ FileUtils . touch ( "tmp/some_file" )
193+
194+ status = Struct . new ( :success? )
195+ callable = proc do
196+ [ "Something went wrong" , status . new ( false ) ]
197+ end
198+
199+ Open3 . stub ( :capture2e , callable ) do
200+ assert_raises ( RuntimeError ) do
201+ CLI . start ( [ "release" , "--glob" , "tmp/*" ] )
202+ end
203+ end
204+ ensure
205+ FileUtils . rm_rf ( "tmp/foo.gem" )
206+ FileUtils . rm_rf ( "tmp/bar.gem" )
207+ FileUtils . rm_rf ( "tmp/some_file" )
208+ end
209+
150210 def test_print_ruby_cc_version
151211 out , _ = capture_subprocess_io do
152212 Dir . chdir ( "test/fixtures/dummy_gem" ) do
0 commit comments