@@ -382,6 +382,88 @@ def test_execute_outside_dir_without_gem_name
382382 assert_equal "this is a summary" , spec . summary
383383 end
384384
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+
385467 def test_can_find_gemspecs_without_dot_gemspec
386468 gemspec_file = File . join ( @tempdir , @gem . name )
387469
0 commit comments