使用RSPEC,我如何编写一个在嵌套目录中捕获_spec文件的表达式?

发布于 2025-01-22 19:39:16 字数 552 浏览 2 评论 0原文

我将Rails 6与RSPEC 3.10一起使用。我有以下目录结构,

spec/models/my_object_spec.rb
spec/models/module_name/product_spec.rb

我以类似于下面

bundle exec rspec --color --require spec_helper --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/rspec.xml --format progress $(circleci tests glob spec/**/*_spec.rb | circleci tests split --split-by=timings)

问题的命令运行测试是正则表达式“ spec/**/*spec.rb”似乎仅运行文件“ spec/spec/models/my_object_spec.rb”。但是,“模型”的子目录中的另一个文件不会运行。有没有办法编写正则表达式,以便它可以捕获“ _spec”以“ _spec”结尾的所有文件?

I’m using Rails 6 with RSpec 3.10. I have the following directory structure

spec/models/my_object_spec.rb
spec/models/module_name/product_spec.rb

I run the tests with a command similar to the below

bundle exec rspec --color --require spec_helper --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/rspec.xml --format progress $(circleci tests glob spec/**/*_spec.rb | circleci tests split --split-by=timings)

The issue is that the regular expression “spec/**/*_spec.rb” only seems to run the file “spec/models/my_object_spec.rb”, however, the other file in the child directory of “models” doesn’t get run. Is there a way to write the regular expression so that it would capture all files ending in “_spec” regardless of which child directory they are in?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野鹿林 2025-01-29 19:39:16

Glob不是正则义务,因此您需要启用Shell-Option globstar才能重新浏览子目录。

在测试呼叫之前添加行- 运行:shopt -s globstar无法正常工作,因为CircleCi中的每个步骤都在自己的Shell实例中运行它。您需要将Shell-Opt设置为与运行测试相同的步骤。这样的事情:

- run:
  command: |
    shopt -s globstar
    bundle exec rspec --color --require spec_helper --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/rspec.xml --format progress $(circleci tests glob spec/**/*_spec.rb | circleci tests split --split-by=timings)

glob is not a regex, so you need to enable the shell-option globstar in order to recurse subdirectories.

Adding the line - run: shopt -s globstar before your test call won't work because each step in CircleCI runs it in its own shell instance. You need to set the shell-opt in the same step that you run your tests. Something like this:

- run:
  command: |
    shopt -s globstar
    bundle exec rspec --color --require spec_helper --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/rspec.xml --format progress $(circleci tests glob spec/**/*_spec.rb | circleci tests split --split-by=timings)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文