Sha256: 6884acbd58570dcba7fd124b2f2f6c651d607ea4c461e1debecdb23ccccf358a

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'test/unit'
require 'fileutils'

$:.unshift("#{File.dirname(__FILE__)}/../lib")

# Ensure the app root is empty
FileUtils.rm_rf('test/app_root')
FileUtils.mkdir('test/app_root')

# Use an in-memory log so that the app root can be removed without having to
# close all loggers in use
require 'logger'
require 'stringio'
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(StringIO.new))

Test::Unit::TestCase.class_eval do
  private
    def assert_valid_environment
      assert_not_nil ApplicationController
      assert ActiveRecord::Base.connection.active?
    end
    
    def setup_app(name)
      FileUtils.cp_r(Dir["test/app_roots/#{name}/*"], 'test/app_root')
      
      # Load the environment
      load 'plugin_test_helper.rb'
      assert_valid_environment
    end
    
    def teardown_app
      # Clear dependencies
      self.class.use_transactional_fixtures = false
      ActiveRecord::Base.reset_subclasses
      ActiveSupport::Dependencies.clear
      
      # Reset open streams
      ActiveRecord::Base.clear_reloadable_connections!
      
      # Forget that the environment files were loaded so that a new app environment
      # can be set up again
      $".delete('config/environment.rb')
      $".delete('test_help.rb')
      
      # Remove the app folder
      FileUtils.rm_r(Dir['test/app_root/*'])
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plugin_test_helper-0.1.6 test/test_helper.rb
plugin_test_helper-0.2.0 test/test_helper.rb