测试 [求助] RSpec 测试用例代码重用时的 Stacktrace 美化

msg7086 · October 03, 2015 · 2014 hits

比如我有个测试用例文件,内容是(伪代码)

# testcases.rb
good_cases = [{...}, {...}, ...]
bad_cases = ...

然后 spec 文件里则生成对应的测试代码(伪代码)

# something_spec.rb
describe something do
  good_cases.each do |case|
    it "blah blah #{case.name}" { expect(f(case.data)).to be_what }
  end
end

那么问题来了。测试出错的时候,stacktrace 总是会指向 something_spec.rb[1:1:5]。如何才能手工篡改使其指向 testcases.rb:10 呢?

我知道 __FILE____LINE__,然而并不知道怎样塞给 RSpec。

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.