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,17 +10,14 @@ 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
|
||||
require "nokogiri"
|
||||
require "webrat/core/xml/nokogiri"
|
||||
gem "nokogiri", ">= 1.0.6"
|
||||
end
|
||||
|
||||
require "nokogiri"
|
||||
require "webrat/core/xml/nokogiri"
|
||||
end
|
||||
|
||||
def self.on_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,16 +2,18 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
|||
|
||||
module Webrat
|
||||
describe Field do
|
||||
it "should have nice inspect output" do
|
||||
html = <<-HTML
|
||||
<html>
|
||||
<input type='checkbox' checked='checked' />
|
||||
</html>
|
||||
HTML
|
||||
unless Webrat.on_java?
|
||||
it "should have nice inspect output" do
|
||||
html = <<-HTML
|
||||
<html>
|
||||
<input type='checkbox' checked='checked' />
|
||||
</html>
|
||||
HTML
|
||||
|
||||
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
||||
checkbox = CheckboxField.new(nil, element)
|
||||
checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
|
||||
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
|
||||
checkbox = CheckboxField.new(nil, element)
|
||||
checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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