Capybara::RackTest::Browser#refresh includes changes to environment hash during previous request processing
jeremyevans opened this issue · comments
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.