Skip to content

Instantly share code, notes, and snippets.

@ches
Created November 29, 2010 18:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ches/720308 to your computer and use it in GitHub Desktop.
Save ches/720308 to your computer and use it in GitHub Desktop.
Set up Rake tasks to execute defined sets of specs
# Nice idea from:
# http://kpumuk.info/ruby-on-rails/my-top-7-rspec-best-practices/
#
# ~/test$ rake -T spec:suite
#
# (in /Users/kpumuk/test)
# rake spec:suite:acl # Run all specs in access control spec suite
# rake spec:suite:amazon # Run all specs in Amazon libraries spec suite
SPEC_SUITES = [
{ :id => :acl, :title => 'access control', :files => %w(spec/controllers/**/acl_spec.rb) },
{ :id => :amazon, :title => 'Amazon libraries', :dirs => %w(spec/lib/amazon) }
]
namespace :spec do
namespace :suite do
SPEC_SUITES.each do |suite|
desc "Run all specs in #{suite[:title]} spec suite"
Spec::Rake::SpecTask.new(suite[:id]) do |t|
spec_files = []
if suite[:files]
suite[:files].each { |glob| spec_files += Dir[glob] }
end
if suite[:dirs]
suite[:dirs].each { |glob| spec_files += Dir["#{glob}/**/*_spec.rb"] }
end
t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""]
t.spec_files = spec_files
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment