Files
swiftpm-stencil/Tests/StencilTests/EnvironmentSpec.swift
2016-12-01 01:29:48 +00:00

42 lines
1.2 KiB
Swift

import Spectre
import Stencil
func testEnvironment() {
describe("Environment") {
let environment = Environment(loader: ExampleLoader())
$0.it("can load a template from a name") {
let template = try environment.loadTemplate(name: "example.html")
try expect(template.name) == "example.html"
}
$0.it("can load a template from a names") {
let template = try environment.loadTemplate(names: ["first.html", "example.html"])
try expect(template.name) == "example.html"
}
$0.it("can render a template from a string") {
let result = try environment.renderTemplate(string: "Hello World")
try expect(result) == "Hello World"
}
$0.it("can render a template from a file") {
let result = try environment.renderTemplate(name: "example.html")
try expect(result) == "Hello World!"
}
}
}
fileprivate class ExampleLoader: Loader {
func loadTemplate(name: String, environment: Environment) throws -> Template {
if name == "example.html" {
return Template(templateString: "Hello World!", environment: environment, name: name)
}
throw TemplateDoesNotExist(templateNames: [name], loader: self)
}
}