# How to write test cases for rake tasks

**URL:** <https://www.ruby-forum.com/t/how-to-write-test-cases-for-rake-tasks/152210>\
**Category:** Rails\
**Created:** [October 31, 2008, 10:08am UTC](https://www.ruby-forum.com/t/how-to-write-test-cases-for-rake-tasks/152210 "2008-10-31T10:08:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vamsi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b38774/32.png) [@vamsi](https://www.ruby-forum.com/u/vamsi)\
**Post date:** [October 31, 2008, 10:08am UTC](https://www.ruby-forum.com/t/how-to-write-test-cases-for-rake-tasks/152210/1 "2008-10-31T10:08:03Z")

</div>

hi,

i don’t 've idea about how to write test cases for a rake task(rake  
file)

like i’ve a rake file named daily\_summary.rake and i had written some  
code like extracting from the database based on some criteria. and the  
rake file is executed , its working fine.

```
    but i need to write test cases for this rake

```

file(daily\_summary.rake)  
so any body can help me how to write test cases for rake file.

Thanks  
Vamsi.

---

<div class="post-metadata">

**Author:** ![vamsi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b38774/32.png) [@vamsi](https://www.ruby-forum.com/u/vamsi)\
**Post date:** [November 1, 2008, 3:26pm UTC](https://www.ruby-forum.com/t/how-to-write-test-cases-for-rake-tasks/152210/2 "2008-11-01T15:26:49Z")

</div>

Hi there,

Facade design pattern?  
Try to keep your rake files as simple as possible.  
The best would be to extract all the logic to the separate lib file  
and just call the logic from rake task.

task :daily\_summary =\> :environment do  
#extract params  
day = ENV[‘DAY’]  
DailySummary.process(day)  
end

This way you can test your lib easily.  
Cheers

On 31 Pa¼, 10:08, Vamsi K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
