lib/gemika/env.rb
##
# Changes the gemfile to the given `path`, runs the given `block`, then resets
# the gemfile to its original path.
#
# @example
#   Gemika::Env.with_gemfile('gemfiles/Gemfile.rails3') do
#     system('rspec spec') or raise 'RSpec failed'
#   end
#
Changes the gemfile to the given `path`, runs the given `block`, then resets
the gemfile to its original path.
Changes the gemfile to the given ` path ` runs the given ` block ` then resets the gemfile to its original path .
def with_gemfile(path, *args, &block)
      @gemfile_changed = true
      @process_gemfile = ENV['BUNDLE_GEMFILE']
      bundler_method = if Gemika::Env.gem?('bundler', '< 2')
        :with_clean_env
      else
        :with_unbundled_env
      end
      Bundler.send(bundler_method) do
        ENV['BUNDLE_GEMFILE'] = path
        block.call(*args)
      end
    ensure
      @gemfile_changed = false
      ENV['BUNDLE_GEMFILE'] = @process_gemfile
    end
def with_gemfile ( path , * args , & block ) @gemfile_changed = true @process_gemfile = ENV [ 'BUNDLE_GEMFILE' ] bundler_method = if Gemika :: Env . gem? ( 'bundler' , '< 2' ) :with_clean_env else :with_unbundled_env end Bundler . send ( bundler_method ) do ENV [ 'BUNDLE_GEMFILE' ] = path block . call ( * args ) end ensure @gemfile_changed = false ENV [ 'BUNDLE_GEMFILE' ] = @process_gemfile end
Changes the gemfile to the given `path`, runs the given `block`, then resets
the gemfile to its original path.
Changes the gemfile to the given ` path ` runs the given ` block ` then resets the gemfile to its original path .
# Make sure that if block calls  #gemfile we still return the gemfile for this # process, regardless of what's in ENV temporarily # .with_clean_env is deprecated since Bundler ~> 2.
path
args
block
example
:Env.with_gemfile('gemfiles/Gemfile.rails3') do system('rspec spec') or raise 'RSpec failed' end
: Env . with_gemfile ( ' gemfiles / Gemfile . rails3 ' ) do system ( ' rspec spec ' ) or raise ' RSpec failed ' end