Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get rspec, spork and debugger to play nice

Given I am a dumb programmer
  and I am using rspec
  and I am using spork
  and I want to debug ...mmm...let's saaay, a spec for Phone. 

Then, where should I put the "require 'ruby-debug'" line in order to halt processing at a particular point in the phone_spec.rb? (All I'm asking for is a big fat arrow that even a challenged programmer could see :-3 )

I've tried many locations, and unless I didn't test them correctly, there's something weird going on:

In spec_helper.rb at the following locations:

require 'rubygems'
require 'spork'
                                            <= TRIED IT HERE
ENV["RAILS_ENV"] ||= 'test'

Spork.prefork do
  require File.dirname(__FILE__) + "/../config/environment" #unless defined?(RAILS_ROOT)
  require 'spec/autorun'
  require 'spec/rails'
  require 'machinist/active_record'
  require 'faker'
  require 'sham'
                                            <= TRIED IT HERE
end

Spork.each_run do
  require File.expand_path(File.dirname(__FILE__) + "/blueprints")

                                            <= TRIED IT HERE
end

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

Spec::Runner.configure do |config|
  config.use_transactional_fixtures = true
  config.use_instantiated_fixtures  = false
  config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
  config.before(:all)    { Sham.reset(:before_all)  }
  config.before(:each)   { Sham.reset(:before_each) }

                                            <= TRIED IT HERE

end
like image 528
btelles Avatar asked Nov 13 '09 22:11

btelles


2 Answers

I'm running Spork and Autospec with ruby-debug. Later versions of Spork have an external ruby-debug library you can require, it's experimental so use at your own risk. In my prefork block I just have :

require 'spork/ext/ruby-debug'

It'll break out to a debug session in the terminal you have Spork running. There are methods etc to initiate remote connection setup and so on, and recent commits have had updates and fixes applied to their debugging functionality so it's under active development. Hopefully it'll be core and tested soon ...

like image 110
ozzyaaron Avatar answered Oct 03 '22 06:10

ozzyaaron


I've always put it in config/environments/test.rb and the put the debugger at the breakpoint in my app code (as opposed to the spec).

like image 32
Patrick Ritchie Avatar answered Oct 03 '22 06:10

Patrick Ritchie