2
我有一个导轨发生器我要作出这样的,除其他事项外,将运行基于关闭YAML文件中的一些支架:单元测试Rails生成调用另一个生成
class MyGenerator < Rails::Generators::Base
...
def run_scaffolds
...
invoke 'scaffold', fields
...
end
end
我调用如here所述的脚手架发生器。
的问题是,如果我尝试在单元测试运行此:
class ScaffoldTest < Rails::Generators::TestCase
tests MyGenerator
destination File.expand_path("../tmp", File.dirname(__FILE__))
setup :prepare_destination
test "run scaffolds" do
run_generator ["example_file.yaml"]
# doesn't get to here
end
end
我结束了一个错误:
Errno::ENOENT: No such file or directory - .../tmp/config/routes.rb
这是因为在TMP没有Rails应用程序目录。我的问题是我如何可能测试这个生成器,如果它不能没有轨应用程序执行?当然,我不应该在每次运行我的测试时在tmp文件夹中创建一个新的rails应用程序?