Skip to content

Commit

Permalink
individual methods still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewland committed Feb 9, 2009
1 parent 73308b5 commit 6d82cac
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 97 deletions.
1 change: 1 addition & 0 deletions config.ru
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ $:.unshift LIB_PATH
require 'rack_rubygems' require 'rack_rubygems'
use Rack::Lint use Rack::Lint
use GemsAndRdocs, :urls => ['/cache', '/doc'], :root => Gem.dir use GemsAndRdocs, :urls => ['/cache', '/doc'], :root => Gem.dir
use Rack::Compress
run RackRubygems.new run RackRubygems.new
2 changes: 0 additions & 2 deletions lib/rack_rubygems.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@


class RackRubygems < Sinatra::Base class RackRubygems < Sinatra::Base


use Rack::Compress

head "/Marshal.#{Gem.marshal_version}" do head "/Marshal.#{Gem.marshal_version}" do
content_type 'application/octet-stream' content_type 'application/octet-stream'
response['Content-Length'] = source_index.length.to_s response['Content-Length'] = source_index.length.to_s
Expand Down
14 changes: 4 additions & 10 deletions spec/rack_rubygems_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -56,17 +56,11 @@


describe "provides access to individual gemspecs" do describe "provides access to individual gemspecs" do
it "via name and version" do it "via name and version" do
should_match_webrick_behavior "/quick/a-1.gemspec.rz", :quick should_match_webrick_behavior "/quick/rack-0.9.1.gemspec.rz", :quick
end end


it "via name, version, and platform" do it "via name, version, and platform" do
a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end should_match_webrick_behavior "/quick/rack-0.9.1-#{Gem::Platform.local}.gemspec.rz", :quick
should_match_webrick_behavior "/quick/a-1-#{Gem::Platform.local}.gemspec.rz", :quick
end

it "performing substring matching" do
ab1 = quick_gem 'ab', '1'
should_match_webrick_behavior "/quick/ab-1.gemspec.rz", :quick
end end


it "via a quick index" do it "via a quick index" do
Expand All @@ -91,11 +85,11 @@
end end


it "marshalled via name and version" do it "marshalled via name and version" do
should_match_webrick_behavior "/quick/Marshal.#{Gem.marshal_version}/a-1.gemspec.rz", :quick should_match_webrick_behavior "/quick/Marshal.#{Gem.marshal_version}/rack-0.9.1.gemspec.rz", :quick
end end


it "marshalled via name, version, and platform" do it "marshalled via name, version, and platform" do
should_match_webrick_behavior "/quick/Marshal.#{Gem.marshal_version}/a-1-#{Gem::Platform.local}.gemspec.rz", :quick should_match_webrick_behavior "/quick/Marshal.#{Gem.marshal_version}/rack-0.9.1-#{Gem::Platform.local}.gemspec.rz", :quick
end end
end end


Expand Down
88 changes: 3 additions & 85 deletions spec/spec_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,48 +43,6 @@ def should_match_webrick_behavior(url, server_method, method = :get)
} }
end end


#stub gem
def quick_gem(gemname, version='2')
require 'rubygems/specification'

spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = gemname
s.version = version
s.author = 'A User'
s.email = 'example@example.com'
s.homepage = 'http://example.com'
s.has_rdoc = true
s.summary = "this is a summary"
s.description = "This is a test description"

yield(s) if block_given?
end

path = File.join "specifications", "#{spec.full_name}.gemspec"
written_path = write_file path do |io|
io.write(spec.to_ruby)
end

spec.loaded_from = written_path

Gem.source_index.add_spec spec

return spec
end

def write_file(path)
path = File.join(@gemhome, path)
dir = File.dirname path
FileUtils.mkdir_p dir

open path, 'wb' do |io|
yield io
end

path
end

def process_based_port def process_based_port
@@process_based_port ||= 8000 + $$ % 1000 @@process_based_port ||= 8000 + $$ % 1000
end end
Expand All @@ -94,58 +52,18 @@ def process_based_port
Spec::Runner.configure do |config| Spec::Runner.configure do |config|
config.before(:each) { config.before(:each) {


tmpdir = nil
Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
@tempdir = File.join tmpdir, "test_rubygems_#{$$}"
@tempdir.untaint
@gemhome = File.join @tempdir, "gemhome"
@gemcache = File.join(@gemhome, "source_cache")
@usrcache = File.join(@gemhome, ".gem", "user_cache")
@latest_usrcache = File.join(@gemhome, ".gem", "latest_user_cache")
@userhome = File.join @tempdir, 'userhome'

@orig_ENV_HOME = ENV['HOME']
ENV['HOME'] = @userhome
Gem.instance_variable_set :@user_home, nil

FileUtils.mkdir_p @gemhome
FileUtils.mkdir_p @userhome

ENV['GEMCACHE'] = @usrcache
Gem.use_paths(@gemhome)
Gem.loaded_specs.clear

Gem.configuration.verbose = true
Gem.configuration.update_sources = true

@gem_repo = "http://gems.example.com/"
@uri = URI.parse @gem_repo
Gem.sources.replace [@gem_repo]

Gem::SpecFetcher.fetcher = nil

@orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:RUBY_INSTALL_NAME]

@orig_arch = Gem::ConfigMap[:arch]

@marshal_version = "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"

@private_key = File.expand_path File.join(File.dirname(__FILE__), 'private_key.pem')
@public_cert = File.expand_path File.join(File.dirname(__FILE__), 'public_cert.pem')

@app = Rack::Builder.new { @app = Rack::Builder.new {
use GemsAndRdocs, :urls => ['/cache', '/doc'], :root => Gem.dir use GemsAndRdocs, :urls => ['/cache', '/doc'], :root => Gem.dir
use Rack::Compress
run RackRubygems.new run RackRubygems.new
} }


@a1 = quick_gem 'a', '1'
@a2 = quick_gem 'a', '2'

@webrick = Gem::Server.new Gem.dir, process_based_port, false @webrick = Gem::Server.new Gem.dir, process_based_port, false
@webrick_request = WEBrick::HTTPRequest.new :Logger => nil @webrick_request = WEBrick::HTTPRequest.new :Logger => nil
@webrick_response = WEBrick::HTTPResponse.new :HTTPVersion => '1.0' @webrick_response = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'

} }

config.include Sinatra::Test config.include Sinatra::Test
config.include RackRubygemsTestHelpers config.include RackRubygemsTestHelpers
end end

0 comments on commit 6d82cac

Please sign in to comment.