这对我没有任何意义。我试图断言这两个日期是一样的。他们看起来一样,但不知怎的,他们是不同的。
#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))
我在测试单元内运行
答案 0 :(得分: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