require 'test_helper'
require 'mocha'
class FeedTest < Test::Unit::TestCase
context "bootstrapping test" do
setup do
@devlicious = File.read(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "devlicious.rss"))
@rubyyot = File.read(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "rubyyot.rss"))
end
should "read rss files" do
assert_not_nil @devlicious
assert_not_nil @rubyyot
end
end
context "formatting items" do
should "format items as link wrapped in li tags" do
reader = Flannel::FeedParser.new()
assert_equal("
\n bar\n \n", reader.format_item('foo', 'bar'))
end
end
context "basic call" do
setup do
@devlicious = File.read(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "devlicious.rss"))
@rubyyot = File.read(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "rubyyot.rss"))
@expected_rubyyot = " \n Plans for Rubyyot.com and the Summer of Learning Challenge\n \n \n Using Rack to generate content from an rss feed\n \n \n Rubyyot.com is dead; Long live Rubyyot.com\n \n"
@expected_devlicious = " \n JavaScript and its love for zeroes\n \n \n JavaScript: Not your father's inheritance model - Part 2\n \n \n JavaScript: Not your father's inheritance model - Part 1\n \n \n JavaScript: Avoid the Evil eval\n \n \n JavaScript, inner functions and private members\n \n \n JavaScript, time to grok closures\n \n \n JavaScript, 5 ways to call a function\n \n"
end
should "substitute feed line with feed" do
feed = "http://blog.rubyyot.com/tag/rubyyot/feed/rss"
reader = Flannel::FeedParser.new()
reader.expects(:get_document).with(feed).returns(@rubyyot)
body = reader.sub_feeds(feed)
assert_equal(@expected_rubyyot, body)
end
should "substitute without http://" do
feed = "blog.rubyyot.com/tag/rubyyot/feed/rss"
reader = Flannel::FeedParser.new()
reader.expects(:get_document).with("http://#{feed}").returns(@rubyyot)
body = reader.sub_feeds(feed)
assert_equal(@expected_rubyyot, body)
end
should "modify using provided url" do
feed = "http://devlicio.us/blogs/sergio_pereira/rss.aspx?Tags=JavaScript-Demystified&AndTags=1"
reader = Flannel::FeedParser.new()
reader.expects(:get_document).with(feed).returns(@devlicious)
body = reader.sub_feeds(feed)
assert_equal(@expected_devlicious, body)
end
should "format url from body" do
reader = Flannel::FeedParser.new
url = reader.format_url("http://blog.rubyyot.com/tag/rubyyot/feed/rss" )
assert_equal("http://blog.rubyyot.com/tag/rubyyot/feed/rss", url)
end
should "format url from body and add http if necessary" do
reader = Flannel::FeedParser.new
url = reader.format_url("blog.rubyyot.com/tag/rubyyot/feed/rss" )
assert_equal("http://blog.rubyyot.com/tag/rubyyot/feed/rss", url)
end
end
end