forked from sinatra/sinatra
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmarkaby_test.rb
80 lines (68 loc) · 1.97 KB
/
markaby_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require File.expand_path('../helper', __FILE__)
begin
require 'markaby'
class MarkabyTest < Test::Unit::TestCase
def markaby_app(&block)
mock_app do
set :views, File.dirname(__FILE__) + '/views'
get '/', &block
end
get '/'
end
it 'renders inline markaby strings' do
markaby_app { markaby 'h1 "Hiya"' }
assert ok?
assert_equal "<h1>Hiya</h1>", body
end
it 'renders .markaby files in views path' do
markaby_app { markaby :hello }
assert ok?
assert_equal "<h1>Hello From Markaby</h1>", body
end
it "renders with inline layouts" do
mock_app do
layout { 'h1 { text "THIS. IS. "; yield }' }
get('/') { markaby 'em "SPARTA"' }
end
get '/'
assert ok?
assert_equal "<h1>THIS. IS. <em>SPARTA</em></h1>", body
end
it "renders with file layouts" do
markaby_app { markaby 'text "Hello World"', :layout => :layout2 }
assert ok?
assert_equal "<h1>Markaby Layout!</h1><p>Hello World</p>", body
end
it 'renders inline markaby blocks' do
markaby_app { markaby { h1 'Hiya' } }
assert ok?
assert_equal "<h1>Hiya</h1>", body
end
it 'renders inline markaby blocks with inline layouts' do
markaby_app do
settings.layout { 'h1 { text "THIS. IS. "; yield }' }
markaby { em 'SPARTA' }
end
assert ok?
assert_equal "<h1>THIS. IS. <em>SPARTA</em></h1>", body
end
it 'renders inline markaby blocks with file layouts' do
markaby_app { markaby(:layout => :layout2) { text "Hello World" } }
assert ok?
assert_equal "<h1>Markaby Layout!</h1><p>Hello World</p>", body
end
it "raises error if template not found" do
mock_app { get('/') { markaby :no_such_template } }
assert_raise(Errno::ENOENT) { get('/') }
end
it "allows passing locals" do
markaby_app do
markaby 'text value', :locals => { :value => 'foo' }
end
assert ok?
assert_equal 'foo', body
end
end
rescue LoadError
warn "#{$!.to_s}: skipping markaby tests"
end