2 Comments

RSpec Backtrace Filtering

Recently I ran into some trouble with the way I was trying to use the Mongoid gem. Some error was happening, but I wasn’t getting good output on the screen. Eventually I realized that RSpec (version 2) was filtering out parts of my backtrace.

Here’s the default configuration for RSpec’s backtrace filtering:


RSpec.configure do |config|
  # RSpec automatically cleans stuff out of backtraces;
  # sometimes this is annoying when trying to debug something e.g. a gem
  config.backtrace_clean_patterns = [
    /\/lib\d*\/ruby\//,
    /bin\//,
    /gems/,
    /spec\/spec_helper\.rb/,
    /lib\/rspec\/(core|expectations|matchers|mocks)/
  ]
end

Since this filter configuration is matching lines with the word gem, the Mongoid errors I was hoping to see were getting filtered out. To get around my problem, I temporarily changed the configuration to this:


RSpec.configure do |config|
  # RSpec automatically cleans stuff out of backtraces;
  # sometimes this is annoying when trying to debug something e.g. a gem
  config.backtrace_clean_patterns = [
    /\/lib\d*\/ruby\//,
    /bin\//,
    #/gems/,
    /spec\/spec_helper\.rb/,
    /lib\/rspec\/(core|expectations|matchers|mocks)/
  ]
end

Not particularily elegant.

Generally speaking I like the backtrace filtering, but sometimes I want to see the whole thing. Is anyone aware of any sweet command line parameters to RSpec or other tricks to make it a little easier to disable the filter sometimes? A formatter maybe? Or should I hack a configuration variable into my runner?