2015-12-06 14:05:16 +00:00
|
|
|
require "./spec_helper"
|
|
|
|
|
2015-12-18 08:34:26 +00:00
|
|
|
macro render_with_base_and_layout(filename)
|
|
|
|
render "spec/asset/#{{{filename}}}", "spec/asset/layout.ecr"
|
|
|
|
end
|
|
|
|
|
2015-12-06 14:05:16 +00:00
|
|
|
describe "Views" do
|
|
|
|
it "renders file" do
|
|
|
|
kemal = Kemal::Handler.new
|
|
|
|
kemal.add_route "GET", "/view/:name" do |env|
|
|
|
|
render "spec/asset/hello.ecr"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/view/world")
|
|
|
|
response = kemal.call(request)
|
|
|
|
response.body.should contain("Hello world")
|
|
|
|
end
|
2015-12-09 15:52:56 +00:00
|
|
|
|
2015-12-18 08:34:26 +00:00
|
|
|
it "renders file with dynamic variables" do
|
|
|
|
kemal = Kemal::Handler.new
|
|
|
|
kemal.add_route "GET", "/view/:name" do |env|
|
|
|
|
render_with_base_and_layout "hello.ecr"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/view/world")
|
|
|
|
response = kemal.call(request)
|
|
|
|
response.body.should contain("Hello world")
|
|
|
|
end
|
|
|
|
|
2015-12-09 15:52:56 +00:00
|
|
|
it "renders layout" do
|
|
|
|
kemal = Kemal::Handler.new
|
|
|
|
kemal.add_route "GET", "/view/:name" do |env|
|
|
|
|
render "spec/asset/hello.ecr", "spec/asset/layout.ecr"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/view/world")
|
|
|
|
response = kemal.call(request)
|
|
|
|
response.body.should contain("<html>Hello world")
|
|
|
|
end
|
2015-12-06 14:05:16 +00:00
|
|
|
end
|