Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm developing a gem, and my Gemfile looks like this:

source :rubygems

gemspec

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

However, I don't want people to have to install pry and debugger when running tests, but I also want to be able to require them in my tests (because I'm running tests prefixed with bundle exec, and I cannot get it them in my load path if they're not in the Gemfile). How do I achieve this?

Also, when to put gems that I use for development in the gemspec, and when to put them in the Gemfile? I really don't know the difference.

like image 961
janko-m Avatar asked Sep 08 '26 18:09

janko-m


1 Answers

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.

like image 101
Andrew Vit Avatar answered Sep 11 '26 15:09

Andrew Vit