2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-06 07:45:09 +08:00
|
|
|
require 'rss'
|
|
|
|
require 'feed_item_accessor'
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe FeedItemAccessor do
|
2017-12-06 07:45:09 +08:00
|
|
|
context 'for ATOM feed' do
|
|
|
|
let(:atom_feed) { RSS::Parser.parse(file_from_fixtures('feed.atom', 'feed'), false) }
|
|
|
|
let(:atom_feed_item) { atom_feed.items.first }
|
|
|
|
let(:item_accessor) { FeedItemAccessor.new(atom_feed_item) }
|
|
|
|
|
|
|
|
describe '#element_content' do
|
|
|
|
it { expect(item_accessor.element_content('title')).to eq(atom_feed_item.title.content) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#link' do
|
|
|
|
it { expect(item_accessor.link).to eq(atom_feed_item.link.href) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for RSS feed' do
|
|
|
|
let(:rss_feed) { RSS::Parser.parse(file_from_fixtures('feed.rss', 'feed'), false) }
|
|
|
|
let(:rss_feed_item) { rss_feed.items.first }
|
|
|
|
let(:item_accessor) { FeedItemAccessor.new(rss_feed_item) }
|
|
|
|
|
|
|
|
describe '#element_content' do
|
|
|
|
it { expect(item_accessor.element_content('title')).to eq(rss_feed_item.title) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#link' do
|
|
|
|
it { expect(item_accessor.link).to eq(rss_feed_item.link) }
|
|
|
|
end
|
|
|
|
end
|
2022-01-21 23:54:18 +08:00
|
|
|
|
|
|
|
context 'with multiple links' do
|
|
|
|
let(:rss_feed) { RSS::Parser.parse(file_from_fixtures('multiple-links.atom', 'feed'), false) }
|
|
|
|
let(:rss_feed_item) { rss_feed.items.first }
|
|
|
|
let(:item_accessor) { FeedItemAccessor.new(rss_feed_item) }
|
|
|
|
|
|
|
|
describe '#link' do
|
|
|
|
it 'gets the web page link' do
|
|
|
|
expect(item_accessor.link).to eq('http://workspaceupdates.googleblog.com/2022/01/improved-editing-experience-in-google.html')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-12-06 07:45:09 +08:00
|
|
|
end
|