1

I have a block of code that triggers my pry session via an integration test but no unit test exists. As such I'm not sure which test is exercising this code and need to run all tests each time I want it to trigger. Is there a way, in a pry session, to bubble up the test/test file? I do not need the _file_ that triggered the pry session.

My best solution has been to raise errors while in the pry session and then continue the test suite hoping that'll flub up a test and be able to locate that test in the testing report. This approach is a bit too much like stabbing in the dark.

1 Answer 1

4

You should be able to get the full call stack by simply invoking 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>'"]

Sign up to request clarification or add additional context in comments.

2 Comments

That'll work for me. It is a few dozen lines that come up, but the test file does eventually show up. Awesome, thank you @John Ledbetter you made my day better.
This is also a useful trick when you're debugging something deep in the application and want to know the call trace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.