Forum: Ruby on Rails Tests running in standalone script

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.
4e89608512e0a111544f875816f1b244?d=identicon&s=25 DZ (Guest)
on 2007-06-09 19:08
(Received via mailing list)

I have a simple script that I want to run against my database. What is
happening is that I found that it wanted to run a test suite
automatically. I've tried to run down how that is happening, but I
don't follow how it is done. It seems to be set up in the initializer
somewhere, but I can't seem to find it. Since I found that it wanted
to run tests, I put a small test class in there, and sure enough it
runs it.

Can somebody shed some light on how this magic is happening?

Here is an example:

ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development'
puts "Loading #{ENV['RAILS_ENV']} environment."
require File.dirname(__FILE__) + '/../config/environment'

class MyClass

  def run
    puts "Running calculation"


class MyClass; def rescue_action(e) raise e end; end

class MyClassTest < Test::Unit::TestCase
  def setup
    puts "running setup"

  def test_running_a_test
    puts "running a test "
    assert true


if __FILE__ == $0

  mc =

and when I run it:

Loading development environment.
Running calculation
Loaded suite ./myclass
running setup
running a test
Finished in 0.013593 seconds.

1 tests, 1 assertions, 0 failures, 0 errors
4e89608512e0a111544f875816f1b244?d=identicon&s=25 DZ (Guest)
on 2007-07-13 21:14
(Received via mailing list)
So just for posterity, I found that one of the other developers had
included TestUnit in an underlying library. Since my script loaded the
Rails environment to run, it also included TestUnit, which lead to the
behaviour I described.
This topic is locked and can not be replied to.