0

这对我来说没有任何意义。我试图断言这两个日期是相同的。它们看起来一样,但不知何故它们是不同的。

#assert correct time and date
assert_equal(/[0-9]{1,2}, [0-9]{4} at [0-9]{1,2}:[0-9]{2} [A-Z]{2}/.match($driver.find_element(:class, "flash-information").text), /[0-9]{1,2}, [0-9]{4} at [0-9]{1,2}:[0-9]{2} [A-Z]{2}/.match($driver.find_element(:class, "news_date").text))

这是我得到的失败。

F
===============================================================================
Failure: <#<MatchData "10, 2013 at 4:13 PM">> expected but was
<#<MatchData "10, 2013 at 4:13 PM">>. 

   39:     #assert correct time and date
=> 40:     assert_equal(/[0-9]{1,2}, [0-9]{4} at [0-9]{1,2}:[0-9]{2} [A-Z]{2}/.match($driver.find_element(:class, "flash-information").text), /[0-9]{1,2}, [0-9]{4} at [0-9]{1,2}:[0-9]{2} [A-Z]{2}/.match($driver.find_element(:class, "news_date").text))

我在测试单元中运行它

4

1 回答 1

2

您不是在匹配字符串,而是在匹配MatchData对象。

a = "foobar".match /f/   # #<MatchData "f">
b = "foobar".match /f/   # #<MatchData "f">
c = "barfoo".match /f/   # #<MatchData "f">

a == b   # true
a == c   # false

如果要比较匹配的字符串,则必须从MatchData对象中提取它们:

a[0]           # "f"
a[0] == b[0]   # true
a[0] == c[0]   # true
于 2013-01-11T00:46:22.663 回答