File: bundler_test.rb

package info (click to toggle)
ruby-bootsnap 1.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 520 kB
  • sloc: ruby: 3,637; ansic: 844; sh: 14; makefile: 9
file content (57 lines) | stat: -rw-r--r-- 1,180 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true

require "test_helper"

class BundlerTest < Minitest::Test
  def test_bundler_with_bundle_bin_path_env
    without_required_env_keys do
      ENV["BUNDLE_BIN_PATH"] = "foo"
      assert_predicate(Bootsnap, :bundler?)
    end
  end

  def test_bundler_with_bundle_gemfile_env
    without_required_env_keys do
      ENV["BUNDLE_GEMFILE"] = "foo"
      assert_predicate(Bootsnap, :bundler?)
    end
  end

  def test_bundler_without_bundler_const
    without_bundler do
      refute_predicate(Bootsnap, :bundler?)
    end
  end

  def test_bundler_without_required_env_keys
    without_required_env_keys do
      assert(defined?(::Bundler))
      refute_predicate(Bootsnap, :bundler?)
    end
  end

  private

  def without_bundler
    b = ::Bundler
    begin
      Object.send(:remove_const, :Bundler)
      yield
    ensure
      Object.send(:const_set, :Bundler, b)
    end
  end

  def without_required_env_keys
    original_env = {}
    begin
      %w(BUNDLE_BIN_PATH BUNDLE_GEMFILE).each do |k|
        original_env[k] = ENV[k]
        ENV[k] = nil
      end
      yield
    ensure
      original_env.each { |k, v| ENV[k] = v }
    end
  end
end