Last active
March 27, 2020 13:00
-
-
Save lujanfernaud/47a458cc26ee2eddec222dfcf19ccbe5 to your computer and use it in GitHub Desktop.
RSpec: Rake Tasks Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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