Module: Autoshell::TestHelper

Defined in:
lib/autoshell/test_helper.rb

Overview

Helper test class

Constant Summary collapse

REPO_URL =
File.expand_path(
'../../../test/fixtures/autotune-example-blueprint.git', __FILE__)
FIXTURES_PATH =
File.expand_path('../../../test/fixtures', __FILE__)

Instance Method Summary collapse

Instance Method Details

#after_teardownObject



16
17
18
19
20
# File 'lib/autoshell/test_helper.rb', line 16

def after_teardown
  @dirs.values.each do |dir|
    FileUtils.rm_rf(dir) if File.exist?(dir)
  end
end

#autoshell(name) ⇒ Autoshell::Base

autoshell fixture retriever

Parameters:

  • name (Symbol)

    name of the fixture to retrieve

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/autoshell/test_helper.rb', line 34

def autoshell(name)
  @fixtures[name.to_sym] ||= begin
    tmpdir = dir(name)
    dest_path = tmpdir.join(name.to_s)

    # if there is a matching dir in fixtures, copy it to the temp dir
    fixtures_path = File.join(FIXTURES_PATH, name.to_s)
    if Dir.exist? fixtures_path
      FileUtils.mkdir_p(tmpdir)
      FileUtils.cp_r(fixtures_path, dest_path)
    end

    Autoshell.new(dest_path)
  end
end

#before_setupObject



11
12
13
14
# File 'lib/autoshell/test_helper.rb', line 11

def before_setup
  @dirs = {}
  @fixtures = {}
end

#dir(name = :test) ⇒ Pathname

Get a temp dir that will get cleaned-up after this test

Parameters:

  • name (Symbol) (defaults to: :test)

    name name of the tmpdir to get

Returns:

  • (Pathname)

    absolute path



25
26
27
28
# File 'lib/autoshell/test_helper.rb', line 25

def dir(name = :test)
  @dirs[name.to_sym] ||= Pathname.new(
    File.expand_path("#{Dir.tmpdir}/#{Time.now.to_i}#{rand(1000)}/"))
end