Sha256: 5df6ac21cb2876781ce6aa33a383ba60094ed5966d9e5ed372296c2910a1a870
Contents?: true
Size: 1.55 KB
Versions: 1
Compression:
Stored size: 1.55 KB
Contents
require 'test/unit' require 'stringio' begin require 'quickl' rescue LoadError $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) require 'quickl' end $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'delegate' class DelegateTest < Test::Unit::TestCase def assert_exits(match, exit_code) yield assert_false true, "Expected to exit with #{match}, nothing raised" rescue Quickl::Exit => ex assert_equal ex.exit_code, exit_code assert ex.message =~ match end def run_command(*args) $stdout = StringIO.new Delegate.no_react_to(Quickl::Exit) Delegate.run args $stdout.string ensure $stdout = STDOUT end def test_alone assert_exits(/Delegate execution to a sub command/, 0){ run_command } end def test_help_option assert_exits(/DESCRIPTION/, 0){ run_command("--help") } end def test_version_option assert_exits(/(c)/, 0){ run_command("--version") } end def test_no_such_option assert_exits(/invalid option/, -1){ run_command("--no-such-option") } end def test_help_delegation assert run_command("help", "hello-world") =~ /Say hello/ end def test_hello_delegation assert_equal "Hello world!\n", run_command("hello-world") assert_equal "Hello bob!\n", run_command("hello-world", "bob") end def test_hello_capitalize assert_equal "Hello World!\n", run_command("hello-world", "--capitalize") assert_equal "Hello Bob!\n", run_command("hello-world", "bob", "--capitalize") end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
quickl-0.1.1 | examples/delegate/test/delegate_test.rb |