提交 29664446 编写于 作者: M Mislav Marohnić

Merge pull request #597 from github/cukes-galore

Port a bunch more tests to cukes
Feature: hub am
Background:
Given I am in "git://github.com/mislav/dotfiles.git" git repo
And I am "mislav" on github.com with OAuth token "OTOKEN"
Scenario: Apply a local patch
When I run `hub am some.patch`
Then the git command should be unchanged
Scenario: Apply commits from pull request
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub am -q -3 https://github.com/mislav/dotfiles/pull/387`
Then there should be no output
Then the latest commit message should be "Create a README"
Scenario: Apply commits when TMPDIR is empty
Given $TMPDIR is ""
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub am -q https://github.com/mislav/dotfiles/pull/387`
Then the latest commit message should be "Create a README"
Scenario: Enterprise repo
Given I am in "git://git.my.org/mislav/dotfiles.git" git repo
And I am "mislav" on git.my.org with OAuth token "FITOKEN"
......@@ -7,23 +39,37 @@ Feature: hub am
"""
get('/api/v3/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
<<PATCH
From 7eb75a26ee8e402aad79fcf36a4c1461e3ec2592 Mon Sep 17 00:00:00 2001
From: Mislav <mislav.marohnic@gmail.com>
Date: Tue, 24 Jun 2014 11:07:05 -0700
Subject: [PATCH] Create a README
---
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/README.md
+hello
--
1.9.3
PATCH
generate_patch "Create a README"
}
"""
When I successfully run `hub am -q -3 https://git.my.org/mislav/dotfiles/pull/387`
And I successfully run `git log -1 --format=%s`
Then the output should contain exactly "Create a README\n"
Then the latest commit message should be "Create a README"
Scenario: Apply patch from commit
Given the GitHub API server:
"""
get('/repos/davidbalbert/dotfiles/commits/fdb9921') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub am -q https://github.com/davidbalbert/dotfiles/commit/fdb9921`
Then the latest commit message should be "Create a README"
Scenario: Apply patch from gist
Given the GitHub API server:
"""
get('/gists/8da7fb575debd88c54cf', :host_name => 'api.github.com') {
json :files => {
'file.diff' => {
:raw_url => "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff"
}
}
}
get('/raw/8da7fb575debd88c54cf/SHA/file.diff', :host_name => 'gist.github.com') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'text/plain'
generate_patch "Create a README"
}
"""
When I successfully run `hub am -q https://gist.github.com/8da7fb575debd88c54cf`
Then the latest commit message should be "Create a README"
Feature: hub apply
Background:
Given I am in "git://github.com/mislav/dotfiles.git" git repo
And I am "mislav" on github.com with OAuth token "OTOKEN"
And I make a commit
Scenario: Apply a local patch
When I run `hub apply some.patch`
Then the git command should be unchanged
And the file "README.md" should not exist
Scenario: Apply commits from pull request
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub apply -3 https://github.com/mislav/dotfiles/pull/387`
Then there should be no output
Then a file named "README.md" should exist
Scenario: Apply commits when TMPDIR is empty
Given $TMPDIR is ""
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub apply https://github.com/mislav/dotfiles/pull/387`
Then a file named "README.md" should exist
Scenario: Enterprise repo
Given I am in "git://git.my.org/mislav/dotfiles.git" git repo
And I am "mislav" on git.my.org with OAuth token "FITOKEN"
And "git.my.org" is a whitelisted Enterprise host
Given the GitHub API server:
"""
get('/api/v3/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub apply https://git.my.org/mislav/dotfiles/pull/387`
Then a file named "README.md" should exist
Scenario: Apply patch from commit
Given the GitHub API server:
"""
get('/repos/davidbalbert/dotfiles/commits/fdb9921') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub apply https://github.com/davidbalbert/dotfiles/commit/fdb9921`
Then a file named "README.md" should exist
Scenario: Apply patch from gist
Given the GitHub API server:
"""
get('/gists/8da7fb575debd88c54cf', :host_name => 'api.github.com') {
json :files => {
'file.diff' => {
:raw_url => "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff"
}
}
}
get('/raw/8da7fb575debd88c54cf/SHA/file.diff', :host_name => 'gist.github.com') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'text/plain'
generate_patch "Create a README"
}
"""
When I successfully run `hub apply https://gist.github.com/8da7fb575debd88c54cf`
Then a file named "README.md" should exist
......@@ -2,6 +2,11 @@ Feature: hub browse
Background:
Given I am "mislav" on github.com with OAuth token "OTOKEN"
Scenario: No repo
When I run `hub browse`
Then the exit status should be 1
Then the output should contain exactly "Usage: hub browse [<USER>/]<REPOSITORY>\n"
Scenario: Project with owner
When I successfully run `hub browse mislav/dotfiles`
Then there should be no output
......@@ -105,7 +110,7 @@ Feature: hub browse
And I am on the "feature" branch pushed to "mislav/feature"
When I successfully run `hub browse -- issues`
Then there should be no output
# Then "open https://github.com/jashkenas/coffee-script/issues" should be run
Then "open https://github.com/jashkenas/coffee-script/issues" should be run
Scenario: Complex branch
Given I am in "git://github.com/mislav/dotfiles.git" git repo
......@@ -168,3 +173,24 @@ Feature: hub browse
And "git.my.org" is a whitelisted Enterprise host
When I successfully run `hub browse`
Then "open http://git.my.org/mislav/dotfiles" should be run
Scenario: SSH alias
Given the SSH config:
"""
Host gh
User git
HostName github.com
"""
Given I am in "gh:singingwolfboy/sekrit.git" git repo
When I successfully run `hub browse`
Then "open https://github.com/singingwolfboy/sekrit" should be run
Scenario: SSH GitHub alias
Given the SSH config:
"""
Host github.com
HostName ssh.github.com
"""
Given I am in "git@github.com:suan/git-sanity.git" git repo
When I successfully run `hub browse`
Then "open https://github.com/suan/git-sanity" should be run
Feature: hub init
Background:
Given I am "mislav" on github.com with OAuth token "OTOKEN"
Given a directory named "dotfiles"
When I cd to "dotfiles"
Scenario: Initializes a git repo with remote
When I successfully run `hub init -g`
Then the url for "origin" should be "git@github.com:mislav/dotfiles.git"
Scenario: Enterprise host
Given $GITHUB_HOST is "git.my.org"
And I am "mislav" on git.my.org with OAuth token "FITOKEN"
And "git.my.org" is a whitelisted Enterprise host
When I successfully run `hub init -g`
Then the url for "origin" should be "git@git.my.org:mislav/dotfiles.git"
Feature: hub push
Background:
Given I am in "git://github.com/mislav/coral.git" git repo
Scenario: Normal push
When I successfully run `hub push`
Then the git command should be unchanged
Scenario: Push current branch to multiple remotes
Given I am on the "cool-feature" branch
When I successfully run `hub push origin,staging`
Then "git push origin cool-feature" should be run
Then "git push staging cool-feature" should be run
Scenario: Push explicit branch to multiple remotes
When I successfully run `hub push origin,staging,qa cool-feature`
Then "git push origin cool-feature" should be run
Then "git push staging cool-feature" should be run
Then "git push qa cool-feature" should be run
Scenario: Push multiple refs to multiple remotes
When I successfully run `hub push origin,staging master new-feature`
Then "git push origin master new-feature" should be run
Then "git push staging master new-feature" should be run
......@@ -41,7 +41,7 @@ Given(/^\$(\w+) is "([^"]*)"$/) do |name, value|
end
Given(/^I am in "([^"]*)" git repo$/) do |dir_name|
if dir_name.include? '://'
if dir_name.include?(':')
origin_url = dir_name
dir_name = File.basename origin_url, '.git'
end
......@@ -69,6 +69,11 @@ When(/^I make (a|\d+) commits?(?: with message "([^"]+)")?$/) do |num, msg|
num.times { empty_commit(msg) }
end
Then(/^the latest commit message should be "([^"]+)"$/) do |subject|
step %(I successfully run `git log -1 --format=%s`)
step %(the output should contain exactly "#{subject}\\n")
end
Given(/^the "([^"]+)" branch is pushed to "([^"]+)"$/) do |name, upstream|
full_upstream = ".git/refs/remotes/#{upstream}"
in_current_dir do
......@@ -234,3 +239,9 @@ end
Given(/^the git commit editor is "([^"]+)"$/) do |cmd|
set_env('GIT_EDITOR', cmd)
end
Given(/^the SSH config:$/) do |config_lines|
ssh_config = "#{ENV['HOME']}/.ssh/config"
FileUtils.mkdir_p(File.dirname(ssh_config))
File.open(ssh_config, 'w') {|f| f << config_lines }
end
......@@ -77,6 +77,24 @@ module Hub
)
end
end
def generate_patch(subject)
<<PATCH
From 7eb75a26ee8e402aad79fcf36a4c1461e3ec2592 Mon Sep 17 00:00:00 2001
From: Mislav <mislav.marohnic@gmail.com>
Date: Tue, 24 Jun 2014 11:07:05 -0700
Subject: [PATCH] #{subject}
---
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/README.md
+hello
--
1.9.3
PATCH
end
end
new(klass.new).start
......
......@@ -690,7 +690,7 @@ module Hub
elsif subpage && !%w[commits tree blob settings].include?(subpage)
branch = master_branch
project = local_repo.main_project
else
elsif local_repo(false)
# $ hub browse
prefer_upstream = current_branch && current_branch.master?
branch, project = remote_branch_and_project(method(:github_user), prefer_upstream)
......
......@@ -161,162 +161,6 @@ class HubTest < Minitest::Test
"cherry-pick xoebus@a319d88"
end
def test_am_untouched
assert_forwarded "am some.patch"
end
def test_am_pull_request
stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/55").
with(:headers => {'Accept'=>'application/vnd.github.v3.patch', 'Authorization'=>'token OTOKEN'}).
to_return(:status => 200)
with_tmpdir('/tmp/') do
assert_commands %r{git am --signoff /tmp/55\.patch[\w-]+ -p2},
"am --signoff https://github.com/defunkt/hub/pull/55#comment_123 -p2"
cmd = Hub("am https://github.com/defunkt/hub/pull/55/files").command
assert_includes '/tmp/55.patch', cmd
end
end
def test_am_no_tmpdir
stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/55").
to_return(:status => 200)
with_tmpdir(nil) do
cmd = Hub("am https://github.com/defunkt/hub/pull/55").command
assert_includes '/tmp/55.patch', cmd
end
end
def test_am_commit_url
stub_request(:get, "https://api.github.com/repos/davidbalbert/hub/commits/fdb9921").
with(:headers => {'Accept'=>'application/vnd.github.v3.patch', 'Authorization'=>'token OTOKEN'}).
to_return(:status => 200)
with_tmpdir('/tmp/') do
url = 'https://github.com/davidbalbert/hub/commit/fdb9921'
assert_commands %r{git am --signoff /tmp/fdb9921\.patch[\w-]+ -p2},
"am --signoff #{url} -p2"
end
end
def test_am_gist
stub_request(:get, "https://api.github.com/gists/8da7fb575debd88c54cf").
with(:headers => {'Authorization'=>'token OTOKEN'}).
to_return(:body => Hub::JSON.generate(:files => {
'file.diff' => {
:raw_url => "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff"
}
}))
stub_request(:get, "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff").
with(:headers => {'Accept'=>'text/plain'}).
to_return(:status => 200)
with_tmpdir('/tmp/') do
url = 'https://gist.github.com/8da7fb575debd88c54cf'
assert_commands %r{git am --signoff /tmp/gist-8da7fb575debd88c54cf\.txt[\w-]+ -p2},
"am --signoff #{url} -p2"
end
end
def test_apply_untouched
assert_forwarded "apply some.patch"
end
def test_apply_pull_request
stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/55").
to_return(:status => 200)
with_tmpdir('/tmp/') do
assert_commands %r{git apply /tmp/55\.patch[\w-]+ -p2},
"apply https://github.com/defunkt/hub/pull/55 -p2"
cmd = Hub("apply https://github.com/defunkt/hub/pull/55/files").command
assert_includes '/tmp/55.patch', cmd
end
end
def test_apply_commit_url
stub_request(:get, "https://api.github.com/repos/davidbalbert/hub/commits/fdb9921").
to_return(:status => 200)
with_tmpdir('/tmp/') do
url = 'https://github.com/davidbalbert/hub/commit/fdb9921'
assert_commands %r{git apply /tmp/fdb9921\.patch[\w-]+ -p2},
"apply #{url} -p2"
end
end
def test_apply_gist
stub_request(:get, "https://api.github.com/gists/8da7fb575debd88c54cf").
with(:headers => {'Authorization'=>'token OTOKEN'}).
to_return(:body => Hub::JSON.generate(:files => {
'file.diff' => {
:raw_url => "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff"
}
}))
stub_request(:get, "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff").
to_return(:status => 200)
with_tmpdir('/tmp/') do
url = 'https://gist.github.com/mislav/8da7fb575debd88c54cf'
assert_commands %r{git apply /tmp/gist-8da7fb575debd88c54cf\.txt[\w-]+ -p2},
"apply #{url} -p2"
end
end
def test_init
stub_no_remotes
stub_no_git_repo
assert_commands "git init", "git remote add origin git@github.com:tpw/hub.git", "init -g"
end
def test_init_enterprise
stub_no_remotes
stub_no_git_repo
edit_hub_config do |data|
data['git.my.org'] = [{'user'=>'myfiname'}]
end
with_host_env('git.my.org') do
assert_commands "git init", "git remote add origin git@git.my.org:myfiname/hub.git", "init -g"
end
end
def test_push_untouched
assert_forwarded "push"
end
def test_push_two
assert_commands "git push origin cool-feature", "git push staging cool-feature",
"push origin,staging cool-feature"
end
def test_push_current_branch
stub_branch('refs/heads/cool-feature')
assert_commands "git push origin cool-feature", "git push staging cool-feature",
"push origin,staging"
end
def test_push_more
assert_commands "git push origin cool-feature",
"git push staging cool-feature",
"git push qa cool-feature",
"push origin,staging,qa cool-feature"
end
def test_push_multiple_refs
assert_commands "git push origin master new-feature",
"git push staging master new-feature",
"push origin,staging master new-feature"
end
def test_pullrequest_from_branch_tracking_local
stub_config_value 'push.default', 'upstream'
stub_branch('refs/heads/feature')
......@@ -423,25 +267,6 @@ class HubTest < Minitest::Test
assert_includes 'This file is generated code', hub("hub standalone")
end
def test_hub_browse_no_repo
stub_repo_url(nil)
assert_equal "Usage: hub browse [<USER>/]<REPOSITORY>\n", hub("browse")
end
def test_hub_browse_ssh_alias
with_ssh_config "Host gh\n User git\n HostName github.com" do
stub_repo_url "gh:singingwolfboy/sekrit.git"
assert_command "browse", "open https://github.com/singingwolfboy/sekrit"
end
end
def test_hub_browse_ssh_github_alias
with_ssh_config "Host github.com\n HostName ssh.github.com" do
stub_repo_url "git@github.com:suan/git-sanity.git"
assert_command "browse", "open https://github.com/suan/git-sanity"
end
end
def test_custom_browser
with_browser_env("custom") do
assert_browser("custom")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册