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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
require_relative './../test_helper'
require 'minitest/autorun'
class TestXMLRequired < Minitest::Test
def setup
@full_book = <<BOOK
<book ISBN="1234">
<title>This & that</title>
<contributor_array>
<contributor role="Author">
<name>Johnny</name>
</contributor>
</contributor_array>
<contributor_hash>
<contributor role="Author" name="Johnny" />
</contributor_hash>
</book>
BOOK
@book_missing_attr = <<BOOK
<book>
<title>This & that</title>
<contributor_array>
<contributor role="Author">
<name>Johnny</name>
</contributor>
</contributor_array>
<contributor_hash>
<contributor role="Author" name="Johnny" />
</contributor_hash>
</book>
BOOK
@book_missing_text = <<BOOK
<book ISBN="1234">
<contributor_array>
<contributor role="Author">
<name>Johnny</name>
</contributor>
</contributor_array>
<contributor_hash>
<contributor role="Author" name="Johnny" />
</contributor_hash>
</book>
BOOK
@book_missing_array = <<BOOK
<book ISBN="1234">
<title>This & that</title>
<contributor_hash>
<contributor role="Author" name="Johnny" />
</contributor_hash>
</book>
BOOK
@book_missing_hash = <<BOOK
<book ISBN="1234">
<title>This & that</title>
<contributor_array>
<contributor role="Author">
<name>Johnny</name>
</contributor>
</contributor_array>
</book>
BOOK
end
def test_required_passes_on_prescence
BookWithRequired.from_xml(@full_book)
end
def test_required_throws_on_attr_absence
assert_raises ROXML::RequiredElementMissing do
BookWithRequired.from_xml(@book_missing_attr)
end
end
def test_required_throws_on_text_absence
assert_raises ROXML::RequiredElementMissing do
BookWithRequired.from_xml(@book_missing_text)
end
end
def test_required_throws_on_array_absence
assert_raises ROXML::RequiredElementMissing do
BookWithRequired.from_xml(@book_missing_array)
end
end
def test_required_throws_on_hash_absence
assert_raises ROXML::RequiredElementMissing do
BookWithRequired.from_xml(@book_missing_hash)
end
end
end
|