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

describe "when using sudo" do
  before :each do
    pending "set BUNDLER_SUDO_TESTS to run sudo specs" unless test_sudo?
  end

  describe "and GEM_HOME is owned by root" do
    before :each do
      chown_system_gems_to_root
    end

    it "installs" do
      install_gemfile <<-G
        source "file://#{gem_repo1}"
        gem "rack", '1.0'
      G

      system_gem_path("gems/rack-1.0.0").should exist
      check system_gem_path("gems/rack-1.0.0").stat.uid.should == 0
      should_be_installed "rack 1.0"
    end

    it "installs when BUNDLE_PATH is owned by root" do
      bundle_path = tmp("owned_by_root")
      FileUtils.mkdir_p bundle_path
      sudo "chown -R root #{bundle_path}"

      ENV['BUNDLE_PATH'] = bundle_path.to_s
      install_gemfile <<-G
        source "file://#{gem_repo1}"
        gem "rack", '1.0'
      G

      bundle_path.join("gems/rack-1.0.0").should exist
      check bundle_path.join("gems/rack-1.0.0").stat.uid.should == 0
      should_be_installed "rack 1.0"
    end

    it "installs when BUNDLE_PATH does not exist"
  end

  describe "and BUNDLE_PATH is not writable" do
    it "installs" do
      sudo "chmod ugo-w #{default_bundle_path}"
      install_gemfile <<-G
        source "file://#{gem_repo1}"
        gem "rack", '1.0'
      G

      default_bundle_path("gems/rack-1.0.0").should exist
      should_be_installed "rack 1.0"
    end
  end

  describe "and BUNDLE_PATH is not writable" do
    it "installs" do
      begin
        gem_home = tmp('sudo_gem_home')

        sudo "mkdir -p #{gem_home}"
        sudo "chmod ugo-w #{gem_home}"
        ENV['GEM_HOME'] = gem_home.to_s
        ENV['GEM_PATH'] = nil

        install_gemfile <<-G
          source "file://#{gem_repo1}"
          gem "rack", '1.0'
        G

        gem_home.join('bin/rackup').should exist
        should_be_installed "rack 1.0"
      end
    end
  end

end