Sha256: 26ee8dffc5b3b380c15de6fb89f6ff6092c00bf2d9095105a8120fc4736a6332

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

# Copyright 2006-2007 Michel Casabianca <michel.casabianca@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'test/unit'
require 'fileutils'

# Test case that creates a 'tmp' directory before each test and deletes it
# after. Also disable tests if we can't write on disk (if we run tests while
# installing with gem in a system directory for instance).
class TmpTestCase < Test::Unit::TestCase

  # Temporary directory.
  TEMP_DIR = 'tmp'

  # Constructor: disable test if we don't have write permission.
  def initialize(*args)
    super(*args)
    @home = File.expand_path(File.dirname(__FILE__))
    @working_dir = Dir.getwd
    @tmp_dir = File.join(@home, TEMP_DIR)
    begin
      FileUtils.makedirs(@tmp_dir)
      @run_tests = true
    rescue
      @run_tests = false
      methods = self.class.public_instance_methods
      for method in methods
        self.class.remove_method(Symbol.new(method)) if method =~ /^test_.*/
      end
    end
  end
  
  # Run before any test: create temporary directory.
  def setup
    FileUtils.makedirs(@tmp_dir)
  end
  
  # Run after any test: delete temporary directory.
  def teardown
    Dir.chdir(@working_dir)
    FileUtils.rm_rf(@tmp_dir)
  end
  
  def test_
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bee-0.4.0 test/tmp_test_case.rb