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