Sha256: c0cea2791f64ee1b38d13b941785f1c70f9783924a0f255b4dac6c5fc4ba3cd7

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

# -*- coding: utf-8 -*-
require 'test/unit'
require File.join(File.dirname(__FILE__), "..", "lib", "apricoteatsgorilla")

class HashToXmlTest < Test::Unit::TestCase

  def setup
    ApricotEatsGorilla.sort_keys = true
  end

  def test_dead_simple
    hash = { "dude" => "likes beer" }
    expected = "<dude>likes beer</dude>"

    result = ApricotEatsGorilla.hash_to_xml(hash)
    assert_equal expected, result
  end

  def test_nested_hash
    hash = { "dude" => { "likes" => "beer", "hates" => "appletini" } }
    expected = "<dude><hates>appletini</hates><likes>beer</likes></dude>"

    result = ApricotEatsGorilla.hash_to_xml(hash)
    assert_equal expected, result
  end

  def test_nested_hash_with_array
    hash = { "dude" => { "likes" => [ "beer", "helicopters" ] } }
    expected = "<dude><likes>beer</likes><likes>helicopters</likes></dude>"

    result = ApricotEatsGorilla.hash_to_xml(hash)
    assert_equal expected, result
  end

  def test_nested_hash_with_array_containing_a_hash
    hash = { "dude" => { "likes" => [ { "beer" => "a lot" }, { "helicopters" => "a little more" } ] } }
    expected = "<dude><likes><beer>a lot</beer></likes><likes><helicopters>a little more</helicopters></likes></dude>"

    result = ApricotEatsGorilla.hash_to_xml(hash)
    assert_equal expected, result
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smacks-apricoteatsgorilla-0.2.5 tests/hash_to_xml_test.rb