Forum: Ruby Weird test/unit behavior

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.
9aafe2636a115bbdc137c93445054f22?d=identicon&s=25 Nasir Khan (Guest)
on 2007-07-06 23:28
(Received via mailing list)
Consider a simple test -

my_test.rb:
----------------------------------------
require 'test/unit'

class MyTest < Test::Unit::TestCase

  def test1
    assert(true)
  end

end
----------------------------------------

Now consider a simple script to run this.

run2.rb:
----------------------------------------
if ARGV.length == 0
  puts "usage run testfile"
else
  type = ARGV.shift
  if type == "-t"
    f = ARGV.shift
    load f
  end
end
----------------------------------------

So if you run it then you get the expected result.

run2 -t my_test.rb
Loaded suite ~sparkle:/nasir/misc/test/run2
Started
.
Finished in 0.0 seconds.

1 tests, 1 assertions, 0 failures, 0 errors


But now consider another script to run the same test.

run1.rb:
--------------------------------------------
D:\nasir\misc\test>cat run1.rb
if ARGV.length == 0
  puts "usage: run testfile"
else
  ARGV.each_with_index do |arg, i|
    if arg == "-t"
      load ARGV[i+1]
    end
  end
end
--------------------------------------------

When you run it the testcase is loaded alright but it doesnt run!

run1.rb -t my_test.rb
Loaded suite ~sparkle:/nasir/misc/test/run1
Started

Finished in 0.0 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

------

Apparently the testsuite is not run/loaded in this case.

Any help in finding out what is going on is appreciated.

- nasir
9aafe2636a115bbdc137c93445054f22?d=identicon&s=25 Nasir Khan (Guest)
on 2007-07-07 00:02
(Received via mailing list)
Ah Gotcha!

It is a side effect of having commandline arguments. ARGV is also used
by
autorunner.rb.
using shift in run2.rb clears the ARGV array.
This topic is locked and can not be replied to.