Mongrel2::

SpecHelpers

module

A collection of helper functions that are generally useful for testing Mongrel2::Handlers.

Public Class Methods

anchor
included( context )

Inclusion callback – install some hooks

# File lib/mongrel2/testing.rb, line 20
def self::included( context )

        context.before( :all ) do
                setup_config_db
        end

        context.around( :each ) do |example|
                if (( setting = example.metadata[:db] ))
                        if setting == :no_transaction || setting == :without_transaction
                                Loggability[ Mongrel2 ].debug "  running without a transaction"
                                example.run
                        else
                                Loggability[ Mongrel2 ].debug "  running with a transaction"
                                Mongrel2::Config.db.transaction( rollback: :always ) do
                                        example.run
                                end
                        end
                else
                        example.run
                end
        end

        super
end

Public Instance Methods

anchor
clean_config_db()

Truncate all the tables in the current config DB.

# File lib/mongrel2/testing.rb, line 54
def clean_config_db
        Mongrel2::Config.db.tables.collect {|t| Mongrel2::Config.db[t] }.each( &:truncate )
end
anchor
setup_config_db()

Set up a Mongrel2 configuration database in memory.

# File lib/mongrel2/testing.rb, line 47
def setup_config_db
        Mongrel2::Config.db ||= Mongrel2::Config.in_memory_db
        Mongrel2::Config.init_database!
end