Skip to content

Instantly share code, notes, and snippets.

@endel
Forked from defunkt/test-spec-mini.rb
Created April 7, 2011 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endel/906858 to your computer and use it in GitHub Desktop.
Save endel/906858 to your computer and use it in GitHub Desktop.
##
# test/spec/mini 3
# http://gist.github.com/25455
# chris@ozmm.org
# file:lib/test/spec/mini.rb
#
def context(*args, &block)
return super unless (name = args.first) && block
require 'test/unit'
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
def self.test(name, &block)
define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
end
def self.xtest(*args) end
def self.setup(&block) define_method(:setup, &block) end
def self.teardown(&block) define_method(:teardown, &block) end
end
(class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
klass.class_eval &block
# XXX: In 1.8.x, not all tests will run unless anonymous classes are kept in scope.
($test_classes ||= []) << klass
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment