Testing "HTML fixtures" with RSpec and rails

I have a web scraper designed to parse html from a website, and I'm trying to write tests for it.

The class I'm trying to validate receives a Nokogiri HTML object and extracts the required data from it. Now, as usual, html can change, sometimes elements will be missing or much more. I need to check out these different situations.

So, what I would like to do is create a bunch of html files, each of which represents a case with the absence of a specific element, etc. For each html file, I also want to build a related hash from the data that I would expect a scraper to extract, provided that it works correctly.

So, I would like to write a test that will iterate over these html files and compare the data extracted by the tested class with the expected data and report whether they are correct.

Any suggestions on how to do this?

+3
source share
1 answer

Check out Artifice , fakeweb, or webmock that override net / http to provide test results.

+3
source

All Articles