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

Commit

Permalink
Ensure backtraces start at user code, not rspec-mocks code
Browse files Browse the repository at this point in the history
Addresses #1592
  • Loading branch information
onlynone committed Sep 17, 2024
1 parent 134b1ac commit 3b45cd4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/rspec/mocks/error_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,20 @@ def differ
def __raise(message, backtrace_line=nil, source_id=nil)
message = opts[:message] unless opts[:message].nil?
exception = RSpec::Mocks::MockExpectationError.new(message)
filtered_backtrace!(exception)
prepend_to_backtrace(exception, backtrace_line) if backtrace_line
notify exception, :source_id => source_id
end

def filtered_backtrace!(exception)
backtrace = exception.backtrace || caller
source = backtrace.rindex { |l| l =~ /#{File::SEPARATOR}rspec-mocks(-[^#{File::SEPARATOR}]+)?#{File::SEPARATOR}/ }
unless source.nil?
backtrace = backtrace[(source+1)..-1]
end
exception.set_backtrace(backtrace)
end

if RSpec::Support::Ruby.jruby?
def prepend_to_backtrace(exception, line)
raise exception
Expand Down

0 comments on commit 3b45cd4

Please sign in to comment.