defmodule FeedParser.Parser.RSS2Test do use ExUnit.Case alias FeedParser.Parser.RSS2 doctest RSS2 test "matches rss2 feed" do data = File.read!("test/fixtures/rss2/feed.xml") assert {true, _} = RSS2.accepts(data, "application/rss+xml") assert {true, _} = RSS2.accepts(data, "text/rss+xml") assert {true, _} = RSS2.accepts(data, "application/xml") assert {true, _} = RSS2.accepts(data, "text/xml") end test "parses rss2 feed" do data = File.read!("test/fixtures/rss2/feed.xml") {true, parsed_data} = RSS2.accepts(data, "application/rss+xml") assert {:ok, %FeedParser.Feed{} = feed} = RSS2.parse_feed(parsed_data) assert feed.title == "Liftoff News" assert feed.site_url == "http://liftoff.msfc.nasa.gov/" assert feed.last_updated == ~U[2003-06-10 09:41:01Z] assert [%FeedParser.Item{} = item] = feed.items assert item.title == "Star City" assert item.url == "http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp" assert item.content == "How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's Star City." assert item.date == ~U[2003-06-03 09:39:21Z] assert item.guid == "http://liftoff.msfc.nasa.gov/2003/06/03.html#item573" end test "parses rss2 item with dc:creator" do data = File.read!("test/fixtures/rss2/dc_creator.xml") {true, parsed_data} = RSS2.accepts(data, "application/rss+xml") assert {:ok, %FeedParser.Feed{} = feed} = RSS2.parse_feed(parsed_data) assert [%FeedParser.Item{} = item] = feed.items assert item.creator == "Jim Newell" end end