Command line parameters testing

Hello,
I’m using Runit to write unit test for a class that takes command line
parameters.

How do I pass commandline parameters from Runit class to my actual class
that it’s testing?

I’m a new bee to ruby and any help will be appreciated.

Thanks,
App

App Ra wrote:

Hello,
I’m using Runit to write unit test for a class that takes command line
parameters.

How do I pass commandline parameters from Runit class to my actual class
that it’s testing?

By typing the Ruby script name and then the arguments. Perhaps a bit
more
detail on your problem would help us help you. Do you want to know how
to
create the command-line arguments, or how to read them?


#!/usr/bin/ruby -w

n = 0

ARGV.each do |arg|
puts “Argument #{n}: #{arg}”
n += 1
end


$ (ruby script name) This is a test.

Output:

Argument 0: This
Argument 1: is
Argument 2: a
Argument 3: test.

On 11/4/06, App Ra [email protected] wrote:

App
Passing arguments to your class instead of runit: (actually I don’t
know much about Runit, but this is common style, and test/unit does it
as well, so): The trick is to deparate parameters to your class with
– i.e. when I’m using test/unit I might do:

tc_whatever.rb -n /test_name/ – -a -b --c --defgh ijkl

Then -n /test_name/ will be processed by test/unit and -a -b --c
–defgh ijkl will be passed to the test.

Now to testing parameters: It’s better to put the command line
processing stuff into a method that you’ll call with ARGV rather than
using ARGV inside the method.
That way you’ll be able to test the parameter parsing without actually
messing with ARGV:

class Main
def parse_params(argv)

end
def run
@params = parse_params(ARGV)
end
end

class TestMain < Test::Unit::TestCase
def setup
@main = Main.new
end
def test_parse_params
assert_something xxx, @main.parse_params(%w[-c -a -b -addsa -das
–d-dsada])
assert_something yyyy, @main.parse_params(%w[-c -a -b --d-dsada])
assert_something_other @main.parse_params(%w[-c -addsa -das
–d-dsada])
end
end