summaryrefslogtreecommitdiff
path: root/test/test_helper.rb
blob: e0cd1e13621c4dc87bb644316796414a1d7926fd (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require 'rubygems'
require File.expand_path('../../lib/leap_cli/load_paths', __FILE__)
require 'bundler/setup'
require 'minitest/autorun'
require 'leap_cli'
require 'gli'
require 'fileutils'

DEBUG = true
TEST  = true

module LeapCli::Commands
  extend GLI::App
end

class Minitest::Test
  attr_accessor :ruby_path

  # Add global extensions to the test case class here

  def initialize(*args)
    super(*args)
    LeapCli::Bootstrap::setup([], provider_path)
    LeapCli::Bootstrap::load_libraries(LeapCli::Commands)
  end

  def setup
  end

  def manager
    @manager ||= begin
      manager = LeapCli::Config::Manager.new
      manager.load
      manager
    end
  end

  def provider
    manager.provider
  end

  def base_path
    File.expand_path '../..', __FILE__
  end

  def leap_bin(*args)
    cmd = "cd #{provider_path} && #{base_path}/bin/leap --no-color #{args.join ' '}"
    `#{cmd}`
  end

  def leap_bin!(*args)
    output = leap_bin(*args)
    exit_code = $?
    assert_equal 0, exit_code,
      "The command `leap #{args.join(' ')}` should have exited 0 " +
      "(was #{exit_code}).\n" +
      "Output was: #{output}"
    output
  end

  def provider_path
    "#{base_path}/test/provider"
  end

  #
  # for tests, we assume that the leap_platform code is
  # in a sister directory to leap_cli.
  #
  def platform_path
    "#{base_path}/../leap_platform"
  end

  def cleanup_files(*args)
    Dir.chdir(provider_path) do
      args.each do |file|
        FileUtils.rm_r(file) if File.exist?(file)
      end
    end
  end

  #
  # we no longer support ruby 1.8, but this might be useful in the future
  #
  def with_multiple_rubies(&block)
    yield
  #  if ENV["RUBY"]
  #    ENV["RUBY"].split(',').each do |ruby|
  #      self.ruby_path = `which #{ruby}`.strip
  #      next unless ruby_path.chars.any?
  #      yield
  #    end
  #  else
  #    self.ruby_path = `which ruby`.strip
  #    yield
  #  end
  #  self.ruby_path = ""
  end

end