我正在創建一個XML文檔:我想單元測試,至少要確保它是格式良好的。 到目前爲止,我只能通過使用REXML庫中的'hasElements'來近似這一點。Ruby單元測試:這是一個有效(格式良好)的XML文檔嗎?
有沒有更好的方法? 最好使用內置庫(我的意思是隨標準Ruby 1.8.x發行版一起提供的庫)。
require "test/unit"
require 'rexml/document'
require 'test/unit/ui/console/testrunner'
include REXML
class TestBasic < Test::Unit::TestCase
def test_createXML
my_xml=...create doc here...
doc = Document.new(my_xml);
assert(doc.has_elements?);
end
end
Test::Unit::UI::Console::TestRunner.run(TestBasic);
+1,因爲我更喜歡nokogiri而不是libxml。 (Uela'Simone :)) – makevoid
感謝 - +1 - 我可能會放棄這一點,但我想避免在此安裝任何其他寶石! – monojohnny
嘿,喬弗朗西斯! –