Skip to content

Instantly share code, notes, and snippets.

@waterlink
Created Mar 18, 2014
Embed
What would you like to do?
RSpec setup for testing rake tasks
# spec/support/rake.rb
require 'rake'
module Rake::TestHelpers
def run_task(name=subject)
Rake::Task[name].reenable
Rake.application.invoke_task name
end
end
RSpec.configure do |config|
config.include Rake::TestHelpers, type: :task
config.before(:each, type: :task) do
Rake::Task.define_task :environment
Rake.application.rake_require example.metadata[:task]
end
end
# spec/tasks/admin_spec.rb
require 'spec_helper'
describe task: 'tasks/admin', type: :task do
before :each { Admin.destroy_all }
describe 'create' do
subject { 'admin:create' }
before { run_task }
it 'creates one admin' do
expect(Admin.count).to be 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment