Use Nokogiri on JRuby -- ~2x faster than REXML on JRuby for me
This commit is contained in:
parent
b5254109f1
commit
35cbfd9643
@ -1,5 +1,9 @@
|
||||
== brynary/master (in git)
|
||||
|
||||
* Major enhancements
|
||||
|
||||
* Improve performance (~2x) on JRuby by supporting Nokogiri
|
||||
|
||||
* Minor enhancements
|
||||
|
||||
* Added support for field_labeled_locators ending in non word characters
|
||||
|
@ -10,18 +10,15 @@ module Webrat
|
||||
VERSION = '0.4.4'
|
||||
|
||||
def self.require_xml
|
||||
gem "nokogiri", ">= 1.0.6"
|
||||
|
||||
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"
|
||||
gem "nokogiri", ">= 1.2.4"
|
||||
else
|
||||
gem "nokogiri", ">= 1.0.6"
|
||||
end
|
||||
|
||||
require "nokogiri"
|
||||
require "webrat/core/xml/nokogiri"
|
||||
end
|
||||
end
|
||||
|
||||
def self.on_java?
|
||||
RUBY_PLATFORM =~ /java/
|
||||
|
@ -60,7 +60,7 @@ module Webrat
|
||||
|
||||
def initialize # :nodoc:
|
||||
self.open_error_files = true
|
||||
self.parse_with_nokogiri = !Webrat.on_java?
|
||||
self.parse_with_nokogiri = true
|
||||
self.application_environment = :test
|
||||
self.application_port = 3001
|
||||
self.application_address = 'localhost'
|
||||
|
@ -13,7 +13,10 @@ module Webrat
|
||||
when :merb
|
||||
Merb.logger
|
||||
else
|
||||
nil
|
||||
@logger ||= begin
|
||||
require "logger"
|
||||
::Logger.new("webrat.log")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -209,8 +209,8 @@ module Webrat
|
||||
# along with the form. An optional <tt>content_type</tt> may be given.
|
||||
#
|
||||
# Example:
|
||||
# attaches_file "Resume", "/path/to/the/resume.txt"
|
||||
# attaches_file "Photo", "/path/to/the/image.png", "image/png"
|
||||
# attach_file "Resume", "/path/to/the/resume.txt"
|
||||
# attach_file "Photo", "/path/to/the/image.png", "image/png"
|
||||
def attach_file(field_locator, path, content_type = nil)
|
||||
locate_field(field_locator, FileField).set(path, content_type)
|
||||
end
|
||||
|
@ -9,17 +9,10 @@ describe Webrat::Configuration do
|
||||
end
|
||||
|
||||
it "should use Nokogiri as the parser by default" do
|
||||
Webrat.stub!(:on_java? => false)
|
||||
config = Webrat::Configuration.new
|
||||
config.should parse_with_nokogiri
|
||||
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
|
||||
config = Webrat::Configuration.new
|
||||
config.should open_error_files
|
||||
|
@ -2,6 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
||||
|
||||
module Webrat
|
||||
describe Field do
|
||||
unless Webrat.on_java?
|
||||
it "should have nice inspect output" do
|
||||
html = <<-HTML
|
||||
<html>
|
||||
@ -14,6 +15,7 @@ module Webrat
|
||||
checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe CheckboxField do
|
||||
it "should say it is checked if it is" do
|
||||
|
@ -331,7 +331,7 @@ describe "click_button" do
|
||||
end
|
||||
|
||||
it "should properly handle HTML entities in textarea default values" do
|
||||
spec = lambda do
|
||||
pending "needs bug fix" do
|
||||
with_html <<-HTML
|
||||
<html>
|
||||
<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"})
|
||||
click_button
|
||||
end
|
||||
|
||||
if Webrat.on_java?
|
||||
spec.call
|
||||
else
|
||||
pending("needs bug fix", &spec)
|
||||
end
|
||||
end
|
||||
|
||||
it "should send default selected option value from select" do
|
||||
|
@ -201,7 +201,7 @@ describe "select" do
|
||||
end
|
||||
|
||||
it "should properly handle submitting HTML entities in select values" do
|
||||
spec = lambda do
|
||||
pending "needs bug fix" do
|
||||
with_html <<-HTML
|
||||
<html>
|
||||
<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")
|
||||
click_button
|
||||
end
|
||||
|
||||
if Webrat.on_java?
|
||||
spec.call
|
||||
else
|
||||
pending("needs bug fix", &spec)
|
||||
end
|
||||
end
|
||||
|
||||
it "should properly handle locating with HTML entities in select values" do
|
||||
spec = lambda do
|
||||
pending "needs bug fix" do
|
||||
with_html <<-HTML
|
||||
<html>
|
||||
<form method="post" action="/login">
|
||||
@ -236,12 +230,6 @@ describe "select" do
|
||||
select "Peanut butter & jelly"
|
||||
}.should_not raise_error(Webrat::NotFoundError)
|
||||
end
|
||||
|
||||
if Webrat.on_java?
|
||||
spec.call
|
||||
else
|
||||
pending("needs bug fix", &spec)
|
||||
end
|
||||
end
|
||||
|
||||
it "should submit duplicates selected options as a single value" do
|
||||
|
Loading…
Reference in New Issue
Block a user