@@ -231,7 +231,7 @@ def test_execute_missing_file
231231 end
232232
233233 assert_equal '' , @ui . output
234- assert_equal "ERROR: Gemspec file not found: some_gem.gemspec \n " , @ui . error
234+ assert_equal "ERROR: Couldn't find a gemspec file matching ' some_gem' in #{ @tempdir } \n " , @ui . error
235235 end
236236
237237 def test_execute_outside_dir
@@ -272,6 +272,198 @@ def test_execute_outside_dir
272272 assert_equal "this is a summary" , spec . summary
273273 end
274274
275+ def test_execute_outside_dir_with_glob_argument
276+ gemspec_dir = File . join @tempdir , 'build_command_gem'
277+ gemspec_file = File . join gemspec_dir , @gem . spec_name
278+ readme_file = File . join gemspec_dir , 'README.md'
279+
280+ FileUtils . mkdir_p gemspec_dir
281+
282+ File . open readme_file , 'w' do |f |
283+ f . write "My awesome gem"
284+ end
285+
286+ File . open gemspec_file , 'w' do |gs |
287+ gs . write @gem . to_ruby
288+ end
289+
290+ @cmd . options [ :build_path ] = gemspec_dir
291+ @cmd . options [ :args ] = [ "*.gemspec" ]
292+
293+ use_ui @ui do
294+ @cmd . execute
295+ end
296+
297+ output = @ui . output . split "\n "
298+ assert_equal " Successfully built RubyGem" , output . shift
299+ assert_equal " Name: some_gem" , output . shift
300+ assert_equal " Version: 2" , output . shift
301+ assert_equal " File: some_gem-2.gem" , output . shift
302+ assert_equal [ ] , output
303+
304+ gem_file = File . join gemspec_dir , File . basename ( @gem . cache_file )
305+ assert File . exist? ( gem_file )
306+
307+ spec = Gem ::Package . new ( gem_file ) . spec
308+
309+ assert_equal "some_gem" , spec . name
310+ assert_equal "this is a summary" , spec . summary
311+ end
312+
313+ def test_execute_outside_dir_no_gemspec_present
314+ gemspec_dir = File . join @tempdir , 'build_command_gem'
315+ gemspec_file = File . join @tempdir , @gem . spec_name
316+ readme_file = File . join gemspec_dir , 'README.md'
317+
318+ FileUtils . mkdir_p gemspec_dir
319+
320+ File . open readme_file , 'w' do |f |
321+ f . write "My awesome gem"
322+ end
323+
324+ File . open gemspec_file , 'w' do |gs |
325+ gs . write @gem . to_ruby
326+ end
327+
328+ @cmd . options [ :build_path ] = gemspec_dir
329+ @cmd . options [ :args ] = [ "*.gemspec" ]
330+
331+ use_ui @ui do
332+ assert_raises Gem ::MockGemUi ::TermError do
333+ @cmd . execute
334+ end
335+ end
336+
337+ assert_equal "" , @ui . output
338+ assert_equal "ERROR: Couldn't find a gemspec file matching '*.gemspec' in #{ gemspec_dir } \n " , @ui . error
339+
340+ gem_file = File . join gemspec_dir , File . basename ( @gem . cache_file )
341+ refute File . exist? ( gem_file )
342+ end
343+
344+ def test_execute_outside_dir_without_gem_name
345+ gemspec_dir = File . join ( @tempdir , 'build_command_gem' )
346+ gemspec_file = File . join ( gemspec_dir , @gem . spec_name )
347+
348+ readme_file = File . join gemspec_dir , 'README.md'
349+
350+ FileUtils . mkdir_p ( gemspec_dir )
351+
352+ File . open readme_file , 'w' do |f |
353+ f . write "My awesome gem"
354+ end
355+
356+ File . open ( gemspec_file , "w" ) do |gs |
357+ gs . write ( @gem . to_ruby )
358+ end
359+
360+ @cmd . options [ :build_path ] = gemspec_dir
361+ @cmd . options [ :args ] = [ ]
362+
363+ use_ui @ui do
364+ Dir . chdir ( gemspec_dir ) do
365+ @cmd . execute
366+ end
367+ end
368+
369+ output = @ui . output . split ( "\n " )
370+ assert_equal " Successfully built RubyGem" , output . shift
371+ assert_equal " Name: some_gem" , output . shift
372+ assert_equal " Version: 2" , output . shift
373+ assert_equal " File: some_gem-2.gem" , output . shift
374+ assert_equal [ ] , output
375+
376+ gem_file = File . join gemspec_dir , File . basename ( @gem . cache_file )
377+ assert File . exist? ( gem_file )
378+
379+ spec = Gem ::Package . new ( gem_file ) . spec
380+
381+ assert_equal "some_gem" , spec . name
382+ assert_equal "this is a summary" , spec . summary
383+ end
384+
385+ def test_execute_outside_dir_with_external_gemspec
386+ gemspec_dir = File . join @tempdir , 'gemspec_dir'
387+ gemspec_file = File . join gemspec_dir , @gem . spec_name
388+
389+ gemcode_dir = File . join @tempdir , 'build_command_gem'
390+ readme_file = File . join gemcode_dir , 'README.md'
391+
392+ FileUtils . mkdir_p gemspec_dir
393+ FileUtils . mkdir_p gemcode_dir
394+
395+ File . open readme_file , 'w' do |f |
396+ f . write "My awesome gem in nested directory"
397+ end
398+
399+ File . open gemspec_file , 'w' do |gs |
400+ gs . write @gem . to_ruby
401+ end
402+
403+ @cmd . options [ :build_path ] = gemcode_dir
404+ @cmd . options [ :args ] = [ gemspec_file ]
405+
406+ use_ui @ui do
407+ @cmd . execute
408+ end
409+
410+ output = @ui . output . split "\n "
411+ assert_equal " Successfully built RubyGem" , output . shift
412+ assert_equal " Name: some_gem" , output . shift
413+ assert_equal " Version: 2" , output . shift
414+ assert_equal " File: some_gem-2.gem" , output . shift
415+ assert_equal [ ] , output
416+
417+ gem_file = File . join gemcode_dir , File . basename ( @gem . cache_file )
418+ assert File . exist? ( gem_file )
419+
420+ spec = Gem ::Package . new ( gem_file ) . spec
421+
422+ assert_equal "some_gem" , spec . name
423+ assert_equal "this is a summary" , spec . summary
424+ end
425+
426+ def test_execute_outside_dir_with_external_relative_gemspec
427+ gemspec_dir = File . join @tempdir , 'gemspec_dir'
428+ gemspec_file = File . join gemspec_dir , @gem . spec_name
429+
430+ gemcode_dir = File . join @tempdir , 'build_command_gem'
431+ readme_file = File . join gemcode_dir , 'README.md'
432+
433+ FileUtils . mkdir_p gemspec_dir
434+ FileUtils . mkdir_p gemcode_dir
435+
436+ File . open readme_file , 'w' do |f |
437+ f . write "My awesome gem in nested directory"
438+ end
439+
440+ File . open gemspec_file , 'w' do |gs |
441+ gs . write @gem . to_ruby
442+ end
443+
444+ @cmd . options [ :build_path ] = gemcode_dir
445+ @cmd . options [ :args ] = [ File . join ( ".." , "gemspec_dir" , @gem . spec_name ) ]
446+
447+ use_ui @ui do
448+ @cmd . execute
449+ end
450+
451+ output = @ui . output . split "\n "
452+ assert_equal " Successfully built RubyGem" , output . shift
453+ assert_equal " Name: some_gem" , output . shift
454+ assert_equal " Version: 2" , output . shift
455+ assert_equal " File: some_gem-2.gem" , output . shift
456+ assert_equal [ ] , output
457+
458+ gem_file = File . join gemcode_dir , File . basename ( @gem . cache_file )
459+ assert File . exist? ( gem_file )
460+
461+ spec = Gem ::Package . new ( gem_file ) . spec
462+
463+ assert_equal "some_gem" , spec . name
464+ assert_equal "this is a summary" , spec . summary
465+ end
466+
275467 def test_can_find_gemspecs_without_dot_gemspec
276468 gemspec_file = File . join ( @tempdir , @gem . name )
277469
0 commit comments