Skip to content

Instantly share code, notes, and snippets.

@jsuchal
Created March 14, 2012 08:43
Show Gist options
  • Save jsuchal/2035154 to your computer and use it in GitHub Desktop.
Save jsuchal/2035154 to your computer and use it in GitHub Desktop.
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
# 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