From 520f4bbf77be162dcaf8b8f265e8596f851584e4 Mon Sep 17 00:00:00 2001 From: yfractal Date: Mon, 24 Nov 2014 20:38:38 +0800 Subject: [PATCH 1/2] add route tests --- test/runtests.jl | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 29ead8a..4625996 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1 +1,78 @@ using Morsel +using FactCheck +import Requests +req = Requests + +app = Morsel.app() + +get(app, "/") do req, res + "root_get" +end + +@async start(app, 8000) + +# make sure the app has run +response = req.get("http://localhost:8000/") +while (response.status != 200) + response = req.get("http://localhost:8000/") +end + +facts("route") do + facts("get, post, post, put, delete, request") do + # patch doesn't support... + route(app, POST | PUT | DELETE , "/") do req, res + "root" + end + + context("get") do + response = req.get("http://localhost:8000/") + @fact response.status => 200 + @fact response.data => "root_get" + end + + context("post, put, delete") do + @fact req.post("http://localhost:8000/").data => "root" + @fact req.put("http://localhost:8000/").data => "root" + @fact req.delete("http://localhost:8000/").data => "root" + end + end + + facts("Add route when the app is running") do + get(app, "/running") do req, res + "running" + end + @fact req.get("http://localhost:8000/running").status => 200 + end + + facts("dynamic route") do + context("the request will succes if the type is right") do + route(app, GET, "/users/" ) do req, res + string("User id is:", req.params[:id]) + end + + @fact req.get("http://localhost:8000/users/10").status => 200 + @fact req.get("http://localhost:8000/users/abc").status => 404 # wrong type + end + context("can get the value by req.params[:id]") do + @fact req.get("http://localhost:8000/users/10").data => "User id is:10" + end + context("regex route") do + route(app, GET, "/name/") do req, res + req.params[:name] + end + + @fact req.get("http://localhost:8000/name/abc33").data => "abc33" + @fact req.get("http://localhost:8000/name/abc333").status => 404 # not match the regex + end + end + + facts("namespace") do + namespace(app, "/namespace") do app + get(app, "/hello/") do req, res + "hello namespace" + end + end + + @fact req.get("http://localhost:8000/namespace/hello").data => "hello namespace" + end +end From 5a77371a83c1f12ebe7fcc28cd01e4283ecc58db Mon Sep 17 00:00:00 2001 From: yfractal Date: Thu, 18 Dec 2014 07:58:41 +0800 Subject: [PATCH 2/2] add test requirements --- test/REQUIRE | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test/REQUIRE diff --git a/test/REQUIRE b/test/REQUIRE new file mode 100644 index 0000000..ce5cdb9 --- /dev/null +++ b/test/REQUIRE @@ -0,0 +1,2 @@ +FactCheck +Requests