Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 92 lines (79 sloc) 2.426 kb
e001d62 @rkh adjust require lines for test helper, so it also works properly on 1.9.2
rkh authored
1 require File.expand_path('../helper', __FILE__)
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)
46e8bd6 @zzak First pass at block styles for tests
zzak authored
8 mock_app do
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
9 set :views, File.dirname(__FILE__) + '/views'
46e8bd6 @zzak First pass at block styles for tests
zzak authored
10 get('/', &block)
11 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
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
46e8bd6 @zzak First pass at block styles for tests
zzak authored
28 mock_app do
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
29 layout { %q(%h1= 'THIS. IS. ' + yield.upcase) }
30 get('/') { haml '%em Sparta' }
46e8bd6 @zzak First pass at block styles for tests
zzak authored
31 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
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
46e8bd6 @zzak First pass at block styles for tests
zzak authored
38 haml_app { haml 'Hello World', :layout => :layout2 }
72a6e01 @rtomayko 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 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
41 end
2399905 @sr Add the possibility to configure options that are passed to Haml::Engine...
sr authored
42
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
43 it "raises error if template not found" do
46e8bd6 @zzak First pass at block styles for tests
zzak authored
44 mock_app { get('/') { haml :no_such_template } }
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
45 assert_raise(Errno::ENOENT) { get('/') }
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
46 end
2399905 @sr Add the possibility to configure options that are passed to Haml::Engine...
sr authored
47
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
48 it "passes HAML options to the Haml engine" do
d359dc9 @kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
49 mock_app {
46e8bd6 @zzak First pass at block styles for tests
zzak authored
50 get('/') { haml "!!!\n%h1 Hello World", :format => :html5 }
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
51 }
d359dc9 @kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
52 get '/'
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
53 assert ok?
54 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
55 end
2399905 @sr Add the possibility to configure options that are passed to Haml::Engine...
sr authored
56
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
57 it "passes default HAML options to the Haml engine" do
46e8bd6 @zzak First pass at block styles for tests
zzak authored
58 mock_app do
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
59 set :haml, {:format => :html5}
46e8bd6 @zzak First pass at block styles for tests
zzak authored
60 get('/') { haml "!!!\n%h1 Hello World" }
61 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
62 get '/'
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
63 assert ok?
64 assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
2399905 @sr Add the possibility to configure options that are passed to Haml::Engine...
sr authored
65 end
d359dc9 @kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
66
67 it "merges the default HAML options with the overrides and passes them to the Haml engine" do
46e8bd6 @zzak First pass at block styles for tests
zzak authored
68 mock_app do
d359dc9 @kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
69 set :haml, {:format => :html5, :attr_wrapper => '"'} # default HAML attr are <tag attr='single-quoted'>
46e8bd6 @zzak First pass at block styles for tests
zzak authored
70 get('/') { haml "!!!\n%h1{:class => :header} Hello World" }
71 get('/html4') {
49adaa5 @rtomayko Sane template options [#191]
rtomayko authored
72 haml "!!!\n%h1{:class => 'header'} Hello World", :format => :html4
46e8bd6 @zzak First pass at block styles for tests
zzak authored
73 }
74 end
d359dc9 @kematzy Merge app-level haml/sass options with call options [#184]
kematzy authored
75 get '/'
76 assert ok?
77 assert_equal "<!DOCTYPE html>\n<h1 class=\"header\">Hello World</h1>\n", body
78 get '/html4'
79 assert ok?
80 assert_match(/^<!DOCTYPE html PUBLIC (.*) HTML 4.01/, body)
81 end
7e80e37 @rkh add test for locals passed to haml
rkh authored
82
83 it "is possible to pass locals" do
84 haml_app { haml "= foo", :locals => { :foo => 'bar' }}
85 assert_equal "bar\n", body
86 end
520ac2e Haml
Blake Mizerany authored
87 end
e16bc71 @cactus Explicitly handle the exception for failed loading.
cactus authored
88
89 rescue LoadError
e1638a4 @rtomayko skip haml / sass tests when they fail to load due to stupid bullshit
rtomayko authored
90 warn "#{$!.to_s}: skipping haml tests"
91 end
Something went wrong with that request. Please try again.