按照https://github.com/soveran/cuba#usage上的示例并稍作更改:
Cuba.define do
on get do
on 'home' do
res.write "Aloha!"
end
end
on 'api' do
on get do
on "home", params("a"), param("b") do |a,b|
res.write "Hello World!"
end
end
end
end
测试:
scope do
test "Homepage" do
get "/api/home?a=00&b=11"
assert_equal "Hello World!", last_response.body
end
end
但我得到一个断言失败:
AppTest.rb:15:in `block (2 levels) in <main>': "Hello world!" != "" (Cutest::AssertionFailed)
就像我在测试中使用的url不正确。我应该如何改变它?
更新:
我注意到,如果我更改定义,那么它可以正常工作:
Cuba.define do
on 'api' do
on get do
on "home", params("a"), param("b") do |a,b|
res.write "Hello World!"
end
end
end
on get do
on 'home' do
res.write "Aloha!"
end
end
end