Ruby Unit :: Test comparing html output ignoring spaces

I use Ruby Test :: unit to compare the result of the generated html with the expected result. (not using rails). I'm not interested in whitespace differences, but they almost always arise during tests. Is there any testing mechanism to compare html ignoring meaningless spaces. I see a similar question here for python here . I am looking for an answer on Ruby.

0
source share
2 answers

Or just separate the spaces yourself

assert_equal html_string.gsub(/\s+/, ' '), '<a href="foo">' 
+1
source

assert_select is what you want. It allows you to use the CSS selector to parse HTML and validate values.

See this assert_select

EDIT: I missed this, not necessarily the rails. You can either import the appropriate rail into your test environment, or use something like HPricot to allow you to evaluate the result as HTML and check the correct values.

+1
source

Source: https://habr.com/ru/post/1308302/


All Articles