ruby-debug and cucumber
Asked Answered
A

4

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!

Alvaalvan answered 4/2, 2011 at 13:11 Comment(2)
What version of Ruby are you using?Reposit
ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32] on Windows VistaAlvaalvan
B
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.

Barley answered 29/6, 2011 at 19:37 Comment(0)
P
1

Try adding breakpoint instead of debugger.

That should work

Preferable answered 4/2, 2011 at 13:22 Comment(0)
M
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.

Moazami answered 16/5, 2011 at 21:44 Comment(0)
C
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
Centillion answered 17/6, 2015 at 4:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.