Skip to content

Commit

Permalink
Extract ErrorWithFilteredBacktrace to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
floehopper committed Apr 6, 2018
1 parent 5bda7c4 commit b57c386
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
17 changes: 17 additions & 0 deletions lib/mocha/error_with_filtered_backtrace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'mocha/backtrace_filter'

module Mocha

# @private
class ErrorWithFilteredBacktrace < StandardError

# @private
def initialize(message = nil, backtrace = [])
super(message)
filter = BacktraceFilter.new
set_backtrace(filter.filtered(backtrace))
end

end

end
13 changes: 2 additions & 11 deletions lib/mocha/not_initialized_error.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
require 'mocha/backtrace_filter'
require 'mocha/error_with_filtered_backtrace'

module Mocha

# Exception raised when Mocha has not been initialized, e.g. outside the
# context of a test.
class NotInitializedError < StandardError

# @private
def initialize(message = nil, backtrace = [])
super(message)
filter = BacktraceFilter.new
set_backtrace(filter.filtered(backtrace))
end

end
class NotInitializedError < ErrorWithFilteredBacktrace; end

end
13 changes: 2 additions & 11 deletions lib/mocha/stubbing_error.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
require 'mocha/backtrace_filter'
require 'mocha/error_with_filtered_backtrace'

module Mocha

# Exception raised when stubbing a particular method is not allowed.
#
# @see Configuration.prevent
class StubbingError < StandardError

# @private
def initialize(message = nil, backtrace = [])
super(message)
filter = BacktraceFilter.new
set_backtrace(filter.filtered(backtrace))
end

end
class StubbingError < ErrorWithFilteredBacktrace; end

end

0 comments on commit b57c386

Please sign in to comment.