Ruby debugging and cucumber

I have a bad script in a cucumber and I would like to debug my rail controller using ruby-debug. But if I add a "debugger" to the point where I want to break, it will not stop.

I tried adding ruby-debug and rubygems requirements to the /support/env.rb functions, but then he tells me that he cannot load ruby-debug, although ruby-debug is in the list of gems, and I can load it in irb .

So ... what should I do to make it work?

Thanks!

+8
ruby-on-rails cucumber ruby-debug
source share
4 answers

I had the same problem today and I understood it. here's my blog post explaining two different ways I worked with:

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

you just need to add require "ruby-debug" to your /support/env.rb file for it to work.

+12
source share

Try adding breakpoint instead of debugger .

This should work

+1
source share

They here, of course, get a ruby-debug download.

If you have problems with gems that do not load, and the gem is definitely listed in your Gemfile , run a cucumber, for example:

bundle exec oucumber ...

This is often needed using bundler.

0
source share

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

 # `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
source share

All Articles