如何缩短 RSpec 2 中测试失败的回溯? [英] How do I shorten the backtrace for a test failure in RSpec 2?

查看:56
本文介绍了如何缩短 RSpec 2 中测试失败的回溯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的规格出现错误时,我收到如下消息:

When my specs hit an error, I get a message like this:

Vendor should reject duplicate names
     Failure/Error: user_with_duplicate_email.should_not be_valid
     expected valid? to return false, got true
     # /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/rspec-expectations-2.3.0/lib/rspec/expectations/fail_with.rb:29:in `fail_with'
     # /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/rspec-expectations-2.3.0/lib/rspec/expectations/handler.rb:44:in `handle_matcher'
     # /home/kevin/.rvm/gems/ruby-1.9.2-p136@rails3tutorial/gems/rspec-expectations-2.3.0/lib/rspec/expectations/extensions/kernel.rb:50:in `should_not'
.
.
about 15 more lines
.
.
     # /home/kevin/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
     # /home/kevin/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
     # /home/kevin/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'

我正在运行 Ruby 1.0.2、rails (3.0.3) 和 rspec (2.3.0).M .rspec 配置文件只指定了两个选项:

I'm running Ruby 1.0.2, rails (3.0.3), and rspec (2.3.0). M .rspec configuration file has only two options specified:

--drb--颜色

如何关闭扩展跟踪?

推荐答案

spec_helper.rb 中,您可以使用以下代码片段过滤回溯:

In spec_helper.rb you can filter backtrace using the following code snippet:

RSpec.configure do |config|
  # RSpec automatically cleans stuff out of backtraces;
  # sometimes this is annoying when trying to debug something e.g. a gem

  # RSpec 3:
  # config.backtrace_exclusion_patterns = [
  # RSpec 2:
  config.backtrace_clean_patterns = [
    /\/lib\d*\/ruby\//,
    /bin\//,
    /gems/,
    /spec\/spec_helper\.rb/,
    /lib\/rspec\/(core|expectations|matchers|mocks)/
  ]
end

这篇关于如何缩短 RSpec 2 中测试失败的回溯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆