diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rdoc/rubygems_hook.rb | 4 | ||||
-rw-r--r-- | lib/rubygems.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/source.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/specification.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/test_case.rb | 120 | ||||
-rw-r--r-- | lib/rubygems/test_utilities.rb | 158 |
6 files changed, 212 insertions, 76 deletions
diff --git a/lib/rdoc/rubygems_hook.rb b/lib/rdoc/rubygems_hook.rb index b4393114f1..b9d3c0fd1f 100644 --- a/lib/rdoc/rubygems_hook.rb +++ b/lib/rdoc/rubygems_hook.rb @@ -156,6 +156,10 @@ class RDoc::RubygemsHook args.concat @spec.require_paths args.concat @spec.extra_rdoc_files + puts + p @spec.extra_rdoc_files + puts + case config_args = Gem.configuration[:rdoc] when String then args = args.concat config_args.split diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 1c8acda74d..1c84356bd7 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -8,7 +8,7 @@ require 'rbconfig' module Gem - VERSION = '2.2.0.preview.2' + VERSION = '2.2.0' end # Must be first since it unloads the prelude from 1.9.2 diff --git a/lib/rubygems/source.rb b/lib/rubygems/source.rb index bcf814b010..b39b3ae69d 100644 --- a/lib/rubygems/source.rb +++ b/lib/rubygems/source.rb @@ -56,8 +56,6 @@ class Gem::Source # Returns a Set that can fetch specifications from this source. def dependency_resolver_set # :nodoc: - uri = api_uri - bundler_api_uri = api_uri + './api/v1/dependencies' begin diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 5a667870c8..308aa6f011 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -1393,7 +1393,7 @@ class Gem::Specification < Gem::BasicSpecification # Returns the build_args used to install the gem def build_args - if File.exists? build_info_file + if File.exist? build_info_file File.readlines(build_info_file).map { |x| x.strip } else [] diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 08109c6405..b04cbfc1f3 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -30,7 +30,6 @@ require 'fileutils' require 'tmpdir' require 'uri' require 'rubygems/package' -require 'rubygems/test_utilities' require 'pp' require 'zlib' require 'pathname' @@ -84,6 +83,8 @@ end class Gem::TestCase < MiniTest::Unit::TestCase + attr_accessor :fetcher # :nodoc: + def assert_activate expected, *specs specs.each do |spec| case spec @@ -197,7 +198,8 @@ class Gem::TestCase < MiniTest::Unit::TestCase @orig_gem_path = ENV['GEM_PATH'] @current_dir = Dir.pwd - @ui = Gem::MockGemUi.new + @fetcher = nil + @ui = Gem::MockGemUi.new tmpdir = File.expand_path Dir.tmpdir tmpdir.untaint @@ -378,7 +380,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase gem = File.join @tempdir, "gems", "#{spec.full_name}.gem" - unless File.exists? gem + unless File.exist? gem then use_ui Gem::MockGemUi.new do Dir.chdir @tempdir do Gem::Package.build spec @@ -503,28 +505,11 @@ class Gem::TestCase < MiniTest::Unit::TestCase return spec end - def quick_spec name, version = '2' - # TODO: deprecate - require 'rubygems/specification' - - spec = Gem::Specification.new do |s| - s.platform = Gem::Platform::RUBY - s.name = name - s.version = version - s.author = 'A User' - s.email = '[email protected]' - s.homepage = 'http://example.com' - s.summary = "this is a summary" - s.description = "This is a test description" - - yield(s) if block_given? - end - - spec.loaded_from = spec.spec_file - - Gem::Specification.add_spec spec + ## + # TODO: remove in RubyGems 3.0 - return spec + def quick_spec name, version = '2' # :nodoc: + util_spec name, version end ## @@ -561,7 +546,9 @@ class Gem::TestCase < MiniTest::Unit::TestCase def util_clear_gems FileUtils.rm_rf File.join(@gemhome, "gems") # TODO: use Gem::Dirs + FileUtils.mkdir File.join(@gemhome, "gems") FileUtils.rm_rf File.join(@gemhome, "specifications") + FileUtils.mkdir File.join(@gemhome, "specifications") Gem::Specification.reset end @@ -612,10 +599,11 @@ class Gem::TestCase < MiniTest::Unit::TestCase end ## - # Create a new spec (or gem if passed an array of files) and set it - # up properly. Use this instead of util_spec and util_gem. + # new_spec is deprecated as it is never used. + # + # TODO: remove in RubyGems 3.0 - def new_spec name, version, deps = nil, *files + def new_spec name, version, deps = nil, *files # :nodoc: require 'rubygems/specification' spec = Gem::Specification.new do |s| @@ -656,7 +644,8 @@ class Gem::TestCase < MiniTest::Unit::TestCase end def new_default_spec(name, version, deps = nil, *files) - spec = new_spec(name, version, deps) + spec = util_spec name, version, deps + spec.loaded_from = File.join(@default_spec_dir, spec.spec_name) spec.files = files @@ -674,24 +663,38 @@ class Gem::TestCase < MiniTest::Unit::TestCase end ## - # Creates a spec with +name+, +version+ and +deps+. + # Creates a spec with +name+, +version+. +deps+ can specify the dependency + # or a +block+ can be given for full customization of the specification. - def util_spec(name, version, deps = nil, &block) - # TODO: deprecate - raise "deps or block, not both" if deps and block + def util_spec name, version = 2, deps = nil # :yields: specification + raise "deps or block, not both" if deps and block_given? + + spec = Gem::Specification.new do |s| + s.platform = Gem::Platform::RUBY + s.name = name + s.version = version + s.author = 'A User' + s.email = '[email protected]' + s.homepage = 'http://example.com' + s.summary = "this is a summary" + s.description = "This is a test description" + + yield s if block_given? + end if deps then - block = proc do |s| - # Since Hash#each is unordered in 1.8, sort - # the keys and iterate that way so the tests are - # deteriminstic on all implementations. - deps.keys.sort.each do |n| - s.add_dependency n, (deps[n] || '>= 0') - end + # Since Hash#each is unordered in 1.8, sort the keys and iterate that + # way so the tests are deterministic on all implementations. + deps.keys.sort.each do |n| + spec.add_dependency n, (deps[n] || '>= 0') end end - quick_spec(name, version, &block) + spec.loaded_from = spec.spec_file + + Gem::Specification.add_spec spec + + return spec end ## @@ -1132,38 +1135,8 @@ Also, a list: # end def spec_fetcher - gems = {} - - fetcher = Object.new - fetcher.instance_variable_set :@test, self - fetcher.instance_variable_set :@gems, gems - - def fetcher.gem name, version, dependencies = nil, &block - spec, gem = @test.util_gem name, version, dependencies, &block - - @gems[spec] = gem - - spec - end - - def fetcher.spec name, version, dependencies = nil, &block - spec = @test.util_spec name, version, dependencies, &block - - @gems[spec] = nil - - spec - end - - yield fetcher - - util_setup_fake_fetcher unless @fetcher - util_setup_spec_fetcher(*gems.keys) - - gems.each do |spec, gem| - next unless gem - - @fetcher.data["http://gems.example.com/gems/#{spec.file_name}"] = - Gem.read_binary(gem) + Gem::TestCase::SpecFetcherSetup.declare self do |spec_fetcher_setup| + yield spec_fetcher_setup if block_given? end end @@ -1318,3 +1291,6 @@ Also, a list: end if defined?(OpenSSL::SSL) end + +require 'rubygems/test_utilities' + diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb index eddabeb6fd..37f54e601e 100644 --- a/lib/rubygems/test_utilities.rb +++ b/lib/rubygems/test_utilities.rb @@ -160,6 +160,164 @@ end # :startdoc: ## +# The SpecFetcherSetup allows easy setup of a remote source in RubyGems tests: +# +# spec_fetcher do |f| +# f.gem 'a', 1 +# f.spec 'a', 2 +# f.gem 'b', 1' 'a' => '~> 1.0' +# f.clear +# end +# +# The above declaration creates two gems, a-1 and b-1, with a dependency from +# b to a. The declaration creates an additional spec a-2, but no gem for it +# (so it cannot be installed). +# +# After the gems are created they are removed from Gem.dir. + +class Gem::TestCase::SpecFetcherSetup + + ## + # Executes a SpecFetcher setup block. Yields an instance then creates the + # gems and specifications defined in the instance. + + def self.declare test + setup = new test + + yield setup + + setup.execute + end + + def initialize test # :nodoc: + @test = test + + @gems = {} + @installed = [] + @operations = [] + end + + ## + # Removes any created gems or specifications from Gem.dir (the default + # install location). + + def clear + @operations << [:clear] + end + + def created_specs + created = {} + + @gems.keys.each do |spec| + created[spec.full_name] = spec + end + + created + end + + ## + # Creates any defined gems or specifications + + def execute # :nodoc: + execute_operations + + setup_fetcher + + created_specs + end + + def execute_operations # :nodoc: + @operations.each do |operation, *arguments| + case operation + when :clear then + @test.util_clear_gems + @installed.clear + when :gem then + spec, gem = @test.util_gem(*arguments, &arguments.pop) + + write_spec spec + + @gems[spec] = gem + @installed << spec + when :spec then + spec = @test.util_spec(*arguments, &arguments.pop) + + write_spec spec + + @gems[spec] = nil + @installed << spec + end + end + end + + ## + # Creates a gem with +name+, +version+ and +deps+. The created gem can be + # downloaded and installed. + # + # The specification will be yielded before gem creation for customization, + # but only the block or the dependencies may be set, not both. + + def gem name, version, dependencies = nil, &block + @operations << [:gem, name, version, dependencies, block] + end + + ## + # Creates a legacy platform spec with the name 'pl' and version 1 + + def legacy_platform + spec 'pl', 1 do |s| + s.platform = Gem::Platform.new 'i386-linux' + s.instance_variable_set :@original_platform, 'i386-linux' + end + end + + def setup_fetcher # :nodoc; + require 'zlib' + require 'socket' + require 'rubygems/remote_fetcher' + + @test.fetcher = Gem::FakeFetcher.new + Gem::RemoteFetcher.fetcher = @test.fetcher + + Gem::Specification.reset + + @test.util_setup_spec_fetcher(*@gems.keys) + + # This works around util_setup_spec_fetcher adding all created gems to the + # installed set. + Gem::Specification.reset + Gem::Specification.add_specs(*@installed) + + @gems.each do |spec, gem| + next unless gem + + @test.fetcher.data["http://gems.example.com/gems/#{spec.file_name}"] = + Gem.read_binary(gem) + + FileUtils.cp gem, spec.cache_file + end + end + + ## + # Creates a spec with +name+, +version+ and +deps+. The created gem can be + # downloaded and installed. + # + # The specification will be yielded before creation for customization, + # but only the block or the dependencies may be set, not both. + + def spec name, version, dependencies = nil, &block + @operations << [:spec, name, version, dependencies, block] + end + + def write_spec spec # :nodoc: + open spec.spec_file, 'w' do |io| + io.write spec.to_ruby_for_cache + end + end + +end + +## # A StringIO duck-typed class that uses Tempfile instead of String as the # backing store. # |