1

Because of this SO question here, I would like to execute ruby code step-by-step while running rspec or cucumber. Not only would I like to stop execution, but I would like to then proceed through the code, line by line.

Is there a best-practice-approach to step into code that is running while RAILS_ENV = 'test' ? Is there any way to do this currently?

2 Answers 2

4

pry-debugger allows you to step through code line by line:

  • step: Step execution into the next line or method. Takes an optional numeric argument to step multiple times.
  • next: Step over to the next line within the same frame. Also takes an optional numeric argument to step multiple lines.
  • finish: Execute until current stack frame returns.
  • continue: Continue program execution and end the Pry session
Sign up to request clarification or add additional context in comments.

Comments

3

I use pry, which opens an interpreter in your current console so that you can inspect the variables with their current values.

Just require the gem and put binding.pry inside your tests. The Readme file is quite self-explanatory, so I'll leave you to it :)

3 Comments

I looked at pry. Seems great. But, I don't see where it allows for stepwise code execution. I'm looking to debug what I believe might be a cyclical chain of 'require thisFile.rb' commands or some other unintended recursion. Pry looks great at inspecting state and more, but will it provide me a trace of the execution path or some IDE like 'now I am at this line of code' insight?
Damn, it looks like I missed the link :( I was actually meaning pry-debugger and got pry instead, sorry :( Anyway, I'm glad you found pry-debugger useful, it's a really nice tool :)
No problem. I'll be including both in my future rails work. Very handy. Thanks again.

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.