ARGV and unit tests: different problem

Y

yuricake

Hello,

I am experiencing the following strange problem (this is present in
ruby versions 1.8.5 and 1.8.6): if I rely on the test suites to be run
automatically, the ARGV variable is no longer present inside the
testcases. If I run the test suites explicitly, the ARGV variable
remains the same. I do not understand if this is a bug or if I am
misunderstanding what the automatic test runner does.

The two code snippets below illustrate what I mean:

require "test/unit"
require "pp"
class TC_Mysql < Test::Unit::TestCase
def setup()
puts "inside"
pp ARGV
end
def test_one()
assert_equal(1, 1)
end
end
puts "outside"
pp ARGV

if I run the above code with:

ruby test.rb Yo

I get the following output:

outside
["yo"]
Loaded suite args
Started
inside
[]

However, if I modify the code snippet to:

require "test/unit"
require "pp"
class TC_Mysql < Test::Unit::TestCase
def setup()
puts "inside"
pp ARGV
end
def test_one()
assert_equal(1, 1)
end
end
puts "outside"
pp ARGV
require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TC_Mysql)

running it with

ruby test.rb Yo

I get the following output:

outside
["yo"]
Loaded suite TC_Mysql
Started
inside
["yo"]
 
J

Jano Svitok

Hello,

I am experiencing the following strange problem (this is present in
ruby versions 1.8.5 and 1.8.6): if I rely on the test suites to be run
automatically, the ARGV variable is no longer present inside the
testcases. If I run the test suites explicitly, the ARGV variable
remains the same. I do not understand if this is a bug or if I am
misunderstanding what the automatic test runner does.

The two code snippets below illustrate what I mean:

require "test/unit"
require "pp"
class TC_Mysql < Test::Unit::TestCase
def setup()
puts "inside"
pp ARGV
end
def test_one()
assert_equal(1, 1)
end
end
puts "outside"
pp ARGV

if I run the above code with:

ruby test.rb Yo

I get the following output:

outside
["yo"]
Loaded suite args
Started
inside
[]

However, if I modify the code snippet to:

require "test/unit"
require "pp"
class TC_Mysql < Test::Unit::TestCase
def setup()
puts "inside"
pp ARGV
end
def test_one()
assert_equal(1, 1)
end
end
puts "outside"
pp ARGV
require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TC_Mysql)

running it with

ruby test.rb Yo

I get the following output:

outside
["yo"]
Loaded suite TC_Mysql
Started
inside
["yo"]

Hi,

your problem is caused by the fact that autorunner responds to some
command line arguments (run your suite with --help for the list). if
you want to pass arguments to your tests, use -- as a delimiter
between testrunner's and your arguments.

For very detailed info read lib/test/unit/autorunner.rb.

J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top