From 2a115a115ec9fa3961dfdd3bdcf3caeb60ead457 Mon Sep 17 00:00:00 2001 From: Clay Shentrup Date: Sun, 15 Mar 2026 12:54:14 -0700 Subject: [PATCH] Use new_context block form to ensure context cleanup on test failure Co-Authored-By: Claude Sonnet 4.6 --- .../guides/rails_integration_with_null_driver.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/documentation/docs/article/guides/rails_integration_with_null_driver.md b/documentation/docs/article/guides/rails_integration_with_null_driver.md index 8a776221..b5317165 100644 --- a/documentation/docs/article/guides/rails_integration_with_null_driver.md +++ b/documentation/docs/article/guides/rails_integration_with_null_driver.md @@ -121,15 +121,15 @@ RSpec.configure do |config| Capybara.current_driver = :null base_url = Capybara.current_session.server.base_url - browser_context = PlaywrightBrowser.browser.new_context(baseURL: base_url) - @playwright_page = browser_context.new_page - example.run - browser_context.close + PlaywrightBrowser.browser.new_context(baseURL: base_url) do |browser_context| + @playwright_page = browser_context.new_page + example.run + end end end ``` -Each test gets a fresh `BrowserContext` (equivalent to a new incognito window), so cookies and storage never leak between tests. `browser_context.close` cleans it up after each example. +Each test gets a fresh `BrowserContext` (equivalent to a new incognito window), so cookies and storage never leak between tests. The block form of `new_context` ensures the context is always closed — even if the test raises an exception. ## Minitest Usage