0
我想写一个自定义Rake任务来执行一些测试放在lib目录中的类。这适用于不需要任何模型的基本测试,但我需要使用某些模型进行实际测试。这是我第一次尝试更高级的rake用法,并且遇到了一些其他的障碍,我遇到了ConnectionNotE建立的错误。ConnectionNotEstablished在自定义TestTask错误
这里的耙子任务:
Rake::TestTask.new(:test => 'db:test:prepare') do |test|
test.libs << 'test/sync'
test.test_files = Dir['test/sync/*_test.rb']
test.verbose = true
end
下面是提高ConnectionNotEstablished异常测试:
require 'rubygems'
require 'app/models/city'
require 'foo'
require 'test/unit'
class SyncTest < Test::Unit::TestCase
@@sync = Foo::Sync.new('test')
def test_cities
assert City.all.size == 2 # the exception is raised at this point
@@sync.cities
assert City.all.size == 102
end
end
下面是实际工作的单元测试:
require 'test_helper'
class CityTest < ActiveSupport::TestCase
test "the truth" do
assert City.all.size == 2
end
end
我已经尝试使用从ActiveSupport::TestCase
派生我的测试类而不是Test::Unit::TestCase
但它仍然会引发ConnectionNotE已建立的错误。我当然做错了什么,任何人都可以找到或告诉更好的方式来做到这一点?