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

Commit c7e2625

Browse files
committed
Don't handle encoding with Ruby 1.8.7
We are following the same behavior as for rspec-support https://github.com/rspec/rspec-support/blob/9940a8656071655b807f772f36101b4d27f1b67d/lib/rspec/support/spec/string_matcher.rb#L8
1 parent e6ff352 commit c7e2625

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/rspec/core/formatters/exception_presenter.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,12 @@ def formatted_message_and_backtrace(colorizer)
246246

247247
def encoded_description(description)
248248
return if description.nil?
249-
encoded_string(description)
249+
250+
if String.method_defined?(:encoding)
251+
encoded_string(description)
252+
else # for 1.8.7
253+
description
254+
end
250255
end
251256

252257
def exception_backtrace

spec/rspec/core/formatters/exception_presenter_spec.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +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"))
97+
if String.method_defined?(:encoding)
98+
it 'allows the caller to add encoded description' do
99+
the_presenter = Formatters::ExceptionPresenter.new(exception, example,
100+
:description => "ジ".encode("CP932"))
100101

101-
expect(the_presenter.fully_formatted(1)).to eq(<<-EOS.gsub(/^ +\|/, ''))
102+
expect(the_presenter.fully_formatted(1)).to eq(<<-EOS.gsub(/^ +\|/, ''))
102103
|
103104
| 1) ジ
104105
| Failure/Error: # The failure happened here!#{ encoding_check }
105106
|
106107
| Boom
107108
| Bam
108109
| # ./spec/rspec/core/formatters/exception_presenter_spec.rb:#{line_num}
109-
EOS
110+
EOS
111+
end
110112
end
111113

112114
it 'allows the caller to omit the description' do

0 commit comments

Comments
 (0)