mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
general cleanup
This commit is contained in:
parent
9ebc503328
commit
c56170a65c
5 changed files with 24 additions and 24 deletions
|
@ -109,9 +109,8 @@ module Capybara
|
|||
break if @result_cache.size > max
|
||||
@result_cache << @results_enum.next
|
||||
end
|
||||
return 0 if @query.options[:between].include?(@result_cache.size)
|
||||
return -1 if @result_cache.size < min
|
||||
return 1
|
||||
return 0 if @query.options[:between] === @result_cache.size
|
||||
return @result_cache.size <=> min
|
||||
end
|
||||
|
||||
0
|
||||
|
|
|
@ -89,7 +89,7 @@ module Capybara
|
|||
return false if @server_thread&.join(0)
|
||||
|
||||
begin
|
||||
res = if !@using_ssl
|
||||
res = if !using_ssl?
|
||||
http_connect
|
||||
else
|
||||
https_connect
|
||||
|
|
|
@ -189,14 +189,11 @@ module Capybara
|
|||
# Addressable parsing is more lenient than URI
|
||||
uri = ::Addressable::URI.parse(current_url)
|
||||
|
||||
# If current_url ends up being nil, won't be able to call .path on a NilClass.
|
||||
return nil if uri.nil?
|
||||
|
||||
# Addressable doesn't support opaque URIs - we want nil here
|
||||
return nil if uri.scheme == "about"
|
||||
return nil if uri&.scheme == "about"
|
||||
|
||||
path = uri.path
|
||||
path if path && !path.empty?
|
||||
path = uri&.path
|
||||
path if !path&.empty?
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -248,11 +245,10 @@ module Capybara
|
|||
|
||||
visit_uri = ::Addressable::URI.parse(visit_uri.to_s)
|
||||
|
||||
uri_base = if @server
|
||||
::Addressable::URI.parse(config.app_host || "http#{'s' if @server.using_ssl?}://#{@server.host}:#{@server.port}")
|
||||
else
|
||||
config.app_host && ::Addressable::URI.parse(config.app_host)
|
||||
end
|
||||
base = config.app_host
|
||||
base ||= "http#{'s' if @server.using_ssl?}://#{@server.host}:#{@server.port}" if @server
|
||||
|
||||
uri_base = ::Addressable::URI.parse(base)
|
||||
|
||||
if uri_base && [nil, 'http', 'https'].include?(visit_uri.scheme)
|
||||
if visit_uri.relative?
|
||||
|
@ -475,9 +471,8 @@ module Capybara
|
|||
# @raise [ArgumentError] if both or neither arguments were provided
|
||||
#
|
||||
def switch_to_window(window = nil, **options, &window_locator)
|
||||
block_given = block_given?
|
||||
raise ArgumentError, "`switch_to_window` can take either a block or a window, not both" if window && block_given
|
||||
raise ArgumentError, "`switch_to_window`: either window or block should be provided" if !window && !block_given
|
||||
raise ArgumentError, "`switch_to_window` can take either a block or a window, not both" if window && block_given?
|
||||
raise ArgumentError, "`switch_to_window`: either window or block should be provided" if !window && !block_given?
|
||||
unless scopes.last.nil?
|
||||
raise Capybara::ScopeError, "`switch_to_window` is not supposed to be invoked from "\
|
||||
"`within` or `within_frame` blocks."
|
||||
|
@ -569,7 +564,7 @@ module Capybara
|
|||
#
|
||||
def execute_script(script, *args)
|
||||
@touched = true
|
||||
driver.execute_script(script, *args.map { |arg| arg.is_a?(Capybara::Node::Element) ? arg.base : arg })
|
||||
driver.execute_script(script, *driver_args(args))
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -583,7 +578,7 @@ module Capybara
|
|||
#
|
||||
def evaluate_script(script, *args)
|
||||
@touched = true
|
||||
result = driver.evaluate_script(script, *args.map { |arg| arg.is_a?(Capybara::Node::Element) ? arg.base : arg })
|
||||
result = driver.evaluate_script(script, *driver_args(args))
|
||||
element_script_result(result)
|
||||
end
|
||||
|
||||
|
@ -596,7 +591,7 @@ module Capybara
|
|||
#
|
||||
def evaluate_async_script(script, *args)
|
||||
@touched = true
|
||||
result = driver.evaluate_async_script(script, *args.map { |arg| arg.is_a?(Capybara::Node::Element) ? arg.base : arg })
|
||||
result = driver.evaluate_async_script(script, *driver_args(args))
|
||||
element_script_result(result)
|
||||
end
|
||||
|
||||
|
@ -799,6 +794,10 @@ module Capybara
|
|||
|
||||
@@instance_created = false
|
||||
|
||||
def driver_args(args)
|
||||
args.map { |arg| arg.is_a?(Capybara::Node::Element) ? arg.base : arg }
|
||||
end
|
||||
|
||||
def accept_modal(type, text_or_options, options, &blk)
|
||||
driver.accept_modal(type, modal_options(text_or_options, options), &blk)
|
||||
end
|
||||
|
|
|
@ -558,7 +558,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|||
it 'waits if wait time is more than timeout' do
|
||||
@session.click_link("Change title")
|
||||
using_wait_time 0 do
|
||||
expect(@session).to have_title('changed title', wait: 0.5)
|
||||
expect(@session).to have_title('changed title', wait: 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -603,7 +603,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|||
it 'waits if wait time is more than timeout' do
|
||||
@session.click_link("Change page")
|
||||
using_wait_time 0 do
|
||||
expect(@session).to have_current_path('/with_html', wait: 1)
|
||||
expect(@session).to have_current_path('/with_html', wait: 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ RSpec.describe Capybara::Selenium::Driver do
|
|||
end
|
||||
end
|
||||
|
||||
context "#refresh" do
|
||||
context "#refresh", :focus_ do
|
||||
def extract_results(session)
|
||||
expect(session).to have_xpath("//pre[@id='results']")
|
||||
YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.inner_html.lstrip
|
||||
|
@ -134,11 +134,13 @@ RSpec.describe Capybara::Selenium::Driver do
|
|||
@session.visit('/form')
|
||||
@session.select('Sweden', from: 'form_region')
|
||||
@session.click_button('awesome')
|
||||
sleep 1
|
||||
expect do
|
||||
@session.accept_confirm(wait: 0.1) do
|
||||
@session.refresh
|
||||
sleep 2
|
||||
end
|
||||
sleep 1
|
||||
end.to change { extract_results(@session)['post_count'] }.by(1)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue