Command line parameters testing..

Discussion in 'Ruby' started by App Ra, Nov 4, 2006.

  1. App Ra

    App Ra Guest

    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


    --
    Posted via http://www.ruby-forum.com/.
     
    App Ra, Nov 4, 2006
    #1
    1. Advertising

  2. App Ra

    Jan Svitok Guest

    On 11/4/06, 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?
    >
    > 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
     
    Jan Svitok, Nov 4, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonck van der Kogel
    Replies:
    2
    Views:
    1,002
    Jonck van der Kogel
    May 27, 2004
  2. pelon
    Replies:
    1
    Views:
    242
    Steven D'Aprano
    Apr 3, 2007
  3. Peter
    Replies:
    0
    Views:
    394
    Peter
    Dec 3, 2009
  4. Alin Popa
    Replies:
    4
    Views:
    195
    Scott Patten
    Oct 25, 2007
  5. James Coglan
    Replies:
    0
    Views:
    123
    James Coglan
    Oct 3, 2009
Loading...

Share This Page