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 callBundler.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"]
inpreinitializer.rb
points to the correct file if you're organizing yourGemfiles
in funny ways. - Finally, note that even with
Bundler.require
, Bundler will only require gems that are directly quoted in yourGemfile
. 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 onconsul
which depends onmemoizer
, consul needs to sayrequire 'memoizer'
inlib/consul.rb
or similiar.
Posted by Henning Koch to makandra dev (2012-08-02 08:26)