Ruby on Rails:从 test_unit 切换到 rspec [英] Ruby on Rails: Switch from test_unit to rspec
问题描述
我正在阅读一个建议使用 rspec
的教程,但我已经完成了很多默认的 Rails 安装.我真的不想重做安装.反正我跑的时候
I'm going through a tutorial that has suggested using rspec
, but I have already gone through a lot of default rails installation. I really don't want to have to redo the installation at all. Anyway, when I run
$ rails g integration_test named
我明白
invoke test_unit
create test/integration/named_test.rb
当我运行 bundle
时,会列出各种 rspec
gem,但没有列出 test_unit
.本教程似乎让 rails 调用 rspec
而不是 test_unit
而不做任何额外的事情.如何让 Rails 将 rspec
与集成测试生成器命令一起使用?
When I run bundle
, various rspec
gems are listed, but test_unit
is not. The tutorial seems to have rails invoke rspec
instead of test_unit
without doing anything additional. How do I get rails to use rspec
with the integration test generator command?
推荐答案
在你的 config/application.rb
文件中:
config.generators do |g|
g.test_framework :rspec
end
现在,当您运行生成器时(示例 rails generate scaffold post
),您将获得 rspec 测试文件.记得重启你的服务器.有关生成器的更多信息,请参阅:
Now when you run your generators (example rails generate scaffold post
), you get rspec test files. Remember to restart your server. For more information on generators see:
如果你真的想使用integration_test生成器,你需要专门修改命令:
If you really want to use the integration_test generator you'll need to specifically modify the command:
rails g integration_test named --integration-tool=rspec
这篇关于Ruby on Rails:从 test_unit 切换到 rspec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!