forked from stringer-rss/stringer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopml_parser_spec.rb
More file actions
87 lines (76 loc) · 2.66 KB
/
opml_parser_spec.rb
File metadata and controls
87 lines (76 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require "spec_helper"
app_require "utils/opml_parser"
describe OpmlParser do
let(:parser) { OpmlParser.new }
describe "#parse_feeds" do
it "it returns a hash of feed details from an OPML file" do
result = parser.parse_feeds(<<-eos)
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>matt swanson subscriptions in Google Reader</title>
</head>
<body>
<outline text="a sample feed" title="a sample feed" type="rss"
xmlUrl="http://feeds.feedburner.com/foobar" htmlUrl="http://www.example.org/"/>
<outline text="lolol" title="Matt's Blog" type="rss"
xmlUrl="http://mdswanson.com/atom.xml" htmlUrl="http://mdswanson.com/"/>
</body>
</opml>
eos
result.count.should eq 2
result.first[:name].should eq "a sample feed"
result.first[:url].should eq "http://feeds.feedburner.com/foobar"
result.last[:name].should eq "Matt's Blog"
result.last[:url].should eq "http://mdswanson.com/atom.xml"
end
it "handles nested groups of feeds" do
result = parser.parse_feeds(<<-eos)
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>matt swanson subscriptions in Google Reader</title>
</head>
<body>
<outline text="Technology News">
<outline text="a sample feed" title="a sample feed" type="rss"
xmlUrl="http://feeds.feedburner.com/foobar" htmlUrl="http://www.example.org/"/>
</outline>
</body>
</opml>
eos
result.count.should eq 1
result.first[:name].should eq "a sample feed"
result.first[:url].should eq "http://feeds.feedburner.com/foobar"
end
it "doesn't explode when there are no feeds" do
result = parser.parse_feeds(<<-eos)
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>matt swanson subscriptions in Google Reader</title>
</head>
<body>
</body>
</opml>
eos
result.should be_empty
end
it "handles Feedly's exported OPML (missing :title)" do
result = parser.parse_feeds(<<-eos)
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>My feeds (Feedly)</title>
</head>
<body>
<outline text="a sample feed" type="rss"
xmlUrl="http://feeds.feedburner.com/foobar" htmlUrl="http://www.example.org/"/>
</body>
</opml>
eos
result.count.should eq 1
result.first[:name].should eq "a sample feed"
end
end
end