How Can I Debug My Cucumber Right in the Middle of Test Run?
I am currently using cucumber/capybara to test my Rails app and now I’m facing a problem: how the heck can I debug my test right in the middle?
I have found a gem called pry-debugger and since I use pry, so I just want to give it a try.
Installation
Install gem “pry”, “pry-debugger” in Gemfile
gem 'pry-rails' gem 'pry-debugger'
In support/env.rb require the gem
require 'pry'
Put
binding.pry
before the line that you want to debugjust run
bundle exec cucumber --tags @dev
; cannot run in Rubymine since there’s no pry console REPL
Reference Links
pry
pry-debugger
Pry Debugger useful commands
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.
breakpoints: TBD
Tips
Stepping through code often? Add the following shortcuts to ~/.pryrc:
if defined?(PryDebugger)
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 'f', 'finish'
end