0

我们有一些测试(规范)在日期/时间附近失败。猜测这是一个 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

查看(角度模板)#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)>'
4

1 回答 1

0

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

Time.zone = 'Pacific Time (US & Canada)'
let!(:current_date) { Time.parse('2017-01-03').in_time_zone }
于 2018-09-27T23:46:15.880 回答