Sha256: 04b166cf2088f1767e7035aac8c6bb30ff4e01bef104c1a834f46f22ee7e9d83

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))

class TestXml < Test::Unit::TestCase
  context "integration test" do
    context "xml document" do
      context "custom scrubber" do
        should "act as expected" do
          xml = Loofah.xml_document <<-EOXML
            <root>
              <employee deceased='true'>Abraham Lincoln</employee>
              <employee deceased='false'>Abe Vigoda</employee>
            </root>
          EOXML
          bring_out_your_dead = Loofah::Scrubber.new do |node|
            if node.name == "employee" and node["deceased"] == "true"
              node.remove
              Loofah::Scrubber::STOP # don't bother with the rest of the subtree
            end
          end
          assert_equal 2, xml.css("employee").length
          
          xml.scrub!(bring_out_your_dead)

          employees = xml.css "employee"
          assert_equal 1, employees.length
          assert_equal "Abe Vigoda", employees.first.inner_text
        end
      end
    end

    context "xml fragment" do
      context "custom scrubber" do
        should "act as expected" do
          xml = Loofah.xml_fragment <<-EOXML
            <employee deceased='true'>Abraham Lincoln</employee>
            <employee deceased='false'>Abe Vigoda</employee>
          EOXML
          bring_out_your_dead = Loofah::Scrubber.new do |node|
            if node.name == "employee" and node["deceased"] == "true"
              node.remove
              Loofah::Scrubber::STOP # don't bother with the rest of the subtree
            end
          end
          assert_equal 2, xml.css("employee").length
          
          xml.scrub!(bring_out_your_dead)

          employees = xml.css "employee"
          assert_equal 1, employees.length
          assert_equal "Abe Vigoda", employees.first.inner_text
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loofah-1.0.0 test/integration/test_xml.rb
loofah-1.0.0.beta.1 test/integration/test_xml.rb
loofah-0.4.7 test/integration/test_xml.rb