diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2014-09-08 05:32:16 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2014-09-08 05:32:16 -0700 |
commit | 2b41343c34bcbe809537590152506690b84832df (patch) | |
tree | 69f539c5aac0ff73901eac2df5512b0cb9d3f947 /activesupport/test | |
parent | c3207a12be646483e7e0ce8c916e730e7ea5070d (diff) | |
download | rails-2b41343c34bcbe809537590152506690b84832df.tar.gz rails-2b41343c34bcbe809537590152506690b84832df.tar.bz2 rails-2b41343c34bcbe809537590152506690b84832df.zip |
Default to sorting user's test cases for now
Goals:
1. Default to :random for newly generated applications
2. Default to :sorted for existing applications with a warning
3. Only show the warning once
4. Only show the warning if the app actually uses AS::TestCase
Fixes #16769
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/abstract_unit.rb | 2 | ||||
-rw-r--r-- | activesupport/test/test_case_test.rb | 47 |
2 files changed, 48 insertions, 1 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index 52fbaf8a85..f65ec962f9 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -42,4 +42,4 @@ require 'mocha/setup' # FIXME: stop using mocha # FIXME: we have tests that depend on run order, we should fix that and # remove this method call. require 'active_support/test_case' -ActiveSupport::TestCase.my_tests_are_order_dependent! +ActiveSupport::TestCase.test_order = :sorted diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index c93192f207..5e852c8050 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -172,3 +172,50 @@ class TestCaseTaggedLoggingTest < ActiveSupport::TestCase assert_match "#{self.class}: #{name}\n", @out.string end end + +class TestOrderTest < ActiveSupport::TestCase + def setup + @original_test_order = ActiveSupport::TestCase.test_order + end + + def teardown + ActiveSupport::TestCase.test_order = @original_test_order + end + + def test_defaults_to_sorted_with_warning + ActiveSupport::TestCase.test_order = nil + + assert_equal :sorted, assert_deprecated { ActiveSupport::TestCase.test_order } + + # It should only produce a deprecation warning the first time this is accessed + assert_equal :sorted, assert_not_deprecated { ActiveSupport::TestCase.test_order } + assert_equal :sorted, assert_not_deprecated { ActiveSupport.test_order } + end + + def test_test_order_is_global + ActiveSupport::TestCase.test_order = :random + + assert_equal :random, ActiveSupport.test_order + assert_equal :random, ActiveSupport::TestCase.test_order + assert_equal :random, self.class.test_order + assert_equal :random, Class.new(ActiveSupport::TestCase).test_order + + ActiveSupport.test_order = :sorted + + assert_equal :sorted, ActiveSupport.test_order + assert_equal :sorted, ActiveSupport::TestCase.test_order + assert_equal :sorted, self.class.test_order + assert_equal :sorted, Class.new(ActiveSupport::TestCase).test_order + end + + def test_i_suck_and_my_tests_are_order_dependent! + ActiveSupport::TestCase.test_order = :random + + klass = Class.new(ActiveSupport::TestCase) do + i_suck_and_my_tests_are_order_dependent! + end + + assert_equal :alpha, klass.test_order + assert_equal :random, ActiveSupport::TestCase.test_order + end +end |