Skip to content

Commit

Permalink
test: Nokogumbo's contract expectations
Browse files Browse the repository at this point in the history
See rubys/nokogumbo#171 which introduced
forward-looking behavior to integrate with a future Nokogiri::HTML5
after the Nokogumbo merger.

These tests, which are failing right now, will drive much of the rest
of the integration work.
  • Loading branch information
flavorjones committed Apr 28, 2021
1 parent 28b2eb1 commit 941a8b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/nokogiri/version/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ def self.uses_libxml?(requirement = nil) # :nodoc:
Gem::Requirement.new(requirement).satisfied_by?(VersionInfo.instance.loaded_libxml_version)
end

def self.uses_gumbo?
uses_libxml? # TODO: replace with Gumbo functionality
end

def self.jruby? # :nodoc:
VersionInfo.instance.jruby?
end
Expand Down
26 changes: 26 additions & 0 deletions test/test_nokogumbo_contract.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "helper"

describe "Nokogumbo contract expectations" do
# per https://github.com/rubys/nokogumbo/pull/171
it "includes the HTML5 public interface" do
skip("Gumbo is not supported on this platform") unless Nokogiri.uses_gumbo?

assert_includes(::Nokogiri.singleton_methods, :HTML5)

assert_equal(defined?(::Nokogiri::HTML5), "constant")
assert_includes(::Nokogiri::HTML5.singleton_methods, :parse)
assert_includes(::Nokogiri::HTML5.singleton_methods, :fragment)

assert_equal(defined?(::Nokogiri::HTML5::Node), "constant")
assert_equal(defined?(::Nokogiri::HTML5::Document), "constant")
assert_equal(defined?(::Nokogiri::HTML5::DocumentFragment), "constant")
end

it "includes a replacement for the Nokogumbo private interface" do
skip("Gumbo is not supported on this platform") unless Nokogiri.uses_gumbo?

assert_equal(defined?(::Nokogiri::Gumbo), "constant")
assert_includes(::Nokogiri::Gumbo.singleton_methods, :parse)
assert_includes(::Nokogiri::Gumbo.singleton_methods, :fragment)
end
end

0 comments on commit 941a8b0

Please sign in to comment.