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
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