3
class ::MockError < NameError
6
class TestSlimTemplate < TestSlim
7
def test_default_mime_type
8
assert_equal 'text/html', Slim::Template.default_mime_type
11
def test_registered_extension
12
assert_equal Slim::Template, Tilt['test.slim']
15
def test_preparing_and_evaluating
16
template = Slim::Template.new { |t| "p Hello World!\n" }
17
assert_equal "<p>Hello World!</p>", template.render
20
def test_evaluating_in_an_object_scope
21
template = Slim::Template.new { "p = 'Hey ' + @name + '!'\n" }
23
scope.instance_variable_set :@name, 'Joe'
24
assert_equal "<p>Hey Joe!</p>", template.render(scope)
27
def test_passing_a_block_for_yield
28
template = Slim::Template.new { "p = 'Hey ' + yield + '!'\n" }
29
assert_equal "<p>Hey Joe!</p>", template.render { 'Joe' }
32
def test_backtrace_file_and_line_reporting_without_locals
33
data = File.read(__FILE__).split("\n__END__\n").last
34
fail unless data[0] == ?h
35
template = Slim::Template.new('test.slim', 10) { data }
38
fail 'should have raised an exception'
40
assert_kind_of NameError, ex
41
assert_backtrace(ex, 'test.slim:12')
45
def test_backtrace_file_and_line_reporting_with_locals
46
data = File.read(__FILE__).split("\n__END__\n").last
47
fail unless data[0] == ?h
48
template = Slim::Template.new('test.slim') { data }
50
res = template.render(Object.new, :name => 'Joe', :foo => 'bar')
52
assert_kind_of MockError, ex
53
assert_backtrace(ex, 'test.slim:5')
57
def test_compiling_template_source_to_a_method
58
template = Slim::Template.new { |t| "Hello World!" }
60
method = template.send(:compiled_method, [])
61
assert_kind_of UnboundMethod, method
64
def test_passing_locals
65
template = Slim::Template.new { "p = 'Hey ' + name + '!'\n" }
66
assert_equal "<p>Hey Joe!</p>", template.render(Object.new, :name => 'Joe')