2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/commands/build_command'
|
|
|
|
require 'rubygems/format'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsBuildCommand < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
@gem = quick_spec 'some_gem' do |s|
|
2007-12-20 03:39:12 -05:00
|
|
|
s.rubyforge_project = 'example'
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd = Gem::Commands::BuildCommand.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute
|
2010-02-21 21:52:35 -05:00
|
|
|
gemspec_file = File.join(@tempdir, @gem.spec_name)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
File.open gemspec_file, 'w' do |gs|
|
2007-12-20 03:39:12 -05:00
|
|
|
gs.write @gem.to_ruby
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
util_test_build_gem @gem, gemspec_file
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_yaml
|
2010-02-21 21:52:35 -05:00
|
|
|
gemspec_file = File.join(@tempdir, @gem.spec_name)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
File.open gemspec_file, 'w' do |gs|
|
2007-12-20 03:39:12 -05:00
|
|
|
gs.write @gem.to_yaml
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
util_test_build_gem @gem, gemspec_file
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_execute_bad_spec
|
|
|
|
@gem.date = "2010-11-08"
|
|
|
|
|
|
|
|
gemspec_file = File.join(@tempdir, @gem.spec_name)
|
|
|
|
|
|
|
|
File.open gemspec_file, 'w' do |gs|
|
|
|
|
gs.write @gem.to_ruby.sub(/11-08/, "11-8")
|
|
|
|
end
|
|
|
|
|
|
|
|
@cmd.options[:args] = [gemspec_file]
|
|
|
|
|
|
|
|
out, err = use_ui @ui do
|
|
|
|
capture_io do
|
|
|
|
assert_raises Gem::MockGemUi::TermError do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "", out
|
|
|
|
assert_match(/invalid date format in specification/, err)
|
|
|
|
|
|
|
|
assert_equal '', @ui.output
|
|
|
|
assert_equal "ERROR: Error loading gemspec. Aborting.\n", @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_missing_file
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.options[:args] = %w[some_gem]
|
|
|
|
use_ui @ui do
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_raises Gem::MockGemUi::TermError do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal '', @ui.output
|
|
|
|
assert_equal "ERROR: Gemspec file not found: some_gem\n", @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def util_test_build_gem(gem, gemspec_file)
|
|
|
|
@cmd.options[:args] = [gemspec_file]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
output = @ui.output.split "\n"
|
|
|
|
assert_equal " Successfully built RubyGem", output.shift
|
|
|
|
assert_equal " Name: some_gem", output.shift
|
2007-12-20 03:39:12 -05:00
|
|
|
assert_equal " Version: 2", output.shift
|
|
|
|
assert_equal " File: some_gem-2.gem", output.shift
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal [], output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
gem_file = File.join @tempdir, File.basename(gem.cache_file)
|
2007-11-10 02:48:56 -05:00
|
|
|
assert File.exist?(gem_file)
|
|
|
|
|
|
|
|
spec = Gem::Format.from_file_by_path(gem_file).spec
|
|
|
|
|
|
|
|
assert_equal "some_gem", spec.name
|
|
|
|
assert_equal "this is a summary", spec.summary
|
|
|
|
end
|
|
|
|
|
2012-04-17 20:04:12 -04:00
|
|
|
def test_execute_force
|
|
|
|
@gem.instance_variable_set :@required_rubygems_version, nil
|
|
|
|
|
|
|
|
gemspec_file = File.join(@tempdir, @gem.spec_name)
|
|
|
|
|
|
|
|
File.open gemspec_file, 'w' do |gs|
|
|
|
|
gs.write @gem.to_yaml
|
|
|
|
end
|
|
|
|
|
|
|
|
@cmd.options[:args] = [gemspec_file]
|
|
|
|
@cmd.options[:force] = true
|
|
|
|
|
|
|
|
util_test_build_gem @gem, gemspec_file
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|