Skip to content

Instantly share code, notes, and snippets.

@khopkins218
Created February 3, 2014 16:23
Show Gist options
  • Save khopkins218/8787016 to your computer and use it in GitHub Desktop.
Save khopkins218/8787016 to your computer and use it in GitHub Desktop.
Schedule Checker for valid rake tasks. Takes the schedule.rb file from and extracts the defined rake tasks to check for validity (spelling, actual task, etc)
require 'spec_helper'
describe "schedule" do
describe "file" do
it "should be present and named correctly" do
expect {
File.exists?("#{Rails.root}/config/schedule.rb")
}.to be_true
end
end
describe "rake tasks" do
before do
@scheduled_tasks = []
File.open("#{Rails.root}/config/schedule.rb", "r") do |schedule|
while line = schedule.gets
if line.include? "bundle exec rake"
@scheduled_tasks << line
end
end
end
end
it "should contain some tasks" do
expect {
@scheduled_tasks.count > 0
}.to be_true
end
context "valid tasks" do
before do
@valid_tasks = []
@scheduled_tasks.each do |task|
@valid_tasks << Rake::Task.task_defined?(task.match(/[a-zA-Z]+:[a-zA-Z_]+/).to_s)
end
end
it "should only have valid rake tasks" do
expect (
@valid_tasks.include? false
).should be_false
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment