Class: Furnish::Test

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/furnish/test.rb

Overview

Furnish::TestCase is a test harness for testing things with furnish, like provisioner libraries. It is intended to be consumed by other libraries.

There are few others, such as SchedulerTestCase and RunningSchedulerTestCase which are tuned to specific scenarios, but inherit from this class.

The basic case initializes furnish and the logger in a safe way in setup, and cleans up in teardown.

If FURNISH_DEBUG is present in the environment, the output of the furnish log will be presented to the standard error. Otherwise, it is sent a log file.

Direct Known Subclasses

SchedulerTest

Instance Method Summary collapse

Instance Method Details

#setupObject

:nodoc:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/furnish/test.rb', line 24

def setup # :nodoc:
  unless Furnish.initialized? or (Minitest.respond_to?(:keep_scheduler) and Minitest.keep_scheduler rescue nil)
    @tempfiles ||= []
    file = Tempfile.new('furnish_db')
    @tempfiles.push(file)
    if ENV["FURNISH_DEBUG"]
      Furnish.logger = Furnish::Logger.new($stderr, 3)
    else
      logfile = Tempfile.new('furnish_log')
      @tempfiles.push(logfile)
      Furnish.logger = Furnish::Logger.new(logfile, 3)
    end
    Furnish.init(file.path)
  end
end

#teardownObject

:nodoc:



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/furnish/test.rb', line 40

def teardown # :nodoc:
  unless ENV["FURNISH_DEBUG"]
    Furnish.logger.close
  end

  if Furnish.initialized? and !(Minitest.respond_to?(:keep_scheduler) and Minitest.keep_scheduler rescue nil)
    Furnish.shutdown
    @tempfiles.each do |file|
      file.unlink
    end
  end
end