Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created January 13, 2009 23:24
Show Gist options
  • Select an option

  • Save tenderlove/46687 to your computer and use it in GitHub Desktop.

Select an option

Save tenderlove/46687 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'test/unit'
class TestFoo < Test::Unit::TestCase
def setup
@doc = Nokogiri::XML(<<-eoxml)
<SIF_Message>
<SIF_Ack>
<SIF_Header>
<SIF_SourceId>Default Server</SIF_SourceId>
</SIF_Header>
</SIF_Ack>
</SIF_Message>
eoxml
end
def test_equal
source1 = @doc.at("//SIF_Header/SIF_SourceId/text()")
source2 = (@doc/"//SIF_Header/SIF_SourceId/text()")
source3 = @doc.search("//SIF_Header/SIF_SourceId/text()")
assert_instance_of(Nokogiri::XML::Text, source1)
assert_instance_of(Nokogiri::XML::NodeSet, source2)
assert_instance_of(Nokogiri::XML::NodeSet, source3)
[source1, source2, source3].each do |node|
assert_equal('Default Server', source1.text)
end
##
# This fails with:
# 1) Failure:
# test_equal(TestFoo) [test.rb:30]:
# <"Default Server"> expected but was
# <#<Nokogiri::XML::Text:0x5cb714
# @document=
# #<Nokogiri::XML::Document:0x5cb7f0
# @decorators=nil,
# @node_cache=
# {2824624=>
# #<Nokogiri::XML::Element:0x5cb6d8
# @document=#<Nokogiri::XML::Document:0x5cb7f0 ...>>,
# 2908976=>#<Nokogiri::XML::Text:0x5cb714 ...>}>>>.
assert_equal('Default Server', source1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment