如何缩短 RSpec 2 中测试失败的回溯?

发布于 2024-10-17 21:45:42 字数 1124 浏览 4 评论 0原文

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

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 配置文件仅指定了两个选项:

--drb --颜色

如何关闭扩展跟踪?

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'

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
--colour

How do I turn off the extended trace?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

习惯成性 2024-10-24 21:45:43

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

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

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
帥小哥 2024-10-24 21:45:43

我将其更新为与 Rspec 3.2.3 一起使用。在 spec_helper.rb 中输入:

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

这是纯金。谢谢卢阿卡苏斯!

I updated it to work with with Rspec 3.2.3. In spec_helper.rb put:

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

This is pure gold. Thank you luacassus!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文