Skip to content

Commit

Permalink
Merge pull request #34 from ifad/chore/refactor-check-and-raise-failure
Browse files Browse the repository at this point in the history
Refactor check and raise failure
  • Loading branch information
tagliala authored Apr 20, 2024
2 parents 9fe05d3 + 09b2814 commit 47e7f9c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
18 changes: 1 addition & 17 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/sharepoint/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,9 @@ def last_location_header(ethon)
end

def check_and_raise_failure(ethon)
unless (200..299).include? ethon.response_code
raise "Request failed, received #{ethon.response_code}:\n#{ethon.url}\n#{ethon.response_body}"
end
return if (200..299).cover? ethon.response_code

raise "Request failed, received #{ethon.response_code}:\n#{ethon.url}\n#{ethon.response_body}"
end

def prepare_metadata(metadata, type)
Expand Down
14 changes: 13 additions & 1 deletion spec/lib/sharepoint/client_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
end

describe '#search' do
subject { client.search(options) }
subject(:search) { client.search(options) }

before { mock_responses('search_modified_documents.json') }

Expand All @@ -267,6 +267,18 @@
end

it { is_expected.not_to be_empty }

context 'when request fails' do
before do
allow_any_instance_of(Ethon::Easy)
.to receive(:response_code)
.and_return(401)
end

it 'raises an error' do
expect { search }.to raise_error(/\ARequest failed, received 401.+/)
end
end
end

describe '#download' do
Expand Down

0 comments on commit 47e7f9c

Please sign in to comment.