diff options
-rw-r--r-- | .travis.yml | 8 | ||||
-rw-r--r-- | Rakefile | 18 |
2 files changed, 18 insertions, 8 deletions
diff --git a/.travis.yml b/.travis.yml index 1100b8981f..638d19b6e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,7 @@ language: ruby dist: bionic script: - bin/parallel_rspec spec - - sudo -E bin/rake spec:sudo - - sudo chown -R $(whoami) tmp + - bin/rake spec:sudo - BUNDLER_SPEC_PRE_RECORDED=1 bin/rake spec:realworld before_script: @@ -13,11 +12,6 @@ before_script: then travis_retry sudo apt-get install graphviz -y; fi - - if [ "$TRAVIS_RUBY_VERSION" = "2.3.8" ]; - then - sudo sed -i 's/1000::/1000:Travis:/g' /etc/passwd; - sudo sed -i '/secure_path/d' /etc/sudoers; - fi branches: only: @@ -55,7 +55,23 @@ namespace :spec do end desc "Run the spec suite with the sudo tests" - task :sudo => %w[set_sudo spec] + task :sudo => %w[set_sudo] do + require "open3" + output, status = Open3.capture2e("sudo", "cp", "/etc/sudoers", "tmp/old_sudoers") + raise "Couldn't read sudoers file: #{output}" unless status.success? + + begin + output, status = Open3.capture2e("sudo sed -i '/secure_path/d' /etc/sudoers") + raise "Couldn't configure sudo to preserve path: #{output}" unless status.success? + + raise "Couldn't configure sudo correctly to preserve path" unless `ruby -v` == `sudo -E ruby -v` + + sh("sudo -E bin/rspec") + ensure + system("sudo", "cp", "tmp/old_sudoers", "/etc/sudoers") + system("sudo", "chown", "-R", ENV["USER"], "tmp") + end + end task :set_sudo do ENV["BUNDLER_SUDO_TESTS"] = "1" |