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, 8809, 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']
56
yaml = Zlib::Inflate.inflate(@res.body)
57
assert_match %r|Gem::Specification|, yaml
58
assert_match %r|name: a|, yaml
59
assert_match %r|version: "1"|, yaml
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']
75
yaml = Zlib::Inflate.inflate(@res.body)
76
assert_match %r|Gem::Specification|, yaml
77
assert_match %r|name: a|, yaml
78
assert_match %r|version: "1"|, yaml
81
def test_quick_common_substrings
82
ab1 = quick_gem 'ab', '1'
83
si = Gem::SourceIndex.new @a1.full_name => @a1, ab1.full_name => ab1
84
@server.source_index = si
86
data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
89
@server.quick @req, @res
91
assert_equal 200, @res.status, @res.body
93
assert_equal 'text/plain', @res['content-type']
94
yaml = Zlib::Inflate.inflate @res.body
95
assert_match %r|Gem::Specification|, yaml
96
assert_match %r|name: a$|, yaml
97
assert_match %r|version: "1"|, yaml
100
def test_quick_z_9_gemspec_rz
101
data = StringIO.new "GET /quick/z-9.gemspec.rz HTTP/1.0\r\n\r\n"
104
@server.quick @req, @res
106
assert_equal 404, @res.status, @res.body
107
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
108
assert_equal 'text/plain', @res['content-type']
109
assert_equal 'No gems found matching "z" "9" nil', @res.body
110
assert_equal 404, @res.status