Ruby gem Diffy not returning differences

250 Views Asked by At

I need to compare two xml files and display the differences in a html report. In order to do this, I installed the ruby gem Diffy (and the gems rspec and diff-lcs as directed by the Diffy documentation), but it does not seem to be working properly as differences are not being returned.

I have two xmls files I want to compare.

Xml file one:

<?xml version="1.0" encoding="UTF-8"?>
<SourceDetails>
    <Origin>Origin</Origin>
    <Identifier>Identifier</Identifier>
    <Timestamp>2001-12-31T12:00:00</Timestamp>
  </SourceDetails>
  <AsOfDate>2001-01-01</AsOfDate>
  <Instrument>
    <ASXExchangeSecurityIdentifier>ASX</ASXExchangeSecurityIdentifier>
  </Instrument>
  <Rate>0.0</Rate>

Xml file two:

<?xml version="1.0" encoding="UTF-8"?>
<SourceDetails>
        <Origin>FEED</Origin>
        <Identifier>IR</Identifier>
        <Timestamp>2017-01-01T02:11:01Z</Timestamp>
    </SourceDetails>
    <AsOfDate>2017-01-02</AsOfDate>
    <Instrument>
        <CommonCode>GB0</CommonCode>
    </Instrument>
    <Rate>0.69</Rate>

When I supply the two xml files as arguments to the diffy function:

puts Diffy::Diff.new('xmldoc1', 'xmldoc2', :source => 'files').to_s(:html)

no differences are returned. When I store the two xml files in String variables and supply these variables as arguments to the Diffy function:

puts Diffy::Diff.new(doc1, doc2, :include_plus_and_minus_in_html => true).to_s(:html)

again no differences are returned. To figure out if my xmls were causing the problem, I also tried supplying two different strings to the Diffy function:

puts Diffy::Diff.new("Hello how are you", "Hello how are you\nI'm fine\nThat's great\n")

but this also returned nothing when there are clear differences.

Does anyone know what the problem may be?

0

There are 0 best solutions below