Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracting some rexml code into a module
- Loading branch information
Showing
3 changed files
with
33 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require "nokogiri" | ||
require "webrat/core/form" | ||
require "webrat/core/locators" | ||
|
||
|