Ruby Unit ::通过忽略空白来比较html输出的测试 [英] Ruby Unit::Test comparing html output by ignoring whitespace

查看:81
本文介绍了Ruby Unit ::通过忽略空白来比较html输出的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Ruby的Test :: unit将生成的html的结果与预期的结果进行比较。 (不使用导轨)。我并不关心空白区域的差异,但在测试过程中这些差异几乎总是出现。是否有任何测试机制来比较html,而忽略无意义的空白。我可以看到python的这里有类似的问题。我正在寻找Ruby的答案。

解决方案

c $ c> assert_equal html_string.gsub(/ \ s + /,''),'< a href =foo>'


I am using Ruby's Test::unit to compare the result of generated html with the expected result. (not using rails). I am not concerned with whitespace differences but these nearly always crop up during tests. Is there any testing mechanism to compare html while ignoring meaningless whitespace. I can see there's similar question for python here. I'm looking for an answer for Ruby.

解决方案

Or just strip whitespace yourself

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

这篇关于Ruby Unit ::通过忽略空白来比较html输出的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆