ruby-debug and cucumber

拈花ヽ惹草 提交于 2019-12-12 08:01:39

问题


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!


回答1:


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.




回答2:


Try adding breakpoint instead of debugger.

That should work




回答3:


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.




回答4:


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


来源:https://stackoverflow.com/questions/4898334/ruby-debug-and-cucumber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!