开发者

Where do I have to do my Bundler setup?

开发者 https://www.devze.com 2023-02-06 13:38 出处:网络
If I\'m developing a gem using Bundle开发者_运维百科r and RSpec for testing. Where do I do my Bundler.setup? Let\'s assume my gem is called fancy-gem and my directory setup is similar to the following

If I'm developing a gem using Bundle开发者_运维百科r and RSpec for testing. Where do I do my Bundler.setup? Let's assume my gem is called fancy-gem and my directory setup is similar to the following:

Gemfile
Gemfile.lock
lib/
  fancy-gem.rb
Rakefile
README
spec/
  ...

Should I execute Bundler.setup in my 'fancy-gem.rb' or does this cause problems with other gems which might use bundler? I'm thinking, when I'm not doing this, then there is no way to guarantee that the right version of the third party libraries I'm requiring is loaded.

I already asked, if I need to add Bundler itself to the Gemfile. The answer was no, but now I'm not so sure, because if I do execute Bundler.setup somewhere then Bundler actually is a dependency of my Gem and should be installed along with my Gem when it is downloaded from rubygems.org


In my opinion you should neither depend on bundler, nor use it in your gem. The way I'd do it is simply require your gem's dependencies in lib/fancy-gem.rb (almost every gem only has a handful of runtime dependencies, so this should not be too much of a hassle) and I'd call Bundler.setup only in the development files (like spec_helper.rb or Rakefile). This way you don't screw with applications that use your gem and still get all the convenience of automatic dependency management when developing your gem.

0

精彩评论

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