forked from rtomayko/tilt
/
spec_tilt.rb
53 lines (43 loc) · 1.5 KB
/
spec_tilt.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'bacon'
require 'tilt'
describe Tilt do
class MockTemplate
attr_reader :args, :block
def initialize(*args, &block)
@args = args
@block = block
end
end
it "registers template implementation classes by file extension" do
lambda { Tilt.register('mock', MockTemplate) }.should.not.raise
end
it "registers template implementation classes by a file extension given as a symbol" do
lambda { Tilt.register(:mock, MockTemplate) }.should.not.raise
end
it "looks up template implementation classes by file extension" do
impl = Tilt['mock']
impl.should.equal MockTemplate
impl = Tilt['.mock']
impl.should.equal MockTemplate
end
it "looks up template implementation classes with multiple file extensions" do
impl = Tilt['index.html.mock']
impl.should.equal MockTemplate
end
it "looks up template implementation classes by file name" do
impl = Tilt['templates/test.mock']
impl.should.equal MockTemplate
end
it "gives nil when no template implementation classes exist for a filename" do
Tilt['none'].should.be.nil
end
it "exposes the file pattern -> template class Hash at Tilt::mappings" do
Tilt.should.respond_to :mappings
Tilt.mappings.should.respond_to :[]
end
it "creates a new template instance given a filename" do
template = Tilt.new('foo.mock', 1, :key => 'val') { 'Hello World!' }
template.args.should.equal ['foo.mock', 1, {:key => 'val'}]
template.block.call.should.equal 'Hello World!'
end
end