Repository navigation
Expand file tree
/
Copy pathopml_parser_spec.rb
More file actions
86 lines (77 loc) · 2.81 KB
/
Copy pathopml_parser_spec.rb
File metadata and controls
86 lines (77 loc) · 2.81 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
# frozen_string_literal: true
RSpec.describe OpmlParser do
it "returns a hash of feed details from an OPML file" do
result = described_class.call(<<-XML)
<?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>
XML
resulted_values = result.values.flatten
expect(resulted_values.size).to eq(2)
expect(resulted_values.first[:name]).to eq("a sample feed")
expect(resulted_values.first[:url]).to eq("http://feeds.feedburner.com/foobar")
expect(resulted_values.last[:name]).to eq("Matt's Blog")
expect(resulted_values.last[:url]).to eq("http://mdswanson.com/atom.xml")
expect(result.keys.first).to eq("Ungrouped")
end
it "handles nested groups of feeds" do
result = described_class.call(<<-XML)
<?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>
XML
resulted_values = result.values.flatten
expect(resulted_values.count).to eq(1)
expect(resulted_values.first[:name]).to eq("a sample feed")
expect(resulted_values.first[:url]).to eq("http://feeds.feedburner.com/foobar")
expect(result.keys.first).to eq("Technology News")
end
it "doesn't explode when there are no feeds" do
result = described_class.call(<<-XML)
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>matt swanson subscriptions in Google Reader</title>
</head>
<body>
</body>
</opml>
XML
expect(result).to be_empty
end
it "handles Feedly's exported OPML (missing :title)" do
result = described_class.call(<<-XML)
<?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>
XML
resulted_values = result.values.flatten
expect(resulted_values.count).to eq(1)
expect(resulted_values.first[:name]).to eq("a sample feed")
end
end