Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions spec/fixtures/minimal_valid_result.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<twinglydata numberOfMatchesReturned="1" secondsElapsed="0.148" numberOfMatchesTotal="1">
<post contentType="blog">
<url>http://oppogner.blogg.no/1409602010_bare_m_ha.html</url>
<title><![CDATA[Bare MÅ ha!]]></title>
<summary><![CDATA[Ja, velkommen til høsten ...]]></summary>
<languageCode>no</languageCode>
<published>2014-09-02 06:53:26Z</published>
<indexed>2014-09-02 09:00:53Z</indexed>
<blogUrl>http://oppogner.blogg.no/</blogUrl>
<blogName><![CDATA[oppogner]]></blogName>
<authority>1</authority>
<blogRank>1</blogRank>
<tags>
<tag><![CDATA[Blogg]]></tag>
</tags>
</post><post contentType="blog">
<url>http://www.skvallernytt.se/hardtraning-da-galler-swedish-house-mafia</url>
<title><![CDATA[Hårdträning – då gäller Swedish House Mafia]]></title>
<summary><![CDATA[Träning. Och Swedish House Mafia. Det verkar vara ett lyckat koncept. "Don't you worry child" och "Greyhound" är nämligen de två mest spelade träningslåtarna under januari 2013 på Spotify.

Relaterade inlägg:
Swedish House Mafia – ny låt!
Ny knivattack på Swedish House Mafia-konsert
Swedish House Mafia gör succé i USA]]></summary>
<languageCode>sv</languageCode>
<published>2013-01-29 15:21:56Z</published>
<indexed>2013-01-29 15:22:52Z</indexed>
<blogUrl>http://www.skvallernytt.se/</blogUrl>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a blog? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😜

<blogName><![CDATA[Skvallernytt.se]]></blogName>
<authority>38</authority>
<blogRank>4</blogRank>
<tags>
<tag><![CDATA[Okategoriserat]]></tag>
<tag><![CDATA[Träning]]></tag>
<tag><![CDATA[greyhound]]></tag>
<tag><![CDATA[koncept]]></tag>
<tag><![CDATA[mafia]]></tag>
</tags>
</post><post contentType="blog">
<url>http://didriksinspesielleverden.blogg.no/1359472349_justin_bieber.html</url>
<title><![CDATA[Justin Bieber]]></title>
<summary><![CDATA[OMG! Justin Bieber Believe acoustic albumet er nå ute på spotify. Han er helt super. Love him. Personlig liker jeg best beauty and a beat og as long as you love me, kommenter gjerne hva dere synes! <3 #sus YOLO]]></summary>
<languageCode>no</languageCode>
<published>2013-01-29 15:12:29Z</published>
<indexed>2013-01-29 15:14:37Z</indexed>
<blogUrl>http://didriksinspesielleverden.blogg.no/</blogUrl>
<blogName><![CDATA[Didriksinspesielleverden]]></blogName>
<authority>0</authority>
<blogRank>1</blogRank>
</post>
</twinglydata>
177 changes: 176 additions & 1 deletion spec/parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,195 @@
# encoding: utf-8

require 'spec_helper'
require 'date'

include Twingly::Search

describe Parser do
it { should respond_to(:parse) }

describe "#parse" do
subject { described_class.new.parse(document) }
let(:document) { Fixture.get(fixture) }
let(:result) { described_class.new.parse(document) }
subject { result }

context "with a valid result" do
let(:fixture) { :valid }

it { is_expected.to be_a Result }
end

context "with a minimal valid result" do
let(:fixture) { :minimal_valid }

describe "#posts[0]" do
subject(:post) { result.posts[0] }

describe "#url" do
subject { post.url }
it { is_expected.to eq("http://oppogner.blogg.no/1409602010_bare_m_ha.html") }
end

describe "#title" do
subject { post.title }
it { is_expected.to eq("Bare MÅ ha!") }
end

describe "#summary" do
subject { post.summary }
it { is_expected.to eq("Ja, velkommen til høsten ...") }
end

describe "#language_code" do
subject { post.language_code }
it { is_expected.to eq("no") }
end

describe "#published" do
subject { post.published }
it { is_expected.to eq(DateTime.parse("2014-09-02 06:53:26Z")) }
end

describe "#indexed" do
subject { post.indexed }
it { is_expected.to eq(DateTime.parse("2014-09-02 09:00:53Z")) }
end

describe "#blog_url" do
subject { post.blog_url }
it { is_expected.to eq("http://oppogner.blogg.no/") }
end

describe "#authority" do
subject { post.authority }
it { is_expected.to eq(1) }
end

describe "#blog_rank" do
subject { post.blog_rank }
it { is_expected.to eq(1) }
end

describe "#tags" do
subject { post.tags }
it { is_expected.to eq(["Blogg"]) }
end
end

describe "#posts[1]" do
subject(:post) { result.posts[1] }

describe "#url" do
subject { post.url }
it { is_expected.to eq("http://www.skvallernytt.se/hardtraning-da-galler-swedish-house-mafia") }
end

describe "#title" do
subject { post.title }
it { is_expected.to eq("Hårdträning – då gäller Swedish House Mafia") }
end

describe "#summary" do
subject { post.summary }
it { is_expected.to eq("Träning. Och Swedish House Mafia. Det verkar vara ett lyckat koncept. \"Don't you worry child\" och \"Greyhound\" är nämligen de två mest spelade träningslåtarna under januari 2013 på Spotify.

Relaterade inlägg:
Swedish House Mafia – ny låt!
Ny knivattack på Swedish House Mafia-konsert
Swedish House Mafia gör succé i USA") }
end

describe "#language_code" do
subject { post.language_code }
it { is_expected.to eq("sv") }
end

describe "#published" do
subject { post.published }
it { is_expected.to eq(DateTime.parse("2013-01-29 15:21:56Z")) }
end

describe "#indexed" do
subject { post.indexed }
it { is_expected.to eq(DateTime.parse("2013-01-29 15:22:52Z")) }
end

describe "#blog_url" do
subject { post.blog_url }
it { is_expected.to eq("http://www.skvallernytt.se/") }
end

describe "#authority" do
subject { post.authority }
it { is_expected.to eq(38) }
end

describe "#blog_rank" do
subject { post.blog_rank }
it { is_expected.to eq(4) }
end

describe "#tags" do
subject { post.tags }
it { is_expected.to eq(["Okategoriserat", "Träning", "greyhound", "koncept", "mafia"]) }
end
end

describe "#posts[2]" do
subject(:post) { result.posts[2] }

describe "#url" do
subject { post.url }
it { is_expected.to eq("http://didriksinspesielleverden.blogg.no/1359472349_justin_bieber.html") }
end

describe "#title" do
subject { post.title }
it { is_expected.to eq("Justin Bieber") }
end

describe "#summary" do
subject { post.summary }
it { is_expected.to eq("OMG! Justin Bieber Believe acoustic albumet er nå ute på spotify. Han er helt super. Love him. Personlig liker jeg best beauty and a beat og as long as you love me, kommenter gjerne hva dere synes! <3 #sus YOLO") }
end

describe "#language_code" do
subject { post.language_code }
it { is_expected.to eq("no") }
end

describe "#published" do
subject { post.published }
it { is_expected.to eq(DateTime.parse("2013-01-29 15:12:29Z")) }
end

describe "#indexed" do
subject { post.indexed }
it { is_expected.to eq(DateTime.parse("2013-01-29 15:14:37Z")) }
end

describe "#blog_url" do
subject { post.blog_url }
it { is_expected.to eq("http://didriksinspesielleverden.blogg.no/") }
end

describe "#authority" do
subject { post.authority }
it { is_expected.to eq(0) }
end

describe "#blog_rank" do
subject { post.blog_rank }
it { is_expected.to eq(1) }
end

describe "#tags" do
subject { post.tags }
it { is_expected.to eq([]) }
end
end
end

context "with a valid result containing non-blogs" do
let(:fixture) { :valid_non_blog }

Expand Down