Created
June 18, 2014 13:22
-
-
Save joeyates/6609f499cec4d422309b to your computer and use it in GitHub Desktop.
Test rake tasks with rspec
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 '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