Permalink
Browse files

Add test coverage for #607 (safesystem w/ no $SHELL)

Also: Add missing SecureRandom.uuid under 1.8.x (for the tests)
  • Loading branch information...
1 parent ff16e2c commit e4a94be2af0b539a18c4a42263696306d952224d @jordansissel committed Feb 5, 2014
Showing with 66 additions and 0 deletions.
  1. +12 −0 spec/fpm/package/dir_spec.rb
  2. +54 −0 spec/fpm/util_spec.rb
View
12 spec/fpm/package/dir_spec.rb
@@ -3,6 +3,18 @@
require "fpm/package/dir" # local
require "stud/temporary"
+if RUBY_VERSION =~ /^1\.8/
+ # The following method copied from ruby 1.9.3
+ module SecureRandom
+ def self.uuid
+ ary = self.random_bytes(16).unpack("NnnnnN")
+ ary[2] = (ary[2] & 0x0fff) | 0x4000
+ ary[3] = (ary[3] & 0x3fff) | 0x8000
+ "%08x-%04x-%04x-%04x-%04x%08x" % ary
+ end
+ end
+end
+
describe FPM::Package::Dir do
let(:tmpdir) { Stud::Temporary.directory("tmpdir") }
let(:output) { Stud::Temporary.directory("output") }
View
54 spec/fpm/util_spec.rb
@@ -0,0 +1,54 @@
+require "spec_setup"
+require "fpm" # local
+
+describe FPM::Util do
+ subject do
+ Class.new do
+ include FPM::Util
+ def initialize
+ @logger = Cabin::Channel.new
+ end
+ end.new
+ end
+
+ describe "#safe_system" do
+ context "with a missing $SHELL" do
+ before do
+ @orig_shell = ENV["SHELL"]
+ ENV.delete("SHELL")
+ end
+
+ after do
+ ENV["SHELL"] = @orig_shell unless @orig_shell.nil?
+ end
+
+ it "should assume /bin/sh" do
+ insist { subject.default_shell } == "/bin/sh"
+ end
+
+ it "should still run commands correctly" do
+ # This will raise an exception if we can't run it at all.
+ subject.safesystem("true")
+ end
+ end
+ context "with $SHELL set to an empty string" do
+ before do
+ @orig_shell = ENV["SHELL"]
+ ENV["SHELL"] = ""
+ end
+
+ after do
+ ENV["SHELL"] = @orig_shell unless @orig_shell.nil?
+ end
+
+ it "should assume /bin/sh" do
+ insist { subject.default_shell } == "/bin/sh"
+ end
+
+ it "should still run commands correctly" do
+ # This will raise an exception if we can't run it at all.
+ subject.safesystem("true")
+ end
+ end
+ end
+end

0 comments on commit e4a94be

Please sign in to comment.