You don't have to change anything in your spec_helper.rb
. You do, however, need to change example.rb
to example_spec.rb
This is the relevant line of code that implements this, in
/gems/rspec-rails-2.14.1/lib/rspec/rails/tasks/rspec.rake
:
namespace :spec do
types = begin
dirs = Dir['./spec/**/*_spec.rb'].
map { |f| g=f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') ; puts ">>> Found #{g}."; g }.
uniq.
select { |f| File.directory?(f) }
Hash[dirs.map { |d| [d.split('/').last, d] }]
end
So all the text in the filename previous to _spec.rb is a convention -
it doesn't change how Rails processes the files.
To run only some of your specs, you could filter them in the command line by tags or by text, or simply by giving the wanted root dir:
rspec . --example controller # only runs tests which have the word 'controller' in them
rsepc . --tag model # only runs tests which are tagged as 'model' => true
rspec ./spec/unit # only runs specs which are under ./spec/unit