2015-01-31 14:39:50 +00:00
|
|
|
require "./spec_helper"
|
2014-07-30 22:58:48 +00:00
|
|
|
|
2015-10-23 18:33:26 +00:00
|
|
|
describe "Kemal::Handler" do
|
2014-07-30 22:58:48 +00:00
|
|
|
it "routes" do
|
2015-10-23 18:33:26 +00:00
|
|
|
kemal = Kemal::Handler.new
|
|
|
|
kemal.add_route "GET", "/" do
|
2014-07-30 22:58:48 +00:00
|
|
|
"hello"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/")
|
2015-10-23 18:33:26 +00:00
|
|
|
response = kemal.call(request)
|
2014-07-30 22:58:48 +00:00
|
|
|
response.body.should eq("hello")
|
|
|
|
end
|
2014-07-30 23:50:14 +00:00
|
|
|
|
2015-05-29 21:21:15 +00:00
|
|
|
it "routes request with query string" do
|
2015-10-23 18:33:26 +00:00
|
|
|
kemal = Kemal::Handler.new
|
|
|
|
kemal.add_route "GET", "/" do |ctx|
|
2015-05-29 21:21:15 +00:00
|
|
|
"hello #{ctx.params["message"]}"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/?message=world")
|
2015-10-23 18:33:26 +00:00
|
|
|
response = kemal.call(request)
|
2015-05-29 21:21:15 +00:00
|
|
|
response.body.should eq("hello world")
|
|
|
|
end
|
|
|
|
|
2015-10-26 18:49:28 +00:00
|
|
|
it "routes request with multiple query strings" do
|
|
|
|
kemal = Kemal::Handler.new
|
|
|
|
kemal.add_route "GET", "/" do |ctx|
|
|
|
|
"hello #{ctx.params["message"]} time #{ctx.params["time"]}"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/?message=world&time=now")
|
|
|
|
response = kemal.call(request)
|
|
|
|
response.body.should eq("hello world time now")
|
|
|
|
end
|
|
|
|
|
2015-05-29 21:24:31 +00:00
|
|
|
it "route parameter has more precedence than query string arguments" do
|
2015-10-23 18:33:26 +00:00
|
|
|
kemal = Kemal::Handler.new
|
|
|
|
kemal.add_route "GET", "/:message" do |ctx|
|
2015-05-29 21:24:31 +00:00
|
|
|
"hello #{ctx.params["message"]}"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/world?message=coco")
|
2015-10-23 18:33:26 +00:00
|
|
|
response = kemal.call(request)
|
2015-05-29 21:24:31 +00:00
|
|
|
response.body.should eq("hello world")
|
|
|
|
end
|
2014-07-30 22:58:48 +00:00
|
|
|
end
|