File: erb_spec.rb

package info (click to toggle)
ruby-temple 0.10.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 476 kB
  • sloc: ruby: 3,347; makefile: 6
file content (61 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download | duplicates (2)
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
require 'spec_helper'
require 'tilt/erubi'

describe Temple::ERB::Engine do
  it 'should compile erb' do
    src = %q{
%% hi
= hello
<% 3.times do |n| %>
* <%= n %>
<% end %>
}

    expect(erb(src)).to eq(erubi(src))
  end

  it 'should recognize comments' do
    src = %q{
hello
  <%# comment -- ignored -- useful in testing %>
world}

    expect(erb(src)).to eq(erubi(src))
  end

  it 'should recognize <%% and %%>' do
    src = %q{
<%%
<% if true %>
  %%>
<% end %>
}

    expect(erb(src)).to eq("\n<%\n  %>\n")
  end

  it 'should escape automatically' do
    src = '<%== "<" %>'
    ans = '&lt;'
    expect(erb(src)).to eq(ans)
  end

  it 'should support = to disable automatic escape' do
    src = '<%= "<" %>'
    ans = '<'
    expect(erb(src)).to eq(ans)
  end

  it 'should support trim mode' do
    src = %q{
%% hi
= hello
<% 3.times do |n| %>
* <%= n %>
<% end %>
}

    expect(erb(src, trim: true)).to eq(erubi(src, trim: true))
    expect(erb(src, trim: false)).to eq(erubi(src, trim: false))
  end
end