How to use 'debugger' and 'pry' when developing a gem? (Ruby)

℡╲_俬逩灬. 提交于 2019-12-02 03:39:31

You can add gems to your gemspec as a development dependency, like this:

Gem::Specification.new do |s|
  # ...
  s.add_development_dependency 'pry'
  s.add_development_dependency 'debugger'
  s.add_development_dependency 'rake'
end

These will only be installed when working on the gem and not when installing the gem itself.

Just as @andrew-vit said, you can add it to your gem specifications as a development dependency

Gem::Specification.new do |spec|
   #...
   spec.add_development_dependency "pry"
   spec.add_development_dependency "debugger"
   #...
end

Since this will be a development dependency, you don't want to add require 'pry' into your main gem app, so just add it into your spec_helper.rb or whatever your test setup file is.

require 'rspec'
require 'vcr'
require 'pry'
#...

Then when you run your specs, you can still add your binding.pry into the code for your sandbox. Make sure your specs run before pushing your code. That way if it breaks, you'll see you forgot a breakpoint in your code.

I found a solution. I can just put them in groups.

source :rubygems

gemspec

group :development, :test do
  gem "rake"
end

gem "debugger", :group => :debugger
gem "pry",      :group => :pry

This way the contributor can choose to not install them:

bundle install --without debugger pry

For me a mix of the answers above seems to work. I'm currently running with ruby 2.2.4 and with adding this to the .gempsec:

s.add_development_dependency 'pry-byebug'
s.add_development_dependency 'rake'

and this for my spec_helper.rb:

require 'pry'

Not sure if that helps anyone.

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