diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-31 14:03:55 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-31 14:03:55 -0300 |
commit | b22c527e65a41da59dbfcb078968069c6fae5086 (patch) | |
tree | fd50b9a5b79cf2e3cd508032aec320c0280b5b99 /activesupport/lib/active_support | |
parent | 5e5107430bccc0a536e0b264c951793d8fe62235 (diff) | |
parent | cf4afc4d11556609802f640135cc7715e4a6a9fe (diff) | |
download | rails-b22c527e65a41da59dbfcb078968069c6fae5086.tar.gz rails-b22c527e65a41da59dbfcb078968069c6fae5086.tar.bz2 rails-b22c527e65a41da59dbfcb078968069c6fae5086.zip |
Merge branch 'minitest_cleanup'
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/test_case.rb | 42 | ||||
-rw-r--r-- | activesupport/lib/active_support/testing/autorun.rb | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/testing/declarative.rb | 40 |
3 files changed, 59 insertions, 28 deletions
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index e4f182a3aa..8b392c36d0 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -1,10 +1,11 @@ gem 'minitest' # make sure we get the gem, not stdlib -require 'minitest/spec' +require 'minitest/unit' require 'active_support/testing/tagged_logging' require 'active_support/testing/setup_and_teardown' require 'active_support/testing/assertions' require 'active_support/testing/deprecation' require 'active_support/testing/pending' +require 'active_support/testing/declarative' require 'active_support/testing/isolation' require 'active_support/testing/constant_lookup' require 'active_support/core_ext/kernel/reporting' @@ -16,13 +17,7 @@ rescue LoadError end module ActiveSupport - class TestCase < ::MiniTest::Spec - - # Use AS::TestCase for the base class when describing a model - register_spec_type(self) do |desc| - Class === desc && desc < ActiveRecord::Base - end - + class TestCase < ::MiniTest::Unit::TestCase Assertion = MiniTest::Assertion alias_method :method_name, :__name__ @@ -42,31 +37,22 @@ module ActiveSupport include ActiveSupport::Testing::Assertions include ActiveSupport::Testing::Deprecation include ActiveSupport::Testing::Pending - - def self.describe(text) - if block_given? - super - else - message = "`describe` without a block is deprecated, please switch to: `def self.name; #{text.inspect}; end`\n" - ActiveSupport::Deprecation.warn message - - class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 - def self.name - "#{text}" - end - RUBY_EVAL - end - end - - class << self - alias :test :it - end + extend ActiveSupport::Testing::Declarative # test/unit backwards compatibility methods alias :assert_raise :assert_raises - alias :assert_not_nil :refute_nil + alias :assert_not_empty :refute_empty alias :assert_not_equal :refute_equal + alias :assert_not_in_delta :refute_in_delta + alias :assert_not_in_epsilon :refute_in_epsilon + alias :assert_not_includes :refute_includes + alias :assert_not_instance_of :refute_instance_of + alias :assert_not_kind_of :refute_kind_of alias :assert_no_match :refute_match + alias :assert_not_nil :refute_nil + alias :assert_not_operator :refute_operator + alias :assert_not_predicate :refute_predicate + alias :assert_not_respond_to :refute_respond_to alias :assert_not_same :refute_same # Fails if the block raises an exception. diff --git a/activesupport/lib/active_support/testing/autorun.rb b/activesupport/lib/active_support/testing/autorun.rb new file mode 100644 index 0000000000..c446adc16d --- /dev/null +++ b/activesupport/lib/active_support/testing/autorun.rb @@ -0,0 +1,5 @@ +gem 'minitest' + +require 'minitest/unit' + +MiniTest::Unit.autorun diff --git a/activesupport/lib/active_support/testing/declarative.rb b/activesupport/lib/active_support/testing/declarative.rb new file mode 100644 index 0000000000..508e37254a --- /dev/null +++ b/activesupport/lib/active_support/testing/declarative.rb @@ -0,0 +1,40 @@ +module ActiveSupport + module Testing + module Declarative + + def self.extended(klass) #:nodoc: + klass.class_eval do + + unless method_defined?(:describe) + def self.describe(text) + class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 + def self.name + "#{text}" + end + RUBY_EVAL + end + end + + end + end + + unless defined?(Spec) + # test "verify something" do + # ... + # end + def test(name, &block) + test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym + defined = instance_method(test_name) rescue false + raise "#{test_name} is already defined in #{self}" if defined + if block_given? + define_method(test_name, &block) + else + define_method(test_name) do + flunk "No implementation provided for #{name}" + end + end + end + end + end + end +end |