rewrite `hub create` tests as cukes

This commit is contained in:
Mislav Marohnić 2012-05-08 13:01:59 +02:00
Родитель b90b16b754
Коммит ee8b35d828
2 изменённых файлов: 102 добавлений и 120 удалений

102
features/create.feature Normal file
Просмотреть файл

@ -0,0 +1,102 @@
Feature: hub create
Background:
Given I am in "dotfiles" git repo
And I am "mislav" on github.com with OAuth token "OTOKEN"
Scenario: Create repo
Given the GitHub API server:
"""
post('/user/repos') {
halt 400 if params[:private]
status 200
}
"""
When I successfully run `hub create`
Then the url for "origin" should be "git@github.com:mislav/dotfiles.git"
And the output should contain exactly "created repository: mislav/dotfiles\n"
Scenario: Create private repo
Given the GitHub API server:
"""
post('/user/repos') {
halt 400 unless params[:private]
status 200
}
"""
When I successfully run `hub create -p`
Then the url for "origin" should be "git@github.com:mislav/dotfiles.git"
Scenario: HTTPS is preferred
Given the GitHub API server:
"""
post('/user/repos') { status 200 }
"""
And HTTPS is preferred
When I successfully run `hub create`
Then the url for "origin" should be "https://github.com/mislav/dotfiles.git"
Scenario: Create in organization
Given the GitHub API server:
"""
post('/orgs/acme/repos') { status 200 }
"""
When I successfully run `hub create acme/dotfiles`
Then the url for "origin" should be "git@github.com:acme/dotfiles.git"
And the output should contain exactly "created repository: acme/dotfiles\n"
Scenario: Creating repo failed
Given the GitHub API server:
"""
post('/user/repos') { status 500 }
"""
When I run `hub create`
Then the stderr should contain "Error creating repository: Internal Server Error (HTTP 500)"
And the exit status should be 1
And there should be no "origin" remote
Scenario: With custom name
Given the GitHub API server:
"""
post('/user/repos') {
halt 400 unless params[:name] == 'myconfig'
status 200
}
"""
When I successfully run `hub create myconfig`
Then the url for "origin" should be "git@github.com:mislav/myconfig.git"
Scenario: With description and homepage
Given the GitHub API server:
"""
post('/user/repos') {
halt 400 unless params[:description] == 'mydesc' and
params[:homepage] == 'http://example.com'
status 200
}
"""
When I successfully run `hub create -d mydesc -h http://example.com`
Then the url for "origin" should be "git@github.com:mislav/dotfiles.git"
Scenario: Not in git repo
Given the current dir is not a repo
When I run `hub create`
Then the stderr should contain "'create' must be run from inside a git repository"
And the exit status should be 1
Scenario: Origin remote already exists
Given the GitHub API server:
"""
post('/user/repos') { status 200 }
"""
And the "origin" remote has url "git://github.com/mislav/dotfiles.git"
When I successfully run `hub create`
Then the url for "origin" should be "git://github.com/mislav/dotfiles.git"
Scenario: GitHub repo already exists
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') { status 200 }
"""
When I successfully run `hub create`
Then the output should contain "mislav/dotfiles already exists on github.com\n"
And the url for "origin" should be "git@github.com:mislav/dotfiles.git"

Просмотреть файл

@ -244,126 +244,6 @@ class HubTest < Test::Unit::TestCase
"push origin,staging,qa cool-feature" "push origin,staging,qa cool-feature"
end end
def test_create
stub_no_remotes
stub_nonexisting_fork('tpw')
stub_request(:post, "https://api.github.com/user/repos").
with(:body => { 'name' => 'hub', 'private' => false })
expected = "remote add -f origin git@github.com:tpw/hub.git\n"
expected << "created repository: tpw/hub\n"
assert_equal expected, hub("create") { ENV['GIT'] = 'echo' }
end
def test_create_custom_name
stub_no_remotes
stub_nonexisting_fork('tpw', 'hubbub')
stub_request(:post, "https://api.github.com/user/repos").
with(:body => { 'name' => 'hubbub', 'private' => false })
expected = "remote add -f origin git@github.com:tpw/hubbub.git\n"
expected << "created repository: tpw/hubbub\n"
assert_equal expected, hub("create hubbub") { ENV['GIT'] = 'echo' }
end
def test_create_in_organization
stub_no_remotes
stub_nonexisting_fork('acme', 'hubbub')
stub_request(:post, "https://api.github.com/orgs/acme/repos").
with(:body => { 'name' => 'hubbub', 'private' => false })
expected = "remote add -f origin git@github.com:acme/hubbub.git\n"
expected << "created repository: acme/hubbub\n"
assert_equal expected, hub("create acme/hubbub") { ENV['GIT'] = 'echo' }
end
def test_create_failed
stub_no_remotes
stub_nonexisting_fork('tpw')
stub_request(:post, "https://api.github.com/user/repos").
to_return(:status => [401, "Your token is fail"])
expected = "Error creating repository: Your token is fail (HTTP 401)\n"
assert_equal expected, hub("create") { ENV['GIT'] = 'echo' }
end
def test_create_private_repository
stub_no_remotes
stub_nonexisting_fork('tpw')
stub_request(:post, "https://api.github.com/user/repos").
with(:body => { 'name' => 'hub', 'private' => true })
expected = "remote add -f origin git@github.com:tpw/hub.git\n"
expected << "created repository: tpw/hub\n"
assert_equal expected, hub("create -p") { ENV['GIT'] = 'echo' }
end
def test_create_private_repository_fails
stub_no_remotes
stub_nonexisting_fork('tpw')
stub_request(:post, "https://api.github.com/user/repos").
to_return(:status => [422, "Unprocessable Entity"],
:headers => {"Content-type" => "application/json"},
:body => %({"message":"repository creation failed: You are over your quota."}))
expected = "Error creating repository: Unprocessable Entity (HTTP 422)\n"
expected << "repository creation failed: You are over your quota.\n"
assert_equal expected, hub("create -p") { ENV['GIT'] = 'echo' }
end
def test_create_with_description_and_homepage
stub_no_remotes
stub_nonexisting_fork('tpw')
stub_request(:post, "https://api.github.com/user/repos").with(:body => {
'name' => 'hub', 'private' => false,
'description' => 'toyproject', 'homepage' => 'http://example.com'
})
expected = "remote add -f origin git@github.com:tpw/hub.git\n"
expected << "created repository: tpw/hub\n"
assert_equal expected, hub("create -d toyproject -h http://example.com") { ENV['GIT'] = 'echo' }
end
def test_create_with_invalid_arguments
assert_equal "invalid argument: -a\n", hub("create -a blah") { ENV['GIT'] = 'echo' }
assert_equal "invalid argument: bleh\n", hub("create blah bleh") { ENV['GIT'] = 'echo' }
end
def test_create_with_existing_repository
stub_no_remotes
stub_existing_fork('tpw')
expected = "tpw/hub already exists on github.com\n"
expected << "remote add -f origin git@github.com:tpw/hub.git\n"
expected << "set remote origin: tpw/hub\n"
assert_equal expected, hub("create") { ENV['GIT'] = 'echo' }
end
def test_create_https_protocol
stub_no_remotes
stub_existing_fork('tpw')
stub_https_is_preferred
expected = "tpw/hub already exists on github.com\n"
expected << "remote add -f origin https://github.com/tpw/hub.git\n"
expected << "set remote origin: tpw/hub\n"
assert_equal expected, hub("create") { ENV['GIT'] = 'echo' }
end
def test_create_outside_git_repo
stub_no_git_repo
assert_equal "'create' must be run from inside a git repository\n", hub("create")
end
def test_create_origin_already_exists
stub_nonexisting_fork('tpw')
stub_request(:post, "https://api.github.com/user/repos").
with(:body => { 'name' => 'hub', 'private' => false })
expected = "remote -v\ncreated repository: tpw/hub\n"
assert_equal expected, hub("create") { ENV['GIT'] = 'echo' }
end
def test_pullrequest def test_pullrequest
expected = "Aborted: head branch is the same as base (\"master\")\n" << expected = "Aborted: head branch is the same as base (\"master\")\n" <<
"(use `-h <branch>` to specify an explicit pull request head)\n" "(use `-h <branch>` to specify an explicit pull request head)\n"