Skip to content

Instantly share code, notes, and snippets.

@HotFusionMan
Created December 4, 2019 23:50
Show Gist options
  • Save HotFusionMan/c4f80a8b8b03b8e23ed6655f8596e70d to your computer and use it in GitHub Desktop.
Save HotFusionMan/c4f80a8b8b03b8e23ed6655f8596e70d to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
# This technique learned from https://www.eliotsykes.com/test-rails-rake-tasks-with-rspec .
require 'rake'
require 'active_support/concern'
module TaskExampleGroup
extend ActiveSupport::Concern
included do
let(:task_name) { self.class.top_level_description.sub(/\Arake /, "") }
let(:tasks) { Rake::Task }
# Make the Rake task available as `task` in your examples:
subject(:task) { tasks[task_name] }
end
end
RSpec.configure do |config|
# Tag Rake specs with `:rake` metadata or put them in the spec/lib/tasks directory
config.define_derived_metadata(:file_path => %r{/spec/lib/tasks/}) do |metadata|
metadata[:type] = :rake
end
config.include TaskExampleGroup, type: :rake
config.before(:suite) do
Rails.application.load_tasks
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment