Read more

Gem development: When your specs don't see dependencies from your Gemfile

Henning Koch
August 02, 2012Software engineer at makandra GmbH

When you develop a gem and you have a Gemfile in your project directory, you might be surprised that your gem dependencies aren't already required in your specs. Here is some info that should help you out:

  • Bundler actually doesn't automatically require anything. You need to call Bundler.require(:default, :your_custom_group1, ...) for that. The reason why you never had to write this line is that Rails does this for you when it boots the environment.
  • That also means that if you have an embedded Rails app in your spec folder (like has_defaults Show archive.org snapshot ), and you boot its environment, it should call Bundler.require for you and you don't need to require anything yourself.
  • If your embedded app is an old Rails 2.3 app, make sure it has been patched to call Bundler when booting Show archive.org snapshot . Also make sure the ENV["BUNDLE_GEMFILE"] in preinitializer.rb points to the correct file if you're organizing your Gemfiles in funny ways.
  • Finally, note that even with Bundler.require, Bundler will only require gems that are directly quoted in your Gemfile. It will not require gems that are dependencies of these gems. It's the job of a gem to require its dependencies. E.g. if you're working on consul which depends on memoizer, consul needs to say require 'memoizer' in lib/consul.rb or similiar.
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot
Posted by Henning Koch to makandra dev (2012-08-02 10:26)