ruby-debug and cucumber

4.4k views Asked by At

I have a failing scenario in cucumber, and I'd like to debug my rails controller using ruby-debug. But if I add 'debugger' to the point where I want to break, it doesn't stop.

I tried adding require of ruby-debug and rubygems to the features/support/env.rb but then it says to me that it can't load ruby-debug, although ruby-debug is on the gem list and I can load it in irb.

So... what should I do to get it working?

Thanks!

4

There are 4 answers

0
Dan Kohn On

For the modern Ruby version of a debugger (using binding.pry), I recommend create a file features/support/debugging.rb with the following contents, and then calling cucumber with environment variables set to debug:

# `LAUNCHY=1 cucumber` to open page on failure
After do |scenario|
  # rubocop:disable Lint/Debugger
  save_and_open_page if scenario.failed? && ENV['LAUNCHY']
  # rubocop:enable Lint/Debugger
end

# `FAST=1 cucumber` to stop on first failure
After do |scenario|
  Cucumber.wants_to_quit = ENV['FAST'] && scenario.failed?
end

# `DEBUG=1 cucumber` to drop into debugger
Before do |scenario|
  next unless ENV['DEBUG']
  # rubocop:disable Lint/Debugger
  puts "Debugging scenario: #{scenario.title}"
  binding.pry
  # rubocop:enable Lint/Debugger
end
0
changelog On

Try adding breakpoint instead of debugger.

That should work

0
Derick Bailey On

i had this same problem today, and i got it figured out. here's my blog post explaining the two different ways I got it working:

http://lostechies.com/derickbailey/2011/06/29/debugging-cucumber-tests-with-ruby-debug/

you may just need to add require "ruby-debug" to your features/support/env.rb file to get it working.

0
nessur On

They key here is definitely getting ruby-debug loaded first.

If you're having problems with gems not loading, and the gem is definitely listed in your Gemfile, run cucumber like:

bundle exec cucumber ...

This is often necessary with bundler.