简体   繁体   English

RSpec > 有没有办法用一个命令运行所有测试?

[英]RSpec > Is there a way to run all tests with one command?

Is there a command that does this?是否有执行此操作的命令? I've searched but can not find anything我已经搜索过但找不到任何东西

在终端窗口中试试这个:

bundle exec rspec spec

if you are using rspec-rails then you can run using rake spec如果您使用的是 rspec-rails,那么您可以使用rake spec运行

if you're testing models, use rake spec:models (or rake spec:routing or rake spec:controllers )如果您正在测试模型,请使用rake spec:models (或rake spec:routingrake spec:controllers

if just testing one model, use rake SPEC=app/models/modelname.rb如果只测试一个模型,请使用rake SPEC=app/models/modelname.rb

  1. Create a .rspec file in the root of your project在项目的根目录中创建一个.rspec文件
  2. Add the path to where your specs are eg将路径添加到您的规格所在的位置,例如

    --default-path test/spec/

  3. Add the pattern of how your files are named eg添加文件命名方式的模式,例如

    --pattern ****/*.spec

  4. Run rspec and it should pick all your specs and run them :)运行rspec ,它应该选择您所有的规格并运行它们:)

default-path and pattern are simply command line arguments, which means you can also add any other command line argument that rspec takes (can run rspec --help to see the available options) default-pathpattern只是命令行参数,这意味着您还可以添加 rspec 接受的任何其他命令行参数(可以运行rspec --help以查看可用选项)

According to https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/configuration/read-command-line-configuration-options-from-files you can also put the options in ~/.rspec , which will make the options available globally.根据https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/configuration/read-command-line-configuration-options-from-files你也可以把选项放在~/.rspec ,这将使选项全局可用。 Local .rspec file options will override the global options.本地.rspec文件选项将覆盖全局选项。

For controller test用于控制器测试

  1. bundle exec rake spec:controllers bundle exec rake 规范:控制器

For model test用于模型测试

  1. bundle exec rake spec:models捆绑执行耙规格:模型

For all test对于所有测试

  1. bundle exec rake spec捆绑执行耙规范

For specific file test do对于特定的文件测试做

  1. rspec file_name_spec.rb (example rspec spec/controllers/groups_controller_spec.rb) rspec file_name_spec.rb(示例 rspec spec/controllers/groups_controller_spec.rb)

go to your app directory and run rspec spec or bundle exec rspec spec .转到您的应用程序目录并运行rspec specbundle exec rspec spec use spork to speed your testing...(i kinda say its compulsory)使用 spork 来加速你的测试......(我有点说它是强制性的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM