I\'m creating an XML document: I want to unit test at least to make sure it\'s well-formed. So far, I have only been able to approximate this , by using the \'hasElements\'
You can use Nokogiri. It's not a standard Ruby library, but you can easily install it as a Gem.
begin
bad_doc = Nokogiri::XML(badly_formed) { |config| config.options = Nokogiri::XML::ParseOptions::STRICT }
rescue Nokogiri::XML::SyntaxError => e
puts "caught exception: #{e}"
end
# => caught exception: Premature end of data in tag root line 1