Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor check and raise failure #34

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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