File: typecast_xml_value_test.rb

package info (click to toggle)
ruby-multi-xml 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 2,822; sh: 4; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 976 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "test_helper"

# Tests typecast_xml_value with default and custom disallowed types
class TypecastXmlValueTest < Minitest::Test
  cover "MultiXml*"
  include MultiXml::Helpers

  def test_uses_default_disallowed_types
    assert_raises(MultiXml::DisallowedTypeError) do
      typecast_xml_value({"type" => "yaml", "__content__" => "test"})
    end
  end

  def test_with_explicit_empty_disallowed_types
    result = typecast_xml_value({"type" => "yaml", "__content__" => "test"}, [])

    assert_equal "test", result
  end

  def test_passes_disallowed_types_to_array
    value = [{"type" => "yaml", "__content__" => "key: value"}, "second"]
    result = typecast_xml_value(value, [])

    assert_equal [{"key" => "value"}, "second"], result
  end

  def test_custom_disallowed_blocks_in_array
    value = [{"type" => "integer", "__content__" => "42"}]

    assert_raises(MultiXml::DisallowedTypeError) do
      typecast_xml_value(value, ["integer"])
    end
  end
end