Skip to content

Instantly share code, notes, and snippets.

@hchoroomi
Created January 28, 2010 00:57
Show Gist options
  • Save hchoroomi/288324 to your computer and use it in GitHub Desktop.
Save hchoroomi/288324 to your computer and use it in GitHub Desktop.
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
~/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
# Grab recently touched specs
def recent_specs(touched_since)
recent_specs = Dir['app/**/*'].map do |path|
if File.mtime(path) > touched_since
spec = File.join('spec', File.dirname(path).split("/")[1..-1].join('/'),
"#{File.basename(path, ".*")}_spec.rb")
spec if File.exists?(spec)
end
end.compact
recent_specs += Dir['spec/**/*_spec.rb'].select do |path|
File.mtime(path) > touched_since
end.uniq
end
namespace :spec do
desc 'Run all recent specs in spec directory touched in last 10 minutes'
Spec::Rake::SpecTask.new(:recent) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = recent_specs(Time.now - 10.minutes)
end
end
# figure out where we are being loaded from
if $LOADED_FEATURES.grep(/spec\/spec_helper\.rb/).any?
begin
raise "foo"
rescue => e
puts <<-MSG
===================================================
It looks like spec_helper.rb has been loaded
multiple times. Normalize the require to:
require "spec/spec_helper"
Things like File.join and File.expand_path will
cause it to be loaded multiple times.
Loaded this time from:
#{e.backtrace.join("\n ")}
===================================================
MSG
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment