From: Panagiotis Atmatzidis Date: 2012-08-07T01:33:14+09:00 Subject: Questions about test-driven development and optparse Hello, I just finished the first version of a script that gathers info from 'fail2ban.log' [1] and displays it. I'd like to turn it into a gem. Reading the official documentation [2] and a book that I use as a guide, I've read about the importance of "writing tests", before turning anything into a gem. I wonder though, what kind of test should/could I write since my script users optparse. Expected outputs are like: ---- ➜ f2bread git:(master) ruby f2bread.rb -l ../../Local/f2bread/fail2ban.log -i =============================================================================== Log file: '/Users/atma/Dropbox/Programming/Projects/Local/f2bread/fail2ban.log' First entry: 2011-07-23 02:04:51 Last entry: 2012-07-25 15:14:47 Time frame: 1 year, 3 days and 07:09:56 Banned IPs: 1072 Countries: 70 Protocol(s): [ssh-ipfw] Bans per day: 2.91 Most banned IP(s) by fail2ban: ------------------------- IP address - Attacks ------------------------- 121.31.56.62 7 Most hostile Countries: -------------------------- Country: Korea(South) - IP(s): 400 Country: China - IP(s): 195 Country: United_States - IP(s): 86 Country: Russian_Federation - IP(s): 36 Country: Germany - IP(s): 32 ➜ f2bread git:(master) ruby f2bread.rb -l ../../Local/f2bread/fail2ban.log -s country -n 5 Country: Korea(South) - IP(s): 400 Country: China - IP(s): 195 Country: United_States - IP(s): 86 Country: Russian_Federation - IP(s): 36 Country: Germany - IP(s): 32 ----- So in this scenario, does 'testing' have a meaning? I mean, I already see that 'it works'. Writing a function that will match these and other possible outputs looks like a huge regexp hell to me or I'm getting something wrong here. Thanks [1] https://github.com/atmosx/f2bread [2] http://guides.rubygems.org/make-your-own-gem/#writing-tests Panagiotis Atmatzidis ----------------------------- Pharmacy Student at VFU email4lists: ml@convalesco.org More info: http://about.me/atmosx The wise man said: "Never argue with an idiot, he brings you down to his level and beat you with experience."