sinatra 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- data/ChangeLog +64 -0
- data/LICENSE +1 -1
- data/README.rdoc +244 -141
- data/Rakefile +111 -0
- data/lib/sinatra.rb +942 -627
- data/{vendor/rack/lib → lib/sinatra}/rack/handler/mongrel.rb +10 -3
- data/lib/sinatra/test/methods.rb +56 -36
- data/lib/sinatra/test/rspec.rb +10 -0
- data/lib/sinatra/test/spec.rb +2 -2
- data/lib/sinatra/test/unit.rb +1 -1
- data/sinatra.gemspec +71 -43
- data/test/app_test.rb +181 -32
- data/test/application_test.rb +179 -36
- data/test/custom_error_test.rb +17 -22
- data/test/erb_test.rb +42 -22
- data/test/event_context_test.rb +3 -3
- data/test/events_test.rb +8 -11
- data/test/filter_test.rb +30 -0
- data/test/haml_test.rb +83 -31
- data/test/helper.rb +6 -3
- data/test/mapped_error_test.rb +32 -21
- data/test/pipeline_test.rb +66 -0
- data/test/sass_test.rb +7 -7
- data/test/sessions_test.rb +8 -9
- data/test/streaming_test.rb +10 -4
- data/test/sym_params_test.rb +1 -1
- data/test/template_test.rb +11 -11
- data/test/use_in_file_templates_test.rb +9 -10
- metadata +22 -101
- data/CHANGELOG +0 -3
- data/Manifest +0 -122
- data/index.html +0 -9
- data/test/diddy_test.rb +0 -41
- data/test/rest_test.rb +0 -16
- data/vendor/rack/AUTHORS +0 -7
- data/vendor/rack/COPYING +0 -18
- data/vendor/rack/KNOWN-ISSUES +0 -18
- data/vendor/rack/README +0 -242
- data/vendor/rack/Rakefile +0 -174
- data/vendor/rack/bin/rackup +0 -153
- data/vendor/rack/contrib/rack_logo.svg +0 -111
- data/vendor/rack/example/lobster.ru +0 -4
- data/vendor/rack/example/protectedlobster.rb +0 -14
- data/vendor/rack/example/protectedlobster.ru +0 -8
- data/vendor/rack/lib/rack.rb +0 -92
- data/vendor/rack/lib/rack/adapter/camping.rb +0 -22
- data/vendor/rack/lib/rack/auth/abstract/handler.rb +0 -28
- data/vendor/rack/lib/rack/auth/abstract/request.rb +0 -37
- data/vendor/rack/lib/rack/auth/basic.rb +0 -58
- data/vendor/rack/lib/rack/auth/digest/md5.rb +0 -124
- data/vendor/rack/lib/rack/auth/digest/nonce.rb +0 -51
- data/vendor/rack/lib/rack/auth/digest/params.rb +0 -55
- data/vendor/rack/lib/rack/auth/digest/request.rb +0 -40
- data/vendor/rack/lib/rack/auth/openid.rb +0 -116
- data/vendor/rack/lib/rack/builder.rb +0 -56
- data/vendor/rack/lib/rack/cascade.rb +0 -36
- data/vendor/rack/lib/rack/commonlogger.rb +0 -56
- data/vendor/rack/lib/rack/file.rb +0 -112
- data/vendor/rack/lib/rack/handler/cgi.rb +0 -57
- data/vendor/rack/lib/rack/handler/fastcgi.rb +0 -83
- data/vendor/rack/lib/rack/handler/lsws.rb +0 -52
- data/vendor/rack/lib/rack/handler/scgi.rb +0 -57
- data/vendor/rack/lib/rack/handler/webrick.rb +0 -57
- data/vendor/rack/lib/rack/lint.rb +0 -394
- data/vendor/rack/lib/rack/lobster.rb +0 -65
- data/vendor/rack/lib/rack/mock.rb +0 -160
- data/vendor/rack/lib/rack/recursive.rb +0 -57
- data/vendor/rack/lib/rack/reloader.rb +0 -64
- data/vendor/rack/lib/rack/request.rb +0 -197
- data/vendor/rack/lib/rack/response.rb +0 -166
- data/vendor/rack/lib/rack/session/abstract/id.rb +0 -126
- data/vendor/rack/lib/rack/session/cookie.rb +0 -71
- data/vendor/rack/lib/rack/session/memcache.rb +0 -83
- data/vendor/rack/lib/rack/session/pool.rb +0 -67
- data/vendor/rack/lib/rack/showexceptions.rb +0 -344
- data/vendor/rack/lib/rack/showstatus.rb +0 -103
- data/vendor/rack/lib/rack/static.rb +0 -38
- data/vendor/rack/lib/rack/urlmap.rb +0 -48
- data/vendor/rack/lib/rack/utils.rb +0 -240
- data/vendor/rack/test/cgi/lighttpd.conf +0 -20
- data/vendor/rack/test/cgi/test +0 -9
- data/vendor/rack/test/cgi/test.fcgi +0 -7
- data/vendor/rack/test/cgi/test.ru +0 -7
- data/vendor/rack/test/spec_rack_auth_basic.rb +0 -69
- data/vendor/rack/test/spec_rack_auth_digest.rb +0 -169
- data/vendor/rack/test/spec_rack_builder.rb +0 -50
- data/vendor/rack/test/spec_rack_camping.rb +0 -47
- data/vendor/rack/test/spec_rack_cascade.rb +0 -50
- data/vendor/rack/test/spec_rack_cgi.rb +0 -91
- data/vendor/rack/test/spec_rack_commonlogger.rb +0 -32
- data/vendor/rack/test/spec_rack_fastcgi.rb +0 -91
- data/vendor/rack/test/spec_rack_file.rb +0 -40
- data/vendor/rack/test/spec_rack_lint.rb +0 -317
- data/vendor/rack/test/spec_rack_lobster.rb +0 -45
- data/vendor/rack/test/spec_rack_mock.rb +0 -152
- data/vendor/rack/test/spec_rack_mongrel.rb +0 -165
- data/vendor/rack/test/spec_rack_recursive.rb +0 -77
- data/vendor/rack/test/spec_rack_request.rb +0 -384
- data/vendor/rack/test/spec_rack_response.rb +0 -167
- data/vendor/rack/test/spec_rack_session_cookie.rb +0 -49
- data/vendor/rack/test/spec_rack_session_memcache.rb +0 -100
- data/vendor/rack/test/spec_rack_session_pool.rb +0 -84
- data/vendor/rack/test/spec_rack_showexceptions.rb +0 -21
- data/vendor/rack/test/spec_rack_showstatus.rb +0 -71
- data/vendor/rack/test/spec_rack_static.rb +0 -37
- data/vendor/rack/test/spec_rack_urlmap.rb +0 -175
- data/vendor/rack/test/spec_rack_utils.rb +0 -57
- data/vendor/rack/test/spec_rack_webrick.rb +0 -106
- data/vendor/rack/test/testrequest.rb +0 -43
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
|
3
|
-
require 'rack/static'
|
4
|
-
require 'rack/mock'
|
5
|
-
|
6
|
-
class DummyApp
|
7
|
-
def call(env)
|
8
|
-
[200, {}, "Hello World"]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context "Rack::Static" do
|
13
|
-
root = File.expand_path(File.dirname(__FILE__))
|
14
|
-
OPTIONS = {:urls => ["/cgi"], :root => root}
|
15
|
-
|
16
|
-
setup do
|
17
|
-
@request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS))
|
18
|
-
end
|
19
|
-
|
20
|
-
specify "serves files" do
|
21
|
-
res = @request.get("/cgi/test")
|
22
|
-
res.should.be.ok
|
23
|
-
res.body.should =~ /ruby/
|
24
|
-
end
|
25
|
-
|
26
|
-
specify "404s if url root is known but it can't find the file" do
|
27
|
-
res = @request.get("/cgi/foo")
|
28
|
-
res.should.be.not_found
|
29
|
-
end
|
30
|
-
|
31
|
-
specify "calls down the chain if url root is not known" do
|
32
|
-
res = @request.get("/something/else")
|
33
|
-
res.should.be.ok
|
34
|
-
res.body.should == "Hello World"
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,175 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
|
3
|
-
require 'rack/urlmap'
|
4
|
-
require 'rack/mock'
|
5
|
-
|
6
|
-
context "Rack::URLMap" do
|
7
|
-
specify "dispatches paths correctly" do
|
8
|
-
app = lambda { |env|
|
9
|
-
[200, {
|
10
|
-
'X-ScriptName' => env['SCRIPT_NAME'],
|
11
|
-
'X-PathInfo' => env['PATH_INFO'],
|
12
|
-
'Content-Type' => 'text/plain'
|
13
|
-
}, [""]]
|
14
|
-
}
|
15
|
-
map = Rack::URLMap.new({
|
16
|
-
'http://foo.org/bar' => app,
|
17
|
-
'/foo' => app,
|
18
|
-
'/foo/bar' => app
|
19
|
-
})
|
20
|
-
|
21
|
-
res = Rack::MockRequest.new(map).get("/")
|
22
|
-
res.should.be.not_found
|
23
|
-
|
24
|
-
res = Rack::MockRequest.new(map).get("/qux")
|
25
|
-
res.should.be.not_found
|
26
|
-
|
27
|
-
res = Rack::MockRequest.new(map).get("/foo")
|
28
|
-
res.should.be.ok
|
29
|
-
res["X-ScriptName"].should.equal "/foo"
|
30
|
-
res["X-PathInfo"].should.equal ""
|
31
|
-
|
32
|
-
res = Rack::MockRequest.new(map).get("/foo/")
|
33
|
-
res.should.be.ok
|
34
|
-
res["X-ScriptName"].should.equal "/foo"
|
35
|
-
res["X-PathInfo"].should.equal "/"
|
36
|
-
|
37
|
-
res = Rack::MockRequest.new(map).get("/foo/bar")
|
38
|
-
res.should.be.ok
|
39
|
-
res["X-ScriptName"].should.equal "/foo/bar"
|
40
|
-
res["X-PathInfo"].should.equal ""
|
41
|
-
|
42
|
-
res = Rack::MockRequest.new(map).get("/foo/bar/")
|
43
|
-
res.should.be.ok
|
44
|
-
res["X-ScriptName"].should.equal "/foo/bar"
|
45
|
-
res["X-PathInfo"].should.equal "/"
|
46
|
-
|
47
|
-
res = Rack::MockRequest.new(map).get("/foo/quux", "SCRIPT_NAME" => "/bleh")
|
48
|
-
res.should.be.ok
|
49
|
-
res["X-ScriptName"].should.equal "/bleh/foo"
|
50
|
-
res["X-PathInfo"].should.equal "/quux"
|
51
|
-
|
52
|
-
res = Rack::MockRequest.new(map).get("/bar", 'HTTP_HOST' => 'foo.org')
|
53
|
-
res.should.be.ok
|
54
|
-
res["X-ScriptName"].should.equal "/bar"
|
55
|
-
res["X-PathInfo"].should.be.empty
|
56
|
-
|
57
|
-
res = Rack::MockRequest.new(map).get("/bar/", 'HTTP_HOST' => 'foo.org')
|
58
|
-
res.should.be.ok
|
59
|
-
res["X-ScriptName"].should.equal "/bar"
|
60
|
-
res["X-PathInfo"].should.equal '/'
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
specify "dispatches hosts correctly" do
|
65
|
-
map = Rack::URLMap.new("http://foo.org/" => lambda { |env|
|
66
|
-
[200,
|
67
|
-
{ "Content-Type" => "text/plain",
|
68
|
-
"X-Position" => "foo.org",
|
69
|
-
"X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
|
70
|
-
}, [""]]},
|
71
|
-
"http://bar.org/" => lambda { |env|
|
72
|
-
[200,
|
73
|
-
{ "Content-Type" => "text/plain",
|
74
|
-
"X-Position" => "bar.org",
|
75
|
-
"X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
|
76
|
-
}, [""]]},
|
77
|
-
"/" => lambda { |env|
|
78
|
-
[200,
|
79
|
-
{ "Content-Type" => "text/plain",
|
80
|
-
"X-Position" => "default.org",
|
81
|
-
"X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
|
82
|
-
}, [""]]}
|
83
|
-
)
|
84
|
-
|
85
|
-
res = Rack::MockRequest.new(map).get("/")
|
86
|
-
res.should.be.ok
|
87
|
-
res["X-Position"].should.equal "default.org"
|
88
|
-
|
89
|
-
res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "bar.org")
|
90
|
-
res.should.be.ok
|
91
|
-
res["X-Position"].should.equal "bar.org"
|
92
|
-
|
93
|
-
res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "foo.org")
|
94
|
-
res.should.be.ok
|
95
|
-
res["X-Position"].should.equal "foo.org"
|
96
|
-
|
97
|
-
res = Rack::MockRequest.new(map).get("http://foo.org/")
|
98
|
-
res.should.be.ok
|
99
|
-
res["X-Position"].should.equal "default.org"
|
100
|
-
|
101
|
-
res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "example.org")
|
102
|
-
res.should.be.ok
|
103
|
-
res["X-Position"].should.equal "default.org"
|
104
|
-
|
105
|
-
res = Rack::MockRequest.new(map).get("/",
|
106
|
-
"HTTP_HOST" => "example.org:9292",
|
107
|
-
"SERVER_PORT" => "9292")
|
108
|
-
res.should.be.ok
|
109
|
-
res["X-Position"].should.equal "default.org"
|
110
|
-
end
|
111
|
-
|
112
|
-
specify "should be nestable" do
|
113
|
-
map = Rack::URLMap.new("/foo" =>
|
114
|
-
Rack::URLMap.new("/bar" =>
|
115
|
-
Rack::URLMap.new("/quux" => lambda { |env|
|
116
|
-
[200,
|
117
|
-
{ "Content-Type" => "text/plain",
|
118
|
-
"X-Position" => "/foo/bar/quux",
|
119
|
-
"X-PathInfo" => env["PATH_INFO"],
|
120
|
-
"X-ScriptName" => env["SCRIPT_NAME"],
|
121
|
-
}, [""]]}
|
122
|
-
)))
|
123
|
-
|
124
|
-
res = Rack::MockRequest.new(map).get("/foo/bar")
|
125
|
-
res.should.be.not_found
|
126
|
-
|
127
|
-
res = Rack::MockRequest.new(map).get("/foo/bar/quux")
|
128
|
-
res.should.be.ok
|
129
|
-
res["X-Position"].should.equal "/foo/bar/quux"
|
130
|
-
res["X-PathInfo"].should.equal ""
|
131
|
-
res["X-ScriptName"].should.equal "/foo/bar/quux"
|
132
|
-
end
|
133
|
-
|
134
|
-
specify "should route root apps correctly" do
|
135
|
-
map = Rack::URLMap.new("/" => lambda { |env|
|
136
|
-
[200,
|
137
|
-
{ "Content-Type" => "text/plain",
|
138
|
-
"X-Position" => "root",
|
139
|
-
"X-PathInfo" => env["PATH_INFO"],
|
140
|
-
"X-ScriptName" => env["SCRIPT_NAME"]
|
141
|
-
}, [""]]},
|
142
|
-
"/foo" => lambda { |env|
|
143
|
-
[200,
|
144
|
-
{ "Content-Type" => "text/plain",
|
145
|
-
"X-Position" => "foo",
|
146
|
-
"X-PathInfo" => env["PATH_INFO"],
|
147
|
-
"X-ScriptName" => env["SCRIPT_NAME"]
|
148
|
-
}, [""]]}
|
149
|
-
)
|
150
|
-
|
151
|
-
res = Rack::MockRequest.new(map).get("/foo/bar")
|
152
|
-
res.should.be.ok
|
153
|
-
res["X-Position"].should.equal "foo"
|
154
|
-
res["X-PathInfo"].should.equal "/bar"
|
155
|
-
res["X-ScriptName"].should.equal "/foo"
|
156
|
-
|
157
|
-
res = Rack::MockRequest.new(map).get("/foo")
|
158
|
-
res.should.be.ok
|
159
|
-
res["X-Position"].should.equal "foo"
|
160
|
-
res["X-PathInfo"].should.equal ""
|
161
|
-
res["X-ScriptName"].should.equal "/foo"
|
162
|
-
|
163
|
-
res = Rack::MockRequest.new(map).get("/bar")
|
164
|
-
res.should.be.ok
|
165
|
-
res["X-Position"].should.equal "root"
|
166
|
-
res["X-PathInfo"].should.equal "/bar"
|
167
|
-
res["X-ScriptName"].should.equal ""
|
168
|
-
|
169
|
-
res = Rack::MockRequest.new(map).get("")
|
170
|
-
res.should.be.ok
|
171
|
-
res["X-Position"].should.equal "root"
|
172
|
-
res["X-PathInfo"].should.equal "/"
|
173
|
-
res["X-ScriptName"].should.equal ""
|
174
|
-
end
|
175
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'rack/utils'
|
2
|
-
|
3
|
-
context "Rack::Utils" do
|
4
|
-
specify "should escape correctly" do
|
5
|
-
Rack::Utils.escape("fo<o>bar").should.equal "fo%3Co%3Ebar"
|
6
|
-
Rack::Utils.escape("a space").should.equal "a+space"
|
7
|
-
Rack::Utils.escape("q1!2\"'w$5&7/z8)?\\").
|
8
|
-
should.equal "q1%212%22%27w%245%267%2Fz8%29%3F%5C"
|
9
|
-
end
|
10
|
-
|
11
|
-
specify "should unescape correctly" do
|
12
|
-
Rack::Utils.unescape("fo%3Co%3Ebar").should.equal "fo<o>bar"
|
13
|
-
Rack::Utils.unescape("a+space").should.equal "a space"
|
14
|
-
Rack::Utils.unescape("a%20space").should.equal "a space"
|
15
|
-
Rack::Utils.unescape("q1%212%22%27w%245%267%2Fz8%29%3F%5C").
|
16
|
-
should.equal "q1!2\"'w$5&7/z8)?\\"
|
17
|
-
end
|
18
|
-
|
19
|
-
specify "should parse queries correctly" do
|
20
|
-
Rack::Utils.parse_query("foo=bar").should.equal "foo" => "bar"
|
21
|
-
Rack::Utils.parse_query("foo=bar&foo=quux").
|
22
|
-
should.equal "foo" => ["bar", "quux"]
|
23
|
-
Rack::Utils.parse_query("my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F").
|
24
|
-
should.equal "my weird field" => "q1!2\"'w$5&7/z8)?"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "Rack::Utils::HeaderHash" do
|
29
|
-
specify "should capitalize on all accesses" do
|
30
|
-
h = Rack::Utils::HeaderHash.new("foo" => "bar")
|
31
|
-
h["foo"].should.equal "bar"
|
32
|
-
h["Foo"].should.equal "bar"
|
33
|
-
h["FOO"].should.equal "bar"
|
34
|
-
|
35
|
-
h.to_hash.should.equal "Foo" => "bar"
|
36
|
-
|
37
|
-
h["bar-zzle"] = "quux"
|
38
|
-
|
39
|
-
h.to_hash.should.equal "Foo" => "bar", "Bar-Zzle" => "quux"
|
40
|
-
end
|
41
|
-
|
42
|
-
specify "should capitalize correctly" do
|
43
|
-
h = Rack::Utils::HeaderHash.new
|
44
|
-
|
45
|
-
h.capitalize("foo").should.equal "Foo"
|
46
|
-
h.capitalize("foo-bar").should.equal "Foo-Bar"
|
47
|
-
h.capitalize("foo_bar").should.equal "Foo_Bar"
|
48
|
-
h.capitalize("foo bar").should.equal "Foo Bar"
|
49
|
-
h.capitalize("foo-bar-quux").should.equal "Foo-Bar-Quux"
|
50
|
-
h.capitalize("foo-bar-2quux").should.equal "Foo-Bar-2quux"
|
51
|
-
end
|
52
|
-
|
53
|
-
specify "should be converted to real Hash" do
|
54
|
-
h = Rack::Utils::HeaderHash.new("foo" => "bar")
|
55
|
-
h.to_hash.should.be.instance_of Hash
|
56
|
-
end
|
57
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
|
3
|
-
require 'rack/handler/webrick'
|
4
|
-
require 'rack/lint'
|
5
|
-
require 'testrequest'
|
6
|
-
|
7
|
-
Thread.abort_on_exception = true
|
8
|
-
|
9
|
-
context "Rack::Handler::WEBrick" do
|
10
|
-
include TestRequest::Helpers
|
11
|
-
|
12
|
-
setup do
|
13
|
-
@server = WEBrick::HTTPServer.new(:Host => @host='0.0.0.0',
|
14
|
-
:Port => @port=9202,
|
15
|
-
:Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN),
|
16
|
-
:AccessLog => [])
|
17
|
-
@server.mount "/test", Rack::Handler::WEBrick,
|
18
|
-
Rack::Lint.new(TestRequest.new)
|
19
|
-
Thread.new { @server.start }
|
20
|
-
trap(:INT) { @server.shutdown }
|
21
|
-
end
|
22
|
-
|
23
|
-
specify "should respond" do
|
24
|
-
lambda {
|
25
|
-
GET("/test")
|
26
|
-
}.should.not.raise
|
27
|
-
end
|
28
|
-
|
29
|
-
specify "should be a WEBrick" do
|
30
|
-
GET("/test")
|
31
|
-
status.should.be 200
|
32
|
-
response["SERVER_SOFTWARE"].should =~ /WEBrick/
|
33
|
-
response["HTTP_VERSION"].should.equal "HTTP/1.1"
|
34
|
-
response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
|
35
|
-
response["SERVER_PORT"].should.equal "9202"
|
36
|
-
response["SERVER_NAME"].should.equal "0.0.0.0"
|
37
|
-
end
|
38
|
-
|
39
|
-
specify "should have rack headers" do
|
40
|
-
GET("/test")
|
41
|
-
response["rack.version"].should.equal [0,1]
|
42
|
-
response["rack.multithread"].should.be true
|
43
|
-
response["rack.multiprocess"].should.be false
|
44
|
-
response["rack.run_once"].should.be false
|
45
|
-
end
|
46
|
-
|
47
|
-
specify "should have CGI headers on GET" do
|
48
|
-
GET("/test")
|
49
|
-
response["REQUEST_METHOD"].should.equal "GET"
|
50
|
-
response["SCRIPT_NAME"].should.equal "/test"
|
51
|
-
response["REQUEST_PATH"].should.equal "/"
|
52
|
-
response["PATH_INFO"].should.be.nil
|
53
|
-
response["QUERY_STRING"].should.equal ""
|
54
|
-
response["test.postdata"].should.equal ""
|
55
|
-
|
56
|
-
GET("/test/foo?quux=1")
|
57
|
-
response["REQUEST_METHOD"].should.equal "GET"
|
58
|
-
response["SCRIPT_NAME"].should.equal "/test"
|
59
|
-
response["REQUEST_PATH"].should.equal "/"
|
60
|
-
response["PATH_INFO"].should.equal "/foo"
|
61
|
-
response["QUERY_STRING"].should.equal "quux=1"
|
62
|
-
end
|
63
|
-
|
64
|
-
specify "should have CGI headers on POST" do
|
65
|
-
POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
|
66
|
-
status.should.equal 200
|
67
|
-
response["REQUEST_METHOD"].should.equal "POST"
|
68
|
-
response["SCRIPT_NAME"].should.equal "/test"
|
69
|
-
response["REQUEST_PATH"].should.equal "/"
|
70
|
-
response["QUERY_STRING"].should.equal ""
|
71
|
-
response["HTTP_X_TEST_HEADER"].should.equal "42"
|
72
|
-
response["test.postdata"].should.equal "rack-form-data=23"
|
73
|
-
end
|
74
|
-
|
75
|
-
specify "should support HTTP auth" do
|
76
|
-
GET("/test", {:user => "ruth", :passwd => "secret"})
|
77
|
-
response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
|
78
|
-
end
|
79
|
-
|
80
|
-
specify "should set status" do
|
81
|
-
GET("/test?secret")
|
82
|
-
status.should.equal 403
|
83
|
-
response["rack.url_scheme"].should.equal "http"
|
84
|
-
end
|
85
|
-
|
86
|
-
specify "should provide a .run" do
|
87
|
-
block_ran = false
|
88
|
-
catch(:done) {
|
89
|
-
Rack::Handler::WEBrick.run(lambda {},
|
90
|
-
{:Port => 9210,
|
91
|
-
:Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN),
|
92
|
-
:AccessLog => []}) { |server|
|
93
|
-
block_ran = true
|
94
|
-
server.should.be.kind_of WEBrick::HTTPServer
|
95
|
-
@s = server
|
96
|
-
throw :done
|
97
|
-
}
|
98
|
-
}
|
99
|
-
block_ran.should.be true
|
100
|
-
@s.shutdown
|
101
|
-
end
|
102
|
-
|
103
|
-
teardown do
|
104
|
-
@server.shutdown
|
105
|
-
end
|
106
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'net/http'
|
3
|
-
|
4
|
-
class TestRequest
|
5
|
-
def call(env)
|
6
|
-
status = env["QUERY_STRING"] =~ /secret/ ? 403 : 200
|
7
|
-
env["test.postdata"] = env["rack.input"].read
|
8
|
-
[status, {"Content-Type" => "text/yaml"}, [env.to_yaml]]
|
9
|
-
end
|
10
|
-
|
11
|
-
module Helpers
|
12
|
-
attr_reader :status, :response
|
13
|
-
|
14
|
-
def GET(path, header={})
|
15
|
-
Net::HTTP.start(@host, @port) { |http|
|
16
|
-
user = header.delete(:user)
|
17
|
-
passwd = header.delete(:passwd)
|
18
|
-
|
19
|
-
get = Net::HTTP::Get.new(path, header)
|
20
|
-
get.basic_auth user, passwd if user && passwd
|
21
|
-
http.request(get) { |response|
|
22
|
-
@status = response.code.to_i
|
23
|
-
@response = YAML.load(response.body)
|
24
|
-
}
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
def POST(path, formdata={}, header={})
|
29
|
-
Net::HTTP.start(@host, @port) { |http|
|
30
|
-
user = header.delete(:user)
|
31
|
-
passwd = header.delete(:passwd)
|
32
|
-
|
33
|
-
post = Net::HTTP::Post.new(path, header)
|
34
|
-
post.form_data = formdata
|
35
|
-
post.basic_auth user, passwd if user && passwd
|
36
|
-
http.request(post) { |response|
|
37
|
-
@status = response.code.to_i
|
38
|
-
@response = YAML.load(response.body)
|
39
|
-
}
|
40
|
-
}
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|