Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Require Mocha >= 0.9.3 which includes a MiniTest adapter

  • Loading branch information...
commit e931012287df0bca83cae04d95c2e0835ae08758 1 parent 5d3712a
@jeremy jeremy authored
View
2  actionpack/test/abstract_unit.rb
@@ -8,7 +8,7 @@
require 'stringio'
require 'test/unit'
-gem 'mocha', '>= 0.9.0'
+gem 'mocha', '>= 0.9.3'
require 'mocha'
begin
View
2  activemodel/test/test_helper.rb
@@ -1,7 +1,7 @@
require 'rubygems'
require 'test/unit'
-gem 'mocha', '>= 0.5.5'
+gem 'mocha', '>= 0.9.3'
require 'mocha'
require 'active_model'
View
18 activesupport/lib/active_support/test_case.rb
@@ -1,22 +1,18 @@
-require 'test/unit/testcase'
-require 'active_support/testing/setup_and_teardown'
-require 'active_support/testing/assertions'
-require 'active_support/testing/deprecation'
-require 'active_support/testing/declarative'
-
begin
- gem 'mocha', '>= 0.9.0'
+ gem 'mocha', '>= 0.9.3'
require 'mocha'
-
- if defined?(MiniTest)
- require 'active_support/testing/mocha_minitest_adapter'
- end
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
+require 'test/unit/testcase'
+require 'active_support/testing/setup_and_teardown'
+require 'active_support/testing/assertions'
+require 'active_support/testing/deprecation'
+require 'active_support/testing/declarative'
+
module ActiveSupport
class TestCase < ::Test::Unit::TestCase
if defined? MiniTest
View
45 activesupport/lib/active_support/testing/mocha_minitest_adapter.rb
@@ -1,45 +0,0 @@
-class MiniTest::Unit::TestCase
- include Mocha::Standalone
-
- class MochaAssertionCounter
- def initialize(runner) @runner = runner end
- def increment; @runner.assertion_count += 1 end
- end
-
- def run(runner)
- assertion_counter = MochaAssertionCounter.new(runner)
- result = '.'
- begin
- begin
- @passed = nil
- setup
- __send__ name
- mocha_verify(assertion_counter)
- @passed = true
- rescue Exception => e
- @passed = false
- result = runner.puke(self.class, self.name, e)
- ensure
- begin
- teardown
- rescue Exception => e
- result = runner.puke(self.class, self.name, e)
- end
- end
- ensure
- mocha_teardown
- end
- result
- end
-end
-
-module Test
- module Unit
- remove_const :TestCase
-
- class TestCase < MiniTest::Unit::TestCase
- include Test::Unit::Assertions
- def self.test_order; :sorted end
- end
- end
-end
View
2  activesupport/test/abstract_unit.rb
@@ -1,6 +1,6 @@
require 'rubygems'
require 'test/unit'
-gem 'mocha', '>= 0.9.0'
+gem 'mocha', '>= 0.9.3'
require 'mocha'
$:.unshift "#{File.dirname(__FILE__)}/../lib"
View
9 railties/test/abstract_unit.rb
@@ -3,18 +3,15 @@
$:.unshift File.dirname(__FILE__) + "/../lib"
$:.unshift File.dirname(__FILE__) + "/../builtin/rails_info"
+require 'rubygems'
require 'test/unit'
+gem 'mocha', '>= 0.9.3'
+require 'mocha'
require 'stringio'
require 'active_support'
-# Wrap tests that use Mocha and skip if unavailable.
def uses_mocha(test_name)
- require 'rubygems'
- gem 'mocha', '>= 0.5.5'
- require 'mocha'
yield
-rescue LoadError
- $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
end
if defined?(RAILS_ROOT)

5 comments on commit e931012

@methodmissing

http://github.com/jeremy/mocha/tree/master

@floehopper

Do you need me to release current Mocha HEAD as 0.9.3; or is this a typo; or are you expecting other changes in Mocha 0.9.3?

@jeremy
Owner

If you’re ready for 0.9.3, by all means :)

Otherwise, this is just saying that edge Rails needs the next release of Mocha for MiniTest compatibility.

@mattbauer

Won’t this code in test_case.rb cause a problem when the mocha gem is localized? In that case, the require ‘mocha’ statement will never be reached . I think this code snippet in test_case.rb


begin
  gem 'mocha', '>= 0.9.3'
  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

Should be change to:


begin
  gem 'mocha', '>= 0.9.3'
rescue LoadError
ensure
  require 'mocha'
end

unless Object.const_defined?(:Mocha)
  # 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

@jeremy
Owner

Sure, could you work up a patch and post to lighthouse?

Please sign in to comment.
Something went wrong with that request. Please try again.