Skip to content

Instantly share code, notes, and snippets.

@foca
Created May 12, 2009 20:31
Show Gist options
  • Save foca/110723 to your computer and use it in GitHub Desktop.
Save foca/110723 to your computer and use it in GitHub Desktop.
class Test::Unit::TestCase
def self.setup(&block)
include module_with_callback(:setup, &block)
end
def self.teardown(&block)
include module_with_callback(:teardown, &block)
end
def self.global_setup(&block)
include module_with_callback(:global_setup, &block)
end
def self.global_teardown(&block)
include module_with_callback(:global_teardown, &block)
end
class << self
alias_method :before, :setup
alias_method :after, :teardown
alias_method :before_all, :global_setup
alias_method :after_all, :global_teardown
end
def setup
unless @__global_setup_run
@__global_setup_run = true
global_setup
end
end
def teardown
unless @__global_teardown_run
@__global_teardown_run = true
global_teardown
end
end
def global_setup; end
def global_teardown; end
def self.module_with_callback(name, &block)
Module.new { define_method(name, &block) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment