Created
June 30, 2020 07:51
-
-
Save hoangmirs/42b4da1040b6b6222d8330773c5603ed to your computer and use it in GitHub Desktop.
RSpec 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
# 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 |
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 | |
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