2015-01-31 14:39:50 +00:00
|
|
|
require "./spec_helper"
|
2014-07-30 22:58:48 +00:00
|
|
|
|
|
|
|
describe "Frank::Handler" do
|
|
|
|
it "routes" do
|
|
|
|
frank = Frank::Handler.new
|
|
|
|
frank.add_route "GET", "/" do
|
|
|
|
"hello"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/")
|
|
|
|
response = frank.call(request)
|
|
|
|
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
|
|
|
|
frank = Frank::Handler.new
|
|
|
|
frank.add_route "GET", "/" do |ctx|
|
|
|
|
"hello #{ctx.params["message"]}"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/?message=world")
|
|
|
|
response = frank.call(request)
|
|
|
|
response.body.should eq("hello world")
|
|
|
|
end
|
|
|
|
|
2015-05-29 21:24:31 +00:00
|
|
|
it "route parameter has more precedence than query string arguments" do
|
|
|
|
frank = Frank::Handler.new
|
|
|
|
frank.add_route "GET", "/:message" do |ctx|
|
|
|
|
"hello #{ctx.params["message"]}"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/world?message=coco")
|
|
|
|
response = frank.call(request)
|
|
|
|
response.body.should eq("hello world")
|
|
|
|
end
|
|
|
|
|
2014-07-30 23:50:14 +00:00
|
|
|
it "sets content type" do
|
|
|
|
frank = Frank::Handler.new
|
|
|
|
frank.add_route "GET", "/" do |env|
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/")
|
|
|
|
response = frank.call(request)
|
|
|
|
response.headers["Content-Type"].should eq("application/json")
|
|
|
|
end
|
2014-07-30 22:58:48 +00:00
|
|
|
end
|