Switching from Hpricot to Nokogiri

This commit is contained in:
Bryan Helmkamp 2008-11-06 17:53:41 -05:00
parent 006a70c0c5
commit 5510a6a61d
9 changed files with 15 additions and 23 deletions

View File

@ -78,13 +78,6 @@ In your stories/helper.rb:
You could also unpack the gem into vendor/plugins. You could also unpack the gem into vendor/plugins.
=== Requirements
- Rails >= 1.2.6
- Hpricot >= 0.6
- Rails integration tests in Test::Unit _or_
- Cucumber
=== Authors === Authors
- Maintained by [Bryan Helmkamp](mailto:bryan@brynary.com) - Maintained by [Bryan Helmkamp](mailto:bryan@brynary.com)

View File

@ -27,7 +27,6 @@ spec = Gem::Specification.new do |s|
s.extra_rdoc_files = %w(README.txt MIT-LICENSE.txt) s.extra_rdoc_files = %w(README.txt MIT-LICENSE.txt)
# Dependencies # Dependencies
s.add_dependency "hpricot", ">= 0.6"
s.add_dependency "nokogiri", ">= 1.0.3" s.add_dependency "nokogiri", ">= 1.0.3"
end end

View File

@ -67,7 +67,7 @@ module Webrat
elsif defined?(ActionController::AbstractRequest) elsif defined?(ActionController::AbstractRequest)
ActionController::AbstractRequest.parse_query_parameters(key_and_value) ActionController::AbstractRequest.parse_query_parameters(key_and_value)
else else
Merb::Parse.query(key_and_value) ::Merb::Parse.query(key_and_value)
end end
end end
@ -141,7 +141,7 @@ module Webrat
class ButtonField < Field class ButtonField < Field
def matches_text?(text) def matches_text?(text)
@element.innerHTML =~ /#{Regexp.escape(text.to_s)}/i @element.inner_html =~ /#{Regexp.escape(text.to_s)}/i
end end
def matches_value?(value) def matches_value?(value)
@ -315,7 +315,7 @@ module Webrat
selected_options = @element / "option:first" if selected_options.empty? selected_options = @element / "option:first" if selected_options.empty?
selected_options.map do |option| selected_options.map do |option|
return "" if option.nil? return "" if option.nil?
option["value"] || option.innerHTML option["value"] || option.inner_html
end end
end end

View File

@ -11,7 +11,7 @@ module Webrat
end end
def text def text
@element.innerText @element.inner_text
end end
end end

View File

@ -22,7 +22,7 @@ module Webrat
end end
def matches_text?(link_text) def matches_text?(link_text)
html = text.gsub('&nbsp;',' ') html = text.gsub('&#xA0;',' ')
if link_text.is_a?(Regexp) if link_text.is_a?(Regexp)
matcher = link_text matcher = link_text
@ -34,7 +34,7 @@ module Webrat
end end
def text def text
@element.innerHTML @element.inner_html
end end
protected protected

View File

@ -1,4 +1,4 @@
require "hpricot" require "nokogiri"
require "webrat/core/form" require "webrat/core/form"
require "webrat/core/locators" require "webrat/core/locators"
@ -139,7 +139,7 @@ module Webrat
alias_method :clicks_button, :click_button alias_method :clicks_button, :click_button
def dom # :nodoc: def dom # :nodoc:
@dom ||= Hpricot(scoped_html) @dom ||= Nokogiri::Hpricot(scoped_html)
end end
protected protected
@ -155,7 +155,7 @@ module Webrat
def scoped_html def scoped_html
@scoped_html ||= begin @scoped_html ||= begin
if @selector if @selector
(Hpricot(@html) / @selector).first.to_html (Nokogiri::Hpricot(@html) / @selector).first.to_html
else else
@html @html
end end

View File

@ -8,9 +8,9 @@ module Webrat
def matches_text?(text) def matches_text?(text)
if text.is_a?(Regexp) if text.is_a?(Regexp)
@element.innerHTML =~ text @element.inner_html =~ text
else else
@element.innerHTML == text.to_s @element.inner_html == text.to_s
end end
end end
@ -22,7 +22,7 @@ module Webrat
protected protected
def value def value
@element["value"] || @element.innerHTML @element["value"] || @element.inner_html
end end
end end

View File

@ -3,12 +3,12 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
module Webrat module Webrat
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
checkbox = CheckboxField.new(nil, (Hpricot("<input type='checkbox' checked='checked'>")/'input').first) checkbox = CheckboxField.new(nil, (Nokogiri::Hpricot("<input type='checkbox' checked='checked'>")/'input').first)
checkbox.should be_checked checkbox.should be_checked
end end
it "should say it is not checked if it is not" do it "should say it is not checked if it is not" do
checkbox = CheckboxField.new(nil, (Hpricot("<input type='checkbox'>")/'input').first) checkbox = CheckboxField.new(nil, (Nokogiri::Hpricot("<input type='checkbox'>")/'input').first)
checkbox.should_not be_checked checkbox.should_not be_checked
end end
end end

View File

@ -14,7 +14,7 @@ describe Webrat::Session do
"<html></html>" "<html></html>"
end end
session.current_dom.should be_an_instance_of(Hpricot::Doc) session.current_dom.should be_an_instance_of(Nokogiri::HTML::Document)
end end
it "should open the page in the browser" do it "should open the page in the browser" do