Created
January 17, 2013 15:57
-
-
Save traviskroberts/4556977 to your computer and use it in GitHub Desktop.
Rspec shared context 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
require "rake" | |
shared_context "rake" do | |
let(:rake) { Rake::Application.new } | |
let(:task_name) { self.class.top_level_description } | |
let(:task_path) { "lib/tasks/#{task_name.split(":").first}" } | |
subject { rake[task_name] } | |
def loaded_files_excluding_current_rake_file | |
$".reject {|file| file == Rails.root.join("#{task_path}.rake").to_s } | |
end | |
before do | |
Rake.application = rake | |
Rake.application.rake_require(task_path, [Rails.root.to_s], loaded_files_excluding_current_rake_file) | |
Rake::Task.define_task(:environment) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment