Skip to content
This repository
Browse code

Require Mocha >= 0.9.3 which includes a MiniTest adapter

  • Loading branch information...
commit e931012287df0bca83cae04d95c2e0835ae08758 1 parent 5d3712a
Jeremy Kemper authored November 23, 2008
2  actionpack/test/abstract_unit.rb
@@ -8,7 +8,7 @@
8 8
 require 'stringio'
9 9
 require 'test/unit'
10 10
 
11  
-gem 'mocha', '>= 0.9.0'
  11
+gem 'mocha', '>= 0.9.3'
12 12
 require 'mocha'
13 13
 
14 14
 begin
2  activemodel/test/test_helper.rb
... ...
@@ -1,7 +1,7 @@
1 1
 require 'rubygems'
2 2
 require 'test/unit'
3 3
 
4  
-gem 'mocha', '>= 0.5.5'
  4
+gem 'mocha', '>= 0.9.3'
5 5
 require 'mocha'
6 6
 
7 7
 require 'active_model'
18  activesupport/lib/active_support/test_case.rb
... ...
@@ -1,22 +1,18 @@
1  
-require 'test/unit/testcase'
2  
-require 'active_support/testing/setup_and_teardown'
3  
-require 'active_support/testing/assertions'
4  
-require 'active_support/testing/deprecation'
5  
-require 'active_support/testing/declarative'
6  
-
7 1
 begin
8  
-  gem 'mocha', '>= 0.9.0'
  2
+  gem 'mocha', '>= 0.9.3'
9 3
   require 'mocha'
10  
-
11  
-  if defined?(MiniTest)
12  
-    require 'active_support/testing/mocha_minitest_adapter'
13  
-  end
14 4
 rescue LoadError
15 5
   # Fake Mocha::ExpectationError so we can rescue it in #run. Bleh.
16 6
   Object.const_set :Mocha, Module.new
17 7
   Mocha.const_set :ExpectationError, Class.new(StandardError)
18 8
 end
19 9
 
  10
+require 'test/unit/testcase'
  11
+require 'active_support/testing/setup_and_teardown'
  12
+require 'active_support/testing/assertions'
  13
+require 'active_support/testing/deprecation'
  14
+require 'active_support/testing/declarative'
  15
+
20 16
 module ActiveSupport
21 17
   class TestCase < ::Test::Unit::TestCase
22 18
     if defined? MiniTest
45  activesupport/lib/active_support/testing/mocha_minitest_adapter.rb
... ...
@@ -1,45 +0,0 @@
1  
-class MiniTest::Unit::TestCase
2  
-  include Mocha::Standalone
3  
-
4  
-  class MochaAssertionCounter
5  
-    def initialize(runner) @runner = runner end
6  
-    def increment; @runner.assertion_count += 1 end
7  
-  end
8  
-
9  
-  def run(runner)
10  
-    assertion_counter = MochaAssertionCounter.new(runner)
11  
-    result = '.'
12  
-    begin
13  
-      begin
14  
-        @passed = nil
15  
-        setup
16  
-        __send__ name
17  
-        mocha_verify(assertion_counter)
18  
-        @passed = true
19  
-      rescue Exception => e
20  
-        @passed = false
21  
-        result = runner.puke(self.class, self.name, e)
22  
-      ensure
23  
-        begin
24  
-          teardown
25  
-        rescue Exception => e
26  
-          result = runner.puke(self.class, self.name, e)
27  
-        end
28  
-      end
29  
-    ensure
30  
-      mocha_teardown
31  
-    end
32  
-    result
33  
-  end
34  
-end
35  
-
36  
-module Test
37  
-  module Unit
38  
-    remove_const :TestCase
39  
-
40  
-    class TestCase < MiniTest::Unit::TestCase
41  
-      include Test::Unit::Assertions
42  
-      def self.test_order; :sorted end
43  
-    end
44  
-  end
45  
-end
2  activesupport/test/abstract_unit.rb
... ...
@@ -1,6 +1,6 @@
1 1
 require 'rubygems'
2 2
 require 'test/unit'
3  
-gem 'mocha', '>= 0.9.0'
  3
+gem 'mocha', '>= 0.9.3'
4 4
 require 'mocha'
5 5
 
6 6
 $:.unshift "#{File.dirname(__FILE__)}/../lib"
9  railties/test/abstract_unit.rb
@@ -3,18 +3,15 @@
3 3
 $:.unshift File.dirname(__FILE__) + "/../lib"
4 4
 $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info"
5 5
 
  6
+require 'rubygems'
6 7
 require 'test/unit'
  8
+gem 'mocha', '>= 0.9.3'
  9
+require 'mocha'
7 10
 require 'stringio'
8 11
 require 'active_support'
9 12
 
10  
-# Wrap tests that use Mocha and skip if unavailable.
11 13
 def uses_mocha(test_name)
12  
-  require 'rubygems'
13  
-  gem 'mocha', '>= 0.5.5'
14  
-  require 'mocha'
15 14
   yield
16  
-rescue LoadError
17  
-  $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
18 15
 end
19 16
 
20 17
 if defined?(RAILS_ROOT)

5 notes on commit e931012

Lourens Naudé

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

James Mead

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 Kemper
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.

Matt Bauer

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 Kemper
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.