\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef.upgrade/embedded/lib/ruby/gems/2.3.0/gems/nokogiri-1.7.2/test/

Viewing File: test_nokogiri.rb

require "helper"

class TestNokogiri < Nokogiri::TestCase
  def test_versions
    version_match = /\d+\.\d+\.\d+/
    assert_match version_match, Nokogiri::VERSION

    assert_equal Nokogiri::VERSION_INFO['ruby']['version'], ::RUBY_VERSION
    assert_equal Nokogiri::VERSION_INFO['ruby']['platform'], ::RUBY_PLATFORM

    if Nokogiri.uses_libxml?
      assert_match version_match, Nokogiri::LIBXML_VERSION
      assert_equal 'extension', Nokogiri::VERSION_INFO['libxml']['binding']

      assert_match version_match, Nokogiri::VERSION_INFO['libxml']['compiled']
      assert_equal Nokogiri::LIBXML_VERSION, Nokogiri::VERSION_INFO['libxml']['compiled']

      assert_match version_match, Nokogiri::VERSION_INFO['libxml']['loaded']
      Nokogiri::LIBXML_PARSER_VERSION =~ /(\d)(\d{2})(\d{2})/
      major = $1.to_i
      minor = $2.to_i
      bug   = $3.to_i
      assert_equal "#{major}.#{minor}.#{bug}", Nokogiri::VERSION_INFO['libxml']['loaded']
    end
  end

  def test_libxml_iconv
    assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED) if Nokogiri.uses_libxml?
  end

  def test_parse_with_io
    doc = Nokogiri.parse(
      StringIO.new("<html><head><title></title><body></body></html>")
    )
    assert_instance_of Nokogiri::HTML::Document, doc
  end

  def test_xml?
    doc = Nokogiri.parse(File.read(XML_FILE))
    assert doc.xml?
    assert !doc.html?
  end

  def test_atom_is_xml?
    doc = Nokogiri.parse(File.read(XML_ATOM_FILE))
    assert doc.xml?
    assert !doc.html?
  end

  def test_html?
    doc = Nokogiri.parse(File.read(HTML_FILE))
    assert !doc.xml?
    assert doc.html?
  end

  def test_nokogiri_method_with_html
    doc1 = Nokogiri(File.read(HTML_FILE))
    doc2 = Nokogiri.parse(File.read(HTML_FILE))
    assert_equal doc1.serialize, doc2.serialize
  end

  def test_nokogiri_method_with_block
    doc = Nokogiri { b "bold tag" }
    assert_equal('<b>bold tag</b>', doc.to_html.chomp)
  end

  def test_make_with_html
    doc = Nokogiri.make("<b>bold tag</b>")
    assert_equal('<b>bold tag</b>', doc.to_html.chomp)
  end

  def test_make_with_block
    doc = Nokogiri.make { b "bold tag" }
    assert_equal('<b>bold tag</b>', doc.to_html.chomp)
  end

  SLOP_HTML = <<-END
  <html>
    <body>
      <ul>
        <li class='red'>one</li>
        <li class='blue'>two</li>
      </ul>
      <div>
        one
        <div>div two</div>
      </div>
    </body>
  </html>
  END

  def test_slop_css
    doc = Nokogiri::Slop(<<-eohtml)
    <html>
      <body>
        <div>
          one
          <div class='foo'>
            div two
            <div class='foo'>
              div three
            </div>
          </div>
        </div>
      </body>
    </html>
    eohtml
    assert_equal "div", doc.html.body.div.div('.foo').name
  end

  def test_slop
    doc = Nokogiri::Slop(SLOP_HTML)

    assert_equal "one", doc.html.body.ul.li.first.text
    assert_equal "two", doc.html.body.ul.li(".blue").text
    assert_equal "div two", doc.html.body.div.div.text

    assert_equal "two", doc.html.body.ul.li(:css => ".blue").text

    assert_equal "two", doc.html.body.ul.li(:xpath => "position()=2").text
    assert_equal "one", doc.html.body.ul.li(:xpath => ["contains(text(),'o')"]).first.text
    assert_equal "two", doc.html.body.ul.li(:xpath => ["contains(text(),'o')","contains(text(),'t')"]).text

    assert_raise(NoMethodError) { doc.nonexistent }
  end

  def test_slop_decorator
    doc = Nokogiri(SLOP_HTML)
    assert !doc.decorators(Nokogiri::XML::Node).include?(Nokogiri::Decorators::Slop)

    doc.slop!
    assert doc.decorators(Nokogiri::XML::Node).include?(Nokogiri::Decorators::Slop)

    doc.slop!
    assert_equal 1, doc.decorators(Nokogiri::XML::Node).select { |d| d == Nokogiri::Decorators::Slop }.size
  end

end