Sha256: abb5cfd354590fe06825c573791a1f74add4a061fbfb0d3a2d0dae868275b5d8

Contents?: true

Size: 1017 Bytes

Versions: 3

Compression:

Stored size: 1017 Bytes

Contents

require 'spec_helper'
require 'test_models'
require 'active_support/core_ext/hash/keys'

describe Scrapify::Scraper do
  def self.attributes
    {:name => {:css => ".menu_lft li a"},
                :image_url => {:xpath => "//li//input//@value"},
                :price => {:css => ".price", :regex => /([\d\.]+)/},
                :ingredients => {:css => ".ingredients", :regex => /contains (\w+)/, :array => true},
                :ingredient_urls => {:css => ".references ol li",
                                     :block => lambda{|element| element.children.map{|child| child.attributes['href'].value if child.attributes['href']}.compact}
                                    }}
  end

  def self.attributes_with_string_keys
    attributes.each_with_object({}){|(k,v),h| h[k.to_s] = v.stringify_keys}
  end

  it_should_behave_like "Scrapify", Scrapify::Scraper.new(::Pizza.url, :name, attributes)
  it_should_behave_like "Scrapify", Scrapify::Scraper.new(::Pizza.url, 'name', attributes_with_string_keys)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scrapify-0.0.9 spec/scraper_spec.rb
scrapify-0.0.8 spec/scraper_spec.rb
scrapify-0.0.7 spec/scraper_spec.rb