-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathelement_spec.rb
More file actions
85 lines (68 loc) · 2.36 KB
/
element_spec.rb
File metadata and controls
85 lines (68 loc) · 2.36 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Element rendering', type: :render do
it 'parses one-line element' do
expect(render_string('%span hello')).to eq("<span>hello</span>\n")
end
it 'parses multi-line element' do
expect(render_string(<<HAML)).to eq("<span>\nhello\n</span>\n")
%span
hello
HAML
end
it 'parses nested elements' do
expect(render_string(<<HAML)).to eq("<span>\n<b>\nhello\n</b>\n<i>\n<small>world</small>\n</i>\n</span>\n")
%span
%b
hello
%i
%small world
HAML
end
it 'skips empty lines' do
expect(render_string(<<HAML)).to eq("<span>\n<b>\nhello\n</b>\n</span>\n")
%span
%b
hello
HAML
end
it 'parses classes' do
expect(render_string('%span.foo.bar hello')).to eq("<span class='foo bar'>hello</span>\n")
end
it 'parses id' do
expect(render_string('%span#foo-bar hello')).to eq("<span id='foo-bar'>hello</span>\n")
end
it 'parses classes and id' do
expect(render_string('%span.foo#foo-bar.bar hello')).to eq("<span class='foo bar' id='foo-bar'>hello</span>\n")
end
it 'parses #' do
expect(render_string('#main')).to eq("<div id='main'></div>\n")
end
it 'parses .' do
expect(render_string('.wrapper.main')).to eq("<div class='wrapper main'></div>\n")
end
it 'parses string interpolation' do
expect(render_string(%q|%span hello <span> #{'</span>'} </span>|)).to eq("<span>hello <span> </span> </span></span>\n")
expect(render_string(<<'HAML')).to eq("<span>\nhello <span> </span> </span>\n</span>\n")
%span
hello <span> #{{text: '</span>'}[:text]} </span>
HAML
expect(render_string(<<'HAML')).to eq("<span>\nhello <span> </span> </span>\n</span>\n")
- @var = '</span>'
%span
hello <span> #@var </span>
HAML
end
it 'parses string interpolation with multibyte characters' do
expect(render_string(%q|#{'日本語'} にほんご|)).to eq("日本語 にほんご\n")
end
it 'recognized escaped string interpolation' do
expect(render_string(%q|%p hello \#{1 + 2}|)).to eq("<p>hello \#{1 + 2}</p>\n")
end
it 'parses self-closing tag' do
expect(render_string('%p/')).to eq("<p>\n")
end
it 'renders some attributes as self-closing by default' do
expect(render_string('%meta{"http-equiv" => "Content-Type", :content => "text/html"}')).to eq("<meta content='text/html' http-equiv='Content-Type'>\n")
end
end