此类提供了用于测试生成器的 TestCase。要进行设置,您只需配置目标目录并指定正在测试的生成器即可。
class AppGeneratorTest < Rails::Generators::TestCase tests AppGenerator destination File.expand_path("../tmp", __dir__) end
如果您想确保在运行每个测试之前清除目标根目录,可以设置一个 setup 回调。
class AppGeneratorTest < Rails::Generators::TestCase tests AppGenerator destination File.expand_path("../tmp", __dir__) setup :prepare_destination end
包含的模块