Sha256: 3905f8b57be0312638dc14e9efa8f92fcf7be91dc4e123ea9e9d0b92af061240
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 'Delegator' class DelegatorTest < 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 Delegator.no_react_to(Quickl::Exit) Delegator.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.2.0 | examples/delegator/test/delegator_test.rb |