-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathhaml_spec.rb
45 lines (34 loc) · 1.13 KB
/
haml_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
gem 'minitest'
require 'minitest/autorun'
require 'ruby2js/filter/functions'
require 'haml'
require 'ruby2js/haml'
describe 'HAML filter' do
it 'should convert ruby to javascript' do
haml = %{
:ruby2js
alert 'Hello'
}
# unindent template so that the first line starts in column 1
# As in, it is valid haml
haml.gsub!(/^#{haml[/\A\s+/]}/, '')
#copied from from haml tests, module RenderHelper
output = Haml::Template.new({}) { haml }.render(Object.new, {})
_(output).must_include "<script type='text/javascript'>"
_(output).must_include 'alert("Hello")'
_(output).must_include '</script>'
end
it 'should convert ruby with interpolation to javascript' do
haml = %{
:ruby2js
alert HASH{2 + 2}
}
# unindent template so that the first line starts in column 1
# As in, it is valid haml
haml.gsub!(/^#{haml[/\A\s+/]}/, '')
haml.gsub!("HASH", "#") #stop ruby interpreteting the 2 + 2
#copied from from haml tests, module RenderHelper
output = Haml::Template.new({}) { haml }.render(Object.new, {})
_(output).must_include 'alert(4)'
end
end