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

Ensure backtraces start at user code, not rspec-mocks code #1593

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/rspec/mocks/error_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,24 @@ def differ
def __raise(message, backtrace_line=nil, source_id=nil)
message = opts[:message] unless opts[:message].nil?
exception = RSpec::Mocks::MockExpectationError.new(message)
filter_backtrace!(exception)
prepend_to_backtrace(exception, backtrace_line) if backtrace_line
notify exception, :source_id => source_id
end

def filter_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

unless backtrace.empty?
exception.set_backtrace(backtrace)
end
end

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