test/helper.rb in joint-0.1.1 vs test/helper.rb in joint-0.2
- old
+ new
@@ -1,23 +1,28 @@
-require 'test/unit'
require 'tempfile'
require 'pp'
require 'mongo_mapper'
+require 'shoulda'
+require 'matchy'
+require 'mocha'
require File.expand_path(File.dirname(__FILE__) + '/../lib/joint')
MongoMapper.database = "testing"
class Test::Unit::TestCase
- def self.test(name, &block)
- test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
- defined = instance_method(test_name) rescue false
- raise "#{test_name} is already defined in #{self}" if defined
- if block_given?
- define_method(test_name, &block)
- else
- define_method(test_name) do
- flunk "No implementation provided for #{name}"
- end
+ def assert_difference(expression, difference = 1, message = nil, &block)
+ b = block.send(:binding)
+ exps = Array.wrap(expression)
+ before = exps.map { |e| eval(e, b) }
+ yield
+ exps.each_with_index do |e, i|
+ error = "#{e.inspect} didn't change by #{difference}"
+ error = "#{message}.\n#{error}" if message
+ assert_equal(before[i] + difference, eval(e, b), error)
end
+ end
+
+ def assert_no_difference(expression, message = nil, &block)
+ assert_difference(expression, 0, message, &block)
end
end
\ No newline at end of file