-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Problem
If the lazy contains multibyte characters such as Japanese, the test may fail.
Sample code
Situation
An additional condition occurs when one of the following two conditions is met
- A. multibyte characters are used in the description of the ancestor (including the parent) context
- B. There are other parameters in the parameter list to which lazy belongs that contain multibyte characters.
The error is as follows in both cases, but the location where the error occurs depends on the pattern.
Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT
pretty_params = pairs.has_key?(:case_name) ? pairs[:case_name] : pairs.map {|name, val| "#{name}: #{params_inspect(val)}"}.join(", ") |
Cause
In both cases, the error seems to occur in the title generation part of the test case, and is probably caused by not reading the source code with the correct character encoding when interpreting the parameter list as a string.
For example, forcing the following encoding in LazyArgs#inspect
works fine (of course, a deterministic encoding is not a good solution)
"#{@block.to_raw_source}".force_encoding('utf-8')
Tracing the cause, it seems that it is already treated as an unknown charset (ASCII-8BIT) inside the proc_to_ast
gem that is used to read the source code.
Workaround
If you specify case_name
in the parameter list, the problem processing will be skipped and it will work correctly.
Since there are not many tests that use lazy, this solution is not a problem, but we would like to see the hassle of specifying it and the difficulty in understanding the error eliminated.
Remarks
- Sorry, but I haven't come up with a good solution.
- If you expect to specify
case_name
, it would be more helpful to put it in README or something. - If you finally decide that the issue needs to be fixed with
proc_to_ast
, please comment on it (I will make an issue there).