应该破坏我的回溯吗?

pup*_*eno 11 ruby testing ruby-on-rails shoulda backtrace

我有一个或多或少像这样的测试:

class FormDefinitionTest < ActiveSupport::TestCase
  context "a form_definition" do
    setup do
      @definition = SeedData.form_definition
      # ...
Run Code Online (Sandbox Code Playgroud)

我故意添加了一个

raise "blah"
Run Code Online (Sandbox Code Playgroud)

在某个地方,我得到这个错误:

RuntimeError: blah
test/unit/form_definition_test.rb:79:in `__bind_1290079321_362430'
Run Code Online (Sandbox Code Playgroud)

什么时候我应该得到一些东西:

/Users/pupeno/projectx/db/seed/sheet_definitions.rb:17:in `sheet_definition': blah (RuntimeError)
    from /Users/pupeno/projectx/db/seed/form_definitions.rb:4:in `form_definition'
    from /Users/pupeno/projectx/test/unit/form_definition_test.rb:79
Run Code Online (Sandbox Code Playgroud)

什么是消毒/摧毁我的回溯?我怀疑是应该的,因为异常发生在一个设置中,或应该发生.

这是一个Rails 3项目,如果这很重要的话.

Lin*_*ios 0

我想这会给你你想要的回溯。我还没有测试过,但它应该可以工作:

def exclude_backtrace_from_location(location)
  begin
    yeild
  rescue => e
    puts "Error of type #{e.class} with message: #{e.to_s}.\nBacktrace:"
    back=e.backtrace
    back.delete_if {|b| b~=/\A#{location}.+/}
    puts back
  end
end

exclude_backrace_from_location("test/unit") do
  #some shoulda code that raises...
end
Run Code Online (Sandbox Code Playgroud)