This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -220,12 +220,19 @@ def exception_class_name
220
220
name
221
221
end
222
222
223
+ def exception_message
224
+ @exception_message ||= begin
225
+ string = exception . message . to_s
226
+ RSpec ::Support ::EncodedString . new ( string , encoding_of ( string ) )
227
+ end
228
+ end
229
+
223
230
def failure_lines
224
231
@failure_lines ||=
225
232
begin
226
233
lines = [ "Failure/Error: #{ read_failed_line . strip } " ]
227
234
lines << "#{ exception_class_name } :" unless exception_class_name =~ /RSpec/
228
- exception . message . to_s . split ( "\n " ) . each do |line |
235
+ exception_message . split ( "\n " ) . each do |line |
229
236
lines << " #{ line } " if exception . message
230
237
end
231
238
lines
Original file line number Diff line number Diff line change
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'rspec/core/notifications'
4
+
5
+ RSpec . describe "FailedExampleNotification" , :if => String . method_defined? ( :encoding ) do
6
+ include FormatterSupport
7
+
8
+ let ( :notification ) { ::RSpec ::Core ::Notifications ::FailedExampleNotification . new ( example ) }
9
+
10
+ before do
11
+ example . metadata [ :absolute_file_path ] = __FILE__
12
+ end
13
+
14
+ describe '#message_lines' do
15
+ let ( :message_with_invalid_byte_sequence ) do
16
+ "\xEF \255 \xAD I have bad bytes" . force_encoding ( Encoding ::UTF_8 )
17
+ end
18
+ let ( :expected_message ) { "? ? ? I have bad bytes" }
19
+ let ( :exception ) do
20
+ instance_double (
21
+ Exception ,
22
+ :backtrace => [ "#{ __FILE__ } :#{ __LINE__ } " ] ,
23
+ :message => message_with_invalid_byte_sequence
24
+ )
25
+ end
26
+
27
+ let ( :example_group ) do
28
+ class_double (
29
+ RSpec ::Core ::ExampleGroup ,
30
+ :metadata => { } ,
31
+ :parent_groups => [ ] ,
32
+ :location => "#{ __FILE__ } :#{ __LINE__ } "
33
+ )
34
+ end
35
+
36
+ before do
37
+ allow ( example ) . to receive ( :example_group ) { example_group }
38
+ end
39
+
40
+ context "when failure_lines contains an invalid byte sequence" do
41
+ it "replaces bad bytes with a '?'" do
42
+ lines = notification . message_lines
43
+ expect ( lines [ 0 ] ) . to match %r{\A Failure\/ Error}
44
+ expect ( lines [ 1 ] . strip ) . to eq ( expected_message )
45
+ end
46
+ end
47
+
48
+ end
49
+ end
You can’t perform that action at this time.
0 commit comments