Switching from nokogiri's hpricot mode to html mode and fixing bugs

This commit is contained in:
Bryan Helmkamp 2008-11-06 21:51:33 -05:00
parent eaa1c7fe25
commit a7b230304c
5 changed files with 10 additions and 10 deletions

View File

@ -1,4 +1,3 @@
Switch from Nokogiri::Hpricot to Nokogiri::HTML
Add tests for locator strategies
Use Webrat::Methods for Merb and Rails integration
Get file uploads workign with merb

View File

@ -111,7 +111,7 @@ module Webrat
end
unless id.blank?
@label_elements += @form.element / "label[@for=#{id}]"
@label_elements += @form.element.search("label[@for='#{id}']")
end
@label_elements
@ -311,8 +311,9 @@ module Webrat
protected
def default_value
selected_options = @element / "option[@selected='selected']"
selected_options = @element / "option:first" if selected_options.empty?
selected_options = @element / ".//option[@selected='selected']"
selected_options = @element / ".//option[position() = 1]" if selected_options.empty?
selected_options.map do |option|
return "" if option.nil?
option["value"] || option.inner_html
@ -324,7 +325,7 @@ module Webrat
end
def option_elements
(@element / "option")
(@element / ".//option")
end
end

View File

@ -39,7 +39,7 @@ module Webrat
def fields
return @fields if @fields
@fields = (@element / "button, input, textarea, select").collect do |field_element|
@fields = (@element.search(".//button", ".//input", ".//textarea", ".//select")).collect do |field_element|
Field.class_for_element(field_element).new(self, field_element)
end
end

View File

@ -139,7 +139,7 @@ module Webrat
alias_method :clicks_button, :click_button
def dom # :nodoc:
@dom ||= Nokogiri::Hpricot(scoped_html)
@dom ||= Nokogiri::HTML(scoped_html)
end
protected
@ -155,7 +155,7 @@ module Webrat
def scoped_html
@scoped_html ||= begin
if @selector
(Nokogiri::Hpricot(@html) / @selector).first.to_html
(Nokogiri::HTML(@html) / @selector).first.to_html
else
@html
end

View File

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