Skip to content

Instantly share code, notes, and snippets.

@lujanfernaud
Last active March 27, 2020 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lujanfernaud/47a458cc26ee2eddec222dfcf19ccbe5 to your computer and use it in GitHub Desktop.
Save lujanfernaud/47a458cc26ee2eddec222dfcf19ccbe5 to your computer and use it in GitHub Desktop.
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