Skip to content

Instantly share code, notes, and snippets.

@seanreads
Created December 19, 2012 00:32
Show Gist options
  • Save seanreads/4333399 to your computer and use it in GitHub Desktop.
Save seanreads/4333399 to your computer and use it in GitHub Desktop.
Run `rake spec`, `rake spec:models`, `rake spec:controllers`, etc without running prerequisite tasks. Helpful for working with non-migration-aware (i.e., legacy databases).
# Run `rake spec`, `rake spec:models`, `rake spec:controllers`, etc
# without running prerequisite, database tasks. Helpful for working
# with non-migration-aware, legacy databases.
if defined?(RSpec)
tasks = %w{ spec models controllers helpers lib mailers
rcov requests routing views }
skip_db_task = Proc.new do |task|
path = task.eql?('spec') ? 'spec/**' : "spec/#{task}"
RSpec::Core::RakeTask.new("#{task}_skips_db_tasks") do |t|
old_env, ENV['RAILS_ENV'] = ENV['RAILS_ENV'], 'test'
t.pattern = "#{path}/*_spec.rb"
p t.pattern
ENV['RAILS_ENV'] = old_env
end
end
namespace :spec do
tasks.each {|task| skip_db_task.call(task) }
end
tasks.each do |task|
namespace = 'spec'
old_task = (namespace == task) ? 'spec' : "spec:#{task}"
new_task = "spec:#{task}_skips_db_tasks"
task(old_task).clear.enhance([new_task])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment