Created
December 4, 2019 23:50
-
-
Save HotFusionMan/c4f80a8b8b03b8e23ed6655f8596e70d to your computer and use it in GitHub Desktop.
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
# 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