0

これは私には意味がありません。これら 2 つの日付が同じであると断言しようとしています。見た目は同じだけどどこか違う。

#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 に答える