Sha256: b0c5031702a51cba13327b559465ba0370058609c11a8f34ff44474088be1afd

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper')

include TruncateHtmlHelper

class Truncator
  include TruncateHtmlHelper
end

describe TruncateHtmlHelper do

  def truncator
    @truncator ||= Truncator.new
  end

  it 'is included in ActionView::Base' do
    ActionView::Base.included_modules.should include(TruncateHtmlHelper)
  end

  before(:each) do
    @html_truncator_mock = mock(TruncateHtml::HtmlTruncator)
    @original_html = '<p>foo</p>'
    @original_html.stub!(:html_safe).and_return(@original_html)
  end

  it 'creates an instance of HtmlTruncator and calls truncate() on it' do
    @html_truncator_mock.stub!(:truncate).and_return(@original_html)
    TruncateHtml::HtmlTruncator.should_receive(:new).and_return(@html_truncator_mock)
    truncator.truncate_html(@original_html)
  end

  it 'calls truncate() on the HtmlTruncator object' do
    TruncateHtml::HtmlTruncator.stub!(:new).and_return(@html_truncator_mock)
    @html_truncator_mock.should_receive(:truncate).with({}).once.and_return(@original_html)
    truncator.truncate_html('foo')
  end

  context 'the input html is nil' do
    it 'returns an empty string' do
      truncator.truncate_html(nil).should be_empty
      truncator.truncate_html(nil).should be_kind_of(String)
    end
  end

end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
truncate_html-0.9 spec/helpers/truncate_html_helper_spec.rb
truncate_html_sentence-0.5.6 spec/helpers/truncate_html_helper_spec.rb
truncate_html-0.5.5 spec/helpers/truncate_html_helper_spec.rb
truncate_html-0.5.4 spec/helpers/truncate_html_helper_spec.rb
truncate_html-0.5.3 spec/helpers/truncate_html_helper_spec.rb
truncate_html-0.5.2 spec/helpers/truncate_html_helper_spec.rb
truncate_html-0.5.1 spec/helpers/truncate_html_helper_spec.rb
truncate_html-0.5.0 spec/helpers/truncate_html_helper_spec.rb
truncate_html-0.4.0 spec/helpers/truncate_html_helper_spec.rb