RSpec Date 前后的 Timecop 故障似乎与时区有关

RSpec Timecop failures around Date appear to be timezone related

我们有一些测试(规范)在 Date/Time 附近失败了。猜测这是一个 UTC 问题,但不确定为什么上次项目被触及时(~8 个月前)这些规范通过了!?!

#spec/features/comments/creation_spec.rb

feature 'Comment creation', type: :feature, js: true do
  include CommentsPageHelpers
  ...
  let!(:current_date) { Date.parse('2017-01-03') }
  ...

  background do
    Timecop.freeze(current_date)
    ...
  end

  after do
    Timecop.return
  end

  shared_examples 'added comment' do |position:, text:|
    scenario 'adds single comment' do
        ...
        expect(page).to have_text 'January 3rd, 2017'
      end
    end
  end

查看(Angular模板)#app/views/templates/comment.html.slim

.comment
  ...
  {{ comment.createdAt | moment: 'MMMM Do, YYYY' }}

#RSpec失败

Comment creation for image behaves like added comment adds single comment
     Failure/Error: expect(page).to have_text 'January 3rd, 2017'
       expected to find text "January 3rd, 2017" in "John Snow First comment message January 2nd, 2017Remove"
     Shared Example Group: "added comment" called from ./spec/features/comments/creation_spec.rb:76
     # ./spec/features/comments/creation_spec.rb:42:in `block (4 levels) in <top (required)>'
     # ./spec/features/comments/creation_spec.rb:39:in `block (3 levels) in <top (required)>'

let! 行更改为下面的两行似乎已经解决了问题。不知道它还会破坏什么,或者它是否会破坏其他时区的开发人员?!?

Time.zone = 'Pacific Time (US & Canada)'
let!(:current_date) { Time.parse('2017-01-03').in_time_zone }