Running ruby debug in rspec?

后端 未结 6 1370
醉酒成梦
醉酒成梦 2020-12-13 11:47

I\'m trying to get Ruby debugger running in one of my specs:

describe User do
  it \"should be valid\" do
    debugger
    User.new.should be_valid
  end
end         


        
6条回答
  •  醉话见心
    2020-12-13 12:27

    The best and cleanest option is to use --require in your .rspec file. What you put depends on which gem you use for debugging.

    --color
    --require pry
    --require rails_helper
    

    These correspond to command line options (-d or --debug is now deprecated).

    Feel free to use debugger, ruby-debug or pry (pry-rails in your Gemfile).

    For your Gemfile:

    group :test, :development do
      gem 'pry-rails'
    end
    

    Putting require 'ruby-debug' etc. at the top of your spec is simply more tightly coupled -- especially since here the top voted comment suggests putting it individually in ALL your files. With the new .rspec file you shouldn't need to put require 'spec_helper' or require 'rails_helper' at the top of your files anymore.

    They make more sense as implicit command line arguments.

提交回复
热议问题