kemal/spec/param_parser_spec.cr

26 lines
859 B
Crystal
Raw Normal View History

2015-10-28 18:30:27 +00:00
require "./spec_helper"
describe "ParamParser" do
2015-10-28 18:38:24 +00:00
it "parses query params" do
route = Route.new "POST", "/" do |env|
2015-10-28 18:52:34 +00:00
hasan = env.params["hasan"]
"Hello #{hasan}"
end
2015-10-28 18:38:24 +00:00
request = HTTP::Request.new("POST", "/?hasan=cemal")
params = Kemal::ParamParser.new(route, request).parse
params["hasan"].should eq "cemal"
end
it "parses request body" do
route = Route.new "POST", "/" do |env|
2015-10-28 18:52:34 +00:00
name = env.params["name"]
age = env.params["age"]
hasan = env.params["hasan"]
"Hello #{name} #{hasan} #{age}"
end
2015-10-28 18:38:24 +00:00
request = HTTP::Request.new("POST", "/?hasan=cemal", body: "name=serdar&age=99")
params = Kemal::ParamParser.new(route, request).parse
params.should eq({"hasan" => "cemal", "name" => "serdar", "age" => "99"})
2015-10-28 18:30:27 +00:00
end
end