开发者

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

开发者 https://www.devze.com 2022-12-11 23:16 出处:网络
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.
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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消