Skip to content

Instantly share code, notes, and snippets.

@ejhayes
Last active December 17, 2015 23:09
Show Gist options
  • Save ejhayes/5687101 to your computer and use it in GitHub Desktop.
Save ejhayes/5687101 to your computer and use it in GitHub Desktop.
Enable cucumber interactive debugging. Took me a while to find current documentation for this (or I was just looking in the wrong place). All you need to do is include the new debugger gem in your gemfile, add a debugging step definition, then update your features.

Cucumber/Capybara Interactive Debugger

From within your rails project (I run my cucumber test, but you can specify the exact test you want to run too)

$ rake cucumber
~/.rvm/rubies/ruby-1.9.3-p392/bin/ruby -S bundle exec cucumber  --profile default
Using the default profile...
Rack::File headers parameter replaces cache_control after Rack 1.5.
# example.feature
Feature: Example Functionality

  An example set of features that I may or may not want to debug. Yay!

Scenario: I want to debug this thing
  Given I debug

  Scenario: I want to debug this thing # features/report.feature:8
/mnt/hgfs/Projects/status-report/features/step_definitions/steps.rb:81
0

[76, 85] in /mnt/hgfs/Projects/status-report/features/step_definitions/steps.rb
   76    current_path.should == url
   77  end
   78  
   79  Given /^I debug$/ do
   80    breakpoint
=> 81    0
   82  end
(rdb:1) page
#<Capybara::Session>
(rdb:1) exit
Really quit? (y/n) 
y
# search_results.feature
Feature: Example Functionality
An example set of features that I may or may not want to debug. Yay!
Scenario: I want to debug this thing
Given I debug
group :test, :development do
...
gem "rspec-rails", "~> 2.0"
gem "cucumber-rails", :require => false
gem "capybara"
gem "debugger"
...
end
# NOTE: SUPER SUPER IMPORTANT TO HAVE true after the breakpoint or you will enter the debugger
# outside of your step definitions file!!!
...
Given /^I debug$/ do
breakpoint
true
end
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment