Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (86 sloc) 2.515 kb
c00a25e Ryan Tomayko Test framework refactoring
rtomayko authored
1 require File.dirname(__FILE__) + '/helper'
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
2
3 describe "HAML Templates" do
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 Ryan Tomayko Fix whitespace errors across all source files and tests
rtomayko authored
11
a734cf3 Ryan Tomayko 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 Ryan Tomayko 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 Ryan Tomayko Fix whitespace errors across all source files and tests
rtomayko authored
17
a734cf3 Ryan Tomayko 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 Ryan Tomayko 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 Ryan Tomayko Fix whitespace errors across all source files and tests
rtomayko authored
23
a734cf3 Ryan Tomayko 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 Ryan Tomayko 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 Ryan Tomayko 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 Ryan Tomayko 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 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
40 end
2399905 Simon Rozet Add the possibility to configure options that are passed to Haml::Engine...
sr authored
41
a734cf3 Ryan Tomayko 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 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
46 assert_raise(Errno::ENOENT) { get('/') }
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
47 end
2399905 Simon Rozet Add the possibility to configure options that are passed to Haml::Engine...
sr authored
48
a734cf3 Ryan Tomayko 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
52 haml "!!!\n%h1 Hello World", :haml_options => {:format => :html5}
53 end
54 get '/backwards_compatible' do
55 haml "!!!\n%h1 Hello World", :options => {:format => :html4}
56 end
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
57 }
d359dc9 Kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
58 get '/'
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
59 assert ok?
60 assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
d359dc9 Kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
61 get '/backwards_compatible'
62 assert ok?
63 assert_match(/^<!DOCTYPE html PUBLIC (.*) HTML 4.01/, body)
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
64 end
2399905 Simon Rozet Add the possibility to configure options that are passed to Haml::Engine...
sr authored
65
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
66 it "passes default HAML options to the Haml engine" do
67 mock_app {
68 set :haml, {:format => :html5}
2399905 Simon Rozet Add the possibility to configure options that are passed to Haml::Engine...
sr authored
69 get '/' do
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
70 haml "!!!\n%h1 Hello World"
2399905 Simon Rozet Add the possibility to configure options that are passed to Haml::Engine...
sr authored
71 end
a734cf3 Ryan Tomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
72 }
73 get '/'
72a6e01 Ryan Tomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
74 assert ok?
75 assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
2399905 Simon Rozet Add the possibility to configure options that are passed to Haml::Engine...
sr authored
76 end
d359dc9 Kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
77
78 it "merges the default HAML options with the overrides and passes them to the Haml engine" do
79 mock_app {
80 set :haml, {:format => :html5, :attr_wrapper => '"'} # default HAML attr are <tag attr='single-quoted'>
81 get '/' do
82 haml "!!!\n%h1{:class => :header} Hello World"
83 end
84 get '/html4' do
85 haml "!!!\n%h1{:class => 'header'} Hello World", :haml_options => {:format => :html4}
86 end
87 }
88 get '/'
89 assert ok?
90 assert_equal "<!DOCTYPE html>\n<h1 class=\"header\">Hello World</h1>\n", body
91 get '/html4'
92 assert ok?
93 assert_match(/^<!DOCTYPE html PUBLIC (.*) HTML 4.01/, body)
94 end
520ac2e Haml
Blake Mizerany authored
95 end
Something went wrong with that request. Please try again.