Dropping support for Hpricot and REXML

This commit is contained in:
Bryan Helmkamp 2009-08-19 22:43:23 -04:00
parent 997ff97405
commit 11f30d1d2e
31 changed files with 156 additions and 355 deletions

View File

@ -1,5 +1,12 @@
== Git
REMOVED: Support for Hpricot + REXML as an alternative to Nokogiri.
Hpricot and REXML were difficult to work with, REXML is terribly slow,
and Nokogiri is recommended even by the author of Hpricot (_why). Now
that Nokogiri works on JRuby, Webrat is going to use it as it's sole
XML backend.
* Minor enhancements
* Update the Merb support to be based directly on Rack (Simon Rozet)

View File

@ -1,10 +1,10 @@
require "rack"
require "nokogiri"
module Webrat
# The common base class for all exceptions raised by Webrat.
class WebratError < StandardError
end
end
require "rack"
require "nokogiri"
require "webrat/core/xml/nokogiri"
require "webrat/core"

View File

@ -1,6 +1,5 @@
require "webrat/core/configuration"
require "webrat/core/xml"
require "webrat/core/xml/nokogiri"
require "webrat/core/logging"
require "webrat/core/elements/form"
require "webrat/core/scope"

View File

@ -16,13 +16,10 @@ module Webrat
# Webrat can be configured using the Webrat.configure method. For example:
#
# Webrat.configure do |config|
# config.parse_with_nokogiri = false
# config.mode = :sinatra
# end
class Configuration
# Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
attr_writer :parse_with_nokogiri
# Webrat's mode, set automatically when requiring webrat/rails, webrat/merb, etc.
attr_reader :mode # :nodoc:
@ -63,7 +60,6 @@ module Webrat
def initialize # :nodoc:
self.open_error_files = true
self.parse_with_nokogiri = true
self.application_environment = :test
self.application_port = 3001
self.application_address = 'localhost'
@ -74,10 +70,6 @@ module Webrat
self.selenium_browser_startup_timeout = 5
end
def parse_with_nokogiri? #:nodoc:
@parse_with_nokogiri ? true : false
end
def open_error_files? #:nodoc:
@open_error_files ? true : false
end

View File

@ -4,7 +4,7 @@ module Webrat
class Area < Element #:nodoc:
def self.xpath_search
".//area"
[".//area"]
end
def click(method = nil, options = {})
@ -14,7 +14,7 @@ module Webrat
protected
def href
Webrat::XML.attribute(@element, "href")
@element["href"]
end
def absolute_href

View File

@ -3,14 +3,14 @@ module Webrat
class Element # :nodoc:
def self.load_all(session, dom)
Webrat::XML.xpath_search(dom, xpath_search).map do |element|
dom.xpath(*xpath_search).map do |element|
load(session, element)
end
end
def self.load(session, element)
return nil if element.nil?
session.elements[Webrat::XML.xpath_to(element)] ||= self.new(session, element)
session.elements[element.path] ||= self.new(session, element)
end
attr_reader :element
@ -21,7 +21,7 @@ module Webrat
end
def path
Webrat::XML.xpath_to(@element)
@element.path
end
def inspect

View File

@ -32,7 +32,7 @@ module Webrat
def self.load(session, element)
return nil if element.nil?
session.elements[Webrat::XML.xpath_to(element)] ||= field_class(element).new(session, element)
session.elements[element.path] ||= field_class(element).new(session, element)
end
def self.field_class(element)
@ -41,7 +41,7 @@ module Webrat
when "select" then SelectField
when "textarea" then TextareaField
else
case Webrat::XML.attribute(element, "type")
case element["type"]
when "checkbox" then CheckboxField
when "hidden" then HiddenField
when "radio" then RadioField
@ -67,11 +67,11 @@ module Webrat
end
def id
Webrat::XML.attribute(@element, "id")
@element["id"]
end
def disabled?
@element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
@element.attributes.has_key?("disabled") && @element["disabled"] != 'false'
end
def raise_error_if_disabled
@ -128,7 +128,7 @@ module Webrat
end
def name
Webrat::XML.attribute(@element, "name")
@element["name"]
end
def escaped_value
@ -155,14 +155,14 @@ module Webrat
end
unless id.blank?
@label_elements += Webrat::XML.xpath_search(form.element, ".//label[@for = '#{id}']")
@label_elements += form.element.xpath(".//label[@for = '#{id}']")
end
@label_elements
end
def default_value
Webrat::XML.attribute(@element, "value")
@element["value"]
end
def replace_param_value(params, oval, nval)
@ -199,7 +199,7 @@ module Webrat
def click
raise_error_if_disabled
set(Webrat::XML.attribute(@element, "value")) unless Webrat::XML.attribute(@element, "name").blank?
set(@element["value"]) unless @element["name"].blank?
form.submit
end
@ -246,11 +246,11 @@ module Webrat
def check
raise_error_if_disabled
set(Webrat::XML.attribute(@element, "value") || "on")
set(@element["value"] || "on")
end
def checked?
Webrat::XML.attribute(@element, "checked") == "checked"
@element["checked"] == "checked"
end
def uncheck
@ -261,8 +261,8 @@ module Webrat
protected
def default_value
if Webrat::XML.attribute(@element, "checked") == "checked"
Webrat::XML.attribute(@element, "value") || "on"
if @element["checked"] == "checked"
@element["value"] || "on"
else
nil
end
@ -295,11 +295,11 @@ module Webrat
option.set(nil)
end
set(Webrat::XML.attribute(@element, "value") || "on")
set(@element["value"] || "on")
end
def checked?
Webrat::XML.attribute(@element, "checked") == "checked"
@element["checked"] == "checked"
end
protected
@ -309,8 +309,8 @@ module Webrat
end
def default_value
if Webrat::XML.attribute(@element, "checked") == "checked"
Webrat::XML.attribute(@element, "value") || "on"
if @element["checked"] == "checked"
@element["value"] || "on"
else
nil
end
@ -327,7 +327,7 @@ module Webrat
protected
def default_value
Webrat::XML.inner_html(@element)
@element.inner_html
end
end
@ -378,14 +378,14 @@ module Webrat
class ResetField < Field #:nodoc:
def self.xpath_search
".//input[@type = 'reset']"
[".//input[@type = 'reset']"]
end
end
class SelectField < Field #:nodoc:
def self.xpath_search
".//select"
[".//select"]
end
def options
@ -395,12 +395,12 @@ module Webrat
protected
def default_value
selected_options = Webrat::XML.xpath_search(@element, ".//option[@selected = 'selected']")
selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
selected_options = @element.xpath(".//option[@selected = 'selected']")
selected_options = @element.xpath(".//option[position() = 1]") if selected_options.empty?
selected_options.map do |option|
return "" if option.nil?
Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
option["value"] || option.inner_html
end.uniq
end

View File

@ -9,7 +9,7 @@ module Webrat
attr_reader :element
def self.xpath_search
".//form"
[".//form"]
end
def fields
@ -27,7 +27,7 @@ module Webrat
protected
def dom
Webrat::XML.xpath_at(@session.dom, path)
@session.dom.xpath(path).first
end
def fields_by_type(field_types)
@ -50,11 +50,11 @@ module Webrat
end
def form_method
Webrat::XML.attribute(@element, "method").blank? ? :get : Webrat::XML.attribute(@element, "method").downcase
@element["method"].blank? ? :get : @element["method"].downcase
end
def form_action
Webrat::XML.attribute(@element, "action").blank? ? @session.current_url : Webrat::XML.attribute(@element, "action")
@element["action"].blank? ? @session.current_url : @element["action"]
end
def merge(all_params, new_param)

View File

@ -6,11 +6,11 @@ module Webrat
attr_reader :element
def self.xpath_search
".//label"
[".//label"]
end
def for_id
Webrat::XML.attribute(@element, "for")
@element["for"]
end
def field
@ -21,9 +21,9 @@ module Webrat
def field_element
if for_id.blank?
Webrat::XML.xpath_at(@element, *Field.xpath_search_excluding_hidden)
@element.xpath(*Field.xpath_search_excluding_hidden).first
else
Webrat::XML.css_search(@session.current_dom, "#" + for_id).first
@session.current_dom.css("#" + for_id).first
end
end

View File

@ -7,7 +7,7 @@ module Webrat
class Link < Element #:nodoc:
def self.xpath_search
".//a[@href]"
[".//a[@href]"]
end
def click(options = {})
@ -26,7 +26,7 @@ module Webrat
protected
def id
Webrat::XML.attribute(@element, "id")
@element["id"]
end
def data
@ -34,11 +34,11 @@ module Webrat
end
def title
Webrat::XML.attribute(@element, "title")
@element["title"]
end
def href
Webrat::XML.attribute(@element, "href")
@element["href"]
end
def absolute_href
@ -58,7 +58,7 @@ module Webrat
end
def onclick
Webrat::XML.attribute(@element, "onclick")
@element["onclick"]
end
def http_method

View File

@ -4,7 +4,7 @@ module Webrat
class SelectOption < Element #:nodoc:
def self.xpath_search
".//option"
[".//option"]
end
def choose
@ -28,7 +28,7 @@ module Webrat
end
def value
Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
@element["value"] || @element.inner_html
end
end

View File

@ -13,7 +13,7 @@ module Webrat
module Locators
def field_by_xpath(xpath)
Field.load(@session, Webrat::XML.xpath_at(dom, xpath))
Field.load(@session, dom.xpath(xpath).first)
end
end

View File

@ -11,8 +11,8 @@ module Webrat
def area_element
area_elements.detect do |area_element|
Webrat::XML.attribute(area_element, "title") =~ matcher ||
Webrat::XML.attribute(area_element, "id") =~ matcher
area_element["title"] =~ matcher ||
area_element["id"] =~ matcher
end
end
@ -21,7 +21,7 @@ module Webrat
end
def area_elements
Webrat::XML.xpath_search(@dom, Area.xpath_search)
@dom.xpath(*Area.xpath_search)
end
def error_message

View File

@ -20,24 +20,24 @@ module Webrat
end
def matches_id?(element)
(@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") =~ @value) ||
(!@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") == @value.to_s)
(@value.is_a?(Regexp) && element["id"] =~ @value) ||
(!@value.is_a?(Regexp) && element["id"] == @value.to_s)
end
def matches_value?(element)
Webrat::XML.attribute(element, "value") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
element["value"] =~ /^\W*#{Regexp.escape(@value.to_s)}/i
end
def matches_html?(element)
Webrat::XML.inner_html(element) =~ /#{Regexp.escape(@value.to_s)}/i
element.inner_html =~ /#{Regexp.escape(@value.to_s)}/i
end
def matches_alt?(element)
Webrat::XML.attribute(element, "alt") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
element["alt"] =~ /^\W*#{Regexp.escape(@value.to_s)}/i
end
def button_elements
Webrat::XML.xpath_search(@dom, *ButtonField.xpath_search)
@dom.xpath(*ButtonField.xpath_search)
end
def error_message

View File

@ -12,15 +12,15 @@ module Webrat
def field_element
field_elements.detect do |field_element|
if @value.is_a?(Regexp)
Webrat::XML.attribute(field_element, "id") =~ @value
field_element["id"] =~ @value
else
Webrat::XML.attribute(field_element, "id") == @value.to_s
field_element["id"] == @value.to_s
end
end
end
def field_elements
Webrat::XML.xpath_search(@dom, *Field.xpath_search)
@dom.xpath(*Field.xpath_search)
end
def error_message

View File

@ -25,7 +25,7 @@ module Webrat
end
def label_elements
Webrat::XML.xpath_search(@dom, Label.xpath_search)
@dom.xpath(*Label.xpath_search)
end
def error_message
@ -33,7 +33,7 @@ module Webrat
end
def text(element)
str = Webrat::XML.all_inner_text(element)
str = element.inner_text
str.gsub!("\n","")
str.strip!
str.squeeze!(" ")

View File

@ -11,19 +11,19 @@ module Webrat
def field_element
field_elements.detect do |field_element|
Webrat::XML.attribute(field_element, "name") == @value.to_s
field_element["name"] == @value.to_s
end
end
def field_elements
Webrat::XML.xpath_search(@dom, *xpath_searches)
@dom.xpath(*xpath_searches)
end
def xpath_searches
if @field_types.any?
@field_types.map { |field_type| field_type.xpath_search }.flatten
else
Array(Field.xpath_search)
Field.xpath_search
end
end

View File

@ -10,7 +10,7 @@ module Webrat
end
def form_element
Webrat::XML.css_at(@dom, "#" + @value)
@dom.css("#" + @value).first
end
end

View File

@ -17,11 +17,11 @@ module Webrat
end
def label_elements
Webrat::XML.xpath_search(@dom, Label.xpath_search)
@dom.xpath(*Label.xpath_search)
end
def text(label_element)
str = Webrat::XML.all_inner_text(label_element)
str = label_element.inner_text
str.gsub!("\n","")
str.strip!
str.squeeze!(" ")

View File

@ -10,7 +10,7 @@ module Webrat
end
def link_element
matching_links.min { |a, b| Webrat::XML.all_inner_text(a).length <=> Webrat::XML.all_inner_text(b).length }
matching_links.min { |a, b| a.inner_text.length <=> b.inner_text.length }
end
def matching_links
@ -27,21 +27,21 @@ module Webrat
matcher = /#{Regexp.escape(@value.to_s)}/i
end
replace_nbsp(Webrat::XML.all_inner_text(link)) =~ matcher ||
replace_nbsp_ref(Webrat::XML.inner_html(link)) =~ matcher ||
Webrat::XML.attribute(link, "title")=~ matcher
replace_nbsp(link.inner_text) =~ matcher ||
replace_nbsp_ref(link.inner_html) =~ matcher ||
link["title"] =~ matcher
end
def matches_id?(link)
if @value.is_a?(Regexp)
(Webrat::XML.attribute(link, "id") =~ @value) ? true : false
link["id"] =~ @value ? true : false
else
(Webrat::XML.attribute(link, "id") == @value) ? true : false
link["id"] == @value ? true : false
end
end
def link_elements
Webrat::XML.xpath_search(@dom, *Link.xpath_search)
@dom.xpath(*Link.xpath_search)
end
def replace_nbsp(str)

View File

@ -19,17 +19,17 @@ module Webrat
field.options.detect do |o|
if @option_text.is_a?(Regexp)
Webrat::XML.inner_html(o.element) =~ @option_text
o.element.inner_html =~ @option_text
else
Webrat::XML.inner_html(o.element) == @option_text.to_s
o.element.inner_html == @option_text.to_s
end
end
else
option_element = option_elements.detect do |o|
if @option_text.is_a?(Regexp)
Webrat::XML.inner_html(o) =~ @option_text
o.inner_html =~ @option_text
else
Webrat::XML.inner_html(o) == @option_text.to_s
o.inner_html == @option_text.to_s
end
end
@ -38,7 +38,7 @@ module Webrat
end
def option_elements
Webrat::XML.xpath_search(@dom, *SelectOption.xpath_search)
@dom.xpath(*SelectOption.xpath_search)
end
def error_message

View File

@ -7,13 +7,8 @@ module Webrat
end
def matches?(stringlike)
if Webrat.configuration.parse_with_nokogiri?
@document = Webrat.nokogiri_document(stringlike)
else
@document = Webrat.hpricot_document(stringlike)
end
@element = Webrat::XML.inner_text(@document)
@document = Webrat::XML.document(stringlike)
@element = @document.inner_text
case @content
when String

View File

@ -1,5 +1,4 @@
require "webrat/core/xml/nokogiri"
require "webrat/core/xml/rexml"
require "webrat/core/xml"
module Webrat
module Matchers
@ -23,31 +22,7 @@ module Webrat
end
def matches(stringlike)
if Webrat.configuration.parse_with_nokogiri?
nokogiri_matches(stringlike)
else
rexml_matches(stringlike)
end
end
def rexml_matches(stringlike)
if REXML::Node === stringlike || Array === stringlike
@query = query.map { |q| q.gsub(%r'^//', './/') }
else
@query = query
end
add_options_conditions_to(@query)
@document = Webrat.rexml_document(stringlike)
@query.map do |q|
if @document.is_a?(Array)
@document.map { |d| REXML::XPath.match(d, q) }
else
REXML::XPath.match(@document, q)
end
end.flatten.compact
nokogiri_matches(stringlike)
end
def nokogiri_matches(stringlike)

View File

@ -312,12 +312,12 @@ module Webrat
dom = Webrat::XML.html_document(@response_body)
end
Webrat.define_dom_method(@response, dom)
Webrat::XML.define_dom_method(@response, dom)
return dom
end
def scoped_dom
Webrat::XML.css_at(@scope.dom, @selector)
@scope.dom.css(@selector).first
end
def locate_field(field_locator, *field_types) #:nodoc:

View File

@ -1,115 +1,78 @@
require "webrat/core/xml/nokogiri"
require "webrat/core/xml/hpricot"
require "webrat/core/xml/rexml"
require "webrat/core_extensions/meta_class"
module Webrat #:nodoc:
module XML #:nodoc:
def self.document(stringlike) #:nodoc:
if Webrat.configuration.parse_with_nokogiri?
Webrat.nokogiri_document(stringlike)
return stringlike.dom if stringlike.respond_to?(:dom)
if Nokogiri::HTML::Document === stringlike
stringlike
elsif Nokogiri::XML::NodeSet === stringlike
stringlike
elsif StringIO === stringlike
Nokogiri::HTML(stringlike.string)
elsif stringlike.respond_to?(:body)
Nokogiri::HTML(stringlike.body.to_s)
else
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
Nokogiri::HTML(stringlike.to_s)
end
end
def self.html_document(stringlike) #:nodoc:
if Webrat.configuration.parse_with_nokogiri?
Webrat.html_nokogiri_document(stringlike)
return stringlike.dom if stringlike.respond_to?(:dom)
if Nokogiri::HTML::Document === stringlike
stringlike
elsif Nokogiri::XML::NodeSet === stringlike
stringlike
elsif StringIO === stringlike
Nokogiri::HTML(stringlike.string)
elsif stringlike.respond_to?(:body)
Nokogiri::HTML(stringlike.body.to_s)
else
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
Nokogiri::HTML(stringlike.to_s)
end
end
def self.xml_document(stringlike) #:nodoc:
if Webrat.configuration.parse_with_nokogiri?
Webrat.xml_nokogiri_document(stringlike)
return stringlike.dom if stringlike.respond_to?(:dom)
if Nokogiri::HTML::Document === stringlike
stringlike
elsif Nokogiri::XML::NodeSet === stringlike
stringlike
elsif StringIO === stringlike
Nokogiri::XML(stringlike.string)
elsif stringlike.respond_to?(:body)
Nokogiri::XML(stringlike.body.to_s)
else
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
Nokogiri::XML(stringlike.to_s)
end
end
def self.to_html(element)
if Webrat.configuration.parse_with_nokogiri?
element.to_html
else
element.to_s
def self.define_dom_method(object, dom) #:nodoc:
object.meta_class.send(:define_method, :dom) do
dom
end
end
def self.inner_html(element)
if Webrat.configuration.parse_with_nokogiri?
element.inner_html
else
element.text
end
end
def self.all_inner_text(element)
if Webrat.configuration.parse_with_nokogiri?
element.inner_text
else
Hpricot(element.to_s).children.first.inner_text
end
end
def self.inner_text(element)
if Webrat.configuration.parse_with_nokogiri?
element.inner_text
else
if defined?(Hpricot::Doc) && element.is_a?(Hpricot::Doc)
element.inner_text
else
element.text
end
end
end
def self.xpath_to(element)
if Webrat.configuration.parse_with_nokogiri?
element.path
else
element.xpath
end
end
def self.attribute(element, attribute_name)
return element[attribute_name] if element.is_a?(Hash)
if Webrat.configuration.parse_with_nokogiri?
element[attribute_name]
else
element.attributes[attribute_name]
end
end
def self.xpath_at(*args)
xpath_search(*args).first
end
def self.css_at(*args)
css_search(*args).first
end
def self.xpath_search(element, *searches)
searches.flatten.map do |search|
if Webrat.configuration.parse_with_nokogiri?
element.xpath(search)
else
REXML::XPath.match(element, search)
end
end.flatten.compact
end
def self.css_search(element, *searches) #:nodoc:
xpath_search(element, css_to_xpath(*searches))
end
def self.css_to_xpath(*selectors)
selectors.map do |rule|
Nokogiri::CSS.xpath_for(rule, :prefix => ".//")
end.flatten.uniq
end
end
end
module Nokogiri #:nodoc:
module CSS #:nodoc:
class XPathVisitor #:nodoc:
def visit_pseudo_class_text(node) #:nodoc:
"@type='text'"
end
def visit_pseudo_class_password(node) #:nodoc:
"@type='password'"
end
end
end
end

View File

@ -1,19 +0,0 @@
module Webrat
def self.hpricot_document(stringlike)
return stringlike.dom if stringlike.respond_to?(:dom)
if Hpricot::Doc === stringlike
stringlike
elsif Hpricot::Elements === stringlike
stringlike
elsif StringIO === stringlike
Hpricot(stringlike.string)
elsif stringlike.respond_to?(:body)
Hpricot(stringlike.body.to_s)
else
Hpricot(stringlike.to_s)
end
end
end

View File

@ -1,76 +0,0 @@
require "webrat/core_extensions/meta_class"
module Webrat
def self.nokogiri_document(stringlike) #:nodoc:
return stringlike.dom if stringlike.respond_to?(:dom)
if Nokogiri::HTML::Document === stringlike
stringlike
elsif Nokogiri::XML::NodeSet === stringlike
stringlike
elsif StringIO === stringlike
Nokogiri::HTML(stringlike.string)
elsif stringlike.respond_to?(:body)
Nokogiri::HTML(stringlike.body.to_s)
else
Nokogiri::HTML(stringlike.to_s)
end
end
def self.html_nokogiri_document(stringlike) #:nodoc:
return stringlike.dom if stringlike.respond_to?(:dom)
if Nokogiri::HTML::Document === stringlike
stringlike
elsif Nokogiri::XML::NodeSet === stringlike
stringlike
elsif StringIO === stringlike
Nokogiri::HTML(stringlike.string)
elsif stringlike.respond_to?(:body)
Nokogiri::HTML(stringlike.body.to_s)
else
Nokogiri::HTML(stringlike.to_s)
end
end
def self.xml_nokogiri_document(stringlike) #:nodoc:
return stringlike.dom if stringlike.respond_to?(:dom)
if Nokogiri::HTML::Document === stringlike
stringlike
elsif Nokogiri::XML::NodeSet === stringlike
stringlike
elsif StringIO === stringlike
Nokogiri::XML(stringlike.string)
elsif stringlike.respond_to?(:body)
Nokogiri::XML(stringlike.body.to_s)
else
Nokogiri::XML(stringlike.to_s)
end
end
def self.define_dom_method(object, dom) #:nodoc:
object.meta_class.send(:define_method, :dom) do
dom
end
end
end
module Nokogiri #:nodoc:
module CSS #:nodoc:
class XPathVisitor #:nodoc:
def visit_pseudo_class_text(node) #:nodoc:
"@type='text'"
end
def visit_pseudo_class_password(node) #:nodoc:
"@type='password'"
end
end
end
end

View File

@ -1,24 +0,0 @@
module Webrat
def self.rexml_document(stringlike)
stringlike = stringlike.body.to_s if stringlike.respond_to?(:body)
case stringlike
when REXML::Document
stringlike.root
when REXML::Node, Array
stringlike
else
begin
REXML::Document.new(stringlike.to_s).root
rescue REXML::ParseException => e
if e.message.include?("second root element")
REXML::Document.new("<fake-root-element>#{stringlike}</fake-root-element>").root
else
raise e
end
end
end
end
end

View File

@ -1,28 +1,17 @@
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
describe Webrat::Configuration do
Spec::Matchers.define :parse_with_nokogiri do
match do |config|
config.parse_with_nokogiri?
end
end
Spec::Matchers.define :open_error_files do
match do |config|
config.open_error_files?
end
end
it "should have a mode" do
Webrat.configuration.should respond_to(:mode)
end
it "should use Nokogiri as the parser by default" do
config = Webrat::Configuration.new
config.should parse_with_nokogiri
end
it "should open error files by default" do
config = Webrat::Configuration.new
config.should open_error_files

View File

@ -10,7 +10,7 @@ module Webrat
</html>
HTML
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
element = Webrat::XML.document(html).css("input").first
checkbox = CheckboxField.new(nil, element)
checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
end
@ -25,7 +25,7 @@ module Webrat
</html>
HTML
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
element = Webrat::XML.document(html).css("input").first
checkbox = CheckboxField.new(nil, element)
checkbox.should be_checked
end
@ -37,7 +37,7 @@ module Webrat
</html>
HTML
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
element = Webrat::XML.document(html).css("input").first
checkbox = CheckboxField.new(nil, element)
checkbox.should_not be_checked
end
@ -51,7 +51,7 @@ module Webrat
</html>
HTML
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
element = Webrat::XML.document(html).css("input").first
radio_button = RadioField.new(nil, element)
radio_button.should be_checked
end
@ -61,7 +61,7 @@ module Webrat
<html><input type='radio' /></html>
HTML
element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
element = Webrat::XML.document(html).css("input").first
radio_button = RadioField.new(nil, element)
radio_button.should_not be_checked
end
@ -77,7 +77,7 @@ module Webrat
</html>
HTML
element = Webrat::XML.css_search(Webrat::XML.document(html), 'input').first
element = Webrat::XML.document(html).css('input').first
text_field = TextField.new(nil, element)
text_field.to_param.should == { 'email' => 'user@example.com' }
end

View File

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
# if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
describe "Nokogiri Extension" do
include Webrat::Matchers
@ -74,4 +74,4 @@ if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
end
end
end
end
# end