Ruby 撬动定位触发撬动的测试文件

Ruby Pry locate test file that triggered pry

我有一段代码可以通过集成测试触发我的窥探会话,但不存在单元测试。因此,我不确定哪个测试正在执行此代码,并且每次我希望它触发时都需要 运行 所有测试。有没有办法在窥探过程中冒泡 test/test 文件?我不需要触发窥探会话的_file_

我最好的解决方案是在窥探会话时提出错误,然后继续测试套件,希望这会搞砸测试并能够在测试报告中找到该测试。这种做法有点太像暗杀了。

您应该能够通过简单地调用 caller:

来获取完整的调用堆栈
$ pry
[1] pry(main)> caller
=> ["/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:290:in `eval'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:290:in `evaluate_ruby'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:659:in `handle_line'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:261:in `block (2 levels) in eval'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `catch'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `block in eval'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `catch'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `eval'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:77:in `block in repl'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `loop'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `repl'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `block in start'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/input_lock.rb:61:in `__with_ownership'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/input_lock.rb:78:in `with_ownership'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `start'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:15:in `start'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_class.rb:191:in `start'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/cli.rb:119:in `start'",
 "/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/bin/pry:13:in `<top (required)>'",
 "/home/john/.gem/ruby/2.7.0/bin/pry:23:in `load'",
 "/home/john/.gem/ruby/2.7.0/bin/pry:23:in `<main>'"]