Rails assert_equal 并不总是适用于 DateTimes
使用 assert_equal
时,我在功能测试中遇到错误:
1) [31mFailure[0m:
test_should_allow_dealer_to_extend_offer:21
<Thu, 14 Apr 2011 23:59:59 PDT -07:00> expected but was
<Thu, 14 Apr 2011 23:59:59 PDT -07:00>.
请注意,两者显示相同的时间和时区。我检查过,它们是相同的类类型(ActiveSupport::TimeWithZone)。那么为什么它们不相等呢?
这是数据库中的标准日期时间字段,我认为它只存储到右第二个?
我可以通过将它们转换为整数或使用范围为 1 分钟的 assert_in_delta
来使其通过。但只是想知道。
顺便说一句,这是 Rails 2.3.8 和 MySQL。
I get an error in my functional test when using assert_equal
:
1) [31mFailure[0m:
test_should_allow_dealer_to_extend_offer:21
<Thu, 14 Apr 2011 23:59:59 PDT -07:00> expected but was
<Thu, 14 Apr 2011 23:59:59 PDT -07:00>.
Notice that the two show the same time and time zone. I checked and they are the same class type (ActiveSupport::TimeWithZone). So why aren't they equal?
It's a standard DateTime field in the database, which I think is only stored down to the second right?
I can get it to pass by converting them to integers or using assert_in_delta
with a range of 1 minute. But was just wondering.
Btw this is Rails 2.3.8 and MySQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也遇到同样的错误。看起来这是报告回来的2009 年:
建议的解决方案对我有用:
I'm getting the same error too. It looks like this was reported back in 2009:
The suggested solution, which worked for me: