From 95e3260142eb3d3bd2d0ad30c096631a083aff63 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sat, 27 Dec 2008 19:45:31 -0500 Subject: [PATCH] Update requires to fix compatibility with Nokogiri 1.1.0 --- lib/webrat.rb | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/webrat.rb b/lib/webrat.rb index 926e8ae..d8b1abb 100644 --- a/lib/webrat.rb +++ b/lib/webrat.rb @@ -8,20 +8,27 @@ module Webrat def self.root #:nodoc: defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root end + + def self.require_xml + gem "nokogiri", ">= 1.1.0" + + if on_java? + # We need Nokogiri's CSS to XPath support, even if using REXML and Hpricot for parsing and searching + require "nokogiri/css" + require "hpricot" + require "rexml/document" + else + require "nokogiri" + require "webrat/core/nokogiri" + end + end + + def self.on_java? + RUBY_PLATFORM =~ /java/ + end end -# We need Nokogiri's CSS to XPath support, even if using REXML -require "nokogiri/css" - -# Require nokogiri and fall back on rexml -begin - require "nokogiri" - require "webrat/core/nokogiri" -rescue LoadError => e - require "rexml/document" - warn("Standard REXML library is slow. Please consider installing nokogiri.\nUse \"sudo gem install nokogiri\"") -end - +Webrat.require_xml require "webrat/core" # TODO: This is probably not a good idea.