gpt4 book ai didi

ruby-on-rails - Time.now 在测试环境中返回错误结果

转载 作者:行者123 更新时间:2023-11-28 21:09:54 25 4
gpt4 key购买 nike

我正在我的 Rails 应用程序中运行带有 capybara 的 RSpec 测试套件。当我将 binding.pry 放入测试中并尝试 Time.current 时,我得到 => Tue, 15 Dec 2015 00:06:30 UTC + 00:00,也就是三个月前。就我的地理基础知识而言,没有一个时区与 EST 有 3 个月的差异。那我在这里错过了什么? :-)

在开发环境中运行相同的查询(即通过 rails console)返回正确的结果。

最佳答案

听起来您的套件中有使用 the Timecop gem 的规范.因此,查看 Timecop.freeze 的每个实例并确保有相应的 Timecop.return 语句,以便正确拆卸时间卡住并防止意外它泄漏到套件中其他规范的副作用。这是来自 the gem's README 的示例:

describe "some set of tests to mock" do
before do
Timecop.freeze(Time.local(1990))
end

after do
Timecop.return
end

it "should do blah blah blah" do
end
end

关于ruby-on-rails - Time.now 在测试环境中返回错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35967578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com