Skip to content

Commit

Permalink
Add using Turn with natural language test case names if the library i…
Browse files Browse the repository at this point in the history
…s available (which it will be in Rails 3.1) [DHH]
  • Loading branch information
dhh committed Mar 31, 2011
1 parent edf7c9a commit 6eff044
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
2 changes: 2 additions & 0 deletions activesupport/CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
*Rails 3.1.0 (unreleased)* *Rails 3.1.0 (unreleased)*


* Add using Turn with natural language test case names if the library is available (which it will be in Rails 3.1) [DHH]

* LocalCache strategy is now a real middleware class, not an anonymous class * LocalCache strategy is now a real middleware class, not an anonymous class
posing for pictures. posing for pictures.


Expand Down
19 changes: 2 additions & 17 deletions activesupport/lib/active_support/test_case.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,25 +5,10 @@
require 'active_support/testing/declarative' require 'active_support/testing/declarative'
require 'active_support/testing/pending' require 'active_support/testing/pending'
require 'active_support/testing/isolation' require 'active_support/testing/isolation'
require 'active_support/testing/turn_formatting'
require 'active_support/testing/mochaing'
require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/kernel/reporting'


begin
silence_warnings { require 'mocha' }
rescue LoadError
# Fake Mocha::ExpectationError so we can rescue it in #run. Bleh.
Object.const_set :Mocha, Module.new
Mocha.const_set :ExpectationError, Class.new(StandardError)
end

# Added by Turn to support natural case names in the output formatting
if defined?(MiniTest)
require 'turn'

if MiniTest::Unit.respond_to?(:use_natural_language_case_names=)
MiniTest::Unit.use_natural_language_case_names = true
end
end

module ActiveSupport module ActiveSupport
class TestCase < ::Test::Unit::TestCase class TestCase < ::Test::Unit::TestCase
if defined? MiniTest if defined? MiniTest
Expand Down
7 changes: 7 additions & 0 deletions activesupport/lib/active_support/testing/mochaing.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
begin
silence_warnings { require 'mocha' }
rescue LoadError
# Fake Mocha::ExpectationError so we can rescue it in #run. Bleh.
Object.const_set :Mocha, Module.new
Mocha.const_set :ExpectationError, Class.new(StandardError)
end
33 changes: 33 additions & 0 deletions activesupport/lib/active_support/testing/turn_formatting.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,33 @@
# Turn gives you prettier formatting for MiniTest and inline failure reporting.
# It also allows us to report test cases in natural language rather than with underscores. Example:
#
# CommentsControllerTest:
# PASS the truth (0.03s)
#
# APITest
# test_api_without_subdomain PASS
# test_create_milestone_using_typed_xml FAIL
# /test/integration/api_test.rb:50:in `test_create_milestone_using_typed_xml'
# <2006-05-01> expected but was
# <Mon May 01 07:00:00 UTC 2006>.
# test_create_milestone_using_untyped_xml FAIL
# /test/integration/api_test.rb:38:in `test_create_milestone_using_untyped_xml'
# <2006-05-01> expected but was
# <Mon May 01 07:00:00 UTC 2006>.

#
# vs:
#
# .FF

if defined?(MiniTest)
begin
silence_warnings { require 'turn' }

if MiniTest::Unit.respond_to?(:use_natural_language_case_names=)
MiniTest::Unit.use_natural_language_case_names = true
end
rescue LoadError
# If there's no turn, that's fine, it's just formatting
end
end

1 comment on commit 6eff044

@janx
Copy link
Contributor

@janx janx commented on 6eff044 Apr 2, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! The only one problem is there's no aggregate error information at last, so I have to scroll back to find failed tests :(

Please sign in to comment.