使用RSPEC,我如何编写一个在嵌套目录中捕获_spec文件的表达式?
我将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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Glob不是正则义务,因此您需要启用Shell-Option
globstar
才能重新浏览子目录。在测试呼叫之前添加行
- 运行:shopt -s globstar
无法正常工作,因为CircleCi中的每个步骤都在自己的Shell实例中运行它。您需要将Shell-Opt设置为与运行测试相同的步骤。这样的事情: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: