Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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