user3460354
user3460354

Reputation: 293

Invoking the same rake task twice in 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

Upvotes: 29

Views: 3366

Answers (2)

coderVishal
coderVishal

Reputation: 9079

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


  after(:each) do
    Rake::Task["task:name"].reenable
  end

Upvotes: 4

Guy Segev
Guy Segev

Reputation: 1835

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

Upvotes: 44

Related Questions