8

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!

Thiago
  • 2,238
  • 4
  • 29
  • 42

4 Answers4

12

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.

Derick Bailey
  • 72,004
  • 22
  • 206
  • 219
1

Try adding breakpoint instead of debugger.

That should work

changelog
  • 4,646
  • 4
  • 35
  • 62
0

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
Dan Kohn
  • 33,811
  • 9
  • 84
  • 100
0

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.

nessur
  • 1,143
  • 1
  • 11
  • 18