sandbox: add test? method.

Simplify checking if we’re going to sandbox a test with `Sandbox.test?`.
This commit is contained in:
Mike McQuaid 2016-08-14 17:33:05 +01:00
parent b630ab3d17
commit fed96385ac
2 changed files with 11 additions and 0 deletions

View File

@ -8,6 +8,11 @@ class Sandbox
OS.mac? && File.executable?(SANDBOX_EXEC)
end
def self.test?
return false unless available?
!ARGV.no_sandbox?
end
def self.print_sandbox_message
unless @printed_sandbox_message
ohai "Using the sandbox"

View File

@ -13,6 +13,12 @@ class SandboxTest < Homebrew::TestCase
@dir.rmtree
end
def test_test?
ARGV.stubs(:no_sandbox?).returns false
assert Sandbox.test?,
"Tests should be sandboxed unless --no-sandbox was passed."
end
def test_allow_write
@sandbox.allow_write @file
@sandbox.exec "touch", @file