require "spec_helper"
describe StringMaster do
it "closes unclosed tags" do
parser = StringMaster.new("Hello,world")
parser.close_tags.string.should == 'Hello,world'
end
it "escapes html except for some of the allowed tags" do
parser = StringMaster.new('Hello')
parser.html_escape(:except => %w(img)).string.should == '
<b>Hello</b>'
end
it "makes images of urls that end with .jpg and other image extensions" do
parser = StringMaster.new('Hello, this is my photo http://image.com/image.jpg, yeah baby')
parser.urls_to_images(:wrap_with => ['
', '
'], :html_options => 'class="ico"').string.should == 'Hello, this is my photo
tags" do
code = <puts "hello world"
exit
and here's what my code looks like.
WRAPPED_CODE
end
it "wraps inline code into tags" do
code = "I have a variable called `a` and it has a `nil` value"
parser = StringMaster.new(code)
parser.wrap_inline_code.to_s.should == "I have a variable called a and it has a nil value"
end
it "breaks long words" do
long_string = 'l'; 1.upto(80) { |i| long_string << "o" }; long_string << "ng"
parser = StringMaster.new(long_string)
# fix extra space at the end of the line
parser.break_long_words.string.should == "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oooooong"
end
it "handles 'a' tags when attempt to break long words" do
long_string = 'loooo oong'
end
it "handles 'img' tags when attempt to break long words" do
long_string = '
'
parser = StringMaster.new(long_string)
parser.break_long_words(5).string.should == '
'
end
it "cuts too long string and appends (if specified) characters to its end" do
parser = StringMaster.new("This is quite a long text")
parser.cut(11, 7, :append => '...').string.should == "This is..."
end
it "allows to use block notation" do
parser = StringMaster.new('http://images.com/image.jpg Hello http://url.com ') do |p|
p.urls_to_images.urls_to_links(:html_options => 'target="_blank"')
end
parser.string.should ==
"
Hello http://url.com "
end
end