在我的测试中,我有一个-更长的多行HTML响应,其中包含日期和时间。我以为可以使用assert_match比较预期结果'\ d {4}-\ d {2}-\ d {2} \ d {2}:\ d {2}'与实际结果'yyyy-mm- dd hh:mm':
assert_match <<END_OF_TEXT, response.body
...
... as at: \d{4}-\d{2}-\d{2} \d{2}:\d{2} UTC
...
END_OF_TEXT
以某种方式,即使使用END_OF_TEXT的各种可能的分隔符,似乎也无法使用此语法输入正则表达式。
p = Regexp.new <<'END_OF_TEXT'
...
... as at: \d{4}-\d{2}-\d{2} \d{2}:\d{2} UTC
...
END_OF_TEXT
assert_match p, response.body
assert_match(/\A
[[:digit:]]+ # 1 or more digits before the decimal point
(\. # Decimal point
[[:digit:]]+ # 1 or more digits after the decimal point
)? # The decimal point and following digits are optional
\Z/x,
'3.14')