This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
/
show_loader_spec.rb
90 lines (80 loc) · 3.15 KB
/
show_loader_spec.rb
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
88
89
90
require 'spec_helper'
require 'support/scraper_mocks'
include ScraperMocksHelper
describe "Navd::Scraper::ShowLoader" do
let(:show_number) { 333 }
let(:show_loader) { Navd::Scraper::ShowLoader.new(show_number) }
subject { show_loader }
context "init" do
it { should_not be_nil }
its(:number) { should eql(show_number) }
its(:spider) { should be_a(Navd::Scraper::Spider) }
its(:found) { should be_nil }
its(:published) { should be_nil }
end
describe "#scan_show_assets" do
context "published show" do
let(:expected_attributes) { {
:number => 333,
:published => true,
:show_notes_url=>"http://333.nashownotes.com/",
:audio_url=>"http://m.podshow.com/media/15412/episodes/293390/noagenda-293390-08-25-2011.mp3",
:published_date=>Date.parse('2011-8-25'),
:cover_art_url=>"http://dropbox.curry.com/ShowNotesArchive/2011/08/NA-333-2011-08-25/Assets/na333art.png",
:assets_url=>"http://333.nashownotes.com/assets",
:url=>"http://blog.curry.com/stories/2011/08/25/na33320110825.html",
:credits=>nil
} }
before {
show_loader.spider.stub(:get_page).and_return(Nokogiri::HTML(published_show_page_html))
show_loader.stub(:show_notes).and_return([])
show_loader.scan_show_assets
}
its(:found) { should be_true }
its(:published) { should be_true }
its(:errors) { should be_empty }
its(:attributes) { should eql(expected_attributes) }
describe "#shownotes_menu_uri [protected]" do
subject { show_loader.send(:shownotes_menu_uri) }
let(:expected) { URI.parse('http://333.nashownotes.com/shownotes') }
it { should eql(expected) }
end
context "parsing shownotes menu" do
before {
show_loader.stub(:p_shownotes_menu).and_return(Nokogiri::HTML(shownotes_menu_page_html))
}
describe "#shownotes_detail_main_uri [protected]" do
subject { show_loader.send(:shownotes_detail_main_uri) }
let(:expected) { URI.parse('http://333.nashownotes.com/shownotes/na33320110825Shownotes') }
it { should eql(expected) }
end
describe "#credits_uri [protected]" do
subject { show_loader.send(:credits_uri) }
let(:expected) { URI.parse('http://333.nashownotes.com/shownotes/na33320110825Credits') }
it { should eql(expected) }
end
end
end
context "unpublished show" do
let(:show_number) { 33 }
before {
show_loader.spider.stub(:get_page).and_return(Nokogiri::HTML(unpublished_show_page_html))
show_loader.stub(:show_notes).and_return([])
show_loader.scan_show_assets
}
its(:found) { should be_true }
its(:published) { should be_false }
its(:errors) { should_not be_empty }
end
context "bad url" do
before {
show_loader.spider.stub(:get_uri_for_show).and_return('bad://karma')
show_loader.stub(:show_notes).and_return([])
show_loader.scan_show_assets
}
its(:found) { should be_false }
its(:published) { should be_false }
its(:errors) { should_not be_empty }
end
end
end