Error when comparing binary strings

I have the following problem that is breaking my rspec test suite:

irb
2.4.1 :001 > "a\x01\x00\x00\x00l\xFF\xFF\xFF\xFF\a\x00\x00\x00"
=> "a\u0001\u0000\u0000\u0000l\xFF\xFF\xFF\xFF\a\u0000\u0000\u0000"
2.4.1 :002 > "a\x01\x00\x00\x00l\xFF\xFF\xFF\xFF\a\x00\x00\x00" == "a\u0001\u0000\u0000\u0000l\xFF\xFF\xFF\xFF\a\u0000\u0000\u0000"
=> true

Why does this comparison return false since they are the same strings?

1) Angle::Net::DataBuilder methods #private: data_to_bin convert [2**51 -1] Failure/Error: expect(answer).to eq "a\x01\x00\x00\x00l\xFF\xFF\xFF\xFF\a\x00\x00\x00"

   expected: "a\u0001\u0000\u0000\u0000l\xFF\xFF\xFF\xFF\a\u0000\u0000\u0000"
        got: "a\x01\x00\x00\x00l\xFF\xFF\xFF\xFF\a\x00\x00\x00"

Upvotes: 0

Views: 500

Answers (1)

arjun
arjun

Reputation: 1614

Change definition of sting literal to force the encoding, .force_encoding("ASCII-8BIT")

Probably you can also do String#b

Upvotes: 3

Related Questions