Sha256: e376a7f9f529491efc787b46543c1979e84915912ccdbde5aa23a01d9d39735d
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
require 'spec_helper' describe Earl::Scraper do before :each do Earl.any_instance.stub(:uri_response).and_return(<<-DOC <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html></html> DOC ) end describe 'When validating URLs' do before :each do class Earl::TestScraper < Earl::Scraper match /^http\:\/\/www\.test\.com\/$/ define_attribute(:title) {|response| :test_title } end end it 'should return the result if the URL matches the scraper regexp' do Earl['http://www.test.com/'].title.should == :test_title end end describe 'When retrieving the response' do it 'should return a Nokogiri document' do Earl['test'].response.css('html').size.should == 1 end end describe 'Scraper inheritance' do class SubScraper < Earl::Scraper define_attribute :some_attribute do |doc| doc end end it 'inherits all attributes from its superclass' do scraper = SubScraper.new('foo.bar') scraper.attributes.should include(:title) scraper.attributes.should include(:description) scraper.attributes.should include(:image) scraper.attributes.should include(:some_attribute) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
earl-1.0.0 | spec/unit/earl/scraper_spec.rb |