Module: NokogiriExt::Etest

Defined in:
lib/nokogiri/nokogiri_ext.rb

Constant Summary collapse

SOURCE =
<<-XML
<bb>
<i:xy></i:xy>
</bb>
XML

Instance Method Summary collapse

Instance Method Details

#assert_xml_equals(expected, actual) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/nokogiri/nokogiri_ext.rb', line 47

def assert_xml_equals(expected, actual)
  expected = Nokogiri::XML(expected)
  
  if expected == actual 
    assert true
    return
  end
  
  expected = expected.remove_blanks
  actual = actual.remove_blanks

  if expected == actual 
    assert true
    return
  end

  expected = expected.to_s.gsub(/<\?xml version=\"1.0\"\?>\n/, "")
  actual = actual.to_s.gsub(/<\?xml version=\"1.0\"\?>\n/, "")

  assert_equal expected, actual
end

#test_assertionObject


69
70
71
72
# File 'lib/nokogiri/nokogiri_ext.rb', line 69

def test_assertion
  doc = Nokogiri::XML SOURCE
  assert_xml_equals SOURCE, doc
end

#test_transformObject


74
75
76
77
78
79
80
81
82
# File 'lib/nokogiri/nokogiri_ext.rb', line 74

def test_transform
  doc = Nokogiri::XML SOURCE
  doc.root.transform do |s| "<cc />" end
  assert_xml_equals "<cc/>", doc

  doc = Nokogiri::XML SOURCE
  doc.root.transform do |s| s.name != "xy" end
  assert_xml_equals "<bb/>", doc 
end

#test_transform2Object


84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/nokogiri/nokogiri_ext.rb', line 84

def test_transform2
  doc = Nokogiri::XML SOURCE
  doc.root.transform do |s| 
    if s.name == "xy"
      "<cc />" 
    elsif s.name == "text" && s.text.blank?
      false
    end
  end

  assert_xml_equals "<bb><cc/></bb>", doc
end