Sha256: c362ff37b3ec623e39b86ce391d0ed649f6221aac190e9c7e1768fc298f82654

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

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 &lt;b&gt;save&lt;/b&gt; <i>&lt;i&gt;world&lt;/i&gt;</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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
it-0.2.4 spec/it/parser_spec.rb