Skip to content

Commit

Permalink
Fix with ci
Browse files Browse the repository at this point in the history
  • Loading branch information
paveg committed Aug 4, 2018
1 parent 75edbf6 commit 89e1b7d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
15 changes: 8 additions & 7 deletions lib/lgtm/error_handleable.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
module Lgtm
# ErrorHandleable of module of error handling
module ErrorHandleable
# 2xx http success status.
SUCCESS_STATUSES = [Net::HTTPSuccess, Net::HTTPFound]
# 4xx http status.
CLIENT_ERRORS = [Net::HTTPBadRequest, Net::HTTPForbidden, Net::HTTPNotFound]
CLIENT_ERRORS = [
Net::HTTPBadRequest,
Net::HTTPForbidden,
Net::HTTPNotFound
].freeze
# 5xx http status.
SERVER_ERRORS = [
Net::HTTPInternalServerError,
Net::HTTPBadGateway,
Net::HTTPServiceUnavailable,
Net::HTTPGatewayTimeOut,
]
Net::HTTPGatewayTimeOut
].freeze

def validate_response(response)
case response
when *SUCCESS_STATUSES
# Nothing to do.
when *SERVER_ERRORS
raise ::Lgtm::Errors::UnexpectedError
when *CLIENT_ERRORS
Expand Down
3 changes: 1 addition & 2 deletions lib/lgtm/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def fetch_image_url(https_image_only: false)
return fetch_image_url(https_image_only: true)
end
url
rescue ::Lgtm::Errors::UnexpectedError
nil
rescue ::Lgtm::Errors::UnexpectedError; nil
end

def process_request(url)
Expand Down
10 changes: 8 additions & 2 deletions spec/lgtm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ def mock(request_url: 'https://lgtm.in/p/sSuI4hm0q',
end

describe '#check_lgtm' do
subject { lgtm.check_lgtm(https_image_only: https_image_only, image_url: image_url) }
subject do
lgtm.check_lgtm(
https_image_only: https_image_only,
image_url: image_url
)
end

let(:dangerfile) { testing_dangerfile }
let(:lgtm) { dangerfile.lgtm }
Expand All @@ -42,7 +47,8 @@ def mock(request_url: 'https://lgtm.in/p/sSuI4hm0q',
end

it 'lgtm with errors' do
allow(lgtm).to receive(:validate_response).and_raise(::Lgtm::Errors::UnexpectedError)
allow(lgtm).to receive(:validate_response)
.and_raise(::Lgtm::Errors::UnexpectedError)
is_expected
expect(dangerfile.status_report[:markdowns][0].message)
.to eq("<h1 align='center'>LGTM</h1>")
Expand Down

0 comments on commit 89e1b7d

Please sign in to comment.