简体   繁体   中英

Writing multiple Rake tasks

I've written two Rspec tests each which invoke the same Rake task. The second task never gets run, as invoke only triggers once so I need to reenable. My issue is that I can't get the rake task to run, here is the command I'm using:

Rake::Task["product:delete"].reenable(product.id)

I get a run time error for this command:

Don't know how to build task 'product:delete[1]' Did you mean? product:delete

Anybody know how I should write this? I'm confused because in isolation I get it to pass by running:

Rake.application.invoke_task("product:delete[#{product.id}]"

You shouldn't need to pass an argument to reenable (it doesn't take one)

You should however be passing your argument to invoke (not invoke_task) rather than specifying it as part of the task name.

Eg

Rake::Task['product:delete'].reenable
Rake::Task['product:delete'].invoke(product.id)

You could streamline it a little more perhaps by saving the task in a variable:

t = Rake::Task['product:delete']
t.renable
t.invoke(product.id)

PS It looks a lot like that error "Don't know how to build task 'product:delete[1]' Did you mean? product:delete" has actually come from you trying to invoke the task with the argument in the task name rather than from the reenable. Possibly as a result of trying a lot of different things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM