Sha256: cd01d365bc31af4a9d0bc52a7078642ee114587074e65adfcd32f1c1f6ff69c0

Contents?: true

Size: 740 Bytes

Versions: 4

Compression:

Stored size: 740 Bytes

Contents

# encoding: utf-8
require "yaml"

# Returns the path to the temporary `spec/sandbox`.
# @return [String] The absolute path.
def sandbox
  @sandbox ||= File.expand_path "../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.3.0 config/initializers/sandbox/helpers.rb
hexx-rspec-0.2.2 config/initializers/sandbox/helpers.rb
hexx-rspec-0.2.1 config/initializers/sandbox/helpers.rb
hexx-rspec-0.2.0 config/initializers/sandbox/helpers.rb