feat: Add DictionaryLoader to load templates from dictionary

Closes #97
This commit is contained in:
Kyle Fuller
2017-09-07 18:40:21 +01:00
parent 7b9817ed50
commit 000e9a7f1a
4 changed files with 62 additions and 0 deletions

View File

@@ -29,4 +29,27 @@ func testTemplateLoader() {
try expect(try environment.loadTemplate(name: "../LoaderSpec.swift")).toThrow()
}
}
describe("DictionaryLoader") {
let loader = DictionaryLoader(templates: [
"index.html": "Hello World"
])
let environment = Environment(loader: loader)
$0.it("errors when a template cannot be found") {
try expect(try environment.loadTemplate(name: "unknown.html")).toThrow()
}
$0.it("errors when an array of templates cannot be found") {
try expect(try environment.loadTemplate(names: ["unknown.html", "unknown2.html"])).toThrow()
}
$0.it("can load a template from a known templates") {
_ = try environment.loadTemplate(name: "index.html")
}
$0.it("can load a known template from a collection of templates") {
_ = try environment.loadTemplate(names: ["unknown.html", "index.html"])
}
}
}