/
parser_spec.rb
38 lines (28 loc) · 1.51 KB
/
parser_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
require 'spec_helper'
require 'it'
describe It::Parser do
describe '#process' do
it 'calls the Interpolation as required' do
values = {'b' => It.tag(:b), 'link' => '/messages'}
parser = It::Parser.new('You have %{b:%{link:new messages}}!', values)
return1 = double('It::Interpolation', process: '<a href="/messages">new messages</a>')
It::Interpolation.should_receive(:new).with('%{link:new messages}', values).and_return(return1)
return2 = double('It::Interpolation', process: '<b><a href="/messages">new messages</a></b>')
It::Interpolation.should_receive(:new).with('%{b:<a href="/messages">new messages</a>}', values).and_return(return2)
expect(parser.process).to eq('You have <b><a href="/messages">new messages</a></b>!')
end
it 'escapes HTML in the string and the labels' do
parser = It::Parser.new('It is a <b>save</b> %{word:<i>world</i>}', 'word' => It.tag(:i))
expect(parser.process).to eq('It is a <b>save</b> <i><i>world</i></i>')
end
it 'marks the result as html safe' do
parser = It::Parser.new('test', {})
expect(parser.process).to be_html_safe
end
it 'delegates pluralization to I18n' do
I18n.backend.stub(:pluralize).with('en', {other: 'You have %{count} messages'}, 2) { 'This is the pluralized string' }
parser = It::Parser.new({other: 'You have %{count} messages'}, 'locale' => 'en', 'count' => 2)
expect(parser.process).to eq('This is the pluralized string')
end
end
end