Use Nokogiri on JRuby -- ~2x faster than REXML on JRuby for me

This commit is contained in:
Bryan Helmkamp 2009-05-11 00:11:01 -04:00
parent b5254109f1
commit 35cbfd9643
9 changed files with 30 additions and 49 deletions

View File

@ -1,5 +1,9 @@
== brynary/master (in git) == brynary/master (in git)
* Major enhancements
* Improve performance (~2x) on JRuby by supporting Nokogiri
* Minor enhancements * Minor enhancements
* Added support for field_labeled_locators ending in non word characters * Added support for field_labeled_locators ending in non word characters

View File

@ -10,18 +10,15 @@ module Webrat
VERSION = '0.4.4' VERSION = '0.4.4'
def self.require_xml def self.require_xml
gem "nokogiri", ">= 1.0.6"
if on_java? if on_java?
# We need Nokogiri's CSS to XPath support, even if using REXML and Hpricot for parsing and searching gem "nokogiri", ">= 1.2.4"
require "nokogiri/css"
require "hpricot"
require "rexml/document"
else else
gem "nokogiri", ">= 1.0.6"
end
require "nokogiri" require "nokogiri"
require "webrat/core/xml/nokogiri" require "webrat/core/xml/nokogiri"
end end
end
def self.on_java? def self.on_java?
RUBY_PLATFORM =~ /java/ RUBY_PLATFORM =~ /java/

View File

@ -60,7 +60,7 @@ module Webrat
def initialize # :nodoc: def initialize # :nodoc:
self.open_error_files = true self.open_error_files = true
self.parse_with_nokogiri = !Webrat.on_java? self.parse_with_nokogiri = true
self.application_environment = :test self.application_environment = :test
self.application_port = 3001 self.application_port = 3001
self.application_address = 'localhost' self.application_address = 'localhost'

View File

@ -13,7 +13,10 @@ module Webrat
when :merb when :merb
Merb.logger Merb.logger
else else
nil @logger ||= begin
require "logger"
::Logger.new("webrat.log")
end
end end
end end

View File

@ -209,8 +209,8 @@ module Webrat
# along with the form. An optional <tt>content_type</tt> may be given. # along with the form. An optional <tt>content_type</tt> may be given.
# #
# Example: # Example:
# attaches_file "Resume", "/path/to/the/resume.txt" # attach_file "Resume", "/path/to/the/resume.txt"
# attaches_file "Photo", "/path/to/the/image.png", "image/png" # attach_file "Photo", "/path/to/the/image.png", "image/png"
def attach_file(field_locator, path, content_type = nil) def attach_file(field_locator, path, content_type = nil)
locate_field(field_locator, FileField).set(path, content_type) locate_field(field_locator, FileField).set(path, content_type)
end end

View File

@ -9,17 +9,10 @@ describe Webrat::Configuration do
end end
it "should use Nokogiri as the parser by default" do it "should use Nokogiri as the parser by default" do
Webrat.stub!(:on_java? => false)
config = Webrat::Configuration.new config = Webrat::Configuration.new
config.should parse_with_nokogiri config.should parse_with_nokogiri
end end
it "should not use Nokogiri as the parser when on JRuby" do
Webrat.stub!(:on_java? => true)
config = Webrat::Configuration.new
config.should_not parse_with_nokogiri
end
it "should open error files by default" do it "should open error files by default" do
config = Webrat::Configuration.new config = Webrat::Configuration.new
config.should open_error_files config.should open_error_files

View File

@ -2,6 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
module Webrat module Webrat
describe Field do describe Field do
unless Webrat.on_java?
it "should have nice inspect output" do it "should have nice inspect output" do
html = <<-HTML html = <<-HTML
<html> <html>
@ -14,6 +15,7 @@ module Webrat
checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/ checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
end end
end end
end
describe CheckboxField do describe CheckboxField do
it "should say it is checked if it is" do it "should say it is checked if it is" do

View File

@ -331,7 +331,7 @@ describe "click_button" do
end end
it "should properly handle HTML entities in textarea default values" do it "should properly handle HTML entities in textarea default values" do
spec = lambda do pending "needs bug fix" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<form method="post" action="/posts"> <form method="post" action="/posts">
@ -343,12 +343,6 @@ describe "click_button" do
webrat_session.should_receive(:post).with("http://www.example.com/posts", "post" => {"body" => "Peanut butter & jelly"}) webrat_session.should_receive(:post).with("http://www.example.com/posts", "post" => {"body" => "Peanut butter & jelly"})
click_button click_button
end end
if Webrat.on_java?
spec.call
else
pending("needs bug fix", &spec)
end
end end
it "should send default selected option value from select" do it "should send default selected option value from select" do

View File

@ -201,7 +201,7 @@ describe "select" do
end end
it "should properly handle submitting HTML entities in select values" do it "should properly handle submitting HTML entities in select values" do
spec = lambda do pending "needs bug fix" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<form method="post" action="/login"> <form method="post" action="/login">
@ -213,16 +213,10 @@ describe "select" do
webrat_session.should_receive(:post).with("http://www.example.com/login", "month" => "Peanut butter & jelly") webrat_session.should_receive(:post).with("http://www.example.com/login", "month" => "Peanut butter & jelly")
click_button click_button
end end
if Webrat.on_java?
spec.call
else
pending("needs bug fix", &spec)
end
end end
it "should properly handle locating with HTML entities in select values" do it "should properly handle locating with HTML entities in select values" do
spec = lambda do pending "needs bug fix" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<form method="post" action="/login"> <form method="post" action="/login">
@ -236,12 +230,6 @@ describe "select" do
select "Peanut butter & jelly" select "Peanut butter & jelly"
}.should_not raise_error(Webrat::NotFoundError) }.should_not raise_error(Webrat::NotFoundError)
end end
if Webrat.on_java?
spec.call
else
pending("needs bug fix", &spec)
end
end end
it "should submit duplicates selected options as a single value" do it "should submit duplicates selected options as a single value" do