Improve screenshot capture to include all rspec hooks
Problem
We use capybara-screenshot
to automatically capture a screenshot when a test/example fails. However, because it only captures a screenshot in the after
hook following a failed test, it doesn't capture a screenshot if there's a failure in a before(:context)
hook. It also doesn't capture the screenshot at the point of failure if the test has an after
hook that uses the UI (because the screenshot is captured in a config.after
hook, which is executed after the test's after
hooks).
We have guidelines to work around these limits, but we can do better.
Proposal
Add our own config
hooks to capture a screenshot if there's a failure at any point in a spec, including in before
, before(:context)
, after
, and after(:context)
hooks.