refactor(loader): Throw when template not found

This commit is contained in:
Kyle Fuller
2016-11-30 17:07:38 +00:00
parent 63c2b935f7
commit 2ebb79df8b
8 changed files with 156 additions and 10 deletions

View File

@@ -0,0 +1,31 @@
import Spectre
import Stencil
import PathKit
func testTemplateLoader() {
describe("FileSystemLoader") {
let path = Path(#file) + ".." + "fixtures"
let loader = FileSystemLoader(paths: [path])
$0.it("errors when a template cannot be found") {
try expect(try loader.loadTemplate(name: "unknown.html")).toThrow()
}
$0.it("errors when an array of templates cannot be found") {
try expect(try loader.loadTemplate(names: ["unknown.html", "unknown2.html"])).toThrow()
}
$0.it("can load a template from a file") {
_ = try loader.loadTemplate(name: "test.html")
}
$0.it("errors when loading absolute file outside of the selected path") {
try expect(try loader.loadTemplate(name: "/etc/hosts")).toThrow()
}
$0.it("errors when loading relative file outside of the selected path") {
try expect(try loader.loadTemplate(name: "../LoaderSpec.swift")).toThrow()
}
}
}