Fix Ruby warnings during tests

This commit is contained in:
Thomas Walpole 2017-05-28 08:54:55 -07:00
parent 9ebb7fca0b
commit 8f5f55af89
11 changed files with 29 additions and 16 deletions

View File

@ -8,6 +8,10 @@ module Capybara
attr_reader :options
attr_writer :session_options
def initialize(options)
@session_options = options.delete(:session_options)
end
def session_options
@session_options || Capybara.session_options
end

View File

@ -6,6 +6,7 @@ module Capybara
module Queries
class CurrentPathQuery < BaseQuery
def initialize(expected_path, options = {})
super(options)
@expected_path = expected_path
@options = {
url: false,

View File

@ -9,7 +9,7 @@ module Capybara
def initialize(*args, &filter_block)
@options = if args.last.is_a?(Hash) then args.pop.dup else {} end
self.session_options = @options.delete(:session_options)
super(@options)
@filter_block = filter_block

View File

@ -7,7 +7,7 @@ module Capybara
@type = (args.first.is_a?(Symbol) || args.first.nil?) ? args.shift : nil
# @type = (Capybara.ignore_hidden_elements or Capybara.visible_text_only) ? :visible : :all if @type.nil?
@options = if args.last.is_a?(Hash) then args.pop.dup else {} end
self.session_options = @options.delete(:session_options)
super(@options)
@type = (session_options.ignore_hidden_elements or session_options.visible_text_only) ? :visible : :all if @type.nil?

View File

@ -6,6 +6,7 @@ module Capybara
def initialize(expected_title, options = {})
@expected_title = expected_title
@options = options
super(@options)
unless @expected_title.is_a?(Regexp)
@expected_title = Capybara::Helpers.normalize_whitespace(@expected_title)
end

View File

@ -15,6 +15,7 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
def initialize(app, options={})
raise ArgumentError, "rack-test requires a rack application, but none was given" unless app
@session = nil
@app = app
@options = DEFAULT_OPTIONS.merge(options)
end

View File

@ -19,14 +19,18 @@ module Capybara
end
module DSL
def self.included(base)
warn "including Capybara::DSL in the global scope is not recommended!" if base == Object
class <<self
remove_method :included
if defined?(::RSpec::Matchers) && base.include?(::RSpec::Matchers)
base.send(:include, ::Capybara::RSpecMatcherProxies)
def included(base)
warn "including Capybara::DSL in the global scope is not recommended!" if base == Object
if defined?(::RSpec::Matchers) && base.include?(::RSpec::Matchers)
base.send(:include, ::Capybara::RSpecMatcherProxies)
end
super
end
super
end
end
end

View File

@ -44,6 +44,7 @@ module Capybara
end
def session_options
@context_el ||= nil
@context_el ? @context_el.session_options : Capybara.session_options
end
end

View File

@ -37,6 +37,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
end
def initialize(app, options={})
@session = nil
begin
require 'selenium-webdriver'
# Fix for selenium-webdriver 3.4.0 which misnamed these

View File

@ -37,10 +37,10 @@ class MinitestSpecTest < Minitest::Spec
page.must_have_xpath('.//input[@id="customer_email"]')
page.wont_have_xpath('.//select[@id="not_form_title"]')
page.wont_have_xpath('.//input[@id="customer_email"]') { |el| el[:id] == "not_customer_email" }
el = find(:select, 'form_title')
el.must_have_xpath('.//option[@class="title"]')
el.must_have_xpath('.//option', count: 1) { |el| el[:class] != 'title' && !el.disabled?}
el.wont_have_xpath('.//input[@id="customer_email"]')
select = find(:select, 'form_title')
select.must_have_xpath('.//option[@class="title"]')
select.must_have_xpath('.//option', count: 1) { |option| option[:class] != 'title' && !option.disabled?}
select.wont_have_xpath('.//input[@id="customer_email"]')
end
it "support css expectations" do

View File

@ -40,12 +40,12 @@ RSpec.describe Capybara::SessionConfig do
it "doesn't allow session config when false" do
Capybara.threadsafe = false
session = Capybara::Session.new(:rack_test, TestApp)
expect { session.config.default_selector = :title }.to raise_error /Per session settings are only supported when Capybara.threadsafe == true/
expect { session.config.default_selector = :title }.to raise_error(/Per session settings are only supported when Capybara.threadsafe == true/)
expect do
session.configure do |config|
config.exact = true
end
end.to raise_error /Session configuration is only supported when Capybara.threadsafe == true/
end.to raise_error(/Session configuration is only supported when Capybara.threadsafe == true/)
end
it "uses the config from the session" do
@ -60,8 +60,8 @@ RSpec.describe Capybara::SessionConfig do
it "won't change threadsafe once a session is created" do
Capybara.threadsafe = true
Capybara.threadsafe = false
session = Capybara::Session.new(:rack_test, TestApp)
expect { Capybara.threadsafe = true }.to raise_error /Threadsafe setting cannot be changed once a session is created/
Capybara::Session.new(:rack_test, TestApp)
expect { Capybara.threadsafe = true }.to raise_error(/Threadsafe setting cannot be changed once a session is created/)
end
end
end