2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2016-08-06 11:58:50 -04:00
|
|
|
gem "minitest" # make sure we get the gem, not stdlib
|
|
|
|
require "minitest"
|
2017-10-21 09:11:29 -04:00
|
|
|
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/declarative"
|
|
|
|
require "active_support/testing/isolation"
|
|
|
|
require "active_support/testing/constant_lookup"
|
|
|
|
require "active_support/testing/time_helpers"
|
|
|
|
require "active_support/testing/file_fixtures"
|
2008-11-23 17:48:36 -05:00
|
|
|
|
2008-11-22 22:18:30 -05:00
|
|
|
module ActiveSupport
|
2013-05-06 20:38:45 -04:00
|
|
|
class TestCase < ::Minitest::Test
|
|
|
|
Assertion = Minitest::Assertion
|
|
|
|
|
2014-08-12 09:51:41 -04:00
|
|
|
class << self
|
2014-12-17 17:55:15 -05:00
|
|
|
# Sets the order in which test cases are run.
|
|
|
|
#
|
|
|
|
# ActiveSupport::TestCase.test_order = :random # => :random
|
|
|
|
#
|
|
|
|
# Valid values are:
|
|
|
|
# * +:random+ (to run tests in random order)
|
|
|
|
# * +:parallel+ (to run tests in parallel)
|
|
|
|
# * +:sorted+ (to run tests alphabetically by method name)
|
|
|
|
# * +:alpha+ (equivalent to +:sorted+)
|
2014-09-08 08:32:16 -04:00
|
|
|
def test_order=(new_order)
|
2014-09-10 23:54:43 -04:00
|
|
|
ActiveSupport.test_order = new_order
|
2014-09-08 08:32:16 -04:00
|
|
|
end
|
|
|
|
|
2014-12-17 17:55:15 -05:00
|
|
|
# Returns the order in which test cases are run.
|
|
|
|
#
|
2015-01-02 20:43:06 -05:00
|
|
|
# ActiveSupport::TestCase.test_order # => :random
|
2014-12-17 17:55:15 -05:00
|
|
|
#
|
|
|
|
# Possible values are +:random+, +:parallel+, +:alpha+, +:sorted+.
|
2015-01-02 20:43:06 -05:00
|
|
|
# Defaults to +:random+.
|
2014-09-08 08:32:16 -04:00
|
|
|
def test_order
|
2015-05-04 07:46:12 -04:00
|
|
|
ActiveSupport.test_order ||= :random
|
2014-09-08 08:32:16 -04:00
|
|
|
end
|
2014-08-12 09:51:41 -04:00
|
|
|
end
|
|
|
|
|
2013-05-06 20:38:45 -04:00
|
|
|
alias_method :method_name, :name
|
2008-11-07 12:45:48 -05:00
|
|
|
|
2012-09-26 14:16:43 -04:00
|
|
|
include ActiveSupport::Testing::TaggedLogging
|
2008-11-07 12:45:48 -05:00
|
|
|
include ActiveSupport::Testing::SetupAndTeardown
|
|
|
|
include ActiveSupport::Testing::Assertions
|
2008-11-23 16:11:07 -05:00
|
|
|
include ActiveSupport::Testing::Deprecation
|
Add `#travel` and `#travel_to` to AS::TestCase
Add `ActiveSupport::Testing::TimeHelpers#travel` and `#travel_to`. These
methods change current time to the given time or time difference by
stubbing `Time.now` and `Date.today` to return the time or date after
the difference calculation, or the time or date that got passed into the
method respectively. These methods also accept a block, which will
return current time back to its original state at the end of the block.
Example for `#travel`:
Time.now # => 2013-11-09 15:34:49 -05:00
travel 1.day
Time.now # => 2013-11-10 15:34:49 -05:00
Date.today # => Sun, 10 Nov 2013
Example for `#travel_to`:
Time.now # => 2013-11-09 15:34:49 -05:00
travel_to Time.new(2004, 11, 24, 01, 04, 44)
Time.now # => 2004-11-24 01:04:44 -05:00
Date.today # => Wed, 24 Nov 2004
Both of these methods also accept a block, which will return the current
time back to its original state at the end of the block:
Time.now # => 2013-11-09 15:34:49 -05:00
travel 1.day do
User.create.created_at # => Sun, 10 Nov 2013 15:34:49 EST -05:00
end
travel_to Time.new(2004, 11, 24, 01, 04, 44) do
User.create.created_at # => Wed, 24 Nov 2004 01:04:44 EST -05:00
end
Time.now # => 2013-11-09 15:34:49 -05:00
This module is included in `ActiveSupport::TestCase` automatically.
2013-11-09 13:03:28 -05:00
|
|
|
include ActiveSupport::Testing::TimeHelpers
|
2015-01-23 09:45:34 -05:00
|
|
|
include ActiveSupport::Testing::FileFixtures
|
2012-12-28 12:06:10 -05:00
|
|
|
extend ActiveSupport::Testing::Declarative
|
2012-01-05 18:46:17 -05:00
|
|
|
|
|
|
|
# test/unit backwards compatibility methods
|
|
|
|
alias :assert_raise :assert_raises
|
2012-12-28 18:49:41 -05:00
|
|
|
alias :assert_not_empty :refute_empty
|
2012-01-05 18:46:17 -05:00
|
|
|
alias :assert_not_equal :refute_equal
|
2012-12-28 18:49:41 -05:00
|
|
|
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
|
2012-01-05 18:46:17 -05:00
|
|
|
alias :assert_no_match :refute_match
|
2012-12-28 18:49:41 -05:00
|
|
|
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
|
2012-01-06 17:04:09 -05:00
|
|
|
alias :assert_not_same :refute_same
|
2016-10-21 17:44:17 -04:00
|
|
|
|
|
|
|
ActiveSupport.run_load_hooks(:active_support_test_case, self)
|
2008-11-07 12:45:48 -05:00
|
|
|
end
|
2008-11-22 22:18:30 -05:00
|
|
|
end
|