summaryrefslogtreecommitdiff
path: root/spec/install/gems/env_spec.rb
blob: 973b291abf932a7b17cef1505ddf743a4f2fb85e (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
require "spec_helper"

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
      should_not_be_installed "rack"
    end

    it "includes the gems when the ENV variable is set" do
      env['BUNDLER_TEST'] = '1'
      bundle :install
      should_be_installed "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
      should_not_be_installed "rack"
    end

    it "includes the gems when the ENV variable is set" do
      env['BUNDLER_TEST'] = '1'
      bundle :install
      should_be_installed "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
      should_not_be_installed "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
      should_not_be_installed "rack"
    end

    it "includes the gems when the ENV variable is set and matches the condition" do
      env['BUNDLER_TEST'] = 'foo'
      bundle :install
      should_be_installed "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
      should_not_be_installed "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
      should_not_be_installed "rack"
    end

    it "includes the gems when the ENV variable is set and matches the condition" do
      env['BUNDLER_TEST'] = 'foobar'
      bundle :install
      should_be_installed "rack 1.0"
    end
  end
end