Trip
Trip

Reputation: 27114

Is there any better way to ignore \n?

My test started failing because I added a debugger after an XML expected block. Now it produces a single \n at the end of the statement that fails my test. And I can't seem to get rid of it anyway I delete or move around my text.

Then I wrote this to make it pass :

      expected = <<-XML
    <?xml version="1.0" ?>
    <?qbxml version="5.0" ?>
    <QBXML>
      <QBXMLMsgsRq onError="continueOnError">
      </QBXMLMsgsRq>
    </QBXML>
    XML
  assert_equal expected.gsub(/\n/,'').gsub(' ',''), result.gsub(/\n/,'').gsub(' ','')
  #assert_equal expected.strip, result

Otherwise the commented out one used to work. Is there some dumb obvious sense I'm missing here?

Upvotes: 0

Views: 113

Answers (2)

apneadiving
apneadiving

Reputation: 115531

I would not compare strings, it just sucks.

Instead I would compare the object representations.

Try to use: Hash#from_xml and compare the hashes.

Upvotes: 1

Baldrick
Baldrick

Reputation: 24340

You could use \s in the regular expression to replace both the new line and space characters, it's a bit more readable:

assert_equal expected.gsub(/\s/,''), result.gsub(/\s/,'')

Upvotes: 2

Related Questions