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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7203941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 01:51:40  来源:igfitidea点击:

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

ruby-on-railsruby-on-rails-3rspec

提问by ahmet

Is there a command that does this? I've searched but can not find anything

是否有执行此操作的命令?我已经搜索过但找不到任何东西

回答by Waseem

Try this:

尝试这个:

$ bundle exec rspec spec

回答by arunagw

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:routingor rake spec:controllers)

如果您正在测试模型,请使用rake spec:models(or rake spec:routingor rake spec:controllers)

if just testing one model, use rake SPEC=app/models/modelname.rb

如果只测试一个模型,请使用 rake SPEC=app/models/modelname.rb

回答by Louis Sayers

  1. Create a .rspecfile in the root of your project
  2. Add the path to where your specs are e.g.

    --default-path test/spec/

  3. Add the pattern of how your files are named e.g.

    --pattern ****/*.spec

  4. Run rspecand it should pick all your specs and run them :)
  1. .rspec在项目的根目录中创建一个文件
  2. 将路径添加到您的规格所在的位置,例如

    --default-path test/spec/

  3. 添加文件命名方式的模式,例如

    --pattern ****/*.spec

  4. 运行rspec它应该选择你所有的规格并运行它们:)

default-pathand patternare simply command line arguments, which means you can also add any other command line argument that rspec takes (can run rspec --helpto see the available options)

default-path并且pattern只是命令行参数,这意味着您还可以添加 rspec 采用的任何其他命令行参数(可以运行rspec --help以查看可用选项)

According to https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/configuration/read-command-line-configuration-options-from-filesyou can also put the options in ~/.rspec, which will make the options available globally. Local .rspecfile options will override the global options.

根据https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/configuration/read-command-line-configuration-options-from-files您还可以将选项放入~/.rspec,其中将使选项在全球范围内可用。本地.rspec文件选项将覆盖全局选项。

回答by Sandip Mondal

For controller test

用于控制器测试

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

For model test

用于模型测试

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

For all test

对于所有测试

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

For specific file test do

对于特定的文件测试做

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

回答by Morpheus

go to your app directory and run rspec specor bundle exec rspec spec. use spork to speed your testing...(i kinda say its compulsory)

转到您的应用程序目录并运行rspec specbundle exec rspec spec。使用 spork 来加速你的测试......(我有点说它是强制性的)