验证包含符号的文本

时间:2012-03-16 16:10:38

标签: ruby regex watir

我需要验证网页上显示的文字。 有些文字有符号。

验证我的页面上是否显示以下内容的最佳方法是什么

"Test® Software for the low price of 7.451¢ per install"

我看过试图逃避符号,但我得到以下错误

 test.rb:61: invalid multibyte char (US-ASCII)
 test.rb:61: unterminated string meets end of file
 test.rb:61: syntax error, unexpected $end, expecting keyword_then or ';' or '\n'

2 个答案:

答案 0 :(得分:2)

你需要把

# encoding: UTF-8

位于包含unicode字符的测试文件的顶部。这被称为“魔术评论”。您可以而且应该阅读有关encoding in Ruby 1.9的更多信息。

答案 1 :(得分:0)

听起来您想使用HTML实体而不是符号进行显示。如果这样做,您可以在测试中检查这些实体而不会出现这些问题。所以HTML变成了:

"Test® Software for the low price of 7.451¢ per install"