Skip to content

Commit 283bfc7

Browse files
committed
Test outside dir and no gemspec is present
1 parent a2e6287 commit 283bfc7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/rubygems/commands/build_command.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ def build_gem(gem_name)
9292
if File.exist?(gemspec)
9393
spec = Gem::Specification.load(gemspec)
9494
build_package(spec)
95+
elsif gemspec.scan(".gemspec").size > 1
96+
alert_error "No Gemspec in #{Dir.pwd}"
97+
terminate_interaction(1)
9598
else
9699
alert_error "Gemspec file not found: #{gemspec}"
97100
terminate_interaction(1)

test/rubygems/test_gem_commands_build_command.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,37 @@ def test_execute_outside_dir_with_glob_argument
310310
assert_equal "this is a summary", spec.summary
311311
end
312312

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: No 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+
313344
def test_execute_outside_dir_without_gem_name
314345
gemspec_dir = File.join(@tempdir, 'build_command_gem')
315346
gemspec_file = File.join(gemspec_dir, @gem.spec_name)

0 commit comments

Comments
 (0)