You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then expression failed at [...]
expected: "\x00"
to equal: "\u0000\u0000"
false <- read == "\x00\x00"
"\x00" <- read
However, it is hard to see the difference between the strings (more so with larger strings of non-nulls) when one is displayed in hex and the other uses unicode escaping. Optimally rspec-given should display both exactly like they are written in the spec (in this case both in hex), like this:
Then expression failed at [...]
expected: "\x00"
to equal: "\x00\x00"
false <- read == "\x00\x00"
"\x00" <- read
The text was updated successfully, but these errors were encountered:
After deeper investigation it turns out this is not a problem related to rspec-given.
The "problem" is that strings has the encoding of the source file in which they are contained (in my case UTF8). On the other hand IO.read returns strings with ASCII-8BIT encoding when the length parameter is used. As a result, in the above example, read.encoding is ASCII-8BIT while "\x00\x00".encoding is UTF-8. This causes Ruby to output the strings differently, at least when inspect is used (which is what rspec-given/rspec uses to output with I guess).
Are you still having this issue? I ran into something similar, and just had to explicitly specify the right encoding (ASCII_8BIT) in my test case. Otherwise they were UTF-8, which is ruby's default encoding. This matches what ruby uses for binary strings, like the return value of Array#pack.
I've found two ways to do this on a string literal:
This code:
Outputs the following:
However, it is hard to see the difference between the strings (more so with larger strings of non-nulls) when one is displayed in hex and the other uses unicode escaping. Optimally rspec-given should display both exactly like they are written in the spec (in this case both in hex), like this:
The text was updated successfully, but these errors were encountered: