require File.join(File.dirname(__FILE__), '..', 'spec_helper') describe TruncateHtml::HtmlTruncator do def truncator(html = nil) @truncator ||= TruncateHtml::HtmlTruncator.new(html) end describe '#html_tokens' do before(:each) do @html = '

Hi there

This is sweet!

' end it 'returns each token in the string as an array element' do truncator(@html).html_tokens.should == ['

', 'Hi', ' ', 'there', '

', ' ', '

', 'This', ' ', 'is', ' ', 'sweet!', '

'] end end describe '#html_tag?' do it 'returns false when the string parameter is not an html tag' do truncator.html_tag?('no tags').should be_false end it 'returns true when the string parameter is an html tag' do truncator.html_tag?('').should be_true truncator.html_tag?('').should be_true end end describe '#open_tag?' do it 'returns true if the tag is an open tag' do truncator.open_tag?('').should be_true end it 'returns true if the tag is an open tag, and has whitespace and html properties with either single or double quotes' do truncator.open_tag?(' ').should be_true truncator.open_tag?(" ").should be_true end it 'returns false if the tag is a close tag' do truncator.open_tag?('').should be_false end it 'returns false if the string is not an html tag' do truncator.open_tag?('foo bar').should be_false end end describe '#matching_close_tag' do it 'closes a tag given an open tag' do truncator.matching_close_tag('').should == '' truncator.matching_close_tag('
').should == '
' truncator.matching_close_tag('

').should == '

' truncator.matching_close_tag('').should == '' end end describe 'nil string' do it 'returns an empty string' do truncator(nil).truncate.should be_empty truncator(nil).truncate.should be_kind_of String end end end