Forum: Ruby on Rails Testing Rake Tasks

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
49a48ca275503a198115c1d072a427c7?d=identicon&s=25 cheeseprophet (Guest)
on 2008-11-18 07: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")
  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?
This topic is locked and can not be replied to.