Hi
I am new to ruby and like it so far.
I have an existing test harness to plug into and need to run a number of
scripts in a specific order.
I am using load in a "for loop" to run them. Unfortunately the scripts
get run out of order.
Below is my main script and my other scripts follow.
Files are:
test.rb
Tests/A-test.rb
Tests/B-test.rb
Tests/C-test.rb
Tests/D-test.rb
To simplify the question, I have created an array of the scripts I need
to run in the required order. But the output shows that the scripts run
in the following order D-test.rb, A-test.rb, C-test.rb and then
B-test.rb.
Somehow A gets run before C.
Is there any way to run the scripts in the correct order? And how come
it loops through the puts first and then the load?
Thanks in advance
#****** test.rb ********************
TOPDIR = File.join(File.dirname(__FILE__), '.')
$LOAD_PATH.unshift TOPDIR
require 'test/unit'
require 'test/unit/ui/console/testrunner'
Dir.chdir TOPDIR
testList = []
testList[0]="Tests/D-test.rb"
testList[1]="Tests/C-test.rb"
testList[2]="Tests/A-test.rb"
testList[3]="Tests/B-test.rb"
begin
for i in 0 .. testList.length-1
puts "i: #{i} testname: #{testList[i]}"
load(testList[i])
end
end
#************* A-test.rb ***************
class TC_One < Test::Unit::TestCase
def setup
puts
puts "***********"
puts "In A-test setup"
end
def test_one
puts "In A-test.rb testcase one"
sleep 1
end
def teardown
puts "In A-test teardown"
puts "***********"
puts
end
end
#************* B-test.rb ***************
class TC_Two < Test::Unit::TestCase
def setup
puts
puts "***********"
puts "In B-test setup"
end
def test_one
puts "In B-test.rb testcase one"
sleep 1
end
def teardown
puts "In B-test teardown"
puts "***********"
puts
end
end
#************* C-test.rb ***************
class TC_Three < Test::Unit::TestCase
def setup
puts
puts "***********"
puts "In C-test setup"
end
def test_one
puts "In C-test.rb testcase one"
sleep 1
end
def teardown
puts "In C-test teardown"
puts "***********"
puts
end
end
#************* D-test.rb ***************
class TC_Four < Test::Unit::TestCase
def setup
puts
puts "***********"
puts "In D-test setup"
end
def test_one
puts "In D-test.rb testcase one"
t = Time.now
sleep 2
puts t
end
def teardown
puts "In D-test teardown"
puts "***********"
puts
end
end
#************* Output ***************
Y:\ruby>test.rb
i: 0 testname: Tests/D-test.rb
i: 1 testname: Tests/C-test.rb
i: 2 testname: Tests/A-test.rb
i: 3 testname: Tests/B-test.rb
Loaded suite Y:/ruby/test
Started
···
***********
In D-test setup
In D-test.rb testcase one
Wed Jan 23 10:14:33 -0800 2008
In D-test teardown
***********
.
***********
In A-test setup
In A-test.rb testcase one
In A-test teardown
***********
.
***********
In C-test setup
In C-test.rb testcase one
In C-test teardown
***********
.
***********
In B-test setup
In B-test.rb testcase one
In B-test teardown
***********
.
Finished in 5.002 seconds.
4 tests, 0 assertions, 0 failures, 0 errors
--
Posted via http://www.ruby-forum.com/.