test/unit/cdf_test.rb in feedtools-0.2.17 vs test/unit/cdf_test.rb in feedtools-0.2.18

- old
+ new

@@ -1,110 +1,116 @@ require 'test/unit' require 'feed_tools' +require 'feed_tools/helpers/feed_tools_helper' class CdfTest < Test::Unit::TestCase + include FeedToolsHelper + def setup FeedTools.tidy_enabled = false FeedTools.feed_cache = FeedTools::DatabaseFeedCache + FeedToolsHelper.default_local_path = + File.expand_path( + File.expand_path(File.dirname(__FILE__)) + '/../feeds') end def test_feed_title - feed = FeedTools::Feed.new - feed.feed_data = <<-FEED + with_feed(:from_data => <<-FEED <CHANNEL> <TITLE>Example Title</TITLE> </CHANNEL> FEED - assert_equal("Example Title", feed.title) - feed = FeedTools::Feed.open( - 'http://feedparser.org/tests/wellformed/cdf/channel_title.xml') + ) { |feed| + assert_equal("Example Title", feed.title) + } + with_feed(:from_file => 'wellformed/cdf/channel_title.xml') { |feed| assert_equal("Example feed", feed.title) + } end def test_feed_description - feed = FeedTools::Feed.open( - 'http://feedparser.org/tests/wellformed/cdf/' + - 'channel_abstract_map_description.xml') - assert_equal("Example description", feed.description) - feed = FeedTools::Feed.open( - 'http://feedparser.org/tests/wellformed/cdf/' + - 'channel_abstract_map_tagline.xml') - assert_equal("Example description", feed.tagline) + with_feed(:from_file => 'wellformed/cdf/channel_abstract_map_description.xml') { |feed| + assert_equal("Example description", feed.description) + } + with_feed(:from_file => 'wellformed/cdf/channel_abstract_map_tagline.xml') { |feed| + assert_equal("Example description", feed.tagline) + } end def test_feed_href - feed = FeedTools::Feed.new - feed.feed_data = <<-FEED + with_feed(:from_data => <<-FEED <CHANNEL HREF="http://www.example.com/"> </CHANNEL> FEED - assert_equal("http://www.example.com/", feed.link) - feed = FeedTools::Feed.open( - 'http://feedparser.org/tests/wellformed/cdf/channel_href_map_link.xml') - assert_equal("http://www.example.org/", feed.link) + ) { |feed| + assert_equal("http://www.example.com/", feed.link) + } + with_feed(:from_file => 'wellformed/cdf/channel_href_map_link.xml') { |feed| + assert_equal("http://www.example.org/", feed.link) + } end def test_feed_links # TODO end def test_feed_images - feed = FeedTools::Feed.new - feed.feed_data = <<-FEED + with_feed(:from_data => <<-FEED <CHANNEL> <LOGO HREF="http://www.example.com/exampleicon.gif" STYLE="ICON" /> <LOGO HREF="http://www.example.com/exampleimage.gif" STYLE="IMAGE" /> </CHANNEL> FEED - assert_equal("http://www.example.com/exampleicon.gif", feed.images[0].url) - assert_equal("icon", feed.images[0].style) - assert_equal("http://www.example.com/exampleimage.gif", feed.images[1].url) - assert_equal("image", feed.images[1].style) + ) { |feed| + assert_equal("http://www.example.com/exampleicon.gif", feed.images[0].url) + assert_equal("icon", feed.images[0].style) + assert_equal("http://www.example.com/exampleimage.gif", feed.images[1].url) + assert_equal("image", feed.images[1].style) + } end def test_feed_item_title - feed = FeedTools::Feed.open( - 'http://feedparser.org/tests/wellformed/cdf/item_title.xml') - assert_equal("Example item", feed.items.first.title) + with_feed(:from_file => 'wellformed/cdf/item_title.xml') { |feed| + assert_equal("Example item", feed.items.first.title) + } end def test_feed_item_description - feed = FeedTools::Feed.open( - 'http://feedparser.org/tests/wellformed/cdf/' + - 'item_abstract_map_description.xml') - assert_equal("Example description", feed.items.first.description) - feed = FeedTools::Feed.open( - 'http://feedparser.org/tests/wellformed/cdf/' + - 'item_abstract_map_summary.xml') - assert_equal("Example description", feed.items.first.summary) + with_feed(:from_file => 'wellformed/cdf/item_abstract_map_description.xml') { |feed| + assert_equal("Example description", feed.items.first.description) + } + with_feed(:from_file => 'wellformed/cdf/item_abstract_map_summary.xml') { |feed| + assert_equal("Example description", feed.items.first.summary) + } end def test_feed_item_href - feed = FeedTools::Feed.open( - 'http://feedparser.org/tests/wellformed/cdf/item_href_map_link.xml') - assert_equal("http://www.example.org/", feed.items.first.link) + with_feed(:from_file => 'wellformed/cdf/item_href_map_link.xml') { |feed| + assert_equal("http://www.example.org/", feed.items.first.link) + } end def test_feed_item_links # TODO end def test_feed_item_images - feed = FeedTools::Feed.new - feed.feed_data = <<-FEED + with_feed(:from_data => <<-FEED <CHANNEL> <ITEM HREF="http://www.example.com/item"> <LOGO HREF="http://www.example.com/exampleicon.gif" STYLE="ICON" /> <LOGO HREF="http://www.example.com/exampleimage.gif" STYLE="IMAGE" /> </ITEM> </CHANNEL> FEED - assert_equal("http://www.example.com/item", - feed.items.first.link) - assert_equal("http://www.example.com/exampleicon.gif", - feed.items.first.images[0].url) - assert_equal("icon", feed.items.first.images[0].style) - assert_equal("http://www.example.com/exampleimage.gif", - feed.items.first.images[1].url) - assert_equal("image", feed.items.first.images[1].style) + ) { |feed| + assert_equal("http://www.example.com/item", + feed.items.first.link) + assert_equal("http://www.example.com/exampleicon.gif", + feed.items.first.images[0].url) + assert_equal("icon", feed.items.first.images[0].style) + assert_equal("http://www.example.com/exampleimage.gif", + feed.items.first.images[1].url) + assert_equal("image", feed.items.first.images[1].style) + } end end