When I use
require 'bundler/setup'
i get Bundler.with_clean_env
is not supported.
But when I change this to
require 'bundler'
It supports Bundler.with_clean_env
. The confusion that rises here is what is the difference between requiring 'bundler'
and 'bundler/setup'
?
When referring to gems, require 'foo'
would require the foo.rb
file that is located in the gem's lib
directory. That file has usually the same name as the gem and is responsible for requiring all other necessary files for the gem to function.
When you do require 'foo/bar'
, you search for lib/foo/bar.rb
. In other words, you require only a specific file from that gem and not the whole thing.
The bundler/setup
is responsible for loading all gems described in your Gemfile. Bundler.with_clean_env
is a completely different functionality, defined in the gem's main file.
Gemfiles can include groups like :test
or :development
.
From the documentation:
Configure the load path so all dependencies in your Gemfile can be required
require 'rubygems'
require 'bundler/setup'
require 'nokogiri'
Only add gems from specified groups to the load path. If you want the gems in the default group, make sure to include it
require 'rubygems'
require 'bundler'
Bundler.setup(:default, :ci)
require 'nokogiri'