davetron5000 / optparse-plus

Start your command line scripts off right in Ruby
http://davetron5000.github.com/optparse-plus
Apache License 2.0
521 stars 54 forks source link

Document how to test for parameters in options #66

Closed Telmo closed 11 years ago

Telmo commented 11 years ago

When using opt("-e environment", "--environment", "needed environment") I want to be able to reference an example So I don't drive myself insane trying to do it.

Basically I have an app that does not take arguments. I am using the options as a type of switch, it this option is defined and its value is not nill do this, else do this other thing. But I am having a hard time with aruba/cucumber testing this scenarion. I am aware that this can be done for arguments but I don't see anywhere where it can be done for options (in the wiki, the book, or the ibook)

davetron5000 commented 11 years ago

The current Aruba steps only allow you to check if an option has documentation, but if you want to check behavior, you should be able to run the app and observe the output, e.g.

When I successfully run `my_app -e testing`
Then the output should contain:
"""
whatever might be output for -e testing
"""

Not sure if that explains it, but with the Aruba tests, you are kinda limited to just testing things like output or standard error from your app. It kinda depends on what your app does in those situations.

Does that help?

Dave


Buy My Book: http://www.awesomecommandlineapps.com My Blog: http://www.naildrivin5.com/blog Fork me on Github: http://davetron5000.github.com

On Mon, May 13, 2013 at 9:01 AM, Roberto notifications@github.com wrote:

When using opt("-e environment", "--environment", "needed environment") I want to be able to reference an example So I don't drive myself insane trying to do it.

Basically I have an app that does not take arguments. I am using the options as a type of switch, it this option is defined and its value is not nill do this, else do this other thing. But I am having a hard time with aruba/cucumber testing this scenarion. I am aware that this can be done for arguments but I don't see anywhere where it can be done for options (in the wiki, the book, or the ibook)

— Reply to this email directly or view it on GitHubhttps://github.com/davetron5000/methadone/issues/66 .

Telmo commented 11 years ago

it does help, unfortunately I had to resort to good old optionsparser :(

davetron5000 commented 11 years ago

Can you post a code snippet? Methadone is a proxy for optionparser, so you should theoretically never need it…

Dave

(Sent from my iPhone [I CAN spell])

On May 14, 2013, at 7:45 AM, Roberto notifications@github.com wrote:

it does help, unfortunately I had to resort to good old optionsparser :(

— Reply to this email directly or view it on GitHub.

Telmo commented 11 years ago

What I did is to drop aruba/cucumber all together and just go with plain rspec tests, since I am more used to work with optionsparser than methadone I feel that best approach for me was to just go with optionsparser. If I were not in a tight deadline I would invest more time in methadone as I've done with GLI in the pass. GLI is now the standard way we write "complex" CLI at work.

davetron5000 commented 11 years ago

OK, cool. I, too, find the aruba tests a bit cumbersome, so I'd be interested in what you come up with. FWIW, Methadone uses OptionParser fairly directly, e.g.

on("--env ENV")

literally just does

opts.on("--env ENV") do |arg|
  options[:env] = arg
end

where opts is an OptionParser.

Anyway, good luck and sorry it didn't work out!

Dave


Buy My Book: http://www.awesomecommandlineapps.com My Blog: http://www.naildrivin5.com/blog Fork me on Github: http://davetron5000.github.com

On Tue, May 14, 2013 at 8:32 AM, Roberto notifications@github.com wrote:

What I did is to drop aruba/cucumber all together and just go with plain rspec tests, since I am more used to work with optionsparser than methadone I feel that best approach for me was to just go with optionsparser. If I were not in a tight deadline I would invest more time in methadone as I've done with GLI in the pass. GLI is now the standard way we write "complex" CLI at work.

— Reply to this email directly or view it on GitHubhttps://github.com/davetron5000/methadone/issues/66#issuecomment-17872885 .