diff options
author | Andre Arko <andre@arko.net> | 2010-07-11 17:47:28 -0700 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2010-07-11 18:11:40 -0700 |
commit | 05287ae8580ea2deb92a2ebb248de78fea89e382 (patch) | |
tree | 2935dc96788109d272cc6c75f3e8609d2b7767e5 | |
parent | 850f8d5fc56fb5efa887d1484d0c3dd86a6c6e44 (diff) | |
download | bundler-05287ae8580ea2deb92a2ebb248de78fea89e382.tar.gz |
Clean up sudo specs
-rw-r--r-- | spec/install/gems/sudo_spec.rb | 22 | ||||
-rw-r--r-- | spec/support/sudo.rb | 31 |
2 files changed, 21 insertions, 32 deletions
diff --git a/spec/install/gems/sudo_spec.rb b/spec/install/gems/sudo_spec.rb index a7e7c007cd..b81ed69d9b 100644 --- a/spec/install/gems/sudo_spec.rb +++ b/spec/install/gems/sudo_spec.rb @@ -1,7 +1,12 @@ require "spec_helper" -describe 'omg' do - describe_sudo "bundle install with GEM_HOME owned by root" do +describe "when using sudo" do + before :each do + pending "set BUNDLER_SUDO_TESTS to run sudo specs" unless test_sudo? + chown_system_gems_to_root + end + + describe "bundle install with GEM_HOME owned by root" do it "works" do install_gemfile <<-G source "file://#{gem_repo1}" @@ -9,20 +14,23 @@ describe 'omg' do G system_gem_path("gems/rack-1.0.0").should exist - File.stat(system_gem_path("gems/rack-1.0.0")).uid.should == 0 + system_gem_path("gems/rack-1.0.0").stat.uid.should == 0 should_be_installed "rack 1.0" end - it "works during the first time when BUNDLE_PATH does not exist" do - bundle_path = "#{tmp}/owned_by_root" - ENV['BUNDLE_PATH'] = bundle_path + it "works when BUNDLE_PATH does not exist" do + bundle_path = tmp("owned_by_root") + FileUtils.mkdir_p bundle_path + sudo "chown -R root #{bundle_path}" + ENV['BUNDLE_PATH'] = bundle_path install_gemfile <<-G source "file://#{gem_repo1}" gem "rack", '1.0' G - tmp("owned_by_root/gems/rack-1.0.0").should exist + bundle_path.join("gems/rack-1.0.0").should exist + bundle_path.join("gems/rack-1.0.0").stat.uid.should == 0 should_be_installed "rack 1.0" end end diff --git a/spec/support/sudo.rb b/spec/support/sudo.rb index 84c19f4e02..5992d56a69 100644 --- a/spec/support/sudo.rb +++ b/spec/support/sudo.rb @@ -1,39 +1,20 @@ module Spec module Sudo - def self.sudo? + def self.present? @which_sudo ||= `which sudo`.strip !@which_sudo.empty? && ENV['BUNDLER_SUDO_TESTS'] end - module Describe - def describe_sudo(*args, &blk) - return unless Sudo.sudo? - describe(*args) do - before :each do - chown_system_gems - end - - instance_eval(&blk) - end - end - end - - def self.included(klass) - klass.extend Describe - end - - def sudo? - Sudo.sudo? + def test_sudo? + Sudo.present? end def sudo(cmd) - cmd = "sudo #{cmd}" if sudo? - sys_exec(cmd) + raise "sudo not present" unless Sudo.present? + sys_exec("sudo #{cmd}") end - def chown_system_gems - FileUtils.mkdir_p tmp('owned_by_root') - sudo "chown -R root #{tmp('owned_by_root')}" + def chown_system_gems_to_root sudo "chown -R root #{system_gem_path}" end end |