test/test_helper.rb in carrot-0.8.1 vs test/test_helper.rb in carrot-1.0.0

- old
+ new

@@ -1,18 +1,27 @@ -require 'rubygems' +dir = File.dirname(File.expand_path(__FILE__)) +$LOAD_PATH.unshift dir + '/../lib' +require 'carrot' require 'test/unit' -#require 'shoulda' -require 'mocha' -require File.dirname(__FILE__) + '/../lib/carrot' +require 'rubygems' +require 'pp' -class << Test::Unit::TestCase - def test(name, &block) - test_name = "test_#{name.gsub(/[\s\W]/,'_')}" - raise ArgumentError, "#{test_name} is already defined" if self.instance_methods.include? test_name - define_method test_name, &block +## +# 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 - - def xtest(name, &block) - # no-op, an empty test method is defined to prevent "no tests in testcase" errors when all tests are disabled - define_method(:test_disabled) { assert true } - end + (class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') } + klass.class_eval &block end