@@ -43,110 +43,19 @@ def self.for(example)
43
43
return SkippedExampleNotification . new ( example ) if execution_result . example_skipped?
44
44
return new ( example ) unless execution_result . status == :pending || execution_result . status == :failed
45
45
46
- klass = FailedExampleNotification
47
- exception = execution_result . exception
48
- ex_presenter_options = { }
49
-
50
- if execution_result . pending_fixed?
51
- klass = PendingExampleFixedNotification
52
- ex_presenter_options = {
53
- :description_formatter => Proc . new { "#{ example . full_description } FIXED" } ,
54
- :message_color => RSpec . configuration . fixed_color ,
55
- :failure_lines => [ "Expected pending '#{ execution_result . pending_message } ' to fail. No Error was raised." ]
56
- }
57
- elsif execution_result . status == :pending
58
- klass = PendingExampleFailedAsExpectedNotification
59
- exception = example . execution_result . pending_exception
60
- ex_presenter_options = {
61
- :message_color => RSpec . configuration . pending_color ,
62
- :detail_formatter => PENDING_DETAIL_FORMATTER
63
- }
64
- end
65
-
66
- if multiple_exceptions_not_met_error? ( exception )
67
- ex_presenter_options = exception_presenter_opts_for_multiple_error (
68
- exception , example , ex_presenter_options
69
- )
70
- end
71
-
72
- ex_presenter = Formatters ::ExceptionPresenter . new ( exception , example , ex_presenter_options )
73
- klass . new ( example , ex_presenter )
74
- end
75
-
76
- def self . exception_presenter_opts_for_multiple_error ( exception , example , options )
77
- ex_presenter_options = options . merge (
78
- :failure_lines => [ ] ,
79
- :extra_detail_formatter => sub_failure_list_formatter ( exception , example ,
80
- options [ :message_color ] ) ,
81
- :detail_formatter => multiple_failure_sumarizer ( exception ,
82
- options [ :detail_formatter ] ,
83
- options [ :message_color ] )
84
- )
85
-
86
- ex_presenter_options [ :description_formatter ] &&= Proc . new { }
87
-
88
- if exception . aggregation_metadata [ :from_around_hook ]
89
- ex_presenter_options [ :backtrace_formatter ] = EmptyBacktraceFormatter
90
- end
91
-
92
- ex_presenter_options
93
- end
94
-
95
- # @private
96
- # Used to prevent a confusing backtrace from showing up from the `aggregate_failures`
97
- # block declared for `:aggregate_failures` metadata.
98
- module EmptyBacktraceFormatter
99
- def self . format_backtrace ( *)
100
- [ ]
101
- end
102
- end
46
+ klass = if execution_result . pending_fixed?
47
+ PendingExampleFixedNotification
48
+ elsif execution_result . status == :pending
49
+ PendingExampleFailedAsExpectedNotification
50
+ else
51
+ FailedExampleNotification
52
+ end
103
53
104
- def self . multiple_exceptions_not_met_error? ( exception )
105
- return false unless defined? ( RSpec ::Expectations ::MultipleExpectationsNotMetError )
106
- RSpec ::Expectations ::MultipleExpectationsNotMetError === exception
54
+ exception_presenter = Formatters ::ExceptionPresenter ::Factory . new ( example ) . build
55
+ klass . new ( example , exception_presenter )
107
56
end
108
57
109
- def self . multiple_failure_sumarizer ( exception , prior_detail_formatter , color )
110
- lambda do |example , colorizer , indentation |
111
- summary = if exception . aggregation_metadata [ :from_around_hook ]
112
- "Got #{ exception . exception_count_description } :"
113
- else
114
- "#{ exception . summary } ."
115
- end
116
-
117
- summary = colorizer . wrap ( summary , color || RSpec . configuration . failure_color )
118
- return summary unless prior_detail_formatter
119
- "#{ prior_detail_formatter . call ( example , colorizer , indentation ) } \n #{ indentation } #{ summary } "
120
- end
121
- end
122
-
123
- def self . sub_failure_list_formatter ( exception , example , message_color )
124
- lambda do |failure_number , colorizer , indentation |
125
- exception . all_exceptions . each_with_index . map do |failure , index |
126
- options = {
127
- :description_formatter => :failure_slash_error_line . to_proc ,
128
- :indentation => indentation . length ,
129
- :message_color => message_color || RSpec . configuration . failure_color ,
130
- :skip_shared_group_trace => true
131
- }
132
-
133
- if multiple_exceptions_not_met_error? ( failure )
134
- options = exception_presenter_opts_for_multiple_error ( failure , example , options )
135
- end
136
-
137
- failure = failure . dup
138
- failure . set_backtrace ( failure . backtrace [ 0 ..-exception . backtrace . size ] )
139
-
140
- Formatters ::ExceptionPresenter . new (
141
- failure , example , options
142
- ) . fully_formatted ( "#{ failure_number } .#{ index + 1 } " , colorizer )
143
- end . join
144
- end
145
- end
146
-
147
- private_class_method :new , :multiple_exceptions_not_met_error? ,
148
- :multiple_failure_sumarizer , :sub_failure_list_formatter ,
149
- :exception_presenter_opts_for_multiple_error
58
+ private_class_method :new
150
59
end
151
60
152
61
# The `ExamplesNotification` represents notifications sent by the reporter
@@ -305,11 +214,6 @@ class PendingExampleFixedNotification < FailedExampleNotification; end
305
214
# @deprecated Use {FailedExampleNotification} instead.
306
215
class PendingExampleFailedAsExpectedNotification < FailedExampleNotification ; end
307
216
308
- # @private
309
- PENDING_DETAIL_FORMATTER = Proc . new do |example , colorizer |
310
- colorizer . wrap ( "# #{ example . execution_result . pending_message } " , :detail )
311
- end
312
-
313
217
# The `SkippedExampleNotification` extends `ExampleNotification` with
314
218
# things useful for specs that are skipped.
315
219
#
@@ -322,9 +226,9 @@ class SkippedExampleNotification < ExampleNotification
322
226
# RSpec's built-in formatters emit.
323
227
def fully_formatted ( pending_number , colorizer = ::RSpec ::Core ::Formatters ::ConsoleCodes )
324
228
formatted_caller = RSpec . configuration . backtrace_formatter . backtrace_line ( example . location )
325
- colorizer . wrap ( "\n #{ pending_number } ) #{ example . full_description } " , :pending ) <<
326
- " \n " << PENDING_DETAIL_FORMATTER . call ( example , colorizer ) << " \n " <<
327
- colorizer . wrap ( " # #{ formatted_caller } \n " , :detail )
229
+ colorizer . wrap ( "\n #{ pending_number } ) #{ example . full_description } " , :pending ) << " \n " <<
230
+ Formatters :: ExceptionPresenter :: PENDING_DETAIL_FORMATTER . call ( example , colorizer ) <<
231
+ " \n " << colorizer . wrap ( " # #{ formatted_caller } \n " , :detail )
328
232
end
329
233
end
330
234
0 commit comments