# Tests running in standalone script

**URL:** <https://www.ruby-forum.com/t/tests-running-in-standalone-script/106395>\
**Category:** Rails\
**Created:** [June 9, 2007, 7:08pm UTC](https://www.ruby-forum.com/t/tests-running-in-standalone-script/106395 "2007-06-09T19:08:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DZDZDZ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f475e1/32.png) [@DZDZDZ](https://www.ruby-forum.com/u/DZDZDZ)\
**Post date:** [June 9, 2007, 7:08pm UTC](https://www.ruby-forum.com/t/tests-running-in-standalone-script/106395/1 "2007-06-09T19:08:25Z")

</div>

Greetings,

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”  
end

end

class MyClass; def rescue\_action(e) raise e end; end

class MyClassTest \< Test::Unit::TestCase  
def setup  
puts “running setup”  
end

def test\_running\_a\_test  
puts "running a test "  
assert true

end  
end

if **FILE** == $0

mc = MyClass.new  
mc.run  
end

and when I run it:

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

1 tests, 1 assertions, 0 failures, 0 errors

---

<div class="post-metadata">

**Author:** ![DZDZDZ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f475e1/32.png) [@DZDZDZ](https://www.ruby-forum.com/u/DZDZDZ)\
**Post date:** [July 13, 2007, 9:14pm UTC](https://www.ruby-forum.com/t/tests-running-in-standalone-script/106395/2 "2007-07-13T21:14:36Z")

</div>

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.
