Module: TestXml

Defined in:
lib/test_xml.rb,
lib/test_xml/version.rb,
lib/test_xml/assertions.rb,
lib/test_xml/nokogiri/node.rb,
lib/test_xml/matcher_methods.rb

Defined Under Namespace

Modules: Assertions, MatcherMethods, NokogiriExt Classes: AssertionConfig

Constant Summary collapse

VERSION =
"0.1.7"
ASSERTIONS =
[
  AssertionConfig.new(
    :name       => :xml_contain,
    :matcher    => :contain_xml,
    :message    => lambda { |expect, actual| "the xml:\n#{actual}\nshould contain xml:\n#{expect}" },
    :message_when_negated => lambda { |expect, actual| "the xml:\n#{actual}\nshould not contain xml:\n#{expect} but it does" }
  ),
  AssertionConfig.new(
    :name       => :xml_structure_contain,
    :matcher    => :contain_xml_structure,
    :message    => lambda { |expect, actual| "the xml:\n#{actual}\nshould match xml structure:\n#{expect}" },
    :message_when_negated => lambda { |expect, actual| "the xml:\n#{actual}\nshould not match xml structure:\n#{expect} but it does" }
  ),
  AssertionConfig.new(
    :name       => :xml_equal,
    :matcher    => :equal_xml,
    :message    => lambda { |expect, actual| sprintf "the xml:\n%s\nshould exactly match xml:\n%s\n\nDiff:\n%s", actual, expect, diff(expect, actual) },
    :message_when_negated => lambda { |expect, actual| "the xml:\n#{actual}\nshould not exactly match xml:\n#{expect} but it does" }
  ),
  AssertionConfig.new(
    :name       => :xml_structure_equal,
    :matcher    => :equal_xml_structure,
    :message    => lambda { |expect, actual| "the xml:\n#{actual}\nshould exactly match xml structure:\n#{expect}" },
    :message_when_negated => lambda { |expect, actual| "the xml:\n#{actual}\nshould not exactly match xml structure:\n#{expect} but it does" }
  )
]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.enable_placeholdersObject

Returns the value of attribute enable_placeholders.



9
10
11
# File 'lib/test_xml.rb', line 9

def enable_placeholders
  @enable_placeholders
end

Class Method Details

.diff(expect, actual) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/test_xml/assertions.rb', line 46

def self.diff(expect, actual)
  doc_actual = Nokogiri::XML.parse(actual, &:noblanks)
  doc_expect = Nokogiri::XML.parse(expect, &:noblanks)

  diff = Diffy::Diff.new(doc_expect.to_xml, doc_actual.to_xml, :context => 3, :include_diff_info => true).to_a
  return "" if diff.empty?

  # Skip diff headers, they're useless since they refer to tempfiles
  diff[2..-1].join("")
end

.placeholders_enabled?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/test_xml.rb', line 11

def placeholders_enabled?
  !!enable_placeholders
end