如何让 Rspec 运行嵌套在文件夹下的所有测试? [英] How can I get Rspec to run all tests nested under a folder?

查看:30
本文介绍了如何让 Rspec 运行嵌套在文件夹下的所有测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢使用在单独选项卡中运行的 Spork 来运行我的 Rspec 测试.我通常使用 rspec spec 运行我的测试,通过它我打算说递归搜索并运行 spec 文件夹中的所有内容."

I like to run my Rspec tests with Spork running in a separate tab. I usually run my tests using rspec spec, by which I intend to say "search recursively and run everything in the spec folder."

我最近意识到这实际上并没有运行我的所有测试.我现在在 spec/requests 中有一个未运行的规范文件.我知道这一点是因为我编辑了其中一个测试以引发错误,并运行以下命令:

I've recently realized that this does not actually run all my tests. I now have a spec file in spec/requests which isn't being run. I know this because I've edited one of the tests to raise an error, and run the following:

  • rspec spec - 没有出现错误.
  • rspec spec/requests - 仍然没有出现错误,并且 0 个示例,0 个失败
  • rspec spec/requests/my_controller.rb - bingo.17 个例子,1 个失败,失败有我的错误信息.
  • rspec spec - no error raised.
  • rspec spec/requests - still no error raised, and 0 examples, 0 failures!
  • rspec spec/requests/my_controller.rb - bingo. 17 examples, 1 failure and the failure has my error message.

为什么 Rspec 没有找到我所有的测试文件?这是配置问题,还是我需要使用不同的命令来运行我的测试?

我需要一次运行所有测试以确保不会引入回归.

I need to run all my tests at once to ensure that I'm not introducing regressions.

(顺便说一下,不使用 Spork 没有区别.)

(Not using Spork makes no difference, by the way.)

推荐答案

Rspec 应该 已经递归查找您命名的目录并找到所有测试.但是请注意,它正在寻找以 _spec.rb 结尾的文件.也许您的某些文件命名不正确?

Rspec should already look recursively through the directory you named and find all tests. Note however, that it's looking for files ending in _spec.rb. Maybe some of your files are not named correctly?

如果您需要更具体地了解它应该找到哪些文件,您还可以使用 --pattern 选项.例如:rspec --pattern spec/requests/*_spec.rb.(选项 --pattern 等于 -P.取自 rspec --help)

If you need to be more specific about which files it should find, you can also use the --pattern option. For example: rspec --pattern spec/requests/*_spec.rb. (Option --pattern is equal to -P. Taken from rspec --help)

这篇关于如何让 Rspec 运行嵌套在文件夹下的所有测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆