Skip to content

HTTPS clone URL

Subversion checkout URL

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