Skip to content

Commit e119ff0

Browse files
committed
Remove dependency on schema.org for conneg tests.
1 parent cb5ef84 commit e119ff0

File tree

3 files changed

+25
-178
lines changed

3 files changed

+25
-178
lines changed

spec/conneg_spec.rb

+20-171
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require_relative 'spec_helper'
4-
require 'rack/linkeddata'
4+
require 'rack/rdf'
55
require 'rack/test'
66

77
describe JSON::LD::ContentNegotiation do
@@ -12,6 +12,25 @@
1212
described_class.new(double("Target Rack Application", :call => [200, {}, @results || "A String"]))
1313
end
1414

15+
let(:example_context) do
16+
JSON::LD::API::RemoteDocument.new('{
17+
"@context": {
18+
"@vocab": "http://example.com/",
19+
"id": "@id",
20+
"type": "@type"
21+
}
22+
}', documentUrl: "http://example.com")
23+
end
24+
25+
before do
26+
JSON::LD::Writer.default_context = 'http://example.com/context'
27+
allow(JSON::LD::API).to receive(:documentLoader).with('http://example.com/context', any_args).and_yield(example_context)
28+
end
29+
30+
after do
31+
JSON::LD::Writer.default_context = nil
32+
end
33+
1534
describe "#parse_accept_header" do
1635
{
1736
"application/n-triples, application/ld+json;q=0.5" => %w[application/ld+json],
@@ -40,15 +59,6 @@
4059
end
4160

4261
describe "#call" do
43-
let(:schema_context) do
44-
JSON::LD::API::RemoteDocument.new('{
45-
"@context": {
46-
"@vocab": "http://schema.org/",
47-
"id": "@id",
48-
"type": "@type"
49-
}
50-
}', documentUrl: "http://schema.org")
51-
end
5262
let(:frame) do
5363
JSON::LD::API::RemoteDocument.new('{
5464
"@context": {
@@ -74,7 +84,6 @@
7484
end
7585

7686
before do
77-
allow(JSON::LD::API).to receive(:documentLoader).with("http://schema.org", any_args).and_yield(schema_context)
7887
allow(JSON::LD::API).to receive(:documentLoader).with("http://conneg.example.com/context",
7988
any_args).and_yield(context)
8089
allow(JSON::LD::API).to receive(:documentLoader).with("http://conneg.example.com/frame",
@@ -216,163 +225,3 @@
216225
end
217226
end
218227
end
219-
220-
describe Rack::LinkedData::ContentNegotiation do
221-
include Rack::Test::Methods
222-
let(:logger) { RDF::Spec.logger }
223-
224-
let(:app) do
225-
graph = RDF::NTriples::Reader.new(%(
226-
<http://example.org/library> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#Library> .
227-
<http://example.org/library> <http://example.org/vocab#contains> <http://example.org/library/the-republic> .
228-
<http://example.org/library/the-republic> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#Book> .
229-
<http://example.org/library/the-republic> <http://purl.org/dc/elements/1.1/title> "The Republic" .
230-
<http://example.org/library/the-republic> <http://purl.org/dc/elements/1.1/creator> "Plato" .
231-
<http://example.org/library/the-republic> <http://example.org/vocab#contains> <http://example.org/library/the-republic#introduction> .
232-
<http://example.org/library/the-republic#introduction> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#Chapter> .
233-
<http://example.org/library/the-republic#introduction> <http://purl.org/dc/elements/1.1/title> "The Introduction" .
234-
<http://example.org/library/the-republic#introduction> <http://purl.org/dc/elements/1.1/description> "An introductory chapter on The Republic." .
235-
))
236-
described_class.new(double("Target Rack Application", :call => [200, {}, graph]), {})
237-
end
238-
239-
describe "#call" do
240-
let(:schema_context) do
241-
JSON::LD::API::RemoteDocument.new('{
242-
"@context": {
243-
"@vocab": "http://schema.org/",
244-
"id": "@id",
245-
"type": "@type"
246-
}
247-
}', documentUrl: "http://schema.org")
248-
end
249-
let(:frame) do
250-
JSON::LD::API::RemoteDocument.new('{
251-
"@context": {
252-
"dc": "http://purl.org/dc/elements/1.1/",
253-
"ex": "http://example.org/vocab#"
254-
},
255-
"@type": "ex:Library",
256-
"ex:contains": {
257-
"@type": "ex:Book",
258-
"ex:contains": {
259-
"@type": "ex:Chapter"
260-
}
261-
}
262-
}', documentUrl: "http://conneg.example.com/frame")
263-
end
264-
let(:context) do
265-
JSON::LD::API::RemoteDocument.new('{
266-
"@context": {
267-
"dc": "http://purl.org/dc/elements/1.1/",
268-
"ex": "http://example.org/vocab#"
269-
}
270-
}', documentUrl: "http://conneg.example.com/context")
271-
end
272-
273-
before do
274-
allow(JSON::LD::API).to receive(:documentLoader).with("http://schema.org", any_args).and_yield(schema_context)
275-
allow(JSON::LD::API).to receive(:documentLoader).with("http://conneg.example.com/context",
276-
any_args).and_yield(context)
277-
allow(JSON::LD::API).to receive(:documentLoader).with("http://conneg.example.com/frame",
278-
any_args).and_yield(frame)
279-
end
280-
281-
{
282-
"application/json" => LIBRARY_FLATTENED_EXPANDED,
283-
"application/ld+json" => LIBRARY_FLATTENED_EXPANDED,
284-
%(application/ld+json;profile=http://www.w3.org/ns/json-ld#expanded) =>
285-
LIBRARY_FLATTENED_EXPANDED,
286-
287-
%(application/ld+json;profile=http://www.w3.org/ns/json-ld#compacted) =>
288-
LIBRARY_FLATTENED_COMPACTED_DEFAULT,
289-
290-
%(application/ld+json;profile=http://www.w3.org/ns/json-ld#flattened) =>
291-
LIBRARY_FLATTENED_EXPANDED,
292-
%(application/ld+json;profile="http://www.w3.org/ns/json-ld#flattened http://www.w3.org/ns/json-ld#expanded") =>
293-
LIBRARY_FLATTENED_EXPANDED,
294-
%(application/ld+json;profile="http://www.w3.org/ns/json-ld#expanded http://www.w3.org/ns/json-ld#flattened") =>
295-
LIBRARY_FLATTENED_EXPANDED,
296-
297-
%(application/ld+json;profile="http://www.w3.org/ns/json-ld#flattened http://www.w3.org/ns/json-ld#compacted") =>
298-
LIBRARY_FLATTENED_COMPACTED_DEFAULT,
299-
%(application/ld+json;profile="http://www.w3.org/ns/json-ld#compacted http://www.w3.org/ns/json-ld#flattened") =>
300-
LIBRARY_FLATTENED_COMPACTED_DEFAULT
301-
302-
}.each do |accepts, result|
303-
context accepts do
304-
before do
305-
get '/', {}, { "HTTP_ACCEPT" => accepts }
306-
end
307-
308-
it "status" do
309-
expect(last_response.status).to satisfy("200 or 406") { |x| [200, 406].include?(x) }
310-
end
311-
312-
it "sets content type" do
313-
expect(last_response.content_type).to eq(last_response.status == 406 ? 'text/plain' : 'application/ld+json')
314-
end
315-
316-
it "returns serialization" do
317-
if last_response.status == 406
318-
expect(last_response.body).to eq result
319-
else
320-
expect(JSON.parse(last_response.body)).to produce_jsonld(result, logger)
321-
end
322-
end
323-
end
324-
end
325-
326-
context "with Link" do
327-
{
328-
"with context" => {
329-
accept: %(application/ld+json),
330-
link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
331-
result: LIBRARY_FLATTENED_COMPACTED
332-
},
333-
"compacted with context" => {
334-
accept: %(application/ld+json;profile=http://www.w3.org/ns/json-ld#compacted),
335-
link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
336-
result: LIBRARY_FLATTENED_COMPACTED
337-
},
338-
"flattened and compacted with context" => {
339-
accept: %(application/ld+json;profile="http://www.w3.org/ns/json-ld#flattened http://www.w3.org/ns/json-ld#compacted"),
340-
link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
341-
result: LIBRARY_FLATTENED_COMPACTED
342-
},
343-
"compacted and flattened with context" => {
344-
accept: %(application/ld+json;profile="http://www.w3.org/ns/json-ld#compacted http://www.w3.org/ns/json-ld#flattened"),
345-
link: %(<http://conneg.example.com/context> rel="http://www.w3.org/ns/json-ld#context"),
346-
result: LIBRARY_FLATTENED_COMPACTED
347-
},
348-
"framed with frame" => {
349-
accept: %(application/ld+json;profile=http://www.w3.org/ns/json-ld#framed),
350-
link: %(<http://conneg.example.com/frame> rel="http://www.w3.org/ns/json-ld#frame"),
351-
result: LIBRARY_FRAMED
352-
}
353-
}.each do |name, params|
354-
context name do
355-
before do
356-
get '/', {}, { "HTTP_ACCEPT" => params[:accept], "HTTP_LINK" => params[:link] }
357-
end
358-
359-
it "status" do
360-
expect(last_response.status).to satisfy("be 200 or 406") { |x| [200, 406].include?(x) }
361-
end
362-
363-
it "sets content type" do
364-
expect(last_response.content_type).to eq(last_response.status == 406 ? 'text/plain' : 'application/ld+json')
365-
end
366-
367-
it "returns serialization" do
368-
if last_response.status == 406
369-
expect(last_response.body).to eq params[:result]
370-
else
371-
expect(JSON.parse(last_response.body)).to produce_jsonld(params[:result], logger)
372-
end
373-
end
374-
end
375-
end
376-
end
377-
end
378-
end

spec/spec_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def replace_nodes(object, bijection)
145145
]))
146146

147147
LIBRARY_COMPACTED_DEFAULT = JSON.parse(%({
148-
"@context": "http://schema.org",
148+
"@context": "http://example.com/context",
149149
"@graph": [
150150
{
151151
"id": "http://example.org/library",
@@ -213,7 +213,7 @@ def replace_nodes(object, bijection)
213213
]))
214214

215215
LIBRARY_FLATTENED_COMPACTED_DEFAULT = JSON.parse(%({
216-
"@context": "http://schema.org",
216+
"@context": "http://example.com/context",
217217
"@graph": [
218218
{
219219
"id": "http://example.org/library",

spec/suite_http_spec.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require_relative 'spec_helper'
2-
require 'rack/linkeddata'
2+
require 'rack/rdf'
33
require 'rack/test'
44

55
begin
@@ -15,10 +15,8 @@
1515

1616
let(:app) do
1717
JSON::LD::ContentNegotiation.new(
18-
Rack::LinkedData::ContentNegotiation.new(
19-
double("Target Rack Application", :call => [200, {}, @results]),
20-
{}
21-
)
18+
double("Target Rack Application", :call => [200, {}, @results]),
19+
{}
2220
)
2321
end
2422

0 commit comments

Comments
 (0)