Skip to content

Test execution fails due to lazy containing multibyte characters #10

@tukiyo320

Description

@tukiyo320

Problem

If the lazy contains multibyte characters such as Japanese, the test may fail.

Sample code

tukiyo320@bd09082

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

A. https://github.com/rspec/rspec-core/blob/f273314f575ab62092b2ad86addb6a3c93d6041f/lib/rspec/core/metadata.rb#L320
B.

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.

https://github.com/joker1007/proc_to_ast/blob/60c95582828edb689d6f701543f8ae1b138139fc/lib/proc_to_ast.rb#L31

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).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions