From f1b4486594311d1daaef4c9038657d7d28c18386 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Wed, 19 Nov 2008 15:52:56 -0500 Subject: [PATCH] Moving requiring of Nokogiri/Hpricot/REXML to a method --- lib/webrat.rb | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/webrat.rb b/lib/webrat.rb index 4060933..39ef24a 100644 --- a/lib/webrat.rb +++ b/lib/webrat.rb @@ -12,22 +12,28 @@ module Webrat defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root end + def self.require_xml + 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 -if RUBY_PLATFORM =~ /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 +Webrat.require_xml require "webrat/core" # TODO: This is probably not a good idea. # Probably better for webrat users to require "webrat/rails" etc. directly -if defined?(RAILS_ENV) - require "webrat/rails" -end +require "webrat/rails" if defined?(RAILS_ENV)