views:

399

answers:

2
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
+1  A: 

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).

Patrick Ritchie
Thanks Patrick. I'll try that Monday Morning as soon as I get to work.
btelles
I haven't tried it with spork yet... will try that over the weekend and update my answer if it works.
Patrick Ritchie
+1  A: 

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 ...

ozzyaaron