test/test_format_helpers.rb in padrino-helpers-0.9.28 vs test/test_format_helpers.rb in padrino-helpers-0.9.29
- old
+ new
@@ -107,23 +107,38 @@
actual_text = truncate("And they found that many people were sleeping better.", :length => 25, :omission => "(clipped)")
assert_equal "And they found t(clipped)", actual_text
end
end
+ context 'for #truncate_words method' do
+ should "support default truncation" do
+ actual_text = truncate_words("Long before books were made, people told stories. They told them to one another and to the children as they sat before the fire. Many of these stories were about interesting people, but most of them were about the ways of fairies and giants.")
+ assert_equal "Long before books were made, people told stories. They told them to one another and to the children as they sat before the fire. Many of these stories were about...", actual_text
+ end
+ should "support specifying length" do
+ actual_text = truncate_words("Once upon a time in a world far far away", :length => 8)
+ assert_equal "Once upon a time in a world far...", actual_text
+ end
+ should "support specifying omission text" do
+ actual_text = truncate_words("And they found that many people were sleeping better.", :length => 4, :omission => "(clipped)")
+ assert_equal "And they found that(clipped)", actual_text
+ end
+ end
+
context 'for #h and #h! method' do
should "escape the simple html" do
- assert_equal '<h1>hello</h1>', h('<h1>hello</h1>')
- assert_equal '<h1>hello</h1>', escape_html('<h1>hello</h1>')
+ assert_equal '<h1>hello</h1>', h('<h1>hello</h1>')
+ assert_equal '<h1>hello</h1>', escape_html('<h1>hello</h1>')
end
should "escape all brackets, quotes and ampersands" do
- assert_equal '<h1><>"&demo&"<></h1>', h('<h1><>"&demo&"<></h1>')
+ assert_equal '<h1><>"&demo&"<></h1>', h('<h1><>"&demo&"<></h1>')
end
should "return default text if text is empty" do
assert_equal 'default', h!("", "default")
assert_equal ' ', h!("")
end
should "return text escaped if not empty" do
- assert_equal '<h1>hello</h1>', h!('<h1>hello</h1>')
+ assert_equal '<h1>hello</h1>', h!('<h1>hello</h1>')
end
end
context 'for #time_ago_in_words method' do
should "less than 5 seconds" do
\ No newline at end of file