Sha256: 728cc5cbe6b7056eb6c66641db8db03ff12a0d339fd78d164e423cece1226dc6

Contents?: true

Size: 894 Bytes

Versions: 4

Compression:

Stored size: 894 Bytes

Contents

require 'rubygems'
require_relative './mocks/mocks'
require_relative './mocks/dictionaries'
require_relative './support/fixtures'

def to_xml_test(*names)
  names = names.first if names.size == 1 && names.first.is_a?(Hash)
  names.each do |name, xml_name|
    xml_name ||= name

    define_method "test_#{name}" do
      klass = name.is_a?(Symbol) ? name.to_s.camelize.constantize : name
      xml = xml_name.is_a?(Symbol) ? xml_fixture(xml_name) : xml_name

      dict = klass.from_xml(xml)
      xml = remove_children(xml)
      assert_equal xml.to_s, dict.to_xml.to_s
    end
  end
end

def remove_children(xml)
  xml = ROXML::XML.parse_string(xml).root if xml.is_a?(String)
  return unless xml.respond_to? :children
  xml.children.each do |child|
    if child.to_s.blank?
      defined?(Nokogiri) ? child.remove : child.remove!
    else
      remove_children(child)
    end
  end
  xml
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roxml-4.2.0 test/test_helper.rb
roxml-4.1.1 test/test_helper.rb
roxml-4.1.0 test/test_helper.rb
roxml-4.0.0 test/test_helper.rb