Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RSpec: Rake Tasks Helper
# Example usage =============
#
# describe :namespace do
# include RakeTasksHelper
#
# describe ':task' do
# it 'works' do
# invoke_task('namespace:task')
# end
# end
# end
#
# You might also want to exclude rake tasks from RSpec/DescribeClass if you use rubocop-rspec:
#
# # .rubocop.yml
# RSpec/DescribeClass:
# Exclude:
# - spec/lib/tasks/**/*
#
module RakeTasksHelper
RSpec.configure do |config|
config.before(:all) do
MyApp::Application.load_tasks
Rake::Task.define_task(:environment)
end
def invoke_task(task)
# Reenable the task so that it will be run again and can be called multiple times in a spec.
Rake::Task[task].reenable
Rake::Task[task].invoke
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.