diff options
author | Jamis Buck <jamis@37signals.com> | 2005-09-19 21:36:36 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-09-19 21:36:36 +0000 |
commit | 390280b842605d78ec1ab968605e5968677c9400 (patch) | |
tree | eb9c062d3043c2a4e510a2e7afd89d89f1d45a52 /actionpack/test/testing_sandbox.rb | |
parent | 5da4c397826b26368efdd0eefc433f990bc90345 (diff) | |
download | rails-390280b842605d78ec1ab968605e5968677c9400.tar.gz rails-390280b842605d78ec1ab968605e5968677c9400.tar.bz2 rails-390280b842605d78ec1ab968605e5968677c9400.zip |
Make the truncate() helper multi-byte safe (assuming $KCODE has been set to something other than "NONE") #2103
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2265 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/testing_sandbox.rb')
-rw-r--r-- | actionpack/test/testing_sandbox.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/actionpack/test/testing_sandbox.rb b/actionpack/test/testing_sandbox.rb new file mode 100644 index 0000000000..b21f411730 --- /dev/null +++ b/actionpack/test/testing_sandbox.rb @@ -0,0 +1,26 @@ +module TestingSandbox + + # This whole thing *could* be much simpler, but I don't think Tempfile, + # popen and others exist on all platforms (like Windows). + def execute_in_sandbox(code) + test_name = "#{File.dirname(__FILE__)}/test.#{$$}.rb" + res_name = "#{File.dirname(__FILE__)}/test.#{$$}.out" + + File.open(test_name, "w+") do |file| + file.write(<<-CODE) + $:.unshift "../lib" + block = Proc.new do + #{code} + end + print block.call + CODE + end + + system("ruby #{test_name} > #{res_name}") or raise "could not run test in sandbox" + File.read(res_name) + ensure + File.delete(test_name) rescue nil + File.delete(res_name) rescue nil + end + +end |