2011-05-04 49 views
4

,我有以下层次结构下一套RSpec的测试中,我想组:递归水珠的RSpec的测试文件在运行时

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

但是当我运行

$ rspec tests 

我得到如下:

rspec tests 
No examples were matched. Perhaps {:unless=>#<Proc:[email protected]/usr/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:51>, :if=>#<Proc:[email protected]/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"` 

,但我怀疑我不应该。我对吗?

回答

6

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

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

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

1

我通常通过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 site了解更多信息。

+0

我会这样做,但也许你也可以尝试类似rspec测试/ **/**。rb? – 2011-05-04 18:09:32

+0

这个特定的调用不起作用,但可能类似。另外,我非常确定,如果遵循RSpec约定并将您的规范命名为whatever_spec.rb,那么您就可以运行rspec测试。 – 2011-05-04 18:12:26

+0

前几天我做了这样的事情,我想终端会议仍然在我的MBP上,当我回家时我会看。我知道这不是确切但接近。 – 2011-05-04 18:23:39