Module: FileSandbox
- Defined in:
- spec_help/file-sandbox.rb
Defined Under Namespace
Classes: HaveContents, Sandbox, SandboxFile
Instance Attribute Summary (collapse)
-
- (Object) sandbox
readonly
Returns the value of attribute sandbox.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) have_contents(expected)
- - (Object) in_sandbox(&block)
- - (Object) setup_sandbox(path = '__sandbox')
- - (Object) teardown_sandbox
Instance Attribute Details
- (Object) sandbox (readonly)
Returns the value of attribute sandbox
36 37 38 |
# File 'spec_help/file-sandbox.rb', line 36 def sandbox @sandbox end |
Class Method Details
+ (Object) included(spec)
5 6 7 8 9 10 11 12 13 14 15 |
# File 'spec_help/file-sandbox.rb', line 5 def self.included(spec) return unless spec.respond_to? :before spec.before do setup_sandbox end spec.after do teardown_sandbox end end |
Instance Method Details
- (Object) have_contents(expected)
32 33 34 |
# File 'spec_help/file-sandbox.rb', line 32 def have_contents(expected) HaveContents.new(expected) end |
- (Object) in_sandbox(&block)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'spec_help/file-sandbox.rb', line 38 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 yield @sandbox 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 |
- (Object) setup_sandbox(path = '__sandbox')
63 64 65 66 67 68 69 |
# File 'spec_help/file-sandbox.rb', line 63 def setup_sandbox(path = '__sandbox') unless @sandbox @sandbox = Sandbox.new(path) @__old_path_for_sandbox = Dir.pwd Dir.chdir(@sandbox.root) end end |
- (Object) teardown_sandbox
71 72 73 74 75 76 77 |
# File 'spec_help/file-sandbox.rb', line 71 def teardown_sandbox if @sandbox Dir.chdir(@__old_path_for_sandbox) @sandbox.clean_up @sandbox = nil end end |