2015-01-31 14:39:50 +00:00
|
|
|
require "./spec_helper"
|
2014-06-11 23:41:02 +00:00
|
|
|
|
|
|
|
describe "Route" do
|
2015-10-31 07:28:25 +00:00
|
|
|
describe "match?" do
|
2014-07-30 22:58:48 +00:00
|
|
|
it "doesn't match because of route" do
|
|
|
|
route = Route.new("GET", "/foo/bar") { "" }
|
2015-10-28 18:30:27 +00:00
|
|
|
request = HTTP::Request.new("GET", "/world?message=coco")
|
|
|
|
route.match?(request).should be_nil
|
2014-07-30 22:58:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't match because of method" do
|
|
|
|
route = Route.new("GET", "/foo/bar") { "" }
|
2015-10-28 18:30:27 +00:00
|
|
|
request = HTTP::Request.new("POST", "/foo/bar")
|
|
|
|
route.match?(request).should be_nil
|
2014-06-11 23:41:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "matches" do
|
2014-07-30 22:58:48 +00:00
|
|
|
route = Route.new("GET", "/foo/:one/path/:two") { "" }
|
2015-10-28 18:30:27 +00:00
|
|
|
request = HTTP::Request.new("GET", "/foo/uno/path/dos")
|
|
|
|
match = route.match?(request)
|
|
|
|
match.should eq true
|
2014-06-11 23:41:02 +00:00
|
|
|
end
|
2015-10-31 07:28:25 +00:00
|
|
|
|
|
|
|
it "matches the correct route" do
|
|
|
|
kemal = Kemal::Handler.new
|
|
|
|
kemal.add_route "GET", "/route1" do |env|
|
|
|
|
"Route 1"
|
|
|
|
end
|
|
|
|
kemal.add_route "GET", "/route2" do |env|
|
|
|
|
"Route 2"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/route2")
|
|
|
|
response = kemal.call(request)
|
|
|
|
response.body.should eq("Route 2")
|
|
|
|
end
|
2014-06-11 23:41:02 +00:00
|
|
|
end
|
|
|
|
end
|