Skip to content

Instantly share code, notes, and snippets.

@joeyates
Created June 18, 2014 13:22
Show Gist options
  • Save joeyates/6609f499cec4d422309b to your computer and use it in GitHub Desktop.
Save joeyates/6609f499cec4d422309b to your computer and use it in GitHub Desktop.
Test rake tasks with rspec
require 'spec_helper'
require 'rake'
describe 'foo tasks' do
before :all do
Rake::Task.clear
Rake.application.rake_require 'tasks/foo'
Rake::Task.define_task(:environment)
end
before do
Rake.application.tasks.map(&:reenable)
end
after :all do
Rake::Task.clear
end
describe 'bar' do
let(:quux) { double(Quux, frob: nil) }
before do
allow(Rake.application).to receive(:invoke_task)
allow(Rake.application).to receive(:invoke_task).with('foo:bar').and_call_original
allow(Quux).to receive(:new).with('a').and_return(quux)
Rake.application.invoke_task 'foo:bar'
end
it "frobs the quuxs" do
expect(quux).to have_received(:frob).with(no_args)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment