@@ -159,6 +159,47 @@ module RSpec::Core
159
159
EOS
160
160
end
161
161
162
+ it 'wont produce a stack error when cause is the exception itself' , :if => RSpec ::Support ::RubyFeatures . supports_exception_cause? do
163
+ allow ( the_exception ) . to receive ( :cause ) { the_exception }
164
+ the_presenter = Formatters ::ExceptionPresenter . new ( the_exception , example )
165
+
166
+ expect ( the_presenter . fully_formatted ( 1 ) ) . to eq ( <<-EOS . gsub ( /^ +\| / , '' ) )
167
+ |
168
+ | 1) Example
169
+ | Failure/Error: # The failure happened here!#{ encoding_check }
170
+ |
171
+ | Boom
172
+ | Bam
173
+ | # ./spec/rspec/core/formatters/exception_presenter_spec.rb:#{ line_num }
174
+ | # ------------------
175
+ | # --- Caused by: ---
176
+ | # Boom
177
+ | # Bam
178
+ | # ./spec/rspec/core/formatters/exception_presenter_spec.rb:#{ line_num }
179
+ EOS
180
+ end
181
+
182
+ it 'wont produce a stack error when the cause is an older exception' , :if => RSpec ::Support ::RubyFeatures . supports_exception_cause? do
183
+ allow ( the_exception ) . to receive ( :cause ) do
184
+ instance_double ( Exception , :cause => the_exception , :message => "A loop" , :backtrace => the_exception . backtrace )
185
+ end
186
+ the_presenter = Formatters ::ExceptionPresenter . new ( the_exception , example )
187
+
188
+ expect ( the_presenter . fully_formatted ( 1 ) ) . to eq ( <<-EOS . gsub ( /^ +\| / , '' ) )
189
+ |
190
+ | 1) Example
191
+ | Failure/Error: # The failure happened here!#{ encoding_check }
192
+ |
193
+ | Boom
194
+ | Bam
195
+ | # ./spec/rspec/core/formatters/exception_presenter_spec.rb:#{ line_num }
196
+ | # ------------------
197
+ | # --- Caused by: ---
198
+ | # A loop
199
+ | # ./spec/rspec/core/formatters/exception_presenter_spec.rb:#{ line_num }
200
+ EOS
201
+ end
202
+
162
203
it "adds extra failure lines from the example metadata" do
163
204
extra_example = example . clone
164
205
failure_line = 'http://www.example.com/job_details/123'
0 commit comments