Skip to content

Commit a62286d

Browse files
committed
Add xkcd (atom and rss) feeds to tests
1 parent 95013eb commit a62286d

File tree

5 files changed

+147
-2
lines changed

5 files changed

+147
-2
lines changed

Muon.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
89CAD4E01BA4A203006D79FC /* atom_large.xml in Resources */ = {isa = PBXBuildFile; fileRef = 8981316F1AFC75270090FA7F /* atom_large.xml */; };
6060
89D427FD1B8CFB44006CD81C /* sparkfun.rss in Resources */ = {isa = PBXBuildFile; fileRef = 89D427FC1B8CFB44006CD81C /* sparkfun.rss */; };
6161
89D428011B8D0143006CD81C /* sparkfun1.html in Resources */ = {isa = PBXBuildFile; fileRef = 89D428001B8D0143006CD81C /* sparkfun1.html */; };
62+
89E08DD61C43751E00E3D5FC /* xkcd.atom in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD51C43751E00E3D5FC /* xkcd.atom */; };
63+
89E08DD71C43758B00E3D5FC /* xkcd.atom in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD51C43751E00E3D5FC /* xkcd.atom */; };
64+
89E08DD91C437B1100E3D5FC /* xkcd.rss in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD81C437B1100E3D5FC /* xkcd.rss */; };
65+
89E08DDA1C437B1500E3D5FC /* xkcd.rss in Resources */ = {isa = PBXBuildFile; fileRef = 89E08DD81C437B1100E3D5FC /* xkcd.rss */; };
6266
89E9C20F1AF495A400620A55 /* String+Muon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89E9C20E1AF495A400620A55 /* String+Muon.swift */; };
6367
89E9C2111AF4987D00620A55 /* StringExtensionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89E9C2101AF4987D00620A55 /* StringExtensionSpec.swift */; };
6468
/* End PBXBuildFile section */
@@ -140,6 +144,8 @@
140144
89BBC1161AF2BCA0006025AA /* Author.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Author.swift; sourceTree = "<group>"; };
141145
89D427FC1B8CFB44006CD81C /* sparkfun.rss */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = sparkfun.rss; sourceTree = "<group>"; };
142146
89D428001B8D0143006CD81C /* sparkfun1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = sparkfun1.html; sourceTree = "<group>"; };
147+
89E08DD51C43751E00E3D5FC /* xkcd.atom */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = xkcd.atom; sourceTree = "<group>"; };
148+
89E08DD81C437B1100E3D5FC /* xkcd.rss */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = xkcd.rss; sourceTree = "<group>"; };
143149
89E9C20E1AF495A400620A55 /* String+Muon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Muon.swift"; sourceTree = "<group>"; };
144150
89E9C2101AF4987D00620A55 /* StringExtensionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensionSpec.swift; sourceTree = "<group>"; };
145151
/* End PBXFileReference section */
@@ -255,6 +261,8 @@
255261
8967016D1AF1749300BCD0DD /* researchkit.rss */,
256262
89D427FC1B8CFB44006CD81C /* sparkfun.rss */,
257263
89D428001B8D0143006CD81C /* sparkfun1.html */,
264+
89E08DD51C43751E00E3D5FC /* xkcd.atom */,
265+
89E08DD81C437B1100E3D5FC /* xkcd.rss */,
258266
89BBC10C1AF1EB2D006025AA /* rss091.rss */,
259267
89BBC10E1AF1EB4E006025AA /* rss092.rss */,
260268
89BBC1121AF1EC06006025AA /* rss100.rss */,
@@ -432,9 +440,11 @@
432440
files = (
433441
89CAD4E01BA4A203006D79FC /* atom_large.xml in Resources */,
434442
89CAD4DA1BA4A203006D79FC /* rss092.rss in Resources */,
443+
89E08DD71C43758B00E3D5FC /* xkcd.atom in Resources */,
435444
89CAD4D71BA4A203006D79FC /* sparkfun.rss in Resources */,
436445
89CAD4DF1BA4A203006D79FC /* rss2_large.rss in Resources */,
437446
89CAD4DC1BA4A203006D79FC /* rss200.rss in Resources */,
447+
89E08DDA1C437B1500E3D5FC /* xkcd.rss in Resources */,
438448
89CAD4D81BA4A203006D79FC /* sparkfun1.html in Resources */,
439449
89CAD4DD1BA4A203006D79FC /* atom100.xml in Resources */,
440450
89CAD4DB1BA4A203006D79FC /* rss100.rss in Resources */,
@@ -457,9 +467,11 @@
457467
files = (
458468
89BBC1131AF1EC06006025AA /* rss100.rss in Resources */,
459469
89BBC10D1AF1EB2D006025AA /* rss091.rss in Resources */,
470+
89E08DD61C43751E00E3D5FC /* xkcd.atom in Resources */,
460471
89BBC10F1AF1EB4E006025AA /* rss092.rss in Resources */,
461472
89BBC1111AF1EB70006025AA /* rss200.rss in Resources */,
462473
89D427FD1B8CFB44006CD81C /* sparkfun.rss in Resources */,
474+
89E08DD91C437B1100E3D5FC /* xkcd.rss in Resources */,
463475
898131741AFC75530090FA7F /* rss2_large.rss in Resources */,
464476
898131701AFC75270090FA7F /* atom_large.xml in Resources */,
465477
8967016E1AF1749300BCD0DD /* researchkit.rss in Resources */,

Muon/FeedParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public class FeedParser: NSOperation, NSXMLParserDelegate {
332332
articleHelper.link += str
333333
case "guid", "id":
334334
articleHelper.guid += str
335-
case "description":
335+
case "description", "summary":
336336
articleHelper.description += str
337337
case "pubdate", "published":
338338
articleHelper.published += str
@@ -394,7 +394,7 @@ public class FeedParser: NSOperation, NSXMLParserDelegate {
394394
}
395395
} else {
396396
if let href = attributeDict["href"] as? String where currentElement == "link" {
397-
if attributeDict["rel"] == nil || attributeDict["rel"] as? String == "self" {
397+
if attributeDict["rel"] == nil || attributeDict["rel"] as? String == "self" || attributeDict["rel"] as? String == "alternate" {
398398
feedHelper.link = href
399399
}
400400
}

MuonTests/IntegrationSpec.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,67 @@ class IntegrationSpec: QuickSpec {
8787
}
8888
}
8989

90+
describe("xkcd (atom)") {
91+
beforeEach {
92+
parser = parserWithContentsOfFile("xkcd.atom")
93+
}
94+
95+
it("should parse the feed") {
96+
expect(feed).toNot(beNil())
97+
if let feed = feed {
98+
expect(feed.title).to(equal("xkcd.com"))
99+
expect(feed.link).to(equal(NSURL(string: "http://xkcd.com/")!))
100+
expect(feed.lastUpdated).to(equal("2016-01-11T00:00:00Z".RFC3339Date()))
101+
}
102+
}
103+
104+
it("should parse the feed's items") {
105+
expect(feed?.articles.count).to(equal(4))
106+
if let article = feed?.articles.first {
107+
expect(article.title).to(equal("Magnus"))
108+
expect(article.link).to(equal(NSURL(string: "http://xkcd.com/1628/")))
109+
expect(article.guid).to(equal("http://xkcd.com/1628/"))
110+
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.\" />"))
111+
expect(article.content).to(beNil())
112+
let updated = "2016-01-11T00:00:00Z".RFC3339Date()
113+
expect(article.published).to(beNil())
114+
expect(article.updated).to(equal(updated))
115+
expect(article.enclosures.count).to(equal(0))
116+
}
117+
}
118+
}
119+
120+
describe("xkcd (rss)") {
121+
beforeEach {
122+
parser = parserWithContentsOfFile("xkcd.rss")
123+
}
124+
125+
it("should parse the feed") {
126+
expect(feed).toNot(beNil())
127+
if let feed = feed {
128+
expect(feed.title).to(equal("xkcd.com"))
129+
expect(feed.link).to(equal(NSURL(string: "http://xkcd.com/")!))
130+
expect(feed.description).to(equal("xkcd.com: A webcomic of romance and math humor."))
131+
expect(feed.language).to(equal(NSLocale(localeIdentifier: "en")))
132+
}
133+
}
134+
135+
it("should parse the feed's items") {
136+
expect(feed?.articles.count).to(equal(4))
137+
if let article = feed?.articles.first {
138+
expect(article.title).to(equal("Magnus"))
139+
expect(article.link).to(equal(NSURL(string: "http://xkcd.com/1628/")))
140+
expect(article.guid).to(equal("http://xkcd.com/1628/"))
141+
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.\" />"))
142+
expect(article.content).to(beNil())
143+
let updated = "Mon, 11 Jan 2016 05:00:00 -0000".RFC822Date()
144+
expect(article.published).to(equal(updated))
145+
expect(article.updated).to(beNil())
146+
expect(article.enclosures.count).to(equal(0))
147+
}
148+
}
149+
}
150+
90151
describe("RSS 0.91") {
91152
beforeEach {
92153
parser = parserWithContentsOfFile("rss091.rss")

MuonTests/xkcd.atom

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
3+
<title>xkcd.com</title>
4+
<link href="http://xkcd.com/" rel="alternate"></link>
5+
<id>http://xkcd.com/</id>
6+
<updated>2016-01-11T00:00:00Z</updated>
7+
<entry>
8+
<title>Magnus</title>
9+
<link href="http://xkcd.com/1628/" rel="alternate"></link>
10+
<updated>2016-01-11T00:00:00Z</updated>
11+
<id>http://xkcd.com/1628/</id>
12+
<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>
13+
</entry>
14+
<entry>
15+
<title>Woosh</title>
16+
<link href="http://xkcd.com/1627/" rel="alternate"></link>
17+
<updated>2016-01-08T00:00:00Z</updated>
18+
<id>http://xkcd.com/1627/</id>
19+
<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>
20+
</entry>
21+
<entry>
22+
<title>Judgment Day</title>
23+
<link href="http://xkcd.com/1626/" rel="alternate"></link>
24+
<updated>2016-01-06T00:00:00Z</updated>
25+
<id>http://xkcd.com/1626/</id>
26+
<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>
27+
</entry>
28+
<entry>
29+
<title>Substitutions 2</title>
30+
<link href="http://xkcd.com/1625/" rel="alternate"></link>
31+
<updated>2016-01-04T00:00:00Z</updated>
32+
<id>http://xkcd.com/1625/</id>
33+
<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>
34+
</entry>
35+
</feed>

MuonTests/xkcd.rss

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<rss version="2.0">
3+
<channel>
4+
<title>xkcd.com</title>
5+
<link>http://xkcd.com/</link>
6+
<description>xkcd.com: A webcomic of romance and math humor.</description>
7+
<language>en</language>
8+
<item>
9+
<title>Magnus</title>
10+
<link>http://xkcd.com/1628/</link>
11+
<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>
12+
<pubDate>Mon, 11 Jan 2016 05:00:00 -0000</pubDate>
13+
<guid>http://xkcd.com/1628/</guid>
14+
</item>
15+
<item>
16+
<title>Woosh</title>
17+
<link>http://xkcd.com/1627/</link>
18+
<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>
19+
<pubDate>Fri, 08 Jan 2016 05:00:00 -0000</pubDate>
20+
<guid>http://xkcd.com/1627/</guid>
21+
</item>
22+
<item>
23+
<title>Judgment Day</title>
24+
<link>http://xkcd.com/1626/</link>
25+
<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>
26+
<pubDate>Wed, 06 Jan 2016 05:00:00 -0000</pubDate>
27+
<guid>http://xkcd.com/1626/</guid>
28+
</item>
29+
<item>
30+
<title>Substitutions 2</title>
31+
<link>http://xkcd.com/1625/</link>
32+
<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>
33+
<pubDate>Mon, 04 Jan 2016 05:00:00 -0000</pubDate>
34+
<guid>http://xkcd.com/1625/</guid>
35+
</item>
36+
</channel>
37+
</rss>

0 commit comments

Comments
 (0)