Skip to content

Instantly share code, notes, and snippets.

@everton
Created September 15, 2017 12:26
Show Gist options
  • Save everton/e189577daa2dbb0086a69b9d68077bd9 to your computer and use it in GitHub Desktop.
Save everton/e189577daa2dbb0086a69b9d68077bd9 to your computer and use it in GitHub Desktop.
IntegrationTest specialization to test rake tasks
require 'rake'
class TasksTest < ActionDispatch::IntegrationTest
include ActionMailer::TestHelper
private
def self.task(t = nil)
return @task unless t
t = t.to_s
@task = Rake::Task[t] rescue nil
unless @task
Rails.application.load_tasks
@task = Rake::Task[t]
raise "Task \"#{t}\" not found" unless @task
end
@task
end
def task
self.class.task
end
def run_task!
task.reenable
task.execute
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment