Sha256: 22dc8258e9c2d776906535e13df6c4ccb415a9b9d781197c2c47eb41e11480bc

Contents?: true

Size: 746 Bytes

Versions: 4

Compression:

Stored size: 746 Bytes

Contents

# encoding: utf-8
require "yaml"

# Returns the path to the temporary `spec/tmp/sandbox`.
# @return [String] The absolute path.
def sandbox
  @sandbox ||= File.expand_path "spec/tmp/sandbox"
end

# Clears the temporary `spec/sandbox`.
def clear_sandbox
  FileUtils.rm_rf sandbox
end

# Re-creates the temporary `spec/sandbox`.
def prepare_sandbox
  clear_sandbox
  FileUtils.mkdir_p sandbox
end

# Runs code from the temporary `spec/sandbox`.
def try_in_sandbox
  FileUtils.cd(sandbox) { yield }
end

# Reads file in sandbox and returns file content.
# Returns a blank string when the file is absent.
# @return [String] The content.
def read_in_sandbox(filename)
  file = Dir[File.join(sandbox, filename)].first
  file ? File.read(file) : ""
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hexx-rspec-0.4.2 config/initializers/sandbox/helpers.rb
hexx-rspec-0.4.1 config/initializers/sandbox/helpers.rb
hexx-rspec-0.4.0 config/initializers/sandbox/helpers.rb
hexx-rspec-0.3.1 config/initializers/sandbox/helpers.rb