Rake タスクをテストするとき、テストコード内で #invoke で呼び出すと、二回目の実行時に Rake タスクが実行されません。 describe 'hoge' do before(:all) do @rake = Rake::Application.new Rake.application = @rake Rake.application.rake_require("hoge", ["#{Rails.root}/lib/tasks"]) Rake::Task.define_task(:environment) end describe "rake hoge" do context "Rake タスク実行後" do before do @rake["book:dismissed_suppliers"].invoke end it "hoge 一回目" do # Rake タスクが実行