require 'runit/testcase' require 'msxml/iterator' class IteratorTest < RUNIT::TestCase def test_iterator doc = Msxml::open('../books.xml') expected_names = [ "Designing Object-Oriented Software", "Using CRC Cards", "新版 C言語プログラミングのエッセンス", ] expected_isbns = [ "0-13-629825-7", "1-884842-07-0", "4-89052-868-7", ] count = 0 for book in Msxml::Iterator.new(doc, "本").sort { |a, b| a.getAttribute("名前") <=> b.getAttribute("名前") } name = book.getAttribute("名前") assert_equals(expected_names[count], name) isbns = Msxml::Iterator.new(book, "ISBN") isbn = isbns.first assert_equals(expected_isbns[count], isbn.text) count += 1 end assert_equals(expected_names.length, count) end end if __FILE__ == $0 require 'runit/cui/testrunner' RUNIT::CUI::TestRunner.run(IteratorTest.suite) end