Skip to content

Instantly share code, notes, and snippets.

@ashmoran
Created October 21, 2009 13:07
Show Gist options
  • Save ashmoran/215089 to your computer and use it in GitHub Desktop.
Save ashmoran/215089 to your computer and use it in GitHub Desktop.
require 'rexml/document'
require 'rexml/formatters/transitive'
require 'rexml/formatters/pretty'
Spec::Matchers.define :be_equivalent_xml_to do |expected_xml|
match do |target_xml|
@expected_xml = expected_xml
formatter = REXML::Formatters::Pretty.new
formatted_target_xml, formatted_expected_xml = "", ""
formatter.write(REXML::Document.new(target_xml), formatted_target_xml)
formatter.write(REXML::Document.new(@expected_xml), formatted_expected_xml)
formatted_target_xml.strip!
formatted_expected_xml.strip!
formatted_target_xml == formatted_expected_xml
end
failure_message_for_should do |target_xml|
"Expected the XML\n" +
"=====\n" +
target_xml + "\n" +
"=====\n" +
"to be equivalent to\n" +
"=====\n" +
@expected_xml + "\n" +
"=====\n" +
"but it wasn't."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment