require 'spec_helper' require 'webrick' HTML = <
HTML PORT = 45555 describe Sunscraper do it "can scrape an HTML provided as a string" do Sunscraper.scrape_html(HTML).should include('It works!') end it "can scrape an URL" do server = WEBrick::HTTPServer.new :Port => PORT, :Logger => WEBrick::Log.new('/dev/null'), :AccessLog => [] server.mount_proc '/' do |req, res| res.body = HTML end Thread.new { server.start } Sunscraper.scrape_url("http://localhost:#{PORT}/").should include('It works!') server.stop end it "should time out if callback is not called" do lambda { Sunscraper.scrape_html("", 1000) }. should raise_exception(Sunscraper::ScrapeTimeout) end end