由于日期格式不同,测试失败

时间:2016-01-05 13:24:39

标签: ruby-on-rails ruby datetime ruby-on-rails-4 integration-testing

下面的测试比较了两个日期。由于日期格式不同,测试失败。我怎样才能使这个测试工作?

expiration = Time.zone.now - 50.days
# some lines to update @organization with a new expiration
assert_equal @organization.exp, expiration
# puts @organization.exp => Mon, 16 Nov 2015
# puts expiration => Mon, 16 Nov 2015 14:22:39 CET +01:00

2 个答案:

答案 0 :(得分:2)

使用.*/.*/^my-text$方法,例如

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

答案 1 :(得分:0)

@organization.exp似乎是Date,但expiration不是:

expiration = Time.zone.now - 50.days
#=> Mon, 16 Nov 2015 14:36:06 CET +01:00

expiration.class
#=> ActiveSupport::TimeWithZone

要获取时区感知Date实例,您可以使用Date#current并使用DateAndTime::Calculations#days_ago进行更改:

expiration = Date.current.days_ago(50)
#=> Mon, 16 Nov 2015

expiration.class
#=> Date