test/path.rb in cuba-1.0.0 vs test/path.rb in cuba-2.0.0.rc1
- old
+ new
@@ -4,11 +4,11 @@
{ "SCRIPT_NAME" => "/", "PATH_INFO" => "/about" }
end
test "one level path" do |env|
Cuba.define do
- on path("about") do
+ on "about" do
res.write "About"
end
end
_, _, resp = Cuba.call(env)
@@ -17,16 +17,16 @@
assert_equal({ "SCRIPT_NAME" => "/", "PATH_INFO" => "/about" }, env)
end
test "two level nested paths" do |env|
Cuba.define do
- on path("about") do
- on path("1") do
+ on "about" do
+ on "1" do
res.write "+1"
end
- on path("2") do
+ on "2" do
res.write "+2"
end
end
end
@@ -43,11 +43,11 @@
assert_equal ["+2"], resp.body
end
test "two level inlined paths" do |env|
Cuba.define do
- on path("a"), path("b") do
+ on "a/b" do
res.write "a"
res.write "b"
end
end
@@ -58,16 +58,30 @@
assert_equal ["a", "b"], resp.body
end
test "a path with some regex captures" do |env|
Cuba.define do
- on path("user(\\d+)") do |uid|
+ on "user(\\d+)" do |uid|
res.write uid
end
end
env["PATH_INFO"] = "/user123"
_, _, resp = Cuba.call(env)
assert_equal ["123"], resp.body
end
+
+test "matching the root" do |env|
+ Cuba.define do
+ on "" do
+ res.write "Home"
+ end
+ end
+
+ env["PATH_INFO"] = "/"
+
+ _, _, resp = Cuba.call(env)
+
+ assert_equal ["Home"], resp.body
+end
\ No newline at end of file