everypolitician / scraper_test

Data-driven scraper tests for Scraped
0 stars 0 forks source link

When a field returns a class or array of classes, test the data of the returned classes also #14

Closed ondenman closed 7 years ago

ondenman commented 7 years ago

Problem

At the moment scraper_test cannot test any object that returns other Scraped::Document objects in its to_h data.

Example

For example, the member page class memberships: field of the New Zealand scraper returns an array of MembershipRow objects. (https://github.com/everypolitician-scrapers/new-zealand-parliament/blob/master/lib/current_member_page.rb)

scraper_test should test New Zealand's CurrentMemberPage against:

:class: CurrentMemberPage
:url: https://www.parliament.nz/en/mps-and-electorates/members-of-parliament/document/51MP1811/tolley-anne
:to_h:
  :id: 51MP1811
  :name: Anne Tolley
  :sort_name: Tolley, Anne
  :photo: https://www.parliament.nz/media/1400/tolley-anne.C24btw.jpg
  :email: anne.tolley@parliament.govt.nz
  :facebook: https://www.facebook.com/honannetolley
  :twitter: https://twitter.com/AnneTolleyMP
  :source: https://www.parliament.nz/en/mps-and-electorates/members-of-parliament/document/51MP1811/tolley-anne
  :honorific_prefix: 
  :memberships:
  - :area: East Coast
    :party: National Party
    :start_date: '2005-09-17'
    :end_date: 
  - :area: List
    :party: National Party
    :start_date: '1999-11-27'
    :end_date: '2002-07-27'

Solution

scraper_test should be aware that the subject hash contains Scraped::Document objects. Any Scraped::Document objects should be replaced by their to_h values.

ondenman commented 7 years ago

Closing as it has been decided that this should be handled by Scraped. Issue: https://github.com/everypolitician/scraped/issues/98