require 'spec_helper' describe HtmlToTextConverter do it 'strips away

tags and adds a newline to the end of the paragraph' do html = '

This is a one sentence paragraph.

' text = HtmlToTextConverter.new(html).parse text.should == "This is a one sentence paragraph.\n" end it 'returns an empty string when given nil' do text = HtmlToTextConverter.new(nil).parse text.should == '' end it 'strips away

tags and adds a newline to the end of each paragraph' do html = '

Paragraph 1

Paragraph 2

' text = HtmlToTextConverter.new(html).parse text.should == "Paragraph 1\nParagraph 2\n" end it 'strips away spaces in between tags' do html = '

Paragraph 1

Paragraph 2

' text = HtmlToTextConverter.new(html).parse text.should == "Paragraph 1\nParagraph 2\n" end it 'consolidates whitespace' do html = '

I like hot sauce.

' text = HtmlToTextConverter.new(html).parse text.should == "I like hot sauce.\n" end it 'converts nbsp to a regular space' do html = ' hello world ' text = HtmlToTextConverter.new(html).parse text.should == " hello world " end it 'turns
into \n' do html = '
foo
bar
' text = HtmlToTextConverter.new(html).parse text.should == "foo\nbar\n" end it 'indents and stars items in a list' do html = '
  1. Item 1
  2. Item 2
  3. Item 3
' text = HtmlToTextConverter.new(html).parse text.should == " * Item 1\n * Item 2\n * Item 3\n\n" end it 'converts complex HTML to clean plain text' do html = "
This is a story:

We need to do something important.

NOTE:
- a note with the word red:
Some more text.

QA:
Instructions for QA.
" expected = <<-TEXT This is a story: * list item 1 * list item 2 We need to do something important. NOTE: - a note with the word red: Some more text. QA: Instructions for QA. TEXT text = HtmlToTextConverter.new(html).parse text.should == expected end end