aboutsummaryrefslogtreecommitdiffstats
path: root/spec/bundler/install/gems/env_spec.rb
blob: 9b1d8e542403e2bebbdb7bacd9379c237207bc63 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# frozen_string_literal: true
require "spec_helper"

RSpec.describe "bundle install with ENV conditionals" do
  describe "when just setting an ENV key as a string" do
    before :each do
      gemfile <<-G
        source "file://#{gem_repo1}"

        env "BUNDLER_TEST" do
          gem "rack"
        end
      G
    end

    it "excludes the gems when the ENV variable is not set" do
      bundle :install
      expect(the_bundle).not_to include_gems "rack"
    end

    it "includes the gems when the ENV variable is set" do
      ENV["BUNDLER_TEST"] = "1"
      bundle :install
      expect(the_bundle).to include_gems "rack 1.0"
    end
  end

  describe "when just setting an ENV key as a symbol" do
    before :each do
      gemfile <<-G
        source "file://#{gem_repo1}"

        env :BUNDLER_TEST do
          gem "rack"
        end
      G
    end

    it "excludes the gems when the ENV variable is not set" do
      bundle :install
      expect(the_bundle).not_to include_gems "rack"
    end

    it "includes the gems when the ENV variable is set" do
      ENV["BUNDLER_TEST"] = "1"
      bundle :install
      expect(the_bundle).to include_gems "rack 1.0"
    end
  end

  describe "when setting a string to match the env" do
    before :each do
      gemfile <<-G
        source "file://#{gem_repo1}"

        env "BUNDLER_TEST" => "foo" do
          gem "rack"
        end
      G
    end

    it "excludes the gems when the ENV variable is not set" do
      bundle :install
      expect(the_bundle).not_to include_gems "rack"
    end

    it "excludes the gems when the ENV variable is set but does not match the condition" do
      ENV["BUNDLER_TEST"] = "1"
      bundle :install
      expect(the_bundle).not_to include_gems "rack"
    end

    it "includes the gems when the ENV variable is set and matches the condition" do
      ENV["BUNDLER_TEST"] = "foo"
      bundle :install
      expect(the_bundle).to include_gems "rack 1.0"
    end
  end

  describe "when setting a regex to match the env" do
    before :each do
      gemfile <<-G
        source "file://#{gem_repo1}"

        env "BUNDLER_TEST" => /foo/ do
          gem "rack"
        end
      G
    end

    it "excludes the gems when the ENV variable is not set" do
      bundle :install
      expect(the_bundle).not_to include_gems "rack"
    end

    it "excludes the gems when the ENV variable is set but does not match the condition" do
      ENV["BUNDLER_TEST"] = "fo"
      bundle :install
      expect(the_bundle).not_to include_gems "rack"
    end

    it "includes the gems when the ENV variable is set and matches the condition" do
      ENV["BUNDLER_TEST"] = "foobar"
      bundle :install
      expect(the_bundle).to include_gems "rack 1.0"
    end
  end
end