LoginSignup
0
0

More than 3 years have passed since last update.

rails_helper.rb内でrake taskを実行する方法

Last updated at Posted at 2019-08-16

環境

  • Rails 5.2.3

やり方

その一: 特定のファイルを読み込んで、それを実行する。

spec/rails_helper.rb
require 'rake'

load Rails.root.join('lib', 'tasks', 'foo.rake') # 実行したいrakeファイル
Rake::Task.define_task(:environment)
Rake::Task['foo:bar:buz'].invoke

その二: 全てのrakeタスクを読み込んで、特定のタスクを実行する。

spec/rails_helper.rb
require 'rake'

Rails.application.load_tasks
Rake::Task['foo:bar:buz'].invoke
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0