Adding trim option to ERB, closes #840
Created by: hron84
The difference described in rspec spec:
require 'rspec/autorun'
require 'erb'
describe ERB do
let(:strip_template) { "<% if 1 == 1 -%>\nPassed<% end -%>\n" }
let(:normal_template) { "<% if 1 == 1 %>\nPassed<% end %>\n" }
context 'without trim mode' do
it 'accepts normal templates' do
template = ERB.new(normal_template)
expect do
template.result(binding)
end.to_not raise_error SyntaxError
end
it 'does not trim newlines' do
template = ERB.new(normal_template)
template.result(binding).should eql "\nPassed\n"
end
it 'does not accept dashes at open/close tags' do
template = ERB.new(strip_template)
expect do
template.result(binding)
end.to raise_error SyntaxError
end
end
context 'with trim mode' do
it 'accepts normal template' do
template = ERB.new(normal_template, nil, '-')
expect do
template.result(binding)
end.to_not raise_error SyntaxError
end
it 'accepts dashes at open/close tags' do
template = ERB.new(strip_template, nil, '-')
expect do
template.result(binding)
end.to_not raise_error SyntaxError
end
it 'trims newlines' do
template = ERB.new(strip_template, nil, '-')
template.result(binding).should eql 'Passed'
end
end
end