Sha256: 71ae04b0eb855570a6f64edaf174e2d28cb4fdef42d24542989cad6922a8ef1a

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

require "lib/roxml"
require 'active_support/test_case'
require 'test/mocks/mocks'
require 'test/mocks/dictionaries'

def fixture(name)
  File.read(fixture_path(name))
end

def xml_fixture(name)
  ROXML::XML::Parser.parse_file(fixture_path(name)).root
end

def fixture_path(name)
  "test/fixtures/#{name}.xml"
end

def to_xml_test(*names)
  names = names.first if names.one? && 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::Parser.parse(xml).root if xml.is_a?(String)
  return unless xml.respond_to? :children
  xml.children.each do |child|
    if child.to_s.blank?
      child.remove!
    else
      remove_children(child)
    end
  end
  xml
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
Empact-roxml-2.5.2 test/test_helper.rb
Empact-roxml-2.5.3 test/test_helper.rb
doxo-roxml-2.5.3 test/test_helper.rb
roxml-2.5.2 test/test_helper.rb
roxml-2.5.3 test/test_helper.rb