Mocha::BacktraceFilter creates a new Regexp object for every line of
every backtrace it filters. It also calls File.expand_path for each
such line.
The Regexp object creation can easily be removed by creating it once
in #initialize. File.expand_path might be more difficult to get rid
of, but File.expand_Path is slow, at least on Windows. Getting rid of
all those calls to it would thus save a lot of time. Rewriting
BacktraceFilter to that below makes running my 108 tests with
Expectations run in less than a third of the time:
def initialize(lib_directory = LIB_DIRECTORY)
@lib_directory = Regexp.new('^' + Regexp.escape(lib_directory))
end
def filtered(backtrace)
backtrace.reject { |location| @lib_directory.match(location) }
end
I realize that this doesn’t filter backtraces correctly if Mocha’s
paths are relative. I was, however, hoping that someone with more
knowledge in this area would be able to resolve this. Perhaps setting
LIB_DIRECTORY = File.dirname(File.dirname(__FILE__)) + File::SEPARATOR
is a good way of doing it? Then both @lib_directory and location will
both be relative or absolute, depending on how Mocha was required.
Hi Nikolai,
That's really helpful - thanks.
I've taken the liberty of creating a ticket [1] on your behalf.
I'm probably not going to have a chance to look at this in the next
week or so, but it'd be great if someone could supply a patch.
Cheers, James.
[1] http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/66