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

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

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:

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



回答2:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!