shard-kemal/spec/view_spec.cr

44 lines
1.6 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-02-03 20:08:54 +00:00
kemal = Kemal::RouteHandler.new
2016-01-24 17:13:10 +00:00
kemal.add_route "GET", "/view/:name" do |env|
name = env.params["name"]
render "spec/asset/hello.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
io_with_context = create_request_and_return_io(kemal, request)
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
client_response.body.should contain("Hello world")
end
it "renders file with dynamic variables" do
2016-02-03 20:08:54 +00:00
kemal = Kemal::RouteHandler.new
2016-01-24 17:13:10 +00:00
kemal.add_route "GET", "/view/:name" do |env|
name = env.params["name"]
render_with_base_and_layout "hello.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
io_with_context = create_request_and_return_io(kemal, request)
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
client_response.body.should contain("Hello world")
end
it "renders layout" do
2016-02-03 20:08:54 +00:00
kemal = Kemal::RouteHandler.new
2016-01-24 17:13:10 +00:00
kemal.add_route "GET", "/view/:name" do |env|
name = env.params["name"]
render "spec/asset/hello.ecr", "spec/asset/layout.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
io_with_context = create_request_and_return_io(kemal, request)
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
client_response.body.should contain("<html>Hello world")
end
end