forked from rtomayko/tilt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtilt_test.rb
60 lines (50 loc) · 1.65 KB
/
tilt_test.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
54
55
56
57
58
59
60
require 'test_helper'
require 'tilt'
class TiltTest < Minitest::Test
class MockTemplate
attr_reader :args, :block
def initialize(*args, &block)
@args = args
@block = block
end
end
test "registering template implementation classes by file extension" do
Tilt.register(MockTemplate, 'mock')
end
test "an extension is registered if explicit handle is found" do
Tilt.register(MockTemplate, 'mock')
assert Tilt.registered?('mock')
end
test "registering template classes by symbol file extension" do
Tilt.register(MockTemplate, :mock)
end
test "looking up template classes by exact file extension" do
Tilt.register(MockTemplate, 'mock')
impl = Tilt['mock']
assert_equal MockTemplate, impl
end
test "looking up template classes by implicit file extension" do
Tilt.register(MockTemplate, 'mock')
impl = Tilt['.mock']
assert_equal MockTemplate, impl
end
test "looking up template classes with multiple file extensions" do
Tilt.register(MockTemplate, 'mock')
impl = Tilt['index.html.mock']
assert_equal MockTemplate, impl
end
test "looking up template classes by file name" do
Tilt.register(MockTemplate, 'mock')
impl = Tilt['templates/test.mock']
assert_equal MockTemplate, impl
end
test "looking up non-existant template class" do
assert_nil Tilt['none']
end
test "creating new template instance with a filename" do
Tilt.register(MockTemplate, 'mock')
template = Tilt.new('foo.mock', 1, :key => 'val') { 'Hello World!' }
assert_equal ['foo.mock', 1, {:key => 'val'}], template.args
assert_equal 'Hello World!', template.block.call
end
end