Manage sandbox test resources in setup/teardown

This commit is contained in:
Jack Nagel 2015-04-28 22:36:54 -04:00
parent a972565739
commit ba26567b03

View File

@ -4,25 +4,25 @@ require "sandbox"
class SandboxTest < Homebrew::TestCase class SandboxTest < Homebrew::TestCase
def setup def setup
skip "sandbox not implemented" unless Sandbox.available? skip "sandbox not implemented" unless Sandbox.available?
@sandbox = Sandbox.new
@dir = Pathname.new(Dir.mktmpdir)
@file = @dir/"foo"
end
def teardown
@dir.rmtree
end end
def test_allow_write def test_allow_write
s = Sandbox.new @sandbox.allow_write @file
testpath = Pathname.new(TEST_TMPDIR) @sandbox.exec "touch", @file
foo = testpath/"foo" assert_predicate @file, :exist?
s.allow_write foo
s.exec "touch", foo
assert_predicate foo, :exist?
foo.unlink
end end
def test_deny_write def test_deny_write
s = Sandbox.new
testpath = Pathname.new(TEST_TMPDIR)
bar = testpath/"bar"
shutup do shutup do
assert_raises(ErrorDuringExecution) { s.exec "touch", bar } assert_raises(ErrorDuringExecution) { @sandbox.exec "touch", @file }
end end
refute_predicate bar, :exist? refute_predicate @file, :exist?
end end
end end