aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJames Mead <james@floehopper.org>2012-11-12 09:34:21 +0000
committerJames Mead <james@floehopper.org>2012-11-12 09:34:21 +0000
commit57b333e25dc797f6023fb84adcf365bd3ca60509 (patch)
tree1e2ecd0a0ea70e71ec29294ffd61e3a4d10864b8 /activesupport/lib
parent2f3d81c764a8b527299be8c33c64814431f83482 (diff)
downloadrails-57b333e25dc797f6023fb84adcf365bd3ca60509.tar.gz
rails-57b333e25dc797f6023fb84adcf365bd3ca60509.tar.bz2
rails-57b333e25dc797f6023fb84adcf365bd3ca60509.zip
Simplify code by taking advantage of latest mocha (v0.13.0).
This only works with mocha v0.13.0 or later. Note that this also fixes a few subtle bugs present in the current implementation :- * Mocha was raising a `MiniTest::Assertion` instead of a `Mocha::ExpectationError` as intended. The latter is not recognized by MiniTest as an assertion failure and so it is recorded as a test *error*, not a test *failure* as it ought to. This leads to potentially confusing output in the test results. * Mocha verification should happen as part of the test. The verification of expectations is equivalent to a set of assertions. These assertions should happen as *part of* the test so that they have a chance to cause the test to fail, and not just as part of the teardown. Also if an assertion fails during the test, then there is no need to verify expectations, because only the first assertion failure is normally reported and all subsequent bets are off. * Expectation verification should be counted as an assertion. Mocha cannot record each expectation verification as an assertion, because we weren't passing in an assertion counter to `#mocha_verify`.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/test_case.rb8
-rw-r--r--activesupport/lib/active_support/testing/mocha_module.rb22
2 files changed, 5 insertions, 25 deletions
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb
index 8b06739b7f..c96ad17aba 100644
--- a/activesupport/lib/active_support/test_case.rb
+++ b/activesupport/lib/active_support/test_case.rb
@@ -5,16 +5,18 @@ require 'active_support/testing/setup_and_teardown'
require 'active_support/testing/assertions'
require 'active_support/testing/deprecation'
require 'active_support/testing/isolation'
-require 'active_support/testing/mocha_module'
require 'active_support/testing/constant_lookup'
require 'active_support/core_ext/kernel/reporting'
require 'active_support/deprecation'
+begin
+ silence_warnings { require 'mocha/setup' }
+rescue LoadError
+end
+
module ActiveSupport
class TestCase < ::MiniTest::Spec
- include ActiveSupport::Testing::MochaModule
-
# Use AS::TestCase for the base class when describing a model
register_spec_type(self) do |desc|
Class === desc && desc < ActiveRecord::Base
diff --git a/activesupport/lib/active_support/testing/mocha_module.rb b/activesupport/lib/active_support/testing/mocha_module.rb
deleted file mode 100644
index 833dc867f0..0000000000
--- a/activesupport/lib/active_support/testing/mocha_module.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-module ActiveSupport
- module Testing
- module MochaModule
- begin
- require 'mocha/api'
- include Mocha::API
-
- def before_setup
- mocha_setup
- super
- end
-
- def after_teardown
- super
- mocha_verify
- mocha_teardown
- end
- rescue LoadError
- end
- end
- end
-end