Skip to content

If take_failed_screenshot fails, the rest of the teardown hooks do not run, breaking transactions #2401

Closed
@markiz

Description

@markiz

What Ruby, Rails and RSpec versions are you using?

Ruby version: 2.6.3
Rails version: 6.0.3.4

RSpec 3.9

  • rspec-core 3.9.3
  • rspec-expectations 3.9.3
  • rspec-mocks 3.9.1
  • rspec-rails 4.0.1
  • rspec-support 3.9.4

Observed behaviour

Sometimes take_failed_screenshot would fail, because driver raised an exception. For us, Ferrum::DeadBrowserError was the most common issue. When this happens, all the consequent teardown hooks do not run, including the transactional fixtures teardown (which would normally roll back the wrapper transaction). That leaves the suite with a dirty db state.

Expected behaviour

I'm not sure. Probably, after_teardown hooks should run even if before_teardown hooks failed?

Can you provide an example app?

Alas, no, but here's an example patch that helped us with this issue:

module ScreenshotHelperPatch
  def take_failed_screenshot(*)
    super
  rescue => e # Silently ignore errors
  end
end

# And in the rails_helper
config.include ScreenshotHelperPatch, type: :system

I guess you can emulate this situation by raising from one of the before_teardown callbacks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions