Forum: Ruby on Rails Testing Rake Tasks

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
cheeseprophet (Guest)
on 2008-11-18 08:36
(Received via mailing list)
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")

However this throws:

  1) Error:
NameError: uninitialized constant MyClassTest::MyClass
active_support/dependencies.rb:492:in `const_missing'
    ./test/unit/masstimes_crawl_test.rb:4:in `test_is_day_word'
active_support/testing/setup_and_teardown.rb:33:in `__send__'
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?
This topic is locked and can not be replied to.