Last Updated: February 25, 2016
·
4.04K
· wenlock

rspec debugging is easy

Trying to debug your rspecs and figure out why it's not working? Don't have an ide debugger handy? No problem: ruby-debug gem to the rescue!

  • Install the ruby-debug gem: gem install ruby-debug --no-rdoc --no-ri
  • Add a ''debugger'' statement to your script
require 'spec_helper'
debugger # <<rdebug stops the code here
describe 'your_function', :default => true do
  it 'should change { \'a\' => \'1\' } to { "a" : "1" }' do
   should run.with_params({ "a" => "1" }).and_return("{\"a\":\"1\"}")
  end
end
  • when starting your rspec test, run your spec with -d option: rspec -d <spec file>
  • alternatively you can run debugger on most commands including rake with rdebug: rdebug rake -- spec