Skip to content

Commit 7461d0b

Browse files
committed
Add unprocessable entity error test.
1 parent 632b431 commit 7461d0b

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Github::Error::UnprocessableEntity do
6+
let(:user) { 'peter-murach' }
7+
let(:repo) { 'github' }
8+
let(:request_path) { "/repos/#{user}/#{repo}/pulls" }
9+
let(:inputs) do
10+
{
11+
"title" => "Amazing new feature",
12+
"body" => "Please pull this in!",
13+
"head" => "noexist",
14+
"base" => "master",
15+
"state" => "open",
16+
'unrelated' => 'giberrish'
17+
}
18+
end
19+
20+
def test_request(body='')
21+
stub_post(request_path).with(inputs.except('unrelated')).
22+
to_return(body: body, status: 422, headers: {content_type: "application/json; charset=utf-8"})
23+
end
24+
25+
it "handles multiple nested errors" do
26+
test_request "{\"message\":\"Validation Failed\",\"errors\":[{\"resource\":\"PullRequest\",\"code\":\"missing_field\",\"field\":\"head_sha\"},{\"resource\":\"PullRequest\",\"code\":\"missing_field\",\"field\":\"base_sha\"},{\"resource\":\"PullRequest\",\"code\":\"custom\",\"message\":\"No commits between master and noexist\"}],\"documentation_url\":\"https://developer.github.com/enterprise/2.6/v3/pulls/#create-a-pull-request\"}"
27+
28+
expect {
29+
Github::Client::PullRequests.new.create(user, repo, inputs)
30+
}.to raise_error(Github::Error::UnprocessableEntity, /No commits between master and noexist/)
31+
end
32+
end # Github::Error::UnprocessableEntity

0 commit comments

Comments
 (0)