Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively glob for RSpec test files at runtime

Tags:

ruby

rspec

rspec2

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?

like image 977
andrewdotnich Avatar asked May 04 '11 01:05

andrewdotnich


2 Answers

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.

like image 101
David Chelimsky Avatar answered Sep 23 '22 05:09

David Chelimsky


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.

like image 20
Michelle Tilley Avatar answered Sep 20 '22 05:09

Michelle Tilley