Class: Gem::TestCase::SpecFetcherSetup
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubygems/test_utilities.rb |
Overview
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'
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 Method Summary
-
.declare(test, repository) {|setup| ... }
Executes a
::Gem::SpecFetcher
setup block. - .new(test, repository) ⇒ SpecFetcherSetup constructor Internal use only
Instance Method Summary
-
#created_specs
Returns a Hash of created
::Gem::Specification
full names and the corresponding::Gem::Specification
. -
#download(name, version, dependencies = nil, &block)
Creates a gem with
name
,version
anddeps
. -
#gem(name, version, dependencies = nil, &block)
Creates a gem with
name
,version
anddeps
. -
#legacy_platform
Creates a legacy platform spec with the name ‘pl’ and version 1.
-
#spec(name, version, dependencies = nil, &block)
Creates a spec with
name
,version
anddeps
. -
#execute
Internal use only
Creates any defined gems or specifications.
- #execute_operations Internal use only
- #setup_fetcher Internal use only
- #write_spec(spec) Internal use only
Constructor Details
.new(test, repository) ⇒ SpecFetcherSetup
# File 'lib/rubygems/test_utilities.rb', line 207
def initialize(test, repository) # :nodoc: @test = test @repository = repository @gems = {} @downloaded = [] @installed = [] @operations = [] end
Class Method Details
.declare(test, repository) {|setup| ... }
Executes a ::Gem::SpecFetcher
setup block. Yields an instance then creates the gems and specifications defined in the instance.
Instance Method Details
#created_specs
Returns a Hash of created ::Gem::Specification
full names and the corresponding ::Gem::Specification
.
#download(name, version, dependencies = nil, &block)
Creates a gem with name
, version
and deps
. The created gem is downloaded in to the cache directory but is not installed
The specification will be yielded before gem creation for customization, but only the block or the dependencies may be set, not both.
# File 'lib/rubygems/test_utilities.rb', line 287
def download(name, version, dependencies = nil, &block) @operations << [:download, name, version, dependencies, block] end
#execute
Creates any defined gems or specifications
# File 'lib/rubygems/test_utilities.rb', line 234
def execute # :nodoc: execute_operations setup_fetcher created_specs end
#execute_operations
# File 'lib/rubygems/test_utilities.rb', line 242
def execute_operations # :nodoc: @operations.each do |operation, *arguments| block = arguments.pop case operation when :gem then spec, gem = @test.util_gem(*arguments, &block) write_spec spec @gems[spec] = gem @installed << spec when :download then spec, gem = @test.util_gem(*arguments, &block) @gems[spec] = gem @downloaded << spec when :spec then spec = @test.util_spec(*arguments, &block) write_spec spec @gems[spec] = nil @installed << spec end end end
#gem(name, version, dependencies = nil, &block)
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.
# File 'lib/rubygems/test_utilities.rb', line 276
def gem(name, version, dependencies = nil, &block) @operations << [:gem, name, version, dependencies, block] end
#legacy_platform
Creates a legacy platform spec with the name ‘pl’ and version 1
#setup_fetcher
# File 'lib/rubygems/test_utilities.rb', line 301
def setup_fetcher # :nodoc: require 'zlib' require 'socket' require 'rubygems/remote_fetcher' unless @test.fetcher @test.fetcher = Gem::FakeFetcher.new Gem::RemoteFetcher.fetcher = @test.fetcher end Gem::Specification.reset begin gem_repo, @test.gem_repo = @test.gem_repo, @repository @test.uri = URI @repository @test.util_setup_spec_fetcher(*@downloaded) ensure @test.gem_repo = gem_repo @test.uri = URI gem_repo end @gems.each do |spec, gem| next unless gem @test.fetcher.data["#{@repository}gems/#{spec.file_name}"] = Gem.read_binary(gem) FileUtils.cp gem, spec.cache_file end end
#spec(name, version, dependencies = nil, &block)
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.
# File 'lib/rubygems/test_utilities.rb', line 340
def spec(name, version, dependencies = nil, &block) @operations << [:spec, name, version, dependencies, block] end