Module: FileSandbox
- Defined in:
- lib/file_sandbox.rb
Defined Under Namespace
Classes: Sandbox, SandboxFile
Constant Summary
collapse
- VERSION =
"0.2"
Instance Method Summary
collapse
Instance Method Details
#file(name) ⇒ Object
45
46
47
|
# File 'lib/file_sandbox.rb', line 45
def file(name)
SandboxFile.new(File.join(@sandbox.root, name))
end
|
#in_sandbox(&block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/file_sandbox.rb', line 7
def in_sandbox(&block)
raise "I expected to create a sandbox as you passed in a block to me" if !block_given?
setup_sandbox
original_error = nil
begin
Dir.chdir(@sandbox.root) do
yield @sandbox
end
rescue => e
original_error = e
raise
ensure
begin
teardown_sandbox
rescue
if original_error
STDERR.puts "ALERT: a test raised an error and failed to release some lock(s) in the sandbox directory"
raise(original_error)
else
raise
end
end
end
end
|
#setup_sandbox(path = '__sandbox') ⇒ Object
34
35
36
|
# File 'lib/file_sandbox.rb', line 34
def setup_sandbox(path = '__sandbox')
@sandbox = Sandbox.new(path)
end
|
#teardown_sandbox ⇒ Object
38
39
40
41
42
43
|
# File 'lib/file_sandbox.rb', line 38
def teardown_sandbox
if @sandbox
@sandbox.clean_up
@sandbox = nil
end
end
|