Skip to content

Commit

Permalink
Change the default test order from :sorted to :random
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Jan 4, 2015
1 parent d6e06ea commit 5f777e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
4 changes: 4 additions & 0 deletions activesupport/CHANGELOG.md
@@ -1,3 +1,7 @@
* Change the default test order from `:sorted` to `:random`.

*Rafael Mendonça França*

* Remove deprecated `ActiveSupport::JSON::Encoding::CircularReferenceError`. * Remove deprecated `ActiveSupport::JSON::Encoding::CircularReferenceError`.


*Rafael Mendonça França* *Rafael Mendonça França*
Expand Down
20 changes: 3 additions & 17 deletions activesupport/lib/active_support/test_case.rb
Expand Up @@ -31,29 +31,15 @@ def test_order=(new_order)


# Returns the order in which test cases are run. # Returns the order in which test cases are run.
# #
# ActiveSupport::TestCase.test_order # => :sorted # ActiveSupport::TestCase.test_order # => :random
# #
# Possible values are +:random+, +:parallel+, +:alpha+, +:sorted+. # Possible values are +:random+, +:parallel+, +:alpha+, +:sorted+.
# Defaults to +:sorted+. # Defaults to +:random+.
def test_order def test_order
test_order = ActiveSupport.test_order test_order = ActiveSupport.test_order


if test_order.nil? if test_order.nil?
ActiveSupport::Deprecation.warn "You did not specify a value for the " \ test_order = :random
"configuration option `active_support.test_order`. In Rails 5, " \
"the default value of this option will change from `:sorted` to " \
"`:random`.\n" \
"To disable this warning and keep the current behavior, you can add " \
"the following line to your `config/environments/test.rb`:\n" \
"\n" \
" Rails.application.configure do\n" \
" config.active_support.test_order = :sorted\n" \
" end\n" \
"\n" \
"Alternatively, you can opt into the future behavior by setting this " \
"option to `:random`."

test_order = :sorted
self.test_order = test_order self.test_order = test_order
end end


Expand Down
24 changes: 11 additions & 13 deletions activesupport/test/test_case_test.rb
Expand Up @@ -182,30 +182,28 @@ def teardown
ActiveSupport::TestCase.test_order = @original_test_order ActiveSupport::TestCase.test_order = @original_test_order
end end


def test_defaults_to_sorted_with_warning def test_defaults_to_random
ActiveSupport::TestCase.test_order = nil ActiveSupport::TestCase.test_order = nil


assert_equal :sorted, assert_deprecated { ActiveSupport::TestCase.test_order } assert_equal :random, ActiveSupport::TestCase.test_order


# It should only produce a deprecation warning the first time this is accessed assert_equal :random, ActiveSupport.test_order
assert_equal :sorted, assert_not_deprecated { ActiveSupport::TestCase.test_order }
assert_equal :sorted, assert_not_deprecated { ActiveSupport.test_order }
end end


def test_test_order_is_global def test_test_order_is_global
ActiveSupport::TestCase.test_order = :random ActiveSupport::TestCase.test_order = :sorted

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.test_order
assert_equal :sorted, ActiveSupport::TestCase.test_order assert_equal :sorted, ActiveSupport::TestCase.test_order
assert_equal :sorted, self.class.test_order assert_equal :sorted, self.class.test_order
assert_equal :sorted, Class.new(ActiveSupport::TestCase).test_order assert_equal :sorted, Class.new(ActiveSupport::TestCase).test_order

ActiveSupport.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
end end


def test_i_suck_and_my_tests_are_order_dependent! def test_i_suck_and_my_tests_are_order_dependent!
Expand Down

0 comments on commit 5f777e4

Please sign in to comment.