mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Added return_with macro to break response in the middle of the block.
This commit is contained in:
parent
7b1bc43a41
commit
8110788a41
3 changed files with 41 additions and 0 deletions
|
@ -34,4 +34,37 @@ describe "Macros" do
|
|||
config.logger.should be_a(CustomLogHandler)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#return_with" do
|
||||
it "can break block with return_with macro" do
|
||||
get "/non-breaking" do |env|
|
||||
"hello"
|
||||
"world"
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/non-breaking")
|
||||
client_response = call_request_on_app(request)
|
||||
client_response.status_code.should eq(200)
|
||||
client_response.body.should eq("world")
|
||||
|
||||
get "/breaking" do |env|
|
||||
return_with env, 404, "hello"
|
||||
"world"
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/breaking")
|
||||
client_response = call_request_on_app(request)
|
||||
client_response.status_code.should eq(404)
|
||||
client_response.body.should eq("hello")
|
||||
end
|
||||
|
||||
it "can break block with return_with macro using default values" do
|
||||
get "/" do |env|
|
||||
return_with env
|
||||
"world"
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/")
|
||||
client_response = call_request_on_app(request)
|
||||
client_response.status_code.should eq(200)
|
||||
client_response.body.should eq("")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue