Rails升级后的神秘rspec错误

时间:2019-01-07 20:31:04

标签: unit-testing ruby-on-rails-5 rspec-rails

我最近尝试在我的代码仓库中升级Rails(至v5.2.2),其中两个在升级后未能通过单元测试。在深入研究并逐行比较Gemfile.lock的失败版本和工作版本之后,我发现升级activestoragev5.2.1-> 5.2.2)是元凶,我能够复制并反转它。似乎已经引入了一个问题(至少对于测试而言;我没有亲自使用代码看到此问题),其中测试套件无法在.click事件之后获取元素属性更新。有人也遇到过吗?可能是个错误吗?

这是我收到的错误消息的示例:

1) Notifications notifications drawer when clicking the nav will open the drawer
   Failure/Error: expect(page).to have_selector('.notifications-drawer', visible: true)
   expected to find visible css ".notifications-drawer" but there were no matches. Also found "View all notifications", which matched the selector but not all filters.
    # ./spec/features/notifications_spec.rb:88:in `block (4 levels) in <top (required)>'

2) Notifications mark notification as read behavior when a notification is loaded will be marked as read after clicked
   Failure/Error: expect(page).to have_css('.notification.read')
   expected to find css ".notification.read" but there were no matches
 # ./spec/features/notifications_spec.rb:140:in `block (4 levels) in <top (required)>'

以下是升级后失败的两个测试:

context 'when clicking the nav' do
    before do
        find('.notifications-drawer-link').click
    end
    it 'will open the drawer' do # line 87
        expect(page).to have_selector('.notifications-drawer', visible: true)
    end
    it 'will have a link to all notifications' do
       expect(page).to have_selector('.notifications-drawer-link')
    end
end

context 'when a notification is loaded' do
  it 'will initially be marked as unread' do
    expect(page).to have_css('.notification.unread')
  end

  it 'will be marked as read after clicked' do # line 137
    notify_element = '[data-notify-id="' + mock_notifications[:items][0][:id] + '"]'
    page.find(notify_element).find('.notifications-date-stamp').trigger("click")
    expect(page).to have_css('.notification.read')
  end
end

0 个答案:

没有答案
相关问题