Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capybara::RackTest::Browser#refresh includes changes to environment hash during previous request processing #2710

Open
jeremyevans opened this issue Oct 2, 2023 · 0 comments

Comments

@jeremyevans
Copy link
Contributor

Meta

Capybara Version:

3.39.1

Driver Information (and browser if relevant):

rack-test

Expected Behavior

Capybara::RackTest::Browser#refresh will use the same request environment hash contents as were used when requesting the current page.

Actual Behavior

Capybara::RackTest::Browser#refresh uses the same request environment object as was used when requesting the current page, which means if the rack application made changes to the environment object during page processing, those changes will included in the refresh request, when they should not be.

Steps to reproduce

require 'capybara'
require 'capybara/dsl'

Capybara.app = proc do |env|
  status = !env['set'] ? 200 : 500
  env['set'] = true
  [status, {}, []]
end
include Capybara::DSL

visit '/'
page.status_code # 200
page.refresh
page.status_code # expect: 200, currently: 500

Fixing this probably means making a copy of the environment hash before submitting the request, and using that copy for refreshes. That's going to slow down all usage with rack-test, even when #refresh is not used, but I think it's necessary for correct behavior. A shallow copy may be sufficient to handle most cases. There might be pathological cases that require a deep copy, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant