Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit caacdca

Browse files
committed
Handle RSpec description with japanese char in CP932 encoded files
When the user create a test with CP932 encoding and japanese chars RSpec fail to properly display characters or crash with the error: > Encoding::CompatibilityError: incompatible character encodings: Windows-31J and UTF-8 Fix: - #2570 - https://github.com/rspec/rspec-core/issues/2543
1 parent 7288702 commit caacdca

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/rspec/core/formatters/exception_presenter.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def fully_formatted(failure_number, colorizer=::RSpec::Core::Formatters::Console
8181

8282
def fully_formatted_lines(failure_number, colorizer)
8383
lines = [
84-
description,
84+
encoded_description(description),
8585
detail_formatter.call(example, colorizer),
8686
formatted_message_and_backtrace(colorizer),
8787
extra_detail_formatter.call(failure_number, colorizer),
@@ -244,6 +244,10 @@ def formatted_message_and_backtrace(colorizer)
244244
end
245245
end
246246

247+
def encoded_description(description)
248+
encoded_string(description) if description
249+
end
250+
247251
def exception_backtrace
248252
exception.backtrace || []
249253
end

spec/rspec/core/formatters/exception_presenter_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@ module RSpec::Core
9494
EOS
9595
end
9696

97+
it 'allows the caller to add encoded description' do
98+
the_presenter = Formatters::ExceptionPresenter.new(exception, example,
99+
:description => "ジ".encode("CP932"))
100+
101+
expect(the_presenter.fully_formatted(1)).to eq(<<-EOS.gsub(/^ +\|/, ''))
102+
|
103+
| 1) ジ
104+
| Failure/Error: # The failure happened here!#{ encoding_check }
105+
|
106+
| Boom
107+
| Bam
108+
| # ./spec/rspec/core/formatters/exception_presenter_spec.rb:#{line_num}
109+
EOS
110+
end
111+
97112
it 'allows the caller to omit the description' do
98113
the_presenter = Formatters::ExceptionPresenter.new(exception, example,
99114
:detail_formatter => Proc.new { "Detail!" },

0 commit comments

Comments
 (0)