# Testing Rake Tasks

**URL:** <https://www.ruby-forum.com/t/testing-rake-tasks/153510>\
**Category:** Rails\
**Created:** [November 18, 2008, 7:36am UTC](https://www.ruby-forum.com/t/testing-rake-tasks/153510 "2008-11-18T07:36:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cheeseprophet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c67d28/32.png) [@cheeseprophet](https://www.ruby-forum.com/u/cheeseprophet)\
**Post date:** [November 18, 2008, 7:36am UTC](https://www.ruby-forum.com/t/testing-rake-tasks/153510/1 "2008-11-18T07:36:28Z")

</div>

I’m somewhat new to RoR and I’ve found that along with my main RoR  
development work I’ve also developed a number of custom rake tasks  
that do various things. I’d like to be able to write unit tests for  
these rake tasks and I’ve done a fair bit of google but I haven’t  
really seen it explained well how to go about doing that. The typical  
advice is to develop your task as a class to test the class, but how  
exactly is that done? I’ve developed my latest task as a class, and  
added the following code to test/unit:

class MyClassTest \< Test::Unit::TestCase  
def test\_is\_day\_word  
assert MyClassTest.is\_day\_word(“Tuesday”)  
end  
end

However this throws:

1. Error:  
test\_is\_day\_word(MyClassTest):  
NameError: uninitialized constant MyClassTest::MyClass  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/  
active\_support/dependencies.rb:492:in `const_missing' ./test/unit/masstimes_crawl_test.rb:4:in`test\_is\_day\_word’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/  
active\_support/testing/setup\_and\_teardown.rb:33:in ` __send__' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/ active_support/testing/setup_and_teardown.rb:33:in`run’

What am I doing wrong and is there a better way to test rake tasks?
