From: Martin Hansen Date: 2010-05-12T18:59:49+09:00 Subject: Re: Unit Test of method calling system() - how? OK, I am getting closer, but are still a bit confused. I feel like staying away from mocks, because I am not proficient enough to tell, if my code and tests are working correctly or not. Now, I have rearranged the code a bit -> http://pastie.org/956728 I still have a problem with $0. I was wondering if I could just add the script name to the parse method as an optional argument (or is that ugly?): def parse(argv, script_name=$0) This would make it possible to write the following tests: test "Options.parse with empty argv and missing wiki file raises" do opt_parser = Options.new assert_raise() { opt_parser.parse([],"foo") } end test "Options.parse with empty argv and existing wiki file don't raise" do opt_parser = Options.new assert_nothing_raised() { opt_parser.parse([],"/foo/bar.rb") } end However, the original problem remains - I really want to test the following: test "Options.parse with empty argv and existing wiki output short usage" do opt_parser = Options.new assert("" == opt_parser.parse([],"/foo/bar.rb")) end test "Options.parse with --help in argv and existing wiki output long usage" do opt_parser = Options.new assert("" == opt_parser.parse(["--help"],"/foo/bar.rb")) end I am actually not interested in the invocation of print_wiki, since this Perl script is tested - so never mind about testing the print_usage_and_exit -> good enuf for government work... But I am interested in testing the print_usage_full? and print_usage_short? methods. So how to do that? There is this send trick for testing private methods: http://stackoverflow.com/questions/267237/whats-the-best-way-to-unit-test-protected-private-methods-in-ruby Martin -- Posted via http://www.ruby-forum.com/.