require File.join(File.dirname(__FILE__), '..', 'spec_helper') include TruncateHtmlHelper describe TruncateHtmlHelper do it 'is included in ActionView::Base' do ActionView::Base.included_modules.should include(TruncateHtmlHelper) end describe '#truncate_html' do it "includes the omission text's length in the returned truncated html" do truncate_html('a b c', :length => 4, :omission => '...').should == 'a...' end context 'the input html is nil' do it 'returns an empty string' do truncate_html(nil).should be_empty truncate_html(nil).should be_kind_of(String) end end context 'truncating in the middle of a link' do before(:each) do @html = '
Look at this#{char} More words here
" end it 'places the punctuation after the tag without any whitespace' do truncate_html(@html, :length => 19).should == "Look at this#{char} More...
" end end end context 'when the html has a non punctuation character after a closing tag' do before(:each) do @html = 'Look at this link for randomness
' end it 'leaves a whitespace between the closing tag and the following word character' do truncate_html(@html, :length => 21).should == 'Look at this link...
' end end #unusual, but just covering my ass context 'when the HTML tags are multiline' do before(:each) do @html = <<-END_HTML END_HTML end it 'recognizes the multiline html properly' do truncate_html(@html, :length => 12).should == ' ' end end %w(br hr img).each do |unpaired_tag| context "when the html contains a #{unpaired_tag} tag" do context "and the #{unpaired_tag} does not have the closing slash" do before(:each) do @html = "