Project

nokofuzzi

0.0
No commit activity in last 3 years
No release in over 3 years
Monkey patches on Nokogiri::XML::Document for manipulation of documents for tests
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 3.0

Runtime

< 1.9, >= 1.6
 Project Readme

nokofuzzi

Fuzz testing iterators and extensions for Nokogiri

Installation

Add this to your Gemfile (in the test group) and run bundle install:

gem 'nokofuzzi'

Usage

I have larger plans for methods to attach to the Nokogiri document, but for now there are two:

each_missing

each_missing sets up an "each" iterator that sends you the string xml that was removed, and the new xml string (both from Nokogiri::XML)

existing_xml = Nokogiri::XML('/path/to/xml')

existing_xml.each_missing do |removed_xml, new_xml|
  puts "String representation of the xml removed: #{removed_xml}"
  puts "String representation of the modified xml #{new_xml}"
end

without_xpath

without_xpath creates a duplicate of the receiver with all matches for the given xpath removed.

modified_xml = Nokogiri::XML('<a><b></b><c><b></b></c></a>').without_xpath('//b')

puts modified_xml.to_xml # <?xml version="1.0"?><a><c/></a>

set_text_at_xpath(xpath, text)

set_text_at_xpath replaces the text for a node (as well as contents below that node)

modified_xml = Nokogiri::XML('<a><b></b><c><b></b></c></a>').set_text_at_xpath('//c', "HI")

puts modified_xml.to_xml # <?xml version="1.0"?><a><b/><c>HI</c></a>

fuzz_at_xpath(xpath)

fuzz_at_xpath passes each node matching the xpath to a given block which contains the operations to perform on the node

modified_xml = Nokogiri::XML('<a><b>HI</b><c><b>HI</b></c></a>').fuzz_at_xpath do |node|
  node.content = "-- #{node.text} --"
end

puts modified_xml.to_xml # <?xml version="1.0"?><a><b>-- HI --</b><c><b>-- HI --</b></c></a>