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

Commit 25e8c6b

Browse files
committed
Ensure backtraces start at user code, not rspec-mocks code
Addresses #1592
1 parent 134b1ac commit 25e8c6b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/rspec/mocks/error_generator.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,20 @@ def differ
328328
def __raise(message, backtrace_line=nil, source_id=nil)
329329
message = opts[:message] unless opts[:message].nil?
330330
exception = RSpec::Mocks::MockExpectationError.new(message)
331+
set_filtered_backtrace(exception)
331332
prepend_to_backtrace(exception, backtrace_line) if backtrace_line
332333
notify exception, :source_id => source_id
333334
end
334335

336+
def set_filtered_backtrace(exception)
337+
backtrace = exception.backtrace || caller
338+
source = backtrace.rindex{ |l| l =~ /#{File::SEPARATOR}rspec-mocks(-[^#{File::SEPARATOR}]+)?#{File::SEPARATOR}/ }
339+
if !source.nil?
340+
backtrace = backtrace[source+1..]
341+
end
342+
exception.set_backtrace(backtrace)
343+
end
344+
335345
if RSpec::Support::Ruby.jruby?
336346
def prepend_to_backtrace(exception, line)
337347
raise exception

0 commit comments

Comments
 (0)