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