test_case.rb 1.9 KB
Newer Older
1
gem 'minitest' # make sure we get the gem, not stdlib
2
require 'minitest/spec'
3 4 5
require 'active_support/testing/setup_and_teardown'
require 'active_support/testing/assertions'
require 'active_support/testing/deprecation'
6
require 'active_support/testing/isolation'
7
require 'active_support/testing/mocha_module'
8
require 'active_support/core_ext/kernel/reporting'
9
require 'active_support/deprecation'
10

11
module ActiveSupport
12 13
  class TestCase < ::MiniTest::Spec

14 15
    include ActiveSupport::Testing::MochaModule

16 17
    # Use AS::TestCase for the base class when describing a model
    register_spec_type(self) do |desc|
18
      Class === desc && desc < ActiveRecord::Model
19 20
    end

V
Vishnu Atrai 已提交
21
    Assertion = MiniTest::Assertion
22
    alias_method :method_name, :__name__
23

24 25 26 27 28
    $tags = {}
    def self.for_tag(tag)
      yield if $tags[tag]
    end

29 30 31 32 33 34
    # FIXME: we have tests that depend on run order, we should fix that and
    # remove this method.
    def self.test_order # :nodoc:
      :sorted
    end

35 36
    include ActiveSupport::Testing::SetupAndTeardown
    include ActiveSupport::Testing::Assertions
37
    include ActiveSupport::Testing::Deprecation
38 39 40 41 42 43 44 45 46 47 48 49 50 51

    def self.describe(text)
      if block_given?
        super
      else
        ActiveSupport::Deprecation.warn("`describe` without a block is deprecated, please switch to: `def self.name; #{text.inspect}; end`\n")

        class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
          def self.name
            "#{text}"
          end
        RUBY_EVAL
      end
    end
52 53 54 55

    class << self
      alias :test :it
    end
56 57 58 59 60 61

    # test/unit backwards compatibility methods
    alias :assert_raise :assert_raises
    alias :assert_not_nil :refute_nil
    alias :assert_not_equal :refute_equal
    alias :assert_no_match :refute_match
A
Aaron Patterson 已提交
62
    alias :assert_not_same :refute_same
63

64 65 66 67 68
    # Fails if the block raises an exception.
    #
    #   assert_nothing_raised do
    #     ...
    #   end
69 70 71
    def assert_nothing_raised(*args)
      yield
    end
72
  end
73
end