Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoking the same rake task twice in RSpec

Tags:

ruby

rspec

I am trying to test a rake task with rspec, and for that purpose I need to invoke it twice but it is only being invoked once.

it 'first test' do
    Rake::Task['my_rake_task'].invoke
    # rake task was processed
end

it 'second test' do
    Rake::Task['my_rake_task'].invoke
    # rake task was NOT processed
end
like image 893
user3460354 Avatar asked Mar 25 '14 15:03

user3460354


2 Answers

if a rake task has already been invoked once it won't run again unless you call:

@rake[@task_name].reenable

or invoke it with

@rake[@task_name].execute

like image 70
Guy Segev Avatar answered Oct 18 '22 16:10

Guy Segev


To adding to Guy Segev answer I prefer adding this to your spec file


  after(:each) do
    Rake::Task["task:name"].reenable
  end
like image 23
coderVishal Avatar answered Oct 18 '22 16:10

coderVishal