开发者

Testing "HTML fixtures" with RSpec and rails

开发者 https://www.devze.com 2023-03-10 06:38 出处:网络
I have a web scraper built to parse html from a website and I\'m trying to write tests for it. The class I\'m trying to test receives a Nokogiri HTML object and extracts the required data from it. No

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

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

So what I'd like to do is make a bunch of html files, each one representing a case with a particular element missing etc. For each html file, I wish to also construct an associated hash of the data I would expect the scraper to extract开发者_开发问答, assuming it is working correctly.

So I would like to write a test which will iterate over these html files and compare the data extracted by the class being tested against the expected data and report whether or not it is correct.

Any suggestions as to how to do this?


Have a look at the Artifice, fakeweb or webmock gems, which override net/http in order to supply testable results.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号