minitest + capybara 出现错误时怎么办save_and_open_page

minitest + capybara how to do save_and_open_page when there is an error

在使用 rspec 时,我通常会这样做:

if ENV['OPEN_ERRORS']
  shown_error_pages = 0

  config.after :each do
    if RSpec.current_example.exception != nil and shown_error_pages == 0
      shown_error_pages += 1
      save_and_open_page
    end
  end
end

例如OPEN_ERRORS=1 bundle exec rspec

我怎样才能用 minitest 做这样的事情?

您可以通过检查 !passed?

在拆解或 after_teardown 块中执行此操作

capybara-screenshot gem 提供了这种行为并且与 RSpec 和 minitest 兼容,你可以在这里看到它是如何实现这种行为的 - https://github.com/mattheworiordan/capybara-screenshot/blob/master/lib/capybara-screenshot/minitest.rb