Hi all,
Is there a way to perform $SAFE checks with test-unit? I tried this
with Ruby 1.8.6:
require ‘test/unit’
class TC_Hash_Replace < Test::Unit::TestCase
def setup
$SAFE = 0
end
def test_replace_in_safe_mode
$SAFE = 4
assert_raise(SecurityError){ {1,2,3,4}.replace({‘a’, ‘b’}) }
end
def teardown
$SAFE = 0
end
end
Running that causes this error:
/usr/local/lib/ruby/1.8/test/unit/testcase.rb:136:in add_error': Insecure: can't modify instance variable (SecurityError) from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:91:in
run’
from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in
run' from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in
each’
from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in
run' from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in
run’
from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in
each' from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in
run’
from /usr/local/lib/ruby/1.8/test/unit/ui/
testrunnermediator.rb:46:in run_suite' from /usr/local/lib/ruby/1.8/test/unit/ui/console/ testrunner.rb:67:in
start_mediator’
from /usr/local/lib/ruby/1.8/test/unit/ui/console/
testrunner.rb:41:in start' from /usr/local/lib/ruby/1.8/test/unit/ui/ testrunnerutilities.rb:29:in
run’
from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:216:in
run' from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:12:in
run’
from /usr/local/lib/ruby/1.8/test/unit.rb:278
If it’s not possible, consider it a feature request. I’ve no idea how
to implement it, however. Perhaps run it in a Sandbox? Dunno.
I haven’t tried rspec yet to see what it does.
Thanks,
Dan