Open olerass opened 10 years ago
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:
binary_str = "\x00\x00".b
binary_str = "\x00\x00".force_encoding('ASCII_8BIT')
Hope that helps. You might be able to close this issue.
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: