CheeseFry
CheeseFry

Reputation: 1319

Ruby Pry locate test file that triggered pry

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.

Upvotes: 1

Views: 214

Answers (1)

John Ledbetter
John Ledbetter

Reputation: 14213

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>'"]

Upvotes: 4

Related Questions