@@ -70,12 +70,21 @@ def colorized_formatted_backtrace(colorizer=::RSpec::Core::Formatters::ConsoleCo
70
70
end
71
71
72
72
def fully_formatted ( failure_number , colorizer = ::RSpec ::Core ::Formatters ::ConsoleCodes )
73
- alignment_basis = "#{ ' ' * @indentation } #{ failure_number } ) "
74
- indentation = ' ' * alignment_basis . length
73
+ lines = fully_formatted_lines ( failure_number , colorizer )
74
+ lines . join ( "\n " ) << "\n "
75
+ end
75
76
76
- "\n #{ alignment_basis } #{ description_and_detail ( colorizer , indentation ) } " \
77
- "\n #{ formatted_message_and_backtrace ( colorizer , indentation ) } " \
78
- "#{ extra_detail_formatter . call ( failure_number , colorizer , indentation ) } "
77
+ def fully_formatted_lines ( failure_number , colorizer )
78
+ lines = [
79
+ description ,
80
+ detail_formatter . call ( example , colorizer ) ,
81
+ formatted_message_and_backtrace ( colorizer ) ,
82
+ extra_detail_formatter . call ( failure_number , colorizer ) ,
83
+ ] . compact . flatten
84
+
85
+ lines = indent_lines ( lines , failure_number )
86
+ lines . unshift ( "" )
87
+ lines
79
88
end
80
89
81
90
def failure_slash_error_line
@@ -92,12 +101,6 @@ def final_exception(exception)
92
101
end
93
102
end
94
103
95
- def description_and_detail ( colorizer , indentation )
96
- detail = detail_formatter . call ( example , colorizer , indentation )
97
- return ( description || detail ) unless description && detail
98
- "#{ description } \n #{ indentation } #{ detail } "
99
- end
100
-
101
104
if String . method_defined? ( :encoding )
102
105
def encoding_of ( string )
103
106
string . encoding
@@ -117,6 +120,21 @@ def encoded_string(string)
117
120
# :nocov:
118
121
end
119
122
123
+ def indent_lines ( lines , failure_number )
124
+ alignment_basis = "#{ ' ' * @indentation } #{ failure_number } ) "
125
+ indentation = ' ' * alignment_basis . length
126
+
127
+ lines . each_with_index . map do |line , index |
128
+ if index == 0
129
+ "#{ alignment_basis } #{ line } "
130
+ elsif line . empty?
131
+ line
132
+ else
133
+ "#{ indentation } #{ line } "
134
+ end
135
+ end
136
+ end
137
+
120
138
def exception_class_name ( exception = @exception )
121
139
name = exception . class . name . to_s
122
140
name = "(anonymous error class)" if name == ''
@@ -171,16 +189,12 @@ def find_failed_line
171
189
end
172
190
end
173
191
174
- def formatted_message_and_backtrace ( colorizer , indentation )
192
+ def formatted_message_and_backtrace ( colorizer )
175
193
lines = colorized_message_lines ( colorizer ) + colorized_formatted_backtrace ( colorizer )
176
-
177
- formatted = ""
178
-
179
- lines . each do |line |
180
- formatted << RSpec ::Support ::EncodedString . new ( "#{ indentation } #{ line } \n " , encoding_of ( formatted ) )
194
+ encoding = encoding_of ( "" )
195
+ lines . map do |line |
196
+ RSpec ::Support ::EncodedString . new ( line , encoding )
181
197
end
182
-
183
- formatted
184
198
end
185
199
186
200
def exception_backtrace
@@ -253,7 +267,7 @@ def multiple_exceptions_error?(exception)
253
267
end
254
268
255
269
def multiple_exception_summarizer ( exception , prior_detail_formatter , color )
256
- lambda do |example , colorizer , indentation |
270
+ lambda do |example , colorizer |
257
271
summary = if exception . aggregation_metadata [ :hide_backtrace ]
258
272
# Since the backtrace is hidden, the subfailures will come
259
273
# immediately after this, and using `:` will read well.
@@ -266,27 +280,30 @@ def multiple_exception_summarizer(exception, prior_detail_formatter, color)
266
280
267
281
summary = colorizer . wrap ( summary , color || RSpec . configuration . failure_color )
268
282
return summary unless prior_detail_formatter
269
- "#{ prior_detail_formatter . call ( example , colorizer , indentation ) } \n #{ indentation } #{ summary } "
283
+ [
284
+ prior_detail_formatter . call ( example , colorizer ) ,
285
+ summary
286
+ ]
270
287
end
271
288
end
272
289
273
290
def sub_failure_list_formatter ( exception , message_color )
274
291
common_backtrace_truncater = CommonBacktraceTruncater . new ( exception )
275
292
276
- lambda do |failure_number , colorizer , indentation |
277
- exception . all_exceptions . each_with_index . map do |failure , index |
293
+ lambda do |failure_number , colorizer |
294
+ FlatMap . flat_map ( exception . all_exceptions . each_with_index ) do |failure , index |
278
295
options = with_multiple_error_options_as_needed (
279
296
failure ,
280
297
:description_formatter => :failure_slash_error_line . to_proc ,
281
- :indentation => indentation . length ,
298
+ :indentation => 0 ,
282
299
:message_color => message_color || RSpec . configuration . failure_color ,
283
300
:skip_shared_group_trace => true
284
301
)
285
302
286
303
failure = common_backtrace_truncater . with_truncated_backtrace ( failure )
287
304
presenter = ExceptionPresenter . new ( failure , @example , options )
288
- presenter . fully_formatted ( "#{ failure_number } .#{ index + 1 } " , colorizer )
289
- end . join
305
+ presenter . fully_formatted_lines ( "#{ failure_number } .#{ index + 1 } " , colorizer )
306
+ end
290
307
end
291
308
end
292
309
0 commit comments