kemal/spec/view_spec.cr

48 lines
1.4 KiB
Crystal
Raw Normal View History

2016-01-24 17:13:10 +00:00
require "./spec_helper"
macro render_with_base_and_layout(filename)
render "spec/asset/#{{{filename}}}", "spec/asset/layout.ecr"
end
describe "Views" do
it "renders file" do
2016-03-21 16:29:48 +00:00
get "/view/:name" do |env|
name = env.params.url["name"]
2016-01-24 17:13:10 +00:00
render "spec/asset/hello.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
2016-03-21 16:29:48 +00:00
client_response = call_request_on_app(request)
2016-01-24 17:13:10 +00:00
client_response.body.should contain("Hello world")
end
it "renders file with dynamic variables" do
2016-03-21 16:29:48 +00:00
get "/view/:name" do |env|
name = env.params.url["name"]
2016-01-24 17:13:10 +00:00
render_with_base_and_layout "hello.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
2016-03-21 16:29:48 +00:00
client_response = call_request_on_app(request)
2016-01-24 17:13:10 +00:00
client_response.body.should contain("Hello world")
end
it "renders layout" do
2016-03-21 16:29:48 +00:00
get "/view/:name" do |env|
name = env.params.url["name"]
2016-01-24 17:13:10 +00:00
render "spec/asset/hello.ecr", "spec/asset/layout.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
2016-03-21 16:29:48 +00:00
client_response = call_request_on_app(request)
2016-01-24 17:13:10 +00:00
client_response.body.should contain("<html>Hello world")
end
2016-07-09 15:57:35 +00:00
it "renders layout with content_for" do
get "/view" do
name = "Kemal"
render "spec/asset/hello_with_content_for.ecr", "spec/asset/layout_with_yield.ecr"
end
request = HTTP::Request.new("GET", "/view")
client_response = call_request_on_app(request)
client_response.body.should contain("<html>Hello world")
end
2016-01-24 17:13:10 +00:00
end