Sha256: 0a627a9340164fe9ae6f9003fa4d0d215ffe4429a4060608d3b6019b954474d3

Contents?: true

Size: 991 Bytes

Versions: 7

Compression:

Stored size: 991 Bytes

Contents

require "lib/roxml"
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, dict.to_xml
    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

7 entries across 7 versions & 2 rubygems

Version Path
Empact-roxml-2.4.1 test/test_helper.rb
Empact-roxml-2.4.2 test/test_helper.rb
Empact-roxml-2.4.3 test/test_helper.rb
roxml-2.4.1 test/test_helper.rb
roxml-2.5.0 test/test_helper.rb
roxml-2.4.2 test/test_helper.rb
roxml-2.4.3 test/test_helper.rb