mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge pull request #2139 from teamcapybara/nokogumbo_disable
Make gumbo use configurable
This commit is contained in:
commit
40d7d2389a
4 changed files with 19 additions and 2 deletions
|
@ -38,6 +38,8 @@ module Capybara
|
|||
# See {Capybara.configure}
|
||||
# @!method javascript_driver
|
||||
# See {Capybara.configure}
|
||||
# @!method allow_gumbo
|
||||
# See {Capybara.configure}
|
||||
Config::OPTIONS.each do |method|
|
||||
def_delegators :config, method, "#{method}="
|
||||
end
|
||||
|
@ -86,6 +88,7 @@ module Capybara
|
|||
# [test_id = Symbol/String/nil] Optional attribute to match locator aginst with builtin selectors along with id (Default: nil)
|
||||
# [predicates_wait = Boolean] Whether Capybaras predicate matchers use waiting behavior by default (Default: true)
|
||||
# [default_normalize_ws = Boolean] Whether text predicates and matchers use normalize whitespace behaviour (Default: false)
|
||||
# [allow_gumbo = Boolean] When `nokogumbo` is available, whether it will be used to parse HTML strings (Default: true)
|
||||
#
|
||||
# === DSL Options
|
||||
#
|
||||
|
@ -366,7 +369,7 @@ module Capybara
|
|||
# @return [Nokogiri::HTML::Document] HTML document
|
||||
#
|
||||
def HTML(html) # rubocop:disable Naming/MethodName
|
||||
if Nokogiri.respond_to?(:HTML5) # Nokogumbo installed
|
||||
if Nokogiri.respond_to?(:HTML5) && Capybara.allow_gumbo # Nokogumbo installed and allowed for use
|
||||
Nokogiri::HTML5(html).tap do |document|
|
||||
document.xpath('//textarea').each do |textarea|
|
||||
# The Nokogumbo HTML5 parser already returns spec compliant contents
|
||||
|
@ -522,6 +525,7 @@ Capybara.configure do |config|
|
|||
config.test_id = nil
|
||||
config.predicates_wait = true
|
||||
config.default_normalize_ws = false
|
||||
config.allow_gumbo = true
|
||||
end
|
||||
|
||||
Capybara.register_driver :rack_test do |app|
|
||||
|
|
|
@ -7,12 +7,13 @@ module Capybara
|
|||
class Config
|
||||
extend Forwardable
|
||||
|
||||
OPTIONS = %i[app reuse_server threadsafe default_wait_time server default_driver javascript_driver].freeze
|
||||
OPTIONS = %i[app reuse_server threadsafe default_wait_time server default_driver javascript_driver allow_gumbo].freeze
|
||||
|
||||
attr_accessor :app
|
||||
attr_reader :reuse_server, :threadsafe
|
||||
attr_reader :session_options
|
||||
attr_writer :default_driver, :javascript_driver
|
||||
attr_accessor :allow_gumbo
|
||||
|
||||
SessionConfig::OPTIONS.each do |method|
|
||||
def_delegators :session_options, method, "#{method}="
|
||||
|
|
|
@ -35,6 +35,7 @@ module Capybara
|
|||
Capybara.test_id = nil
|
||||
Capybara.predicates_wait = true
|
||||
Capybara.default_normalize_ws = false
|
||||
Capybara.allow_gumbo = true
|
||||
reset_threadsafe
|
||||
end
|
||||
|
||||
|
|
|
@ -110,6 +110,17 @@ RSpec.describe Capybara do
|
|||
expect(string.find('//form/input[@name="meh"]')).not_to be_disabled
|
||||
end
|
||||
|
||||
it 'drops illegal fragments when using gumbo' do
|
||||
skip "libxml is less strict thatn Gumbo" unless Nokogiri.respond_to?(:HTML5)
|
||||
expect(Capybara.string("<td>1</td>")).not_to have_css('td')
|
||||
end
|
||||
|
||||
it 'can disable use of gumbo' do
|
||||
skip "Test doesn't make sense unlesss nokogumbo is loaded" unless Nokogiri.respond_to?(:HTML5)
|
||||
Capybara.allow_gumbo = false
|
||||
expect(Capybara.string("<td>1</td>")).to have_css('td')
|
||||
end
|
||||
|
||||
describe '#title' do
|
||||
it 'returns the page title' do
|
||||
expect(string.title).to eq('simple_node')
|
||||
|
|
Loading…
Reference in a new issue