2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/server'
7 attr_accessor :source_index
11 class TestGemServer < RubyGemTestCase
16 @a1 = quick_gem 'a', '1'
18 @server = Gem::Server.new Gem.dir, process_based_port, false
19 @req = WEBrick::HTTPRequest.new :Logger => nil
20 @res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
24 data = StringIO.new "GET /quick/index HTTP/1.0\r\n\r\n"
27 @server.quick @req, @res
29 assert_equal 200, @res.status, @res.body
30 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
31 assert_equal 'text/plain', @res['content-type']
32 assert_equal "a-1", @res.body
35 def test_quick_index_rz
36 data = StringIO.new "GET /quick/index.rz HTTP/1.0\r\n\r\n"
39 @server.quick @req, @res
41 assert_equal 200, @res.status, @res.body
42 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
43 assert_equal 'text/plain', @res['content-type']
44 assert_equal "a-1", Zlib::Inflate.inflate(@res.body)
47 def test_quick_a_1_gemspec_rz
48 data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
51 @server.quick @req, @res
53 assert_equal 200, @res.status, @res.body
55 assert_equal 'text/plain', @res['content-type']
57 spec = YAML.load Zlib::Inflate.inflate(@res.body)
58 assert_equal 'a', spec.name
59 assert_equal Gem::Version.new(1), spec.version
62 def test_quick_a_1_mswin32_gemspec_rz
63 a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end
64 si = Gem::SourceIndex.new @a1.full_name => @a1, a1_p.full_name => a1_p
65 @server.source_index = si
67 data = StringIO.new "GET /quick/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n"
70 @server.quick @req, @res
72 assert_equal 200, @res.status, @res.body
74 assert_equal 'text/plain', @res['content-type']
76 spec = YAML.load Zlib::Inflate.inflate(@res.body)
77 assert_equal 'a', spec.name
78 assert_equal Gem::Version.new(1), spec.version
79 assert_equal Gem::Platform.local, spec.platform
82 def test_quick_common_substrings
83 ab1 = quick_gem 'ab', '1'
84 si = Gem::SourceIndex.new @a1.full_name => @a1, ab1.full_name => ab1
85 @server.source_index = si
87 data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
90 @server.quick @req, @res
92 assert_equal 200, @res.status, @res.body
94 assert_equal 'text/plain', @res['content-type']
96 spec = YAML.load Zlib::Inflate.inflate(@res.body)
97 assert_equal 'a', spec.name
98 assert_equal Gem::Version.new(1), spec.version
101 def test_quick_z_9_gemspec_rz
102 data = StringIO.new "GET /quick/z-9.gemspec.rz HTTP/1.0\r\n\r\n"
105 @server.quick @req, @res
107 assert_equal 404, @res.status, @res.body
108 assert_match %r| \d\d:\d\d:\d\d |, @res['date']
109 assert_equal 'text/plain', @res['content-type']
110 assert_equal 'No gems found matching "z" "9" nil', @res.body
111 assert_equal 404, @res.status