Created
March 14, 2012 08:43
-
-
Save jsuchal/2035154 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Series.create_from_speakerrate('http://speakerrate.com/series/241-rubyslava-pyvo?all') | |
describe Series do | |
it "should " do | |
url = 'http://speakerrate.com/series/241-rubyslava-pyvo?all' | |
html = '' | |
downloader = mock(:Downloader) | |
downloader.should_receive(:download).with(url).and_return(html) | |
instance = mock(:Instance) | |
factory = mock(:Factory) | |
factory.should_receive(:new).and_return(instance) | |
parser = mock(:Parser) | |
parser.should_receive(:parse).with(html, instance) | |
persistor = mock(:Persistor) | |
persistor.should_receive(:persist).with(instance) | |
SimpleCrawler.create_from_url(url, downloader, factory, parser, persistor) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'nokogiri' | |
class SeriesParser | |
def self.parse(html, series) | |
doc = Nokogiri::HTML.parse(html) | |
series.name = doc.css('.title-series .item').first.text | |
series.description = doc.css('.description').first.text.strip | |
doc.css('.vevent h5 a').each do |link| | |
id = link[:href][/\/talks\/(\d+)/, 1].to_i | |
series.add_talk(id) | |
end | |
end | |
end | |
describe SeriesParser do | |
it "should parse all data" do | |
html = File.read(File.dirname(__FILE__) + '/fixtures/rubyslava.html') | |
series = mock(:Series) | |
series.should_receive(:name=).with('Rubyslava + PyVo') | |
series.should_receive(:description=).with('Neformálna skupina ľudí pracujúcich či milujúcich Ruby, ktorí si chcú vymeniť skúsenosti, zanadávať na problémy, ale najmä hľadať elegantné riešenia.') | |
series.should_receive(:add_talk).with(9301) | |
series.should_receive(:add_talk).exactly(23).times | |
series.should_receive(:add_talk).with(8047) | |
SeriesParser.parse(html, series) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment