Skip to content

Commit

Permalink
Add xkcd (atom and rss) feeds to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
younata committed Jan 11, 2016
1 parent 95013eb commit a62286d
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Muon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
89CAD4E01BA4A203006D79FC /* atom_large.xml in Resources */ = {isa = PBXBuildFile; fileRef = 8981316F1AFC75270090FA7F /* atom_large.xml */; };
89D427FD1B8CFB44006CD81C /* sparkfun.rss in Resources */ = {isa = PBXBuildFile; fileRef = 89D427FC1B8CFB44006CD81C /* sparkfun.rss */; };
89D428011B8D0143006CD81C /* sparkfun1.html in Resources */ = {isa = PBXBuildFile; fileRef = 89D428001B8D0143006CD81C /* sparkfun1.html */; };
89E08DD61C43751E00E3D5FC /* xkcd.atom in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD51C43751E00E3D5FC /* xkcd.atom */; };
89E08DD71C43758B00E3D5FC /* xkcd.atom in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD51C43751E00E3D5FC /* xkcd.atom */; };
89E08DD91C437B1100E3D5FC /* xkcd.rss in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD81C437B1100E3D5FC /* xkcd.rss */; };
89E08DDA1C437B1500E3D5FC /* xkcd.rss in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD81C437B1100E3D5FC /* xkcd.rss */; };
89E9C20F1AF495A400620A55 /* String+Muon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89E9C20E1AF495A400620A55 /* String+Muon.swift */; };
89E9C2111AF4987D00620A55 /* StringExtensionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89E9C2101AF4987D00620A55 /* StringExtensionSpec.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -140,6 +144,8 @@
89BBC1161AF2BCA0006025AA /* Author.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Author.swift; sourceTree = "<group>"; };
89D427FC1B8CFB44006CD81C /* sparkfun.rss */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = sparkfun.rss; sourceTree = "<group>"; };
89D428001B8D0143006CD81C /* sparkfun1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = sparkfun1.html; sourceTree = "<group>"; };
89E08DD51C43751E00E3D5FC /* xkcd.atom */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = xkcd.atom; sourceTree = "<group>"; };
89E08DD81C437B1100E3D5FC /* xkcd.rss */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = xkcd.rss; sourceTree = "<group>"; };
89E9C20E1AF495A400620A55 /* String+Muon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Muon.swift"; sourceTree = "<group>"; };
89E9C2101AF4987D00620A55 /* StringExtensionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensionSpec.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -255,6 +261,8 @@
8967016D1AF1749300BCD0DD /* researchkit.rss */,
89D427FC1B8CFB44006CD81C /* sparkfun.rss */,
89D428001B8D0143006CD81C /* sparkfun1.html */,
89E08DD51C43751E00E3D5FC /* xkcd.atom */,
89E08DD81C437B1100E3D5FC /* xkcd.rss */,
89BBC10C1AF1EB2D006025AA /* rss091.rss */,
89BBC10E1AF1EB4E006025AA /* rss092.rss */,
89BBC1121AF1EC06006025AA /* rss100.rss */,
Expand Down Expand Up @@ -432,9 +440,11 @@
files = (
89CAD4E01BA4A203006D79FC /* atom_large.xml in Resources */,
89CAD4DA1BA4A203006D79FC /* rss092.rss in Resources */,
89E08DD71C43758B00E3D5FC /* xkcd.atom in Resources */,
89CAD4D71BA4A203006D79FC /* sparkfun.rss in Resources */,
89CAD4DF1BA4A203006D79FC /* rss2_large.rss in Resources */,
89CAD4DC1BA4A203006D79FC /* rss200.rss in Resources */,
89E08DDA1C437B1500E3D5FC /* xkcd.rss in Resources */,
89CAD4D81BA4A203006D79FC /* sparkfun1.html in Resources */,
89CAD4DD1BA4A203006D79FC /* atom100.xml in Resources */,
89CAD4DB1BA4A203006D79FC /* rss100.rss in Resources */,
Expand All @@ -457,9 +467,11 @@
files = (
89BBC1131AF1EC06006025AA /* rss100.rss in Resources */,
89BBC10D1AF1EB2D006025AA /* rss091.rss in Resources */,
89E08DD61C43751E00E3D5FC /* xkcd.atom in Resources */,
89BBC10F1AF1EB4E006025AA /* rss092.rss in Resources */,
89BBC1111AF1EB70006025AA /* rss200.rss in Resources */,
89D427FD1B8CFB44006CD81C /* sparkfun.rss in Resources */,
89E08DD91C437B1100E3D5FC /* xkcd.rss in Resources */,
898131741AFC75530090FA7F /* rss2_large.rss in Resources */,
898131701AFC75270090FA7F /* atom_large.xml in Resources */,
8967016E1AF1749300BCD0DD /* researchkit.rss in Resources */,
Expand Down
4 changes: 2 additions & 2 deletions Muon/FeedParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public class FeedParser: NSOperation, NSXMLParserDelegate {
articleHelper.link += str
case "guid", "id":
articleHelper.guid += str
case "description":
case "description", "summary":
articleHelper.description += str
case "pubdate", "published":
articleHelper.published += str
Expand Down Expand Up @@ -394,7 +394,7 @@ public class FeedParser: NSOperation, NSXMLParserDelegate {
}
} else {
if let href = attributeDict["href"] as? String where currentElement == "link" {
if attributeDict["rel"] == nil || attributeDict["rel"] as? String == "self" {
if attributeDict["rel"] == nil || attributeDict["rel"] as? String == "self" || attributeDict["rel"] as? String == "alternate" {
feedHelper.link = href
}
}
Expand Down
61 changes: 61 additions & 0 deletions MuonTests/IntegrationSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,67 @@ class IntegrationSpec: QuickSpec {
}
}

describe("xkcd (atom)") {
beforeEach {
parser = parserWithContentsOfFile("xkcd.atom")
}

it("should parse the feed") {
expect(feed).toNot(beNil())
if let feed = feed {
expect(feed.title).to(equal("xkcd.com"))
expect(feed.link).to(equal(NSURL(string: "http://xkcd.com/")!))
expect(feed.lastUpdated).to(equal("2016-01-11T00:00:00Z".RFC3339Date()))
}
}

it("should parse the feed's items") {
expect(feed?.articles.count).to(equal(4))
if let article = feed?.articles.first {
expect(article.title).to(equal("Magnus"))
expect(article.link).to(equal(NSURL(string: "http://xkcd.com/1628/")))
expect(article.guid).to(equal("http://xkcd.com/1628/"))
expect(article.description).to(equal("<img src=\"http://imgs.xkcd.com/comics/magnus.png\" title=\"In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey.\" alt=\"In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey.\" />"))
expect(article.content).to(beNil())
let updated = "2016-01-11T00:00:00Z".RFC3339Date()
expect(article.published).to(beNil())
expect(article.updated).to(equal(updated))
expect(article.enclosures.count).to(equal(0))
}
}
}

describe("xkcd (rss)") {
beforeEach {
parser = parserWithContentsOfFile("xkcd.rss")
}

it("should parse the feed") {
expect(feed).toNot(beNil())
if let feed = feed {
expect(feed.title).to(equal("xkcd.com"))
expect(feed.link).to(equal(NSURL(string: "http://xkcd.com/")!))
expect(feed.description).to(equal("xkcd.com: A webcomic of romance and math humor."))
expect(feed.language).to(equal(NSLocale(localeIdentifier: "en")))
}
}

it("should parse the feed's items") {
expect(feed?.articles.count).to(equal(4))
if let article = feed?.articles.first {
expect(article.title).to(equal("Magnus"))
expect(article.link).to(equal(NSURL(string: "http://xkcd.com/1628/")))
expect(article.guid).to(equal("http://xkcd.com/1628/"))
expect(article.description).to(equal("<img src=\"http://imgs.xkcd.com/comics/magnus.png\" title=\"In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey.\" alt=\"In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey.\" />"))
expect(article.content).to(beNil())
let updated = "Mon, 11 Jan 2016 05:00:00 -0000".RFC822Date()
expect(article.published).to(equal(updated))
expect(article.updated).to(beNil())
expect(article.enclosures.count).to(equal(0))
}
}
}

describe("RSS 0.91") {
beforeEach {
parser = parserWithContentsOfFile("rss091.rss")
Expand Down
35 changes: 35 additions & 0 deletions MuonTests/xkcd.atom
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<title>xkcd.com</title>
<link href="http://xkcd.com/" rel="alternate"></link>
<id>http://xkcd.com/</id>
<updated>2016-01-11T00:00:00Z</updated>
<entry>
<title>Magnus</title>
<link href="http://xkcd.com/1628/" rel="alternate"></link>
<updated>2016-01-11T00:00:00Z</updated>
<id>http://xkcd.com/1628/</id>
<summary type="html">&lt;img src="http://imgs.xkcd.com/comics/magnus.png" title="In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey." alt="In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey." /&gt;</summary>
</entry>
<entry>
<title>Woosh</title>
<link href="http://xkcd.com/1627/" rel="alternate"></link>
<updated>2016-01-08T00:00:00Z</updated>
<id>http://xkcd.com/1627/</id>
<summary type="html">&lt;img src="http://imgs.xkcd.com/comics/woosh.png" title="It also occasionally replies with 'Comment of the year', 'Are you for real', and 'I'm taking a screenshot so I can remember this moment forever'." alt="It also occasionally replies with 'Comment of the year', 'Are you for real', and 'I'm taking a screenshot so I can remember this moment forever'." /&gt;</summary>
</entry>
<entry>
<title>Judgment Day</title>
<link href="http://xkcd.com/1626/" rel="alternate"></link>
<updated>2016-01-06T00:00:00Z</updated>
<id>http://xkcd.com/1626/</id>
<summary type="html">&lt;img src="http://imgs.xkcd.com/comics/judgment_day.png" title="It took a lot of booster rockets, but luckily Amazon had recently built thousands of them to bring Amazon Prime same-day delivery to the Moon colony." alt="It took a lot of booster rockets, but luckily Amazon had recently built thousands of them to bring Amazon Prime same-day delivery to the Moon colony." /&gt;</summary>
</entry>
<entry>
<title>Substitutions 2</title>
<link href="http://xkcd.com/1625/" rel="alternate"></link>
<updated>2016-01-04T00:00:00Z</updated>
<id>http://xkcd.com/1625/</id>
<summary type="html">&lt;img src="http://imgs.xkcd.com/comics/substitutions_2.png" title="Within a few minutes, our roads will be full of uncontrollably-swerving cars and our skies full of Amazon delivery dogs." alt="Within a few minutes, our roads will be full of uncontrollably-swerving cars and our skies full of Amazon delivery dogs." /&gt;</summary>
</entry>
</feed>
37 changes: 37 additions & 0 deletions MuonTests/xkcd.rss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>xkcd.com</title>
<link>http://xkcd.com/</link>
<description>xkcd.com: A webcomic of romance and math humor.</description>
<language>en</language>
<item>
<title>Magnus</title>
<link>http://xkcd.com/1628/</link>
<description>&lt;img src="http://imgs.xkcd.com/comics/magnus.png" title="In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey." alt="In the latest round, 9-year-old Muhammad Ali beat 10-year-old JFK at air hockey, while Secretariat lost the hot-dog-eating crown to 12-year-old Ken Jennings. Meanwhile, in a huge upset, 11-year-old Martha Stewart knocked out the adult Ronda Rousey." /&gt;</description>
<pubDate>Mon, 11 Jan 2016 05:00:00 -0000</pubDate>
<guid>http://xkcd.com/1628/</guid>
</item>
<item>
<title>Woosh</title>
<link>http://xkcd.com/1627/</link>
<description>&lt;img src="http://imgs.xkcd.com/comics/woosh.png" title="It also occasionally replies with 'Comment of the year', 'Are you for real', and 'I'm taking a screenshot so I can remember this moment forever'." alt="It also occasionally replies with 'Comment of the year', 'Are you for real', and 'I'm taking a screenshot so I can remember this moment forever'." /&gt;</description>
<pubDate>Fri, 08 Jan 2016 05:00:00 -0000</pubDate>
<guid>http://xkcd.com/1627/</guid>
</item>
<item>
<title>Judgment Day</title>
<link>http://xkcd.com/1626/</link>
<description>&lt;img src="http://imgs.xkcd.com/comics/judgment_day.png" title="It took a lot of booster rockets, but luckily Amazon had recently built thousands of them to bring Amazon Prime same-day delivery to the Moon colony." alt="It took a lot of booster rockets, but luckily Amazon had recently built thousands of them to bring Amazon Prime same-day delivery to the Moon colony." /&gt;</description>
<pubDate>Wed, 06 Jan 2016 05:00:00 -0000</pubDate>
<guid>http://xkcd.com/1626/</guid>
</item>
<item>
<title>Substitutions 2</title>
<link>http://xkcd.com/1625/</link>
<description>&lt;img src="http://imgs.xkcd.com/comics/substitutions_2.png" title="Within a few minutes, our roads will be full of uncontrollably-swerving cars and our skies full of Amazon delivery dogs." alt="Within a few minutes, our roads will be full of uncontrollably-swerving cars and our skies full of Amazon delivery dogs." /&gt;</description>
<pubDate>Mon, 04 Jan 2016 05:00:00 -0000</pubDate>
<guid>http://xkcd.com/1625/</guid>
</item>
</channel>
</rss>

0 comments on commit a62286d

Please sign in to comment.