mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
Support threadsafe/per session config mode
This commit is contained in:
parent
6670981917
commit
685371079e
4 changed files with 67 additions and 13 deletions
18
Gemfile.lock
18
Gemfile.lock
|
@ -8,7 +8,7 @@ PATH
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
addressable (2.5.0)
|
||||
addressable (2.5.1)
|
||||
public_suffix (~> 2.0, >= 2.0.2)
|
||||
appraisal (0.4.1)
|
||||
bundler
|
||||
|
@ -30,13 +30,13 @@ GEM
|
|||
addressable (~> 2.3)
|
||||
spoon (~> 0.0.1)
|
||||
mime-types (2.99.3)
|
||||
mini_magick (4.6.1)
|
||||
mini_portile2 (2.1.0)
|
||||
nokogiri (1.7.1)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
nokogiri (1.7.1-java)
|
||||
nokogiri (1.7.1-x86-mingw32)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
mini_magick (4.7.0)
|
||||
mini_portile (0.6.2)
|
||||
nokogiri (1.6.6.4)
|
||||
mini_portile (~> 0.6.0)
|
||||
nokogiri (1.6.6.4-java)
|
||||
nokogiri (1.6.6.4-x86-mingw32)
|
||||
mini_portile (~> 0.6.0)
|
||||
public_suffix (2.0.5)
|
||||
rack (1.6.5)
|
||||
rack-protection (1.5.3)
|
||||
|
@ -84,4 +84,4 @@ DEPENDENCIES
|
|||
sinatra
|
||||
|
||||
BUNDLED WITH
|
||||
1.14.5
|
||||
1.14.6
|
||||
|
|
|
@ -359,7 +359,11 @@ module Capybara::Webkit
|
|||
end
|
||||
|
||||
def default_wait_time
|
||||
Capybara.respond_to?(:default_max_wait_time) ? Capybara.default_max_wait_time : Capybara.default_wait_time
|
||||
if respond_to?(:session_options) && session_options
|
||||
session_options.default_max_wait_time
|
||||
else
|
||||
Capybara.respond_to?(:default_max_wait_time) ? Capybara.default_max_wait_time : Capybara.default_wait_time
|
||||
end
|
||||
end
|
||||
|
||||
def find_modal(type, id, options)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Capybara::Webkit
|
||||
class Node < Capybara::Driver::Node
|
||||
def initialize(session, base, browser)
|
||||
super(session, base)
|
||||
def initialize(driver, base, browser)
|
||||
super(driver, base)
|
||||
@browser = browser
|
||||
end
|
||||
|
||||
|
@ -147,7 +147,7 @@ module Capybara::Webkit
|
|||
end
|
||||
|
||||
def automatic_reload?
|
||||
Capybara.respond_to?(:automatic_reload) && Capybara.automatic_reload
|
||||
session_option(:automatic_reload)
|
||||
end
|
||||
|
||||
def attached?
|
||||
|
@ -164,6 +164,14 @@ module Capybara::Webkit
|
|||
|
||||
private
|
||||
|
||||
def session_option(name)
|
||||
if driver.respond_to?(:session_options)
|
||||
driver.session_options.public_send(name)
|
||||
else
|
||||
Capybara.respond_to?(name) && Capybara.public_send(name)
|
||||
end
|
||||
end
|
||||
|
||||
def convert_to_named_keys(key)
|
||||
if key.is_a? Array
|
||||
key.map { |k| convert_to_named_keys(k)}
|
||||
|
|
|
@ -551,4 +551,46 @@ describe Capybara::Session do
|
|||
expect(session).to have_text('Hello')
|
||||
end
|
||||
end
|
||||
|
||||
if Capybara.respond_to?(:threadsafe)
|
||||
context "threadsafe/per-session config mode" do
|
||||
before do
|
||||
Capybara::SpecHelper.reset_threadsafe(true, subject)
|
||||
end
|
||||
|
||||
after do
|
||||
Capybara::SpecHelper.reset_threadsafe(false, subject)
|
||||
end
|
||||
|
||||
it "can allow reload in one session but not in another" do
|
||||
session1, session2 = 2.times.collect do
|
||||
session_for_app do
|
||||
get '/' do
|
||||
<<-HTML
|
||||
<html>
|
||||
<div id="parent">
|
||||
<p id="removeMe">Hello</p>
|
||||
</div>
|
||||
</html>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
session1.config.automatic_reload = false
|
||||
session2.config.automatic_reload = true
|
||||
|
||||
node1, node2 = [session1, session2].map do |session|
|
||||
session.visit('/')
|
||||
|
||||
node = session.find(:xpath, "//p[@id='removeMe']")
|
||||
session.execute_script("document.getElementById('parent').innerHTML = 'Magic'")
|
||||
node
|
||||
end
|
||||
|
||||
expect(node1.text).to eq 'Hello'
|
||||
expect{ node2.text }.to raise_error(Capybara::Webkit::NodeNotAttachedError)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue