This will try to find all the rake tasks defined in the lib/tasks
directory and run them. Note that some tasks might need arguments and will fail. I want to keep this example short so dealing with that is left as an exercise for the intern.
Last active
August 29, 2015 14:18
-
-
Save Manfred/bca184810ece5909d56d to your computer and use it in GitHub Desktop.
Running Rake tasks from your test environment
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
require_relative '../spec_helper' | |
require 'rake' | |
Dir.glob(Rails.root.join('lib/tasks/**/*.rake')).each do |rakefile| | |
begin | |
load rakefile | |
# There could be an RSpec task which will throw a NameError. Which is a | |
# good thing, otherwise we would invoke this spec recursively. | |
rescue NameError => exception | |
puts '[!] ' + exception.message | |
end | |
end | |
describe "Rake tasks" do | |
Rake.application.tasks.each do |task| | |
it "should run `rake #{task.name}'" do | |
task.invoke | |
end | |
end | |
end | |
# Load the standard Rails tasks so other tasks can use the :environment | |
# task. We do this after defining the specs because otherwise we would | |
# invoke all Rails tasks (like db:drop). | |
Rails.application.load_tasks |
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
require_relative '../spec_helper' | |
require 'rake' | |
Dir.glob(Rails.root.join('lib/tasks/**/*.rake')).each do |rakefile| | |
begin | |
load rakefile | |
rescue NameError => exception | |
puts '[!] ' + exception.message | |
end | |
end | |
describe "Rake tasks" do | |
Rake.application.tasks.each do |task| | |
it "should run `rake #{task.name}'" do | |
task.invoke | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment