File: base_context.rb

package info (click to toggle)
vagrant 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,084 kB
  • sloc: ruby: 15,045; python: 230; sh: 66; makefile: 2; lisp: 1
file content (30 lines) | stat: -rw-r--r-- 730 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require "tempfile"

require "unit/support/isolated_environment"

shared_context "unit" do
  # This creates an isolated environment so that Vagrant doesn't
  # muck around with your real system during unit tests.
  #
  # The returned isolated environment has a variety of helper
  # methods on it to easily create files, Vagrantfiles, boxes,
  # etc.
  def isolated_environment
    env = Unit::IsolatedEnvironment.new
    yield env if block_given?
    env
  end

  # This helper creates a temporary file and returns a Pathname
  # object pointed to it.
  def temporary_file(contents=nil)
    f = Tempfile.new("vagrant-unit")

    if contents
      f.write(contents)
      f.flush
    end

    return Pathname.new(f.path)
  end
end