提交 6518a829 编写于 作者: C Chris Wanstrath

refactor tests

上级 98e128c7
......@@ -2,35 +2,68 @@ require 'test/unit'
load File.dirname(__FILE__) + '/../bin/hub'
class HubTest < Test::Unit::TestCase
#
# Test helpers
#
def Hub(args)
Hub.new(*args.split(' '))
end
def hub(args)
args = args.split(' ')
hub = Hub.new(*args)
hub.send(args[0])
hub
parent_read, child_write = IO.pipe
fork do
$stdout.reopen(child_write)
Hub(args).execute
end
child_write.close
parent_read.read
end
def assert_command(input, expected)
assert_equal expected, Hub(input).command
end
#
# Assertions
#
def test_private_clone
h = hub("clone -p rtomayko/ron")
assert_equal 'git@github.com:rtomayko/ron.git', h.args.last
input = "clone -p rtomayko/ron"
command = "git clone git@github.com:rtomayko/ron.git"
assert_command input, command
end
def test_public_clone
h = hub("clone rtomayko/ron")
assert_equal 'git://github.com/rtomayko/ron.git', h.args.last
input = "clone rtomayko/ron"
command = "git clone git://github.com/rtomayko/ron.git"
assert_command input, command
end
def test_private_remote
h = hub("remote add -g -p rtomayko")
assert_equal 'git@github.com:rtomayko/hub.git', h.args.last
input = "remote add -g -p rtomayko"
command = "git remote add rtomayko git@github.com:rtomayko/hub.git"
assert_command input, command
end
def test_public_remote
h = hub("remote add -g rtomayko")
assert_equal 'git://github.com/rtomayko/hub.git', h.args.last
input = "remote add -g rtomayko"
command = "git remote add rtomayko git://github.com/rtomayko/hub.git"
assert_command input, command
end
def test_init
h = hub("init -g")
assert_equal 'git remote add origin git@github.com:defunkt/hub.git', h.after
h = Hub("init -g")
assert_equal "git init", h.command
assert_equal "git remote add origin git@github.com:defunkt/hub.git", h.after
end
def test_version
h = hub("--version")
assert_equal "git version 1.6.4.2\nhub version 0.1.0\n", h
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册