在运行时递归地查找 RSpec 测试文件

发布于 2024-11-04 18:39:08 字数 765 浏览 0 评论 0原文

我有一套 RSpec 测试,我想将其分组到以下层次结构中:

tests/
  featA/
     t1.rb
     t2.rb
  featB/
     t3.rb

但是当我运行时

$ rspec tests

,我得到以下信息:

rspec tests
No examples were matched. Perhaps {:unless=>#<Proc:0x00007f318919cc08@/usr/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:51>, :if=>#<Proc:0x00007f318919cdc0@/usr/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:50>} is excluding everything?

Finished in 0.00003 seconds
0 examples, 0 failures

我觉得我要疯了,但似乎没有办法让 RSpec 递归地进行 glob用于测试文件?有这个功能吗?

编辑:

我有一个解决方法:

$ rspec `find tests -name "*.rb"`

但我怀疑我不应该这样做。我说得对吗?

I have a suite of RSpec tests I want to group under the following hierarchy:

tests/
  featA/
     t1.rb
     t2.rb
  featB/
     t3.rb

but when I run

$ rspec tests

I get the following:

rspec tests
No examples were matched. Perhaps {:unless=>#<Proc:0x00007f318919cc08@/usr/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:51>, :if=>#<Proc:0x00007f318919cdc0@/usr/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:50>} is excluding everything?

Finished in 0.00003 seconds
0 examples, 0 failures

I feel like I'm going mad, but there doesn't seem to be a way to get RSpec to recursively glob for test files? Does this functionality exist?

EDIT:

I have a workaround by doing this:

$ rspec `find tests -name "*.rb"`

but I suspect I shouldn't have to. Am I right?

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

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

发布评论

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

评论(2

清欢 2024-11-11 18:39:08

你暴露了我的疏忽!在 rspec-1 中,您可以这样说:

spec test --pattern "**/*.rb"

但是 rspec-2 中缺少 --pattern 选项。我刚刚添加了它(开发中),它将包含在rspec-2.6.0 版本。

You've exposed an oversight on my part! In rspec-1, you could say this:

spec test --pattern "**/*.rb"

But the --pattern option is missing in rspec-2. I've just added it (in development) and it will be included in the rspec-2.6.0 release.

烦人精 2024-11-11 18:39:08

我通常通过 rake 管理在我的规范上运行 RSpec。我的 Rakefile 的相关部分如下所示:

require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |t|
  t.rspec_opts = ['--color', '-f progress', '-r ./spec/spec_helper.rb']
  t.pattern = 'spec/**/*_spec.rb'
  t.fail_on_error = false
end

现在,rake spec 使用适当的选项运行 RSpec;您需要更改 t.pattern 以匹配您想要运行的规范。

请务必查看 RSpec2网站了解更多信息。

I usually manage running RSpec on my specs via rake. The relevant portion of my Rakefile looks something like this:

require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |t|
  t.rspec_opts = ['--color', '-f progress', '-r ./spec/spec_helper.rb']
  t.pattern = 'spec/**/*_spec.rb'
  t.fail_on_error = false
end

Now rake spec runs RSpec with the appropriate options; you'll need to change t.pattern to match the specs you want to run.

Be sure to check out the RSpec2 site for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文