RSpec setup for testing rake 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
# 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 |
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
# 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