Skip to content

Instantly share code, notes, and snippets.

@hoangmirs
Created June 30, 2020 07:51
Show Gist options
  • Save hoangmirs/42b4da1040b6b6222d8330773c5603ed to your computer and use it in GitHub Desktop.
Save hoangmirs/42b4da1040b6b6222d8330773c5603ed to your computer and use it in GitHub Desktop.
RSpec rake tasks
# frozen_string_literal: true
require 'rake_helper'
describe 'example rake task' do
describe '#run', rake: {
file_name: 'file_name_of_rake_task',
engine: Authentication::Engine
} do
it '' do; end
end
end
describe '#run', rake: 'file_name_of_rake_task' do
it '' do; end
end
end
end
# frozen_string_literal: true
require 'rake'
RSpec.configure do |config|
config.before(:each, rake: true) do |example|
options = example.metadata[:rake]
file_name = options.is_a?(Hash) ? options[:file_name] : options
engine = options.try(:dig, :engine) || Rails
Rake.application = Rake::Application.new
Rake.application.rake_require "lib/tasks/#{file_name}", [engine.root.to_s], []
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