Skip to content

Commit

Permalink
Added XML::Mixin#xml_open (closes #14).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Oct 13, 2023
1 parent 7e2ea9a commit 6fbd4fa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/ronin/support/web/xml/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,35 @@ def xml_parse(xml,&block)
XML.parse(xml,&block)
end

#
# Opens an XML file.
#
# @param [String] path
# The path to the XML file.
#
# @yield [doc]
# If a block is given, it will be passed the newly created document
# object.
#
# @yieldparam [Nokogiri::XML::Document] doc
# The new XML document object.
#
# @return [Nokogiri::XML::Document]
# The parsed XML file.
#
# @example
# doc = XML.open('index.xml')
# # => #<Nokogiri::XML::Document:...>
#
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/XML/Document
# @see XML.open
#
def xml_open(path,&block)
XML.open(path,&block)
end

alias open_xml xml_open

#
# Creates a new `Nokogiri::XML::Builder`.
#
Expand Down
17 changes: 17 additions & 0 deletions spec/xml/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@
end
end

describe ".open" do
it "must open and parse the given path, and return a Nokogiri::XML::Document" do
doc = subject.xml_open(xml_file)

expect(doc).to be_kind_of(Nokogiri::XML::Document)
expect(doc.to_s).to eq(xml)
end

context "when given a block" do
it "must yield the Nokogiri::XML::Document object" do
expect { |b|
subject.xml_open(xml_file,&b)
}.to yield_with_args(Nokogiri::XML::Document)
end
end
end

describe "#xml_build" do
it "must build an XML document" do
doc = subject.xml_build do |xml|
Expand Down

0 comments on commit 6fbd4fa

Please sign in to comment.