Wed Jul 18 09:50:48 EST 2007 Matt Palmer * Add optional Mocha support Load Mocha if it's available, and provide a needs_mocha wrapper that only executes the block if Mocha is loaded. diff -rN -u old-tests/test/lib/test_helper.rb new-tests/test/lib/test_helper.rb --- old-tests/test/lib/test_helper.rb 2008-10-20 23:31:03.315857191 +1100 +++ new-tests/test/lib/test_helper.rb 2008-10-20 23:31:03.351880825 +1100 @@ -6,6 +6,18 @@ require 'fileutils' require 'digest/md5' +begin + begin + require 'mocha' + rescue LoadError + require 'rubygems' + require_gem 'mocha' + end +rescue LoadError + puts "The Mocha mock object system is not available; some tests will not run." + puts "Please install Mocha (gem install mocha) to ensure all tests are working." +end + class Test::Unit::TestCase # Create the necessary fixtures for running each individual test. # @@ -46,4 +58,16 @@ load_plugin(tmpfile) File.unlink(tmpfile) end + + def self.needs_mocha + if defined?(Mocha::Mock) + yield if block_given? + end + end + + def needs_mocha + if defined?(Mocha::Mock) + yield if block_given? + end + end end diff -rN -u old-tests/test/README new-tests/test/README --- old-tests/test/README 2008-10-20 23:31:03.315857191 +1100 +++ new-tests/test/README 2008-10-20 23:31:03.331882657 +1100 @@ -23,6 +23,21 @@ Improvements in documentation (and specifically rdoc-generated HTML) are on the todo list. + +Mocha Support +------------- + +Some tests may use Mocha to create mock objects. If you have Mocha +installed, the test suite will use it, but otherwise all mocha-related tests +should be skipped. To make this happen, you need to wrap your Mocha-using +test code in a 'needs_mocha' block, like so: + + needs_mocha do + x = mock + x.expects(:something).with('funny').returns('a joke') + end + + Extending the framework -----------------------