/
pull_request.feature
149 lines (139 loc) · 5.18 KB
/
pull_request.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
Feature: hub pull-request
Background:
Given I am in "dotfiles" git repo
And I am "mislav" on github.com with OAuth token "OTOKEN"
Scenario: Detached HEAD
Given the "origin" remote has url "git://github.com/mislav/coral.git"
And I am in detached HEAD
When I run `hub pull-request`
Then the stderr should contain "Aborted: not currently on any branch.\n"
And the exit status should be 1
Scenario: Non-GitHub repo
Given the "origin" remote has url "mygh:Manganeez/repo.git"
When I run `hub pull-request`
Then the stderr should contain "Aborted: the origin remote doesn't point to a GitHub repository.\n"
And the exit status should be 1
Scenario: Create pull request respecting "insteadOf" configuration
Given the "origin" remote has url "mygh:Manganeez/repo.git"
When I successfully run `git config url."git@github.com:".insteadOf mygh:`
Given the GitHub API server:
"""
post('/repos/Manganeez/repo/pulls') {
{ :base => 'master',
:head => 'mislav:master',
:title => 'hereyougo'
}.each do |param, value|
if params[param] != value
halt 422, json(
:message => "expected %s to be %s; got %s" % [
param.inspect,
value.inspect,
params[param].inspect
]
)
end
end
json :html_url => "https://github.com/Manganeez/repo/pull/12"
}
"""
When I successfully run `hub pull-request hereyougo`
Then the output should contain exactly "https://github.com/Manganeez/repo/pull/12\n"
Scenario: With Unicode characters
Given the "origin" remote has url "git://github.com/mislav/coral.git"
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
halt 400 if request.content_charset != 'utf-8'
halt 422 if params[:title] != 'ăéñøü'
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request ăéñøü`
Then the output should contain exactly "the://url\n"
Scenario: Non-existing base
Given the "origin" remote has url "git://github.com/mislav/coral.git"
Given the GitHub API server:
"""
post('/repos/origin/coral/pulls') { 404 }
"""
When I run `hub pull-request -b origin:master hereyougo`
Then the exit status should be 1
Then the stderr should contain:
"""
Error creating pull request: Not Found (HTTP 404)
Are you sure that github.com/origin/coral exists?
"""
Scenario: Supplies User-Agent string to API calls
Given the "origin" remote has url "git://github.com/mislav/coral.git"
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
halt 400 unless request.user_agent.include?('Hub')
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request useragent`
Then the output should contain exactly "the://url\n"
Scenario: Text editor adds title and body
Given the "origin" remote has url "git://github.com/mislav/coral.git"
And the text editor adds:
"""
This title comes from vim!
This body as well.
"""
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
{ :title => 'This title comes from vim!',
:body => 'This body as well.'
}.each do |param, value|
if params[param] != value
halt 422, json(
:message => "expected %s to be %s; got %s" % [
param.inspect,
value.inspect,
params[param].inspect
]
)
end
end
json :html_url => "https://github.com/mislav/coral/pull/12"
}
"""
When I successfully run `hub pull-request`
Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
And the file ".git/PULLREQ_EDITMSG" should not exist
Scenario: Failed pull request preserves previous message
Given the "origin" remote has url "git://github.com/mislav/coral.git"
And the text editor adds:
"""
This title will fail
"""
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
halt 422 if params[:title].include?("fail")
halt 422 unless params[:body] == "This title will fail"
json :html_url => "https://github.com/mislav/coral/pull/12"
}
"""
When I run `hub pull-request`
Then the exit status should be 1
And the stderr should contain exactly:
"""
Error creating pull request: (HTTP 422)\n
"""
Given the text editor adds:
"""
But this title will prevail
"""
When I successfully run `hub pull-request`
Then the file ".git/PULLREQ_EDITMSG" should not exist
Scenario: Text editor fails
Given the "origin" remote has url "git://github.com/mislav/coral.git"
And the text editor exits with error status
And an empty file named ".git/PULLREQ_EDITMSG"
When I run `hub pull-request`
Then the stderr should contain "error using text editor for pull request message"
And the exit status should be 1
And the file ".git/PULLREQ_EDITMSG" should not exist