Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Switching from nokogiri's hpricot mode to html mode and fixing bugs
  • Loading branch information
brynary committed Nov 7, 2008
1 parent eaa1c7f commit a7b2303
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion TODO.txt
@@ -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
Expand Down
9 changes: 5 additions & 4 deletions lib/webrat/core/field.rb
Expand Up @@ -111,7 +111,7 @@ def label_elements
end

unless id.blank?
@label_elements += @form.element / "label[@for=#{id}]"
@label_elements += @form.element.search("label[@for='#{id}']")
end

@label_elements
Expand Down Expand Up @@ -311,8 +311,9 @@ def find_option(text)
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
Expand All @@ -324,7 +325,7 @@ def options
end

def option_elements
(@element / "option")
(@element / ".//option")
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/webrat/core/form.rb
Expand Up @@ -39,7 +39,7 @@ def find_button(value = nil)
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
Expand Down
4 changes: 2 additions & 2 deletions lib/webrat/core/scope.rb
Expand Up @@ -139,7 +139,7 @@ def click_button(value = nil)
alias_method :clicks_button, :click_button

def dom # :nodoc:
@dom ||= Nokogiri::Hpricot(scoped_html)
@dom ||= Nokogiri::HTML(scoped_html)
end

protected
Expand All @@ -155,7 +155,7 @@ def locate_field(field_locator, *field_types)
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
Expand Down
4 changes: 2 additions & 2 deletions spec/webrat/core/field_spec.rb
Expand Up @@ -3,12 +3,12 @@
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
Expand Down

0 comments on commit a7b2303

Please sign in to comment.