Sha256: 713193e4d0f357a88eafce8ff0ff9af481775c8e6f0355d33cff96c5ecdf3fcc

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

require 'tempfile'
require 'pp'
require 'shoulda'
require 'matchy'
require 'mocha'
require 'mongo_mapper'

require File.expand_path(File.dirname(__FILE__) + '/../lib/joint')

MongoMapper.database = "testing"

class Test::Unit::TestCase
  def setup
    MongoMapper.database.collections.each(&:remove)
  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

  def assert_grid_difference(difference=1, &block)
    assert_difference("MongoMapper.database['fs.files'].find().count", difference, &block)
  end

  def assert_no_grid_difference(&block)
    assert_grid_difference(0, &block)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
joint-0.5.1 test/helper.rb
joint-0.5 test/helper.rb
joint-0.4 test/helper.rb
joint-0.3.2 test/helper.rb
joint-0.3.1 test/helper.rb
joint-0.3 test/helper.rb