summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/test_bundled_ca.rb60
-rw-r--r--test/rubygems/test_gem.rb23
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb6
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb13
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb17
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb30
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb35
-rw-r--r--test/rubygems/test_gem_dependency_resolver_index_specification.rb27
-rw-r--r--test/rubygems/test_gem_ext_builder.rb89
-rw-r--r--test/rubygems/test_gem_ext_cmake_builder.rb10
-rw-r--r--test/rubygems/test_gem_ext_configure_builder.rb18
-rw-r--r--test/rubygems/test_gem_ext_ext_conf_builder.rb39
-rw-r--r--test/rubygems/test_gem_ext_rake_builder.rb4
-rw-r--r--test/rubygems/test_gem_indexer.rb3
-rw-r--r--test/rubygems/test_gem_package.rb29
-rw-r--r--test/rubygems/test_gem_request.rb17
-rw-r--r--test/rubygems/test_gem_source_fetch_problem.rb19
-rw-r--r--test/rubygems/test_gem_specification.rb317
-rw-r--r--test/rubygems/test_gem_stub_specification.rb133
-rw-r--r--test/rubygems/test_gem_uninstaller.rb26
-rw-r--r--test/rubygems/test_gem_uri_formatter.rb8
-rw-r--r--test/rubygems/test_gem_version.rb9
-rw-r--r--test/rubygems/test_require.rb12
24 files changed, 853 insertions, 93 deletions
diff --git a/test/rubygems/test_bundled_ca.rb b/test/rubygems/test_bundled_ca.rb
new file mode 100644
index 0000000000..d2ccdaf484
--- /dev/null
+++ b/test/rubygems/test_bundled_ca.rb
@@ -0,0 +1,60 @@
+require 'rubygems/test_case'
+require 'net/https'
+require 'rubygems/request'
+
+# = Testing Bundled CA
+#
+# The tested hosts are explained in detail here: https://github.com/rubygems/rubygems/commit/5e16a5428f973667cabfa07e94ff939e7a83ebd9
+#
+class TestBundledCA < Gem::TestCase
+
+ THIS_FILE = File.expand_path __FILE__
+
+ def bundled_certificate_store
+ store = OpenSSL::X509::Store.new
+
+ ssl_cert_glob =
+ File.expand_path '../../../lib/rubygems/ssl_certs/*.pem', THIS_FILE
+
+ Dir[ssl_cert_glob].each do |ssl_cert|
+ store.add_file ssl_cert
+ end
+
+ store
+ end
+
+ def assert_https(host)
+ if self.respond_to? :_assertions # minitest <= 4
+ self._assertions += 1
+ else # minitest >= 5
+ self.assertions += 1
+ end
+ http = Net::HTTP.new(host, 443)
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+ http.cert_store = bundled_certificate_store
+ http.get('/')
+ rescue Errno::ENOENT
+ skip "#{host} seems offline, I can't tell whether ssl would work."
+ rescue OpenSSL::SSL::SSLError => e
+ # Only fail for certificate verification errors
+ if e.message =~ /certificate verify failed/
+ flunk "#{host} is not verifiable using the included certificates. Error was: #{e.message}"
+ end
+ raise
+ end
+
+ def test_accessing_rubygems
+ assert_https('rubygems.org')
+ end
+
+ def test_accessing_cloudfront
+ assert_https('d2chzxaqi4y7f8.cloudfront.net')
+ end
+
+ def test_accessing_s3
+ assert_https('s3.amazonaws.com')
+ end
+
+end if ENV['TRAVIS']
+
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 45db153c22..ac40d97c15 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -257,7 +257,12 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories @gemhome
- assert File.directory? File.join(@gemhome, "cache")
+ assert_path_exists File.join @gemhome, 'build_info'
+ assert_path_exists File.join @gemhome, 'cache'
+ assert_path_exists File.join @gemhome, 'doc'
+ assert_path_exists File.join @gemhome, 'extensions'
+ assert_path_exists File.join @gemhome, 'gems'
+ assert_path_exists File.join @gemhome, 'specifications'
end
def test_self_ensure_gem_directories_permissions
@@ -639,6 +644,22 @@ class TestGem < Gem::TestCase
Gem::ConfigMap[:EXEEXT] = orig_exe_ext
end
+ def test_self_ruby_api_version
+ orig_MAJOR, Gem::ConfigMap[:MAJOR] = Gem::ConfigMap[:MAJOR], '1'
+ orig_MINOR, Gem::ConfigMap[:MINOR] = Gem::ConfigMap[:MINOR], '2'
+ orig_TEENY, Gem::ConfigMap[:TEENY] = Gem::ConfigMap[:TEENY], '3'
+
+ Gem.instance_variable_set :@ruby_api_version, nil
+
+ assert_equal '1.2.3', Gem.ruby_api_version
+ ensure
+ Gem.instance_variable_set :@ruby_api_version, nil
+
+ Gem::ConfigMap[:MAJOR] = orig_MAJOR
+ Gem::ConfigMap[:MINOR] = orig_MINOR
+ Gem::ConfigMap[:TEENY] = orig_TEENY
+ end
+
def test_self_ruby_version_1_8_5
util_set_RUBY_VERSION '1.8.5'
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index 24ee9c8bba..7904a2ea36 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -79,7 +79,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert_equal [], output
if check_licenses
- assert_equal "WARNING: licenses is empty\n", @ui.error
+ assert_match "WARNING: licenses is empty", @ui.error
end
gem_file = File.join @tempdir, File.basename(gem.cache_file)
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index 1767397d16..1dde7d1219 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -117,8 +117,9 @@ class TestGemCommandsPristineCommand < Gem::TestCase
write_file ext_path do |io|
io.write <<-'RUBY'
File.open "Makefile", "w" do |f|
+ f.puts "clean:\n\techo cleaned\n"
f.puts "all:\n\techo built\n"
- f.puts "install:\n\techo built\n"
+ f.puts "install:\n\techo installed\n"
end
RUBY
end
@@ -177,8 +178,9 @@ class TestGemCommandsPristineCommand < Gem::TestCase
write_file ext_path do |io|
io.write <<-'RUBY'
File.open "Makefile", "w" do |f|
+ f.puts "clean:\n\techo cleaned\n"
f.puts "all:\n\techo built\n"
- f.puts "install:\n\techo built\n"
+ f.puts "install:\n\techo installed\n"
end
RUBY
end
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
index 519af595a0..ccd64810fb 100644
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ b/test/rubygems/test_gem_commands_query_command.rb
@@ -577,5 +577,18 @@ pl \(1\)
assert_equal '', @ui.error
end
+ def test_show_gems
+ @cmd.options[:name] = //
+ @cmd.options[:domain] = :remote
+
+ use_ui @ui do
+ @cmd.send :show_gems, /a/i, false
+ end
+
+ assert_match %r%^a %, @ui.output
+ refute_match %r%^pl %, @ui.output
+ assert_empty @ui.error
+ end
+
end
diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb
index 1e5afca009..d1f39425ed 100644
--- a/test/rubygems/test_gem_commands_sources_command.rb
+++ b/test/rubygems/test_gem_commands_sources_command.rb
@@ -198,6 +198,23 @@ beta-gems.example.com is not a URI
refute File.exist?(dir), 'cache dir removed'
end
+ def test_execute_list
+ @cmd.handle_options %w[--list]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+*** CURRENT SOURCES ***
+
+#{@gem_repo}
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
def test_execute_remove
@cmd.handle_options %W[--remove #{@gem_repo}]
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index 189af0ee4b..181784b61c 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -373,6 +373,36 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
assert user_install, 'user_install must be set on the installer'
end
+ def test_fetch_remote_gems
+ expected = [
+ [Gem::NameTuple.new('a', v(2), Gem::Platform::RUBY),
+ Gem::Source.new(@gem_repo)],
+ ]
+
+ assert_equal expected, @cmd.fetch_remote_gems(@a1)
+ end
+
+ def test_fetch_remote_gems_error
+ Gem.sources.replace %w[http://nonexistent.example]
+
+ assert_raises Gem::RemoteFetcher::FetchError do
+ @cmd.fetch_remote_gems @a1
+ end
+ end
+
+ def test_fetch_remote_gems_prerelease
+ @cmd.options[:prerelease] = true
+
+ expected = [
+ [Gem::NameTuple.new('a', v(2), Gem::Platform::RUBY),
+ Gem::Source.new(@gem_repo)],
+ [Gem::NameTuple.new('a', v('3.a'), Gem::Platform::RUBY),
+ Gem::Source.new(@gem_repo)],
+ ]
+
+ assert_equal expected, @cmd.fetch_remote_gems(@a1)
+ end
+
def test_handle_options_system
@cmd.handle_options %w[--system]
diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb
index af6b922fe3..8433be6bd0 100644
--- a/test/rubygems/test_gem_dependency_installer.rb
+++ b/test/rubygems/test_gem_dependency_installer.rb
@@ -388,6 +388,41 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
end
+ def test_install_dependency_existing_extension
+ extconf_rb = File.join @gemhome, 'gems', 'e-1', 'extconf.rb'
+ FileUtils.mkdir_p File.dirname extconf_rb
+
+ open extconf_rb, 'w' do |io|
+ io.write <<-EXTCONF_RB
+ require 'mkmf'
+ create_makefile 'e'
+ EXTCONF_RB
+ end
+
+ e1 = new_spec 'e', '1', nil, 'extconf.rb' do |s|
+ s.extensions << 'extconf.rb'
+ end
+ e1_gem = File.join @tempdir, 'gems', "#{e1.full_name}.gem"
+
+ _, f1_gem = util_gem 'f', '1', 'e' => nil
+
+ Gem::Installer.new(e1_gem).install
+ FileUtils.rm_r e1.extension_install_dir
+
+ FileUtils.mv e1_gem, @tempdir
+ FileUtils.mv f1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'f'
+ end
+
+ assert_equal %w[f-1], inst.installed_gems.map { |s| s.full_name }
+
+ assert_path_exists e1.extension_install_dir
+ end
+
def test_install_dependency_old
_, e1_gem = util_gem 'e', '1'
_, f1_gem = util_gem 'f', '1', 'e' => nil
diff --git a/test/rubygems/test_gem_dependency_resolver_index_specification.rb b/test/rubygems/test_gem_dependency_resolver_index_specification.rb
index 20a7e7d85b..b1e74a3cd1 100644
--- a/test/rubygems/test_gem_dependency_resolver_index_specification.rb
+++ b/test/rubygems/test_gem_dependency_resolver_index_specification.rb
@@ -1,5 +1,6 @@
require 'rubygems/test_case'
require 'rubygems/dependency_resolver'
+require 'rubygems/available_set'
class TestGemDependencyResolverIndexSpecification < Gem::TestCase
@@ -18,6 +19,17 @@ class TestGemDependencyResolverIndexSpecification < Gem::TestCase
assert_equal source, spec.source
end
+ def test_initialize_platform
+ set = Gem::DependencyResolver::IndexSet.new
+ source = Gem::Source::Local.new
+ version = Gem::Version.new '3.0.3'
+
+ spec = Gem::DependencyResolver::IndexSpecification.new(
+ set, 'rails', version, source, Gem::Platform.local)
+
+ assert_equal Gem::Platform.local.to_s, spec.platform
+ end
+
def test_spec
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
@@ -41,6 +53,21 @@ class TestGemDependencyResolverIndexSpecification < Gem::TestCase
assert_equal a_2_p.full_name, spec.full_name
end
+ def test_spec_local
+ a_2_p = quick_spec 'a', 2 do |s| s.platform = Gem::Platform.local end
+ Gem::Package.build a_2_p
+
+ source = Gem::Source::Local.new
+ set = Gem::DependencyResolver::InstallerSet.new :local
+ set.always_install << a_2_p
+
+ i_spec = Gem::DependencyResolver::IndexSpecification.new \
+ set, 'a', v(2), source, Gem::Platform.local
+
+ spec = i_spec.spec
+
+ assert_equal a_2_p.full_name, spec.full_name
+ end
end
diff --git a/test/rubygems/test_gem_ext_builder.rb b/test/rubygems/test_gem_ext_builder.rb
index 8383040f88..ccd1af9d87 100644
--- a/test/rubygems/test_gem_ext_builder.rb
+++ b/test/rubygems/test_gem_ext_builder.rb
@@ -36,6 +36,9 @@ class TestGemExtBuilder < Gem::TestCase
all:
\t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}"
+clean:
+\t@#{Gem.ruby} -e "puts %Q{clean: \#{ENV['DESTDIR']}}"
+
install:
\t@#{Gem.ruby} -e "puts %Q{install: \#{ENV['DESTDIR']}}"
MAKEFILE
@@ -46,21 +49,49 @@ install:
results = results.join "\n"
-
if RUBY_VERSION > '2.0' then
+ assert_match %r%"DESTDIR=#{ENV['DESTDIR']}" clean$%, results
assert_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%, results
assert_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
else
+ refute_match %r%"DESTDIR=#{ENV['DESTDIR']}" clean$%, results
refute_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%, results
refute_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
end
if /nmake/ !~ results
+ assert_match %r%^clean: destination$%, results
assert_match %r%^all: destination$%, results
assert_match %r%^install: destination$%, results
end
end
+ def test_build_extensions
+ @spec.extensions << 'extconf.rb'
+
+ FileUtils.mkdir_p @spec.gem_dir
+
+ extconf_rb = File.join @spec.gem_dir, 'extconf.rb'
+
+ open extconf_rb, 'w' do |f|
+ f.write <<-'RUBY'
+ open 'Makefile', 'w' do |f|
+ f.puts "clean:\n\techo cleaned"
+ f.puts "default:\n\techo built"
+ f.puts "install:\n\techo installed"
+ end
+ RUBY
+ end
+
+ use_ui @ui do
+ @builder.build_extensions
+ end
+
+ assert_path_exists @spec.extension_install_dir
+ assert_path_exists @spec.gem_build_complete_path
+ assert_path_exists File.join @spec.extension_install_dir, 'gem_make.out'
+ end
+
def test_build_extensions_none
use_ui @ui do
@builder.build_extensions
@@ -69,13 +100,30 @@ install:
assert_equal '', @ui.output
assert_equal '', @ui.error
- refute File.exist?('gem_make.out')
+ refute_path_exists File.join @spec.extension_install_dir, 'gem_make.out'
+ end
+
+ def test_build_extensions_rebuild_failure
+ FileUtils.mkdir_p @spec.extension_install_dir
+ FileUtils.touch @spec.gem_build_complete_path
+
+ @spec.extensions << nil
+
+ assert_raises Gem::Ext::BuildError do
+ use_ui @ui do
+ @builder.build_extensions
+ end
+ end
+
+ refute_path_exists @spec.gem_build_complete_path
end
def test_build_extensions_extconf_bad
@spec.extensions << 'extconf.rb'
- e = assert_raises Gem::Installer::ExtensionBuildError do
+ FileUtils.mkdir_p @spec.gem_dir
+
+ e = assert_raises Gem::Ext::BuildError do
use_ui @ui do
@builder.build_extensions
end
@@ -87,20 +135,22 @@ install:
@ui.output
assert_equal '', @ui.error
- gem_make_out = File.join @gemhome, 'gems', @spec.full_name, 'gem_make.out'
+ gem_make_out = File.join @spec.extension_install_dir, 'gem_make.out'
assert_match %r%#{Regexp.escape Gem.ruby} extconf\.rb%,
File.read(gem_make_out)
assert_match %r%#{Regexp.escape Gem.ruby}: No such file%,
File.read(gem_make_out)
+
+ refute_path_exists @spec.gem_build_complete_path
end
def test_build_extensions_unsupported
FileUtils.mkdir_p @spec.gem_dir
- gem_make_out = File.join @spec.gem_dir, 'gem_make.out'
+ gem_make_out = File.join @spec.extension_install_dir, 'gem_make.out'
@spec.extensions << nil
- e = assert_raises Gem::Installer::ExtensionBuildError do
+ e = assert_raises Gem::Ext::BuildError do
use_ui @ui do
@builder.build_extensions
end
@@ -113,6 +163,8 @@ install:
assert_equal '', @ui.error
assert_equal "No builder for extension ''\n", File.read(gem_make_out)
+
+ refute_path_exists @spec.gem_build_complete_path
ensure
FileUtils.rm_f gem_make_out
end
@@ -133,6 +185,7 @@ install:
end
File.open 'Makefile', 'w' do |f|
+ f.puts "clean:\n\techo cleaned"
f.puts "default:\n\techo built"
f.puts "install:\n\techo installed"
end
@@ -146,7 +199,29 @@ install:
path = File.join @spec.gem_dir, "extconf_args"
assert_equal args.inspect, File.read(path).strip
- assert File.directory? File.join(@spec.gem_dir, 'lib')
+ assert_path_exists @spec.extension_install_dir
+ end
+
+ def test_initialize
+ build_info_dir = File.join @gemhome, 'build_info'
+
+ FileUtils.mkdir_p build_info_dir
+
+ build_info_file = File.join build_info_dir, "#{@spec.full_name}.info"
+
+ open build_info_file, 'w' do |io|
+ io.puts '--with-foo-dir=/nonexistent'
+ end
+
+ builder = Gem::Ext::Builder.new @spec
+
+ assert_equal %w[--with-foo-dir=/nonexistent], builder.build_args
+ end
+
+ def test_initialize_build_args
+ builder = Gem::Ext::Builder.new @spec, %w[--with-foo-dir=/nonexistent]
+
+ assert_equal %w[--with-foo-dir=/nonexistent], builder.build_args
end
end
diff --git a/test/rubygems/test_gem_ext_cmake_builder.rb b/test/rubygems/test_gem_ext_cmake_builder.rb
index 24960144d7..b3e32977f4 100644
--- a/test/rubygems/test_gem_ext_cmake_builder.rb
+++ b/test/rubygems/test_gem_ext_cmake_builder.rb
@@ -57,13 +57,7 @@ install (FILES test.txt DESTINATION bin)
shell_error_msg = %r{(CMake Error: .*)}
sh_prefix_cmake = "cmake . -DCMAKE_INSTALL_PREFIX="
- expected = %r(cmake failed:
-
-#{Regexp.escape sh_prefix_cmake}#{Regexp.escape @dest_path}
-#{shell_error_msg}
-)
-
- assert_match expected, error.message
+ assert_match 'cmake failed', error.message
assert_match %r%^#{sh_prefix_cmake}#{Regexp.escape @dest_path}%, output
assert_match %r%#{shell_error_msg}%, output
@@ -71,7 +65,7 @@ install (FILES test.txt DESTINATION bin)
def test_self_build_has_makefile
File.open File.join(@ext, 'Makefile'), 'w' do |makefile|
- makefile.puts "all:\n\t@echo ok\ninstall:\n\t@echo ok"
+ makefile.puts "clean:\n\t@echo ok\nall:\n\t@echo ok\ninstall:\n\t@echo ok"
end
output = []
diff --git a/test/rubygems/test_gem_ext_configure_builder.rb b/test/rubygems/test_gem_ext_configure_builder.rb
index 6137795111..34e9fccd46 100644
--- a/test/rubygems/test_gem_ext_configure_builder.rb
+++ b/test/rubygems/test_gem_ext_configure_builder.rb
@@ -6,7 +6,8 @@ class TestGemExtConfigureBuilder < Gem::TestCase
def setup
super
- @makefile_body = "all:\n\t@echo ok\ninstall:\n\t@echo ok"
+ @makefile_body =
+ "clean:\n\t@echo ok\nall:\n\t@echo ok\ninstall:\n\t@echo ok"
@ext = File.join @tempdir, 'ext'
@dest_path = File.join @tempdir, 'prefix'
@@ -30,6 +31,8 @@ class TestGemExtConfigureBuilder < Gem::TestCase
assert_equal "sh ./configure --prefix=#{@dest_path}", output.shift
assert_equal "", output.shift
+ assert_contains_make_command 'clean', output.shift
+ assert_match(/^ok$/m, output.shift)
assert_contains_make_command '', output.shift
assert_match(/^ok$/m, output.shift)
assert_contains_make_command 'install', output.shift
@@ -49,13 +52,7 @@ class TestGemExtConfigureBuilder < Gem::TestCase
shell_error_msg = %r{(\./configure: .*)|((?:Can't|cannot) open \./configure(?:: No such file or directory)?)}
sh_prefix_configure = "sh ./configure --prefix="
- expected = %r(configure failed:
-
-#{Regexp.escape sh_prefix_configure}#{Regexp.escape @dest_path}
-(?:.*?: )?#{shell_error_msg}
-)
-
- assert_match expected, error.message
+ assert_match 'configure failed', error.message
assert_equal "#{sh_prefix_configure}#{@dest_path}", output.shift
assert_match %r(#{shell_error_msg}), output.shift
@@ -76,8 +73,9 @@ class TestGemExtConfigureBuilder < Gem::TestCase
Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
end
- assert_contains_make_command '', output[0]
- assert_contains_make_command 'install', output[2]
+ assert_contains_make_command 'clean', output[0]
+ assert_contains_make_command '', output[2]
+ assert_contains_make_command 'install', output[4]
end
end
diff --git a/test/rubygems/test_gem_ext_ext_conf_builder.rb b/test/rubygems/test_gem_ext_ext_conf_builder.rb
index dfbf3fe1b9..aa9008c793 100644
--- a/test/rubygems/test_gem_ext_ext_conf_builder.rb
+++ b/test/rubygems/test_gem_ext_ext_conf_builder.rb
@@ -35,8 +35,9 @@ class TestGemExtExtConfBuilder < Gem::TestCase
assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
assert_equal "creating Makefile\n", output[1]
- assert_contains_make_command '', output[2]
- assert_contains_make_command 'install', output[4]
+ assert_contains_make_command 'clean', output[2]
+ assert_contains_make_command '', output[4]
+ assert_contains_make_command 'install', output[6]
assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
end
@@ -54,8 +55,9 @@ class TestGemExtExtConfBuilder < Gem::TestCase
end
assert_equal "creating Makefile\n", output[1]
- assert_contains_make_command '', output[2]
- assert_contains_make_command 'install', output[4]
+ assert_contains_make_command 'clean', output[2]
+ assert_contains_make_command '', output[4]
+ assert_contains_make_command 'install', output[6]
ensure
RbConfig::CONFIG['configure_args'] = configure_args
end
@@ -77,8 +79,8 @@ class TestGemExtExtConfBuilder < Gem::TestCase
end
end
- assert_equal "creating Makefile\n", output[1]
- assert_contains_make_command '', output[2]
+ assert_equal "creating Makefile\n", output[1]
+ assert_contains_make_command 'clean', output[2]
ensure
RbConfig::CONFIG['configure_args'] = configure_args
ENV['make'] = env_make
@@ -103,10 +105,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase
end
end
- assert_match(/\Aextconf failed:
-
-#{Gem.ruby} extconf.rb.*
-checking for main\(\) in .*?nonexistent/m, error.message)
+ assert_equal 'extconf failed, exit code 1', error.message
assert_equal("#{Gem.ruby} extconf.rb", output[0])
end
@@ -130,6 +129,7 @@ ruby =
open 'Makefile', 'w' do |io|
io.write <<-Makefile
+clean: ruby
all: ruby
install: ruby
@@ -147,8 +147,9 @@ end
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
end
- assert_contains_make_command '', output[2]
- assert_contains_make_command 'install', output[4]
+ assert_contains_make_command 'clean', output[2]
+ assert_contains_make_command '', output[4]
+ assert_contains_make_command 'install', output[6]
assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
end
@@ -163,6 +164,7 @@ end
makefile.puts "# π"
makefile.puts "RUBYARCHDIR = $(foo)$(target_prefix)"
makefile.puts "RUBYLIBDIR = $(bar)$(target_prefix)"
+ makefile.puts "clean:"
makefile.puts "all:"
makefile.puts "install:"
end
@@ -171,8 +173,9 @@ end
Gem::Ext::ExtConfBuilder.make @ext, output
end
- assert_contains_make_command '', output[0]
- assert_contains_make_command 'install', output[2]
+ assert_contains_make_command 'clean', output[0]
+ assert_contains_make_command '', output[2]
+ assert_contains_make_command 'install', output[4]
end
def test_class_make_no_Makefile
@@ -182,13 +185,7 @@ end
end
end
- expected = <<-EOF.strip
-Makefile not found:
-
-output
- EOF
-
- assert_equal expected, error.message
+ assert_equal 'Makefile not found', error.message
end
end
diff --git a/test/rubygems/test_gem_ext_rake_builder.rb b/test/rubygems/test_gem_ext_rake_builder.rb
index c8fceb63ee..0f4789a68f 100644
--- a/test/rubygems/test_gem_ext_rake_builder.rb
+++ b/test/rubygems/test_gem_ext_rake_builder.rb
@@ -56,9 +56,7 @@ class TestGemExtRakeBuilder < Gem::TestCase
end
end
- assert_match %r%^rake failed:%, error.message
- assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, error.message
- assert_match %r%^#{Regexp.escape rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, error.message
+ assert_match %r%^rake failed%, error.message
end
end
diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb
index f942ebfadd..ea2be55653 100644
--- a/test/rubygems/test_gem_indexer.rb
+++ b/test/rubygems/test_gem_indexer.rb
@@ -24,6 +24,9 @@ class TestGemIndexer < Gem::TestCase
@d2_0_b = quick_spec 'd', '2.0.b'
util_build_gem @d2_0_b
+ @default = new_default_spec 'default', 2
+ install_default_gems @default
+
@tempdir = File.join(@tempdir, 'indexer')
gems = File.join(@tempdir, 'gems')
diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb
index 79258ca3b4..6a328d5a53 100644
--- a/test/rubygems/test_gem_package.rb
+++ b/test/rubygems/test_gem_package.rb
@@ -427,6 +427,19 @@ class TestGemPackage < Gem::Package::TarTestCase
assert_path_exists extracted
end
+ def test_extract_tar_gz_dot_file
+ package = Gem::Package.new @gem
+
+ tgz_io = util_tar_gz do |tar|
+ tar.add_file '.dot_file.rb', 0644 do |io| io.write 'hi' end
+ end
+
+ package.extract_tar_gz tgz_io, @destination
+
+ extracted = File.join @destination, '.dot_file.rb'
+ assert_path_exists extracted
+ end
+
def test_install_location
package = Gem::Package.new @gem
@@ -450,6 +463,22 @@ class TestGemPackage < Gem::Package::TarTestCase
"#{@destination} is not allowed", e.message)
end
+ def test_install_location_dots
+ package = Gem::Package.new @gem
+
+ file = 'file.rb'
+
+ destination = File.join @destination, 'foo', '..', 'bar'
+
+ FileUtils.mkdir_p File.join @destination, 'foo'
+ FileUtils.mkdir_p File.expand_path destination
+
+ destination = package.install_location file, destination
+
+ # this test only fails on ruby missing File.realpath
+ assert_equal File.join(@destination, 'bar', 'file.rb'), destination
+ end
+
def test_install_location_extra_slash
skip 'no File.realpath on 1.8' if RUBY_VERSION < '1.9'
package = Gem::Package.new @gem
diff --git a/test/rubygems/test_gem_request.rb b/test/rubygems/test_gem_request.rb
index f8b9a90897..04ff50786f 100644
--- a/test/rubygems/test_gem_request.rb
+++ b/test/rubygems/test_gem_request.rb
@@ -89,6 +89,17 @@ class TestGemRequest < Gem::TestCase
assert_equal 'my bar', Gem::UriFormatter.new(proxy.password).unescape
end
+ def test_get_proxy_from_env_escape
+ ENV['http_proxy'] = @proxy_uri
+ ENV['http_proxy_user'] = 'foo@user'
+ ENV['http_proxy_pass'] = 'my@bar'
+
+ proxy = @request.get_proxy_from_env
+
+ assert_equal 'foo%40user', proxy.user
+ assert_equal 'my%40bar', proxy.password
+ end
+
def test_get_proxy_from_env_normalize
ENV['HTTP_PROXY'] = 'fakeurl:12345'
@@ -126,7 +137,7 @@ class TestGemRequest < Gem::TestCase
def test_fetch_unmodified
uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
- t = Time.now
+ t = Time.utc(2013, 1, 2, 3, 4, 5)
@request = Gem::Request.new(uri, Net::HTTP::Get, t, nil)
conn = util_stub_connection_for :body => '', :code => 304
@@ -135,7 +146,9 @@ class TestGemRequest < Gem::TestCase
assert_equal 304, response.code
assert_equal '', response.body
- assert_equal t.rfc2822, conn.payload['if-modified-since']
+ modified_header = conn.payload['if-modified-since']
+
+ assert_equal 'Wed, 02 Jan 2013 03:04:05 GMT', modified_header
end
def test_user_agent
diff --git a/test/rubygems/test_gem_source_fetch_problem.rb b/test/rubygems/test_gem_source_fetch_problem.rb
new file mode 100644
index 0000000000..e8d4785a31
--- /dev/null
+++ b/test/rubygems/test_gem_source_fetch_problem.rb
@@ -0,0 +1,19 @@
+require 'rubygems/test_case'
+
+class TestGemSourceFetchProblem < Gem::TestCase
+
+ def test_exception
+ source = Gem::Source.new @gem_repo
+ error = RuntimeError.new 'test'
+
+ sf = Gem::SourceFetchProblem.new source, error
+
+ e = assert_raises RuntimeError do
+ raise sf
+ end
+
+ assert_equal 'test', e.message
+ end
+
+end
+
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 2e2074fb29..9f7c354334 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -1,6 +1,8 @@
-# -*- coding: us-ascii -*-
+# -*- coding: UTF-8 -*-
require 'rubygems/test_case'
+require 'pathname'
require 'stringio'
+require 'rubygems/ext'
require 'rubygems/specification'
class TestGemSpecification < Gem::TestCase
@@ -56,12 +58,23 @@ end
end
end
+ def ext_spec
+ @ext = quick_spec 'ext', '1' do |s|
+ s.executable = 'exec'
+ s.test_file = 'test/suite.rb'
+ s.extensions = %w[ext/extconf.rb]
+ s.license = 'MIT'
+
+ s.mark_version
+ s.files = %w[lib/code.rb]
+ end
+ end
+
def setup
super
@a1 = quick_spec 'a', '1' do |s|
s.executable = 'exec'
- s.extensions << 'ext/a/extconf.rb'
s.test_file = 'test/suite.rb'
s.requirements << 'A working computer'
s.rubyforge_project = 'example'
@@ -1062,6 +1075,170 @@ dependencies: []
assert_equal %w[lib/code.rb app].sort, @a2.files
end
+ def test_build_extensions
+ ext_spec
+
+ refute_path_exists @ext.extension_install_dir, 'sanity check'
+ refute_empty @ext.extensions, 'sanity check'
+
+ extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
+ FileUtils.mkdir_p File.dirname extconf_rb
+
+ open extconf_rb, 'w' do |f|
+ f.write <<-'RUBY'
+ open 'Makefile', 'w' do |f|
+ f.puts "clean:\n\techo clean"
+ f.puts "default:\n\techo built"
+ f.puts "install:\n\techo installed"
+ end
+ RUBY
+ end
+
+ @ext.build_extensions
+
+ assert_path_exists @ext.extension_install_dir
+ end
+
+ def test_build_extensions_built
+ ext_spec
+
+ refute_empty @ext.extensions, 'sanity check'
+
+ gem_build_complete =
+ File.join @ext.extension_install_dir, 'gem.build_complete'
+
+ FileUtils.mkdir_p @ext.extension_install_dir
+ FileUtils.touch gem_build_complete
+
+ @ext.build_extensions
+
+ gem_make_out = File.join @ext.extension_install_dir, 'gem_make.out'
+ refute_path_exists gem_make_out
+ end
+
+ def test_build_extensions_default_gem
+ spec = new_default_spec 'default', 1
+ spec.extensions << 'extconf.rb'
+
+ extconf_rb = File.join spec.gem_dir, spec.extensions.first
+ FileUtils.mkdir_p File.dirname extconf_rb
+
+ open extconf_rb, 'w' do |f|
+ f.write <<-'RUBY'
+ open 'Makefile', 'w' do |f|
+ f.puts "default:\n\techo built"
+ f.puts "install:\n\techo installed"
+ end
+ RUBY
+ end
+
+ spec.build_extensions
+
+ refute_path_exists spec.extension_install_dir
+ end
+
+ def test_build_extensions_error
+ ext_spec
+
+ refute_empty @ext.extensions, 'sanity check'
+
+ assert_raises Gem::Ext::BuildError do
+ @ext.build_extensions
+ end
+ end
+
+ def test_build_extensions_extensions_dir_unwritable
+ skip 'chmod not supported' if Gem.win_platform?
+
+ ext_spec
+
+ refute_empty @ext.extensions, 'sanity check'
+
+ extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
+ FileUtils.mkdir_p File.dirname extconf_rb
+
+ open extconf_rb, 'w' do |f|
+ f.write <<-'RUBY'
+ open 'Makefile', 'w' do |f|
+ f.puts "clean:\n\techo clean"
+ f.puts "default:\n\techo built"
+ f.puts "install:\n\techo installed"
+ end
+ RUBY
+ end
+
+ FileUtils.mkdir_p File.join @ext.base_dir, 'extensions'
+ FileUtils.chmod 0555, @ext.base_dir
+ FileUtils.chmod 0555, File.join(@ext.base_dir, 'extensions')
+
+ assert_raises Errno::EACCES do
+ @ext.build_extensions
+ end
+ ensure
+ FileUtils.chmod 0755, File.join(@ext.base_dir, 'extensions')
+ FileUtils.chmod 0755, @ext.base_dir
+ end
+
+ def test_build_extensions_no_extensions_dir_unwritable
+ skip 'chmod not supported' if Gem.win_platform?
+
+ ext_spec
+
+ refute_empty @ext.extensions, 'sanity check'
+
+ extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
+ FileUtils.mkdir_p File.dirname extconf_rb
+
+ open extconf_rb, 'w' do |f|
+ f.write <<-'RUBY'
+ open 'Makefile', 'w' do |f|
+ f.puts "clean:\n\techo clean"
+ f.puts "default:\n\techo built"
+ f.puts "install:\n\techo installed"
+ end
+ RUBY
+ end
+
+ FileUtils.rm_r File.join @gemhome, 'extensions'
+ FileUtils.chmod 0555, @gemhome
+
+ @ext.build_extensions
+
+ gem_make_out = File.join @ext.extension_install_dir, 'gem_make.out'
+ refute_path_exists gem_make_out
+ ensure
+ FileUtils.chmod 0755, @gemhome
+ end
+
+ def test_contains_requirable_file_eh
+ code_rb = File.join @a1.gem_dir, 'lib', 'code.rb'
+ FileUtils.mkdir_p File.dirname code_rb
+ FileUtils.touch code_rb
+
+ assert @a1.contains_requirable_file? 'code'
+ end
+
+ def test_contains_requirable_file_eh_extension
+ ext_spec
+
+ extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
+ FileUtils.mkdir_p File.dirname extconf_rb
+
+ open extconf_rb, 'w' do |f|
+ f.write <<-'RUBY'
+ open 'Makefile', 'w' do |f|
+ f.puts "clean:\n\techo cleaned"
+ f.puts "default:\n\techo built"
+ f.puts "install:\n\techo installed"
+ end
+ RUBY
+ end
+
+ refute @ext.contains_requirable_file? 'nonexistent'
+
+ assert_path_exists @ext.extension_install_dir
+ end
+
def test_date
assert_equal Gem::Specification::TODAY, @a1.date
end
@@ -1177,7 +1354,41 @@ dependencies: []
end
def test_extensions
- assert_equal ['ext/a/extconf.rb'], @a1.extensions
+ assert_equal ['ext/extconf.rb'], ext_spec.extensions
+ end
+
+ def test_extension_install_dir_shared
+ enable_shared, RbConfig::CONFIG['ENABLE_SHARED'] =
+ RbConfig::CONFIG['ENABLE_SHARED'], 'yes'
+
+ ext_spec
+
+ refute_empty @ext.extensions
+
+ expected =
+ File.join(@ext.base_dir, 'extensions', Gem::Platform.local.to_s,
+ Gem.ruby_api_version,@ext.full_name)
+
+ assert_equal expected, @ext.extension_install_dir
+ ensure
+ RbConfig::CONFIG['ENABLE_SHARED'] = enable_shared
+ end
+
+ def test_extension_install_dir_static
+ enable_shared, RbConfig::CONFIG['ENABLE_SHARED'] =
+ RbConfig::CONFIG['ENABLE_SHARED'], 'no'
+
+ ext_spec
+
+ refute_empty @ext.extensions
+
+ expected =
+ File.join(@ext.base_dir, 'extensions', Gem::Platform.local.to_s,
+ "#{Gem.ruby_api_version}-static", @ext.full_name)
+
+ assert_equal expected, @ext.extension_install_dir
+ ensure
+ RbConfig::CONFIG['ENABLE_SHARED'] = enable_shared
end
def test_files
@@ -1328,6 +1539,11 @@ dependencies: []
end
end
+ def test_gem_build_complete_path
+ expected = File.join @a1.extension_install_dir, 'gem.build_complete'
+ assert_equal expected, @a1.gem_build_complete_path
+ end
+
def test_hash
assert_equal @a1.hash, @a1.hash
assert_equal @a1.hash, @a1.dup.hash
@@ -1442,14 +1658,29 @@ dependencies: []
end
def test_require_paths
- @a1.require_path = 'lib'
- assert_equal %w[lib], @a1.require_paths
+ ext_spec
+
+ @ext.require_path = 'lib'
+
+ lib = Pathname File.join @ext.gem_dir, 'lib'
+
+ ext_install_dir =
+ Pathname(@ext.extension_install_dir).relative_path_from lib
+
+ assert_equal ['lib', ext_install_dir.to_s], @ext.require_paths
end
def test_full_require_paths
- @a1.require_path = 'lib'
- assert_equal [File.join(@gemhome, 'gems', @a1.original_name, 'lib')],
- @a1.full_require_paths
+ ext_spec
+
+ @ext.require_path = 'lib'
+
+ expected = [
+ File.join(@gemhome, 'gems', @ext.original_name, 'lib'),
+ @ext.extension_install_dir,
+ ]
+
+ assert_equal expected, @ext.full_require_paths
end
def test_require_already_activated
@@ -1577,13 +1808,13 @@ Gem::Specification.new do |s|
s.version = "2"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
+ s.require_paths = ["lib", "other"]
s.authors = ["A User"]
s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
s.description = "This is a test description"
s.email = "example@example.com"
s.files = ["lib/code.rb"]
s.homepage = "http://example.com"
- s.require_paths = ["lib", "other"]
s.rubygems_version = "#{Gem::VERSION}"
s.summary = "this is a summary"
@@ -1625,12 +1856,12 @@ Gem::Specification.new do |s|
s.version = "2"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
+ s.require_paths = ["lib"]
s.authors = ["A User"]
s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
s.description = "This is a test description"
s.email = "example@example.com"
s.homepage = "http://example.com"
- s.require_paths = ["lib"]
s.rubygems_version = "#{Gem::VERSION}"
s.summary = "this is a summary"
@@ -1665,10 +1896,14 @@ end
local = Gem::Platform.local
expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]"
+ stub_require_paths =
+ @c1.instance_variable_get(:@require_paths).join "\u0000"
+ extensions = @c1.extensions.join "\u0000"
expected = <<-SPEC
# -*- encoding: utf-8 -*-
-# stub: a 1 #{win_platform? ? "x86-mswin32-60" : "x86-darwin-8"} lib
+# stub: a 1 #{win_platform? ? "x86-mswin32-60" : "x86-darwin-8"} #{stub_require_paths}
+# stub: #{extensions}
Gem::Specification.new do |s|
s.name = "a"
@@ -1676,6 +1911,7 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform.new(#{expected_platform})
s.required_rubygems_version = Gem::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
+ s.require_paths = ["lib"]
s.authors = ["A User"]
s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
s.description = "This is a test description"
@@ -1685,7 +1921,6 @@ Gem::Specification.new do |s|
s.files = ["bin/exec", "ext/a/extconf.rb", "lib/code.rb", "test/suite.rb"]
s.homepage = "http://example.com"
s.licenses = ["MIT"]
- s.require_paths = ["lib"]
s.requirements = ["A working computer"]
s.rubyforge_project = "example"
s.rubygems_version = "#{Gem::VERSION}"
@@ -1819,7 +2054,7 @@ end
@a1.validate
end
- assert_equal "#{w}: no author specified\n", @ui.error, 'error'
+ assert_match "#{w}: no author specified\n", @ui.error, 'error'
@a1.authors = [Object.new]
@@ -1859,7 +2094,7 @@ end
@a1.validate
end
- assert_equal "#{w}: deprecated autorequire specified\n",
+ assert_match "#{w}: deprecated autorequire specified\n",
@ui.error, 'error'
end
end
@@ -1880,7 +2115,7 @@ end
#{w}: prerelease dependency on c (>= 2.0.rc2, development) is not recommended
EXPECTED
- assert_equal expected, @ui.error, 'warning'
+ assert_match expected, @ui.error, 'warning'
end
end
@@ -1894,7 +2129,7 @@ end
@a1.validate
end
- assert_equal "#{w}: no description specified\n", @ui.error, "error"
+ assert_match "#{w}: no description specified\n", @ui.error, "error"
@ui = Gem::MockGemUi.new
@a1.summary = "this is my summary"
@@ -1904,7 +2139,7 @@ end
@a1.validate
end
- assert_equal "#{w}: description and summary are identical\n",
+ assert_match "#{w}: description and summary are identical\n",
@ui.error, "error"
@a1.description = "#{f} (describe your package)"
@@ -1935,7 +2170,7 @@ end
@a1.validate
end
- assert_equal "#{w}: no email specified\n", @ui.error, "error"
+ assert_match "#{w}: no email specified\n", @ui.error, "error"
@a1.email = "FIxxxXME (your e-mail)".sub(/xxx/, "")
@@ -1963,6 +2198,16 @@ end
assert_equal 'missing value for attribute name', e.message
end
+ def test_validate_error
+ assert_raises Gem::InvalidSpecificationException do
+ use_ui @ui do
+ Gem::Specification.new.validate
+ end
+ end
+
+ assert_match 'See http://guides.rubygems.org/specification-reference/ for help', @ui.error
+ end
+
def test_validate_executables
util_setup_validate
@@ -1979,7 +2224,7 @@ end
assert_equal %w[exec], @a1.executables
assert_equal '', @ui.output, 'output'
- assert_equal "#{w}: bin/exec is missing #! line\n", @ui.error, 'error'
+ assert_match "#{w}: bin/exec is missing #! line\n", @ui.error, 'error'
end
def test_validate_empty_require_paths
@@ -2003,6 +2248,7 @@ end
util_setup_validate
@a1.files += ['lib', 'lib2']
+ @a1.extensions << 'ext/a/extconf.rb'
Dir.chdir @tempdir do
FileUtils.ln_s '/root/path', 'lib2' unless vc_windows?
@@ -2042,7 +2288,7 @@ end
@a1.validate
end
- assert_equal "#{w}: no homepage specified\n", @ui.error, 'error'
+ assert_match "#{w}: no homepage specified\n", @ui.error, 'error'
@ui = Gem::MockGemUi.new
@@ -2052,7 +2298,7 @@ end
@a1.validate
end
- assert_equal "#{w}: no homepage specified\n", @ui.error, 'error'
+ assert_match "#{w}: no homepage specified\n", @ui.error, 'error'
@a1.homepage = 'over at my cool site'
@@ -2064,6 +2310,20 @@ end
end
end
+ def test_validate_license
+ util_setup_validate
+
+ use_ui @ui do
+ @a1.licenses.clear
+ @a1.validate
+ end
+
+ assert_match <<-warning, @ui.error
+WARNING: licenses is empty. Use a license abbreviation from:
+ http://opensource.org/licenses/alphabetical
+ warning
+ end
+
def test_validate_name
util_setup_validate
@@ -2168,7 +2428,7 @@ end
@a1.validate
end
- assert_equal "#{w}: no summary specified\n", @ui.error, 'error'
+ assert_match "#{w}: no summary specified\n", @ui.error, 'error'
@a1.summary = "#{f} (describe your package)"
@@ -2188,6 +2448,17 @@ end
end
end
+ def test_validate_warning
+ util_setup_validate
+
+ use_ui @ui do
+ @a1.licenses.clear
+ @a1.validate
+ end
+
+ assert_match 'See http://guides.rubygems.org/specification-reference/ for help', @ui.error
+ end
+
def test_version
assert_equal Gem::Version.new('1'), @a1.version
end
@@ -2390,13 +2661,13 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.metadata = { "one" => "two", "two" => "three" } if s.respond_to? :metadata=
+ s.require_paths = ["lib"]
s.authors = ["A User"]
s.date = "#{Gem::Specification::TODAY.strftime("%Y-%m-%d")}"
s.description = "This is a test description"
s.email = "example@example.com"
s.files = ["lib/code.rb"]
s.homepage = "http://example.com"
- s.require_paths = ["lib"]
s.rubygems_version = "#{Gem::VERSION}"
s.summary = "this is a summary"
end
diff --git a/test/rubygems/test_gem_stub_specification.rb b/test/rubygems/test_gem_stub_specification.rb
index 6feb96eb4f..e315e2c01a 100644
--- a/test/rubygems/test_gem_stub_specification.rb
+++ b/test/rubygems/test_gem_stub_specification.rb
@@ -6,15 +6,38 @@ class TestStubSpecification < Gem::TestCase
FOO = File.join SPECIFICATIONS, "foo-0.0.1.gemspec"
BAR = File.join SPECIFICATIONS, "bar-0.0.2.gemspec"
- def test_basic
- stub = Gem::StubSpecification.new(FOO)
- assert_equal "foo", stub.name
- assert_equal Gem::Version.new("0.0.1"), stub.version
- assert_equal Gem::Platform.new("mswin32"), stub.platform
- assert_equal ["lib", "lib/f oo/ext"], stub.require_paths
+ def setup
+ super
+
+ @foo = Gem::StubSpecification.new FOO
+ end
+
+ def test_initialize
+ assert_equal "foo", @foo.name
+ assert_equal Gem::Version.new("0.0.1"), @foo.version
+ assert_equal Gem::Platform.new("mswin32"), @foo.platform
+ assert_equal ["lib", "lib/f oo/ext"], @foo.require_paths
+ end
+
+ def test_initialize_extension
+ stub = stub_with_extension
+
+ gem_dir = File.join stub.gems_dir, stub.full_name
+
+ lib = Pathname File.join gem_dir, 'lib'
+
+ ext_install_dir =
+ Pathname(stub.extension_install_dir).relative_path_from lib
+ ext_install_dir = ext_install_dir.to_s
+
+ assert_equal 'stub_e', stub.name
+ assert_equal v(2), stub.version
+ assert_equal Gem::Platform::RUBY, stub.platform
+ assert_equal ['lib', ext_install_dir], stub.require_paths
+ assert_equal %w[ext/stub_e/extconf.rb], stub.extensions
end
- def test_missing_stubline
+ def test_initialize_missing_stubline
stub = Gem::StubSpecification.new(BAR)
assert_equal "bar", stub.name
assert_equal Gem::Version.new("0.0.2"), stub.version
@@ -22,9 +45,99 @@ class TestStubSpecification < Gem::TestCase
assert_equal ["lib"], stub.require_paths
end
+ def test_contains_requirable_file_eh
+ stub = stub_without_extension
+ code_rb = File.join stub.gem_dir, 'lib', 'code.rb'
+ FileUtils.mkdir_p File.dirname code_rb
+ FileUtils.touch code_rb
+
+ assert stub.contains_requirable_file? 'code'
+ end
+
+ def test_contains_requirable_file_eh_extension
+ stub_with_extension do |stub|
+ extconf_rb = File.join stub.gem_dir, stub.extensions.first
+ FileUtils.mkdir_p File.dirname extconf_rb
+
+ open extconf_rb, 'w' do |f|
+ f.write <<-'RUBY'
+ open 'Makefile', 'w' do |f|
+ f.puts "clean:\n\techo cleaned"
+ f.puts "default:\n\techo built"
+ f.puts "install:\n\techo installed"
+ end
+ RUBY
+ end
+
+ refute stub.contains_requirable_file? 'nonexistent'
+
+ assert_path_exists stub.extension_install_dir
+ end
+ end
+
+ def test_full_require_paths
+ stub = stub_with_extension
+
+ expected = [
+ File.join(stub.full_gem_path, 'lib'),
+ stub.extension_install_dir,
+ ]
+
+ assert_equal expected, stub.full_require_paths
+ end
+
def test_to_spec
- stub = Gem::StubSpecification.new(FOO)
- assert stub.to_spec.is_a?(Gem::Specification)
- assert_equal "foo", stub.to_spec.name
+ assert @foo.to_spec.is_a?(Gem::Specification)
+ assert_equal "foo", @foo.to_spec.name
end
+
+ def stub_with_extension
+ spec = File.join @gemhome, 'specifications', 'stub_e-2.gemspec'
+ open spec, 'w' do |io|
+ io.write <<-STUB
+# -*- encoding: utf-8 -*-
+# stub: stub_e 2 ruby lib
+# stub: ext/stub_e/extconf.rb
+
+Gem::Specification.new do |s|
+ s.name = 'stub_e'
+ s.version = Gem::Version.new '2'
+ s.extensions = ['ext/stub_e/extconf.rb']
end
+ STUB
+
+ io.flush
+
+ stub = Gem::StubSpecification.new io.path
+
+ yield stub if block_given?
+
+ return stub
+ end
+ end
+
+ def stub_without_extension
+ spec = File.join @gemhome, 'specifications', 'stub-2.gemspec'
+ open spec, 'w' do |io|
+ io.write <<-STUB
+# -*- encoding: utf-8 -*-
+# stub: stub 2 ruby lib
+
+Gem::Specification.new do |s|
+ s.name = 'stub'
+ s.version = Gem::Version.new '2'
+end
+ STUB
+
+ io.flush
+
+ stub = Gem::StubSpecification.new io.path
+
+ yield stub if block_given?
+
+ return stub
+ end
+ end
+
+end
+
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb
index bb17dbf266..49ccea4a5c 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -205,6 +205,32 @@ class TestGemUninstaller < Gem::InstallerTestCase
refute_path_exists spec.gem_dir
end
+ def test_uninstall_extension
+ @spec.extensions << 'extconf.rb'
+ write_file File.join(@tempdir, 'extconf.rb') do |io|
+ io.write <<-RUBY
+require 'mkmf'
+create_makefile '#{@spec.name}'
+ RUBY
+ end
+
+ @spec.files += %w[extconf.rb]
+
+ use_ui @ui do
+ path = Gem::Package.build @spec
+
+ installer = Gem::Installer.new path
+ installer.install
+ end
+
+ assert_path_exists @spec.extension_install_dir, 'sanity check'
+
+ uninstaller = Gem::Uninstaller.new @spec.name, :executables => true
+ uninstaller.uninstall
+
+ refute_path_exists @spec.extension_install_dir
+ end
+
def test_uninstall_nonexistent
uninstaller = Gem::Uninstaller.new 'bogus', :executables => true
diff --git a/test/rubygems/test_gem_uri_formatter.rb b/test/rubygems/test_gem_uri_formatter.rb
index b185797a3a..628b7c54de 100644
--- a/test/rubygems/test_gem_uri_formatter.rb
+++ b/test/rubygems/test_gem_uri_formatter.rb
@@ -16,5 +16,13 @@ class TestGemUriFormatter < Gem::TestCase
Gem::UriFormatter.new('example/').normalize
end
+ def test_escape
+ assert_equal 'a%40b%5Cc', Gem::UriFormatter.new('a@b\c').escape
+ end
+
+ def test_unescape
+ assert_equal 'a@b\c', Gem::UriFormatter.new('a%40b%5Cc').unescape
+ end
+
end
diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb
index 2136034d1f..e0499fe73f 100644
--- a/test/rubygems/test_gem_version.rb
+++ b/test/rubygems/test_gem_version.rb
@@ -23,14 +23,13 @@ class TestGemVersion < Gem::TestCase
assert_bumped_version_equal "6", "5"
end
- # FIX: For "legacy reasons," any object that responds to +version+
- # is returned unchanged. I'm not certain why.
+ # A Gem::Version is already a Gem::Version and therefore not transformed by
+ # Gem::Version.create
def test_class_create
- fake = Object.new
- def fake.version; "1.0" end
+ real = Gem::Version.new(1.0)
- assert_same fake, Gem::Version.create(fake)
+ assert_same real, Gem::Version.create(real)
assert_nil Gem::Version.create(nil)
assert_equal v("5.1"), Gem::Version.create("5.1")
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index b846103f1b..c52c9937fe 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -67,6 +67,18 @@ class TestGemRequire < Gem::TestCase
end
end
+ def test_require_can_use_a_pathname_object
+ a1 = new_spec "a", "1", nil, "lib/test_gem_require_a.rb"
+
+ install_specs a1
+
+ save_loaded_features do
+ assert_require Pathname.new 'test_gem_require_a'
+ assert_equal %w(a-1), loaded_spec_names
+ assert_equal unresolved_names, []
+ end
+ end
+
def test_activate_via_require_respects_loaded_files
require 'benchmark' # stdlib
save_loaded_features do