Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jibiel/5286320 to your computer and use it in GitHub Desktop.
Save jibiel/5286320 to your computer and use it in GitHub Desktop.
ActiveSupport Testing to count the Passed Tests when using Test::Unit (ActiveSupport 3.2.13 compatible. More details here — https://github.com/rails/rails/commit/5573c1d29565f17aca48b6a320a676bf9f962f20#activesupport/lib/active_support/testing/setup_and_teardown.rb)
require 'active_support/concern'
require 'active_support/callbacks'
module ActiveSupport
module Testing
module SetupAndTeardown
module ForClassicTestUnit
# This redefinition is unfortunate but test/unit shows us no alternative.
# Doubly unfortunate: hax to support Mocha's hax.
def run(result)
return if @method_name.to_s == "default_test"
mocha_counter = retrieve_mocha_counter(self, result)
yield(Test::Unit::TestCase::STARTED, name)
@_result = result
begin
begin
_run_setup_callbacks do
setup
__send__(@method_name)
mocha_verify(mocha_counter) if mocha_counter
end
result.add_pass
rescue Mocha::ExpectationError => e
add_failure(e.message, e.backtrace)
rescue Test::Unit::AssertionFailedError => e
add_failure(e.message, e.backtrace)
rescue Exception => e
raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
add_error(e)
ensure
begin
teardown
_run_teardown_callbacks
rescue Test::Unit::AssertionFailedError => e
add_failure(e.message, e.backtrace)
rescue Exception => e
raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
add_error(e)
end
end
ensure
mocha_teardown if mocha_counter
end
result.add_run
yield(Test::Unit::TestCase::FINISHED, name)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment