Skip to content

Commit

Permalink
Fix content-type expectations, as text/plain no longer is the same as…
Browse files Browse the repository at this point in the history
… N-Triples.
  • Loading branch information
gkellogg committed Aug 26, 2023
1 parent d4b44c0 commit 5ea6f0e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def response(header)

it "handles successful response with plain header" do
expect(subject).to receive(:request).and_yield response('text/plain')
expect(RDF::Reader).to receive(:for).with(content_type: 'text/plain').and_call_original
subject.query(query)
expect(RDF::Reader).to receive(:for).with(content_type: 'application/n-triples').and_call_original
subject.query(query, content_type: 'application/n-triples')
end

it "handles successful response with boolean header" do
Expand Down Expand Up @@ -109,17 +109,17 @@ def response(header)
end

it "handles successful response with custom headers" do
expect(subject).to receive(:request).with(anything, {"Authorization" => "Basic XXX=="}).
and_yield response('text/plain')
subject.query(query, headers: {"Authorization" => "Basic XXX=="})
expect(subject).to receive(:request).with(anything, {"Authorization" => "Basic XXX==", "Content-Type" => "application/n-triples"}).
and_yield response('application/n-triples')
subject.query(query, headers: {"Authorization" => "Basic XXX==", "Content-Type" => "application/n-triples"})
end

it "handles successful response with initial custom headers" do
options = {headers: {"Authorization" => "Basic XXX=="}, method: :get}
client = SPARQL::Client.new('http://data.linkedmdb.org/sparql', **options)
client.instance_variable_set :@http, double(request: response('text/plain'))
client.instance_variable_set :@http, double(request: response('application/n-triples'))
expect(Net::HTTP::Get).to receive(:new).with(anything, hash_including(options[:headers]))
client.query(query)
client.query(query, content_type: 'application/n-triples')
end

it "enables overriding the http method" do
Expand Down Expand Up @@ -194,15 +194,15 @@ def response(header)
to_return(body: '', status: 200, headers: { 'Content-Type' => 'application/n-triples'})
subject.query(construct_query)
expect(WebMock).to have_requested(:post, "http://data.linkedmdb.org/sparql").
with(headers: {'Accept'=>'application/n-triples, text/plain, */*;q=0.1'})
with(headers: {'Accept'=>'application/n-triples, */*;q=0.1'})
end

it "uses application/n-triples for DESCRIBE" do
WebMock.stub_request(:any, 'http://data.linkedmdb.org/sparql').
to_return(body: '', status: 200, headers: { 'Content-Type' => 'application/n-triples'})
subject.query(describe_query)
expect(WebMock).to have_requested(:post, "http://data.linkedmdb.org/sparql").
with(headers: {'Accept'=>'application/n-triples, text/plain, */*;q=0.1'})
with(headers: {'Accept'=>'application/n-triples, */*;q=0.1'})
end

it "uses application/sparql-results+json for SELECT" do
Expand Down

0 comments on commit 5ea6f0e

Please sign in to comment.