From 286709336577c767498785bc7be486eefe3faa4b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 30 Mar 2011 21:16:29 -0700 Subject: Delegate pending to skip if Minitest is available --- .../lib/active_support/testing/pending.rb | 46 ++++++++++++---------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/pending.rb b/activesupport/lib/active_support/testing/pending.rb index 3d119e2fba..feac7bc347 100644 --- a/activesupport/lib/active_support/testing/pending.rb +++ b/activesupport/lib/active_support/testing/pending.rb @@ -11,32 +11,36 @@ module ActiveSupport @@at_exit = false def pending(description = "", &block) - if description.is_a?(Symbol) - is_pending = $tags[description] - return block.call unless is_pending - end + if defined?(::MiniTest) + skip(description.blank? ? nil : description) + else + if description.is_a?(Symbol) + is_pending = $tags[description] + return block.call unless is_pending + end - if block_given? - failed = false + if block_given? + failed = false - begin - block.call - rescue Exception - failed = true - end + begin + block.call + rescue Exception + failed = true + end - flunk("<#{description}> did not fail.") unless failed - end + flunk("<#{description}> did not fail.") unless failed + end - caller[0] =~ (/(.*):(.*):in `(.*)'/) - @@pending_cases << "#{$3} at #{$1}, line #{$2}" - print "P" + caller[0] =~ (/(.*):(.*):in `(.*)'/) + @@pending_cases << "#{$3} at #{$1}, line #{$2}" + print "P" - @@at_exit ||= begin - at_exit do - puts "\nPending Cases:" - @@pending_cases.each do |test_case| - puts test_case + @@at_exit ||= begin + at_exit do + puts "\nPending Cases:" + @@pending_cases.each do |test_case| + puts test_case + end end end end -- cgit v1.2.3 From b27057731cba8678265026f0fdfe75f5ae411d4d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 31 Mar 2011 12:11:03 -0700 Subject: Use Turn to format all Rails tests and enable the natural language case names --- activesupport/lib/active_support/test_case.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index fb52fc7083..a48656192c 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -15,6 +15,11 @@ rescue LoadError Mocha.const_set :ExpectationError, Class.new(StandardError) end +# Added by Turn to support natural case names in the output formatting +if defined?(MiniTest) && MiniTest::Unit.respond_to?(:use_natural_language_case_names=) + MiniTest::Unit.use_natural_language_case_names = true +end + module ActiveSupport class TestCase < ::Test::Unit::TestCase if defined? MiniTest -- cgit v1.2.3 From edf7c9a6a3331bfc0beabc9dc9c8beac22677e53 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 31 Mar 2011 12:17:28 -0700 Subject: require turn only for minitest --- activesupport/lib/active_support/test_case.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index a48656192c..d25b092fb4 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -16,8 +16,12 @@ rescue LoadError end # Added by Turn to support natural case names in the output formatting -if defined?(MiniTest) && MiniTest::Unit.respond_to?(:use_natural_language_case_names=) - MiniTest::Unit.use_natural_language_case_names = true +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 -- cgit v1.2.3 From 6eff04499e28865890e1ae3915fe80e4903a997b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 31 Mar 2011 12:25:04 -0700 Subject: Add using Turn with natural language test case names if the library is available (which it will be in Rails 3.1) [DHH] --- activesupport/lib/active_support/test_case.rb | 19 ++----------- .../lib/active_support/testing/mochaing.rb | 7 +++++ .../lib/active_support/testing/turn_formatting.rb | 33 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 activesupport/lib/active_support/testing/mochaing.rb create mode 100644 activesupport/lib/active_support/testing/turn_formatting.rb (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index d25b092fb4..7ac9ad46e9 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -5,25 +5,10 @@ require 'active_support/testing/deprecation' require 'active_support/testing/declarative' require 'active_support/testing/pending' require 'active_support/testing/isolation' +require 'active_support/testing/turn_formatting' +require 'active_support/testing/mochaing' 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 class TestCase < ::Test::Unit::TestCase if defined? MiniTest diff --git a/activesupport/lib/active_support/testing/mochaing.rb b/activesupport/lib/active_support/testing/mochaing.rb new file mode 100644 index 0000000000..4ad75a6681 --- /dev/null +++ b/activesupport/lib/active_support/testing/mochaing.rb @@ -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 \ No newline at end of file diff --git a/activesupport/lib/active_support/testing/turn_formatting.rb b/activesupport/lib/active_support/testing/turn_formatting.rb new file mode 100644 index 0000000000..ed9381e298 --- /dev/null +++ b/activesupport/lib/active_support/testing/turn_formatting.rb @@ -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 +# . +# 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 +# . + +# +# 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 \ No newline at end of file -- cgit v1.2.3 From 0eb6e5e270c0a1114fdafe4a8daa35ee88e176e3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 31 Mar 2011 16:20:59 -0700 Subject: Moved Turn activation/dependency to railties --- activesupport/lib/active_support/test_case.rb | 1 - .../lib/active_support/testing/turn_formatting.rb | 33 ---------------------- 2 files changed, 34 deletions(-) delete mode 100644 activesupport/lib/active_support/testing/turn_formatting.rb (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 7ac9ad46e9..8d6c27e381 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -5,7 +5,6 @@ require 'active_support/testing/deprecation' require 'active_support/testing/declarative' require 'active_support/testing/pending' require 'active_support/testing/isolation' -require 'active_support/testing/turn_formatting' require 'active_support/testing/mochaing' require 'active_support/core_ext/kernel/reporting' diff --git a/activesupport/lib/active_support/testing/turn_formatting.rb b/activesupport/lib/active_support/testing/turn_formatting.rb deleted file mode 100644 index ed9381e298..0000000000 --- a/activesupport/lib/active_support/testing/turn_formatting.rb +++ /dev/null @@ -1,33 +0,0 @@ -# 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 -# . -# 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 -# . - -# -# 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 \ No newline at end of file -- cgit v1.2.3