I want to test a method defined in a rake task.

rake file

#lib/tasks/simple_task.rake
namespace :xyz do
    task :simple_task => :environment do
        begin
            if task_needs_to_run?
                puts "Lets run this..."
                #some code which I don't wish to test
                ...
            end
        end
    end
    def task_needs_to_run?
        # code that needs testing
        return 2 > 1
    end

end

Now, I want to test this method, task_needs_to_run? in a test file How do I do this ?

Additional note: I would ideally want test another private method in the rake task as well... But I can worry about that later.

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top