【问题标题】:System tests producing intermittent failures产生间歇性故障的系统测试
【发布时间】:2018-02-08 16:23:34
【问题描述】:

我们的测试在 Rails 5.1 中相互渗透,仅用于系统测试。具体来说,我们在测试一起运行时会收到“ActiveRecordNotFound”错误,但在单独运行时不会。几乎就像在下一个测试已经开始之后调用 Database Clean 一样。

宝石:

ruby '~> 2.5.0'
gem 'rails', '~> 5.1.4'
gem 'capybara'
gem 'chromedriver-helper'
gem 'rspec-rails'
gem 'selenium-webdriver'

Rails_helper:

Spec.configure do |config|
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true

  config.before(:each, type: :system) do
    driven_by :rack_test
  end

  config.before(:each, type: :system, js: true) do
    driven_by :selenium_chrome_headless
  end

  # Filter lines from Rails gems in backtraces.
  config.filter_rails_from_backtrace!
end

示例失败:

RSpec.describe 'Banana Peeling', type: :system, js: true do
  it 'peels' do
    Timecop.freeze
    banana = create(:banana)
    visit(banana_path(banana.id))
    click_on 'start_peel'
    click_on 'save'
    expect(banana.reload.start_peel).not_to be nil
    Timecop.return
  end
end

ActiveRecord::RecordNotFound:
       Couldn't find Banana with 'id'=6257

【问题讨论】:

    标签: rspec-rails ruby-on-rails-5.1


    【解决方案1】:

    Capybara 作者recommends against 使用Timecop.freeze 而不是使用Timecop.travel

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-13
      • 2011-10-27
      • 1970-01-01
      • 1970-01-01
      • 2012-02-20
      相关资源
      最近更新 更多