Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 90 lines (80 sloc) 2.259 kB
c00a25e @rtomayko Test framework refactoring
rtomayko authored
1 require File.dirname(__FILE__) + '/helper'
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
2
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
3 class HAMLTest < Test::Unit::TestCase
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
4 def haml_app(&block)
5 mock_app {
6 set :views, File.dirname(__FILE__) + '/views'
7 get '/', &block
8 }
9 get '/'
520ac2e Haml
Blake Mizerany authored
10 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
11
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
12 it 'renders inline HAML strings' do
13 haml_app { haml '%h1 Hiya' }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
14 assert ok?
15 assert_equal "<h1>Hiya</h1>\n", body
520ac2e Haml
Blake Mizerany authored
16 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
17
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
18 it 'renders .haml files in views path' do
19 haml_app { haml :hello }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
20 assert ok?
21 assert_equal "<h1>Hello From Haml</h1>\n", body
520ac2e Haml
Blake Mizerany authored
22 end
60d5006 @rtomayko Fix whitespace errors across all source files and tests
rtomayko authored
23
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
24 it "renders with inline layouts" do
25 mock_app {
26 layout { %q(%h1= 'THIS. IS. ' + yield.upcase) }
27 get('/') { haml '%em Sparta' }
28 }
29 get '/'
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
30 assert ok?
31 assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n", body
7d5bc1f Haml & Erb redo
Blake Mizerany authored
32 end
33
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
34 it "renders with file layouts" do
35 haml_app {
36 haml 'Hello World', :layout => :layout2
37 }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
38 assert ok?
39 assert_equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n", body
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
40 end
2399905 @sr Add the possibility to configure options that are passed to Haml::Eng…
sr authored
41
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
42 it "raises error if template not found" do
43 mock_app {
44 get('/') { haml :no_such_template }
45 }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
46 assert_raise(Errno::ENOENT) { get('/') }
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
47 end
2399905 @sr Add the possibility to configure options that are passed to Haml::Eng…
sr authored
48
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
49 it "passes HAML options to the Haml engine" do
d359dc9 @kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
50 mock_app {
51 get '/' do
49adaa5 @rtomayko Sane template options [#191]
rtomayko authored
52 haml "!!!\n%h1 Hello World", :format => :html5
d359dc9 @kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
53 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
54 }
d359dc9 @kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
55 get '/'
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
56 assert ok?
57 assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
58 end
2399905 @sr Add the possibility to configure options that are passed to Haml::Eng…
sr authored
59
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
60 it "passes default HAML options to the Haml engine" do
61 mock_app {
62 set :haml, {:format => :html5}
2399905 @sr Add the possibility to configure options that are passed to Haml::Eng…
sr authored
63 get '/' do
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
64 haml "!!!\n%h1 Hello World"
2399905 @sr Add the possibility to configure options that are passed to Haml::Eng…
sr authored
65 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
66 }
67 get '/'
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
68 assert ok?
69 assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
2399905 @sr Add the possibility to configure options that are passed to Haml::Eng…
sr authored
70 end
d359dc9 @kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
71
72 it "merges the default HAML options with the overrides and passes them to the Haml engine" do
73 mock_app {
74 set :haml, {:format => :html5, :attr_wrapper => '"'} # default HAML attr are <tag attr='single-quoted'>
75 get '/' do
76 haml "!!!\n%h1{:class => :header} Hello World"
77 end
78 get '/html4' do
49adaa5 @rtomayko Sane template options [#191]
rtomayko authored
79 haml "!!!\n%h1{:class => 'header'} Hello World", :format => :html4
d359dc9 @kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
80 end
81 }
82 get '/'
83 assert ok?
84 assert_equal "<!DOCTYPE html>\n<h1 class=\"header\">Hello World</h1>\n", body
85 get '/html4'
86 assert ok?
87 assert_match(/^<!DOCTYPE html PUBLIC (.*) HTML 4.01/, body)
88 end
520ac2e Haml
Blake Mizerany authored
89 end
Something went wrong with that request. Please try again.