earl-report 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,373 @@
1
+ # coding: utf-8
2
+ $:.unshift "."
3
+ require 'spec_helper'
4
+
5
+ describe EarlReport do
6
+ subject {
7
+ EarlReport.new(
8
+ File.expand_path("../test-files/manifest.ttl", __FILE__),
9
+ File.expand_path("../test-files/report-complete.ttl", __FILE__),
10
+ :verbose => false)
11
+ }
12
+
13
+ describe ".new" do
14
+ context "complete report" do
15
+ #before(:each) do
16
+ # RDF::Graph.should_not_receive(:load).with(RDF::URI("http://rubygems.org/gems/rdf-turtle"))
17
+ # RDF::Graph.should_not_receive(:load).with(RDF::URI("http://greggkellogg.net/foaf#me"))
18
+ #end
19
+
20
+ subject {
21
+ EarlReport.new(
22
+ File.expand_path("../test-files/manifest.ttl", __FILE__),
23
+ File.expand_path("../test-files/report-complete.ttl", __FILE__),
24
+ :verbose => false)
25
+ }
26
+ it "loads manifest" do
27
+ subject.graph.subjects.to_a.should include(RDF::URI("http://example/manifest.ttl"))
28
+ subject.graph.subjects.to_a.should include(RDF::URI("http://example/manifest.ttl#testeval00"))
29
+ end
30
+
31
+ it "loads report" do
32
+ subject.graph.predicates.to_a.should include(RDF::URI("http://www.w3.org/ns/earl#assertedBy"))
33
+ end
34
+
35
+ it "loads doap" do
36
+ subject.graph.subjects.to_a.should include(RDF::URI("http://rubygems.org/gems/rdf-turtle"))
37
+ end
38
+
39
+ it "loads foaf" do
40
+ subject.graph.objects.to_a.should include(RDF::FOAF.Person)
41
+ end
42
+ end
43
+
44
+ context "no doap report" do
45
+ #before(:each) do
46
+ # RDF::Graph.should_receive(:load).with(RDF::URI("http://rubygems.org/gems/rdf-turtle"))
47
+ # RDF::Graph.should_not_receive(:load).with(RDF::URI("http://greggkellogg.net/foaf#me"))
48
+ #end
49
+
50
+ subject {
51
+ EarlReport.new(
52
+ File.expand_path("../test-files/manifest.ttl", __FILE__),
53
+ File.expand_path("../test-files/report-no-doap.ttl", __FILE__),
54
+ :verbose => false)
55
+ }
56
+ it "loads manifest" do
57
+ subject.graph.subjects.to_a.should include(RDF::URI("http://example/manifest.ttl"))
58
+ subject.graph.subjects.to_a.should include(RDF::URI("http://example/manifest.ttl#testeval00"))
59
+ end
60
+
61
+ it "loads report" do
62
+ subject.graph.predicates.to_a.should include(RDF::URI("http://www.w3.org/ns/earl#assertedBy"))
63
+ end
64
+
65
+ it "does not load doap" do
66
+ subject.graph.subjects.to_a.should_not include(RDF::URI("http://rubygems.org/gems/rdf-turtle"))
67
+ end
68
+
69
+ it "loads foaf" do
70
+ subject.graph.objects.to_a.should include(RDF::FOAF.Person)
71
+ end
72
+ end
73
+
74
+ context "no foaf report" do
75
+ #before(:each) do
76
+ # RDF::Graph.should_not_receive(:load).with(RDF::URI("http://rubygems.org/gems/rdf-turtle"))
77
+ # RDF::Graph.should_receive(:load).with(RDF::URI("http://greggkellogg.net/foaf#me")).and_return(RDF::Graph.new << [RDF::Node.new, RDF.type, RDF::FOAF.Person])
78
+ #end
79
+
80
+ subject {
81
+ EarlReport.new(
82
+ File.expand_path("../test-files/manifest.ttl", __FILE__),
83
+ File.expand_path("../test-files/report-no-foaf.ttl", __FILE__),
84
+ :verbose => false)
85
+ }
86
+ it "loads manifest" do
87
+ subject.graph.subjects.to_a.should include(RDF::URI("http://example/manifest.ttl"))
88
+ subject.graph.subjects.to_a.should include(RDF::URI("http://example/manifest.ttl#testeval00"))
89
+ end
90
+
91
+ it "loads report" do
92
+ subject.graph.predicates.to_a.should include(RDF::URI("http://www.w3.org/ns/earl#assertedBy"))
93
+ end
94
+
95
+ it "loads doap" do
96
+ subject.graph.subjects.to_a.should include(RDF::URI("http://rubygems.org/gems/rdf-turtle"))
97
+ end
98
+
99
+ it "loads foaf" do
100
+ subject.graph.objects.to_a.should include(RDF::FOAF.Person)
101
+ end
102
+ end
103
+ end
104
+
105
+ describe ".generate" do
106
+ end
107
+
108
+ describe "#json_hash" do
109
+ let(:json) {
110
+ subject.send(:json_hash, {
111
+ bibRef: "[[TURTLE]]",
112
+ name: "Turtle Test Results"
113
+ })
114
+ }
115
+ specify {json.should be_a(Hash)}
116
+ {
117
+ "@id" => "",
118
+ "@type" => %w(earl:Software doap:Project),
119
+ 'bibRef' => "[[TURTLE]]",
120
+ 'name' => "Turtle Test Results"
121
+ }.each do |prop, value|
122
+ specify(prop) {json[prop].should == value}
123
+ end
124
+
125
+ it "testSubjects" do
126
+ json.keys.should include('testSubjects')
127
+ end
128
+
129
+ it "tests" do
130
+ json.keys.should include('tests')
131
+ end
132
+ end
133
+
134
+ describe "#json_test_subject_info" do
135
+ let(:json) {subject.send(:json_test_subject_info)}
136
+ specify {json.should be_a(Array)}
137
+ specify("have length 1") {json.length.should == 1}
138
+
139
+ context "test subject" do
140
+ let(:ts) {json.first}
141
+ {
142
+ "@id" => "http://rubygems.org/gems/rdf-turtle",
143
+ "@type" => %w(earl:TestSubject doap:Project),
144
+ doap_desc: "RDF::Turtle is an Turtle reader/writer for the RDF.rb library suite.",
145
+ homepage: "http://ruby-rdf.github.com/rdf-turtle",
146
+ language: "Ruby",
147
+ name: "RDF::Turtle",
148
+ }.each do |prop, value|
149
+ specify(prop) {ts[prop.to_s].should == value}
150
+ end
151
+
152
+ context "developer" do
153
+ let(:dev) {ts['developer']}
154
+ specify {dev.should be_a(Hash)}
155
+ {
156
+ "@id" => "http://greggkellogg.net/foaf#me",
157
+ "@type" => %(foaf:Person),
158
+ "foaf:name" => "Gregg Kellogg",
159
+ }.each do |prop, value|
160
+ specify(prop) {dev[prop.to_s].should == value}
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ describe "#json_result_info" do
167
+ let(:json) {subject.send(:json_result_info)}
168
+ specify {json.should be_a(Array)}
169
+ specify("have 2 entries") {json.length.should == 2}
170
+
171
+ context "test case" do
172
+ let(:tc) {json.first}
173
+ {
174
+ "@id" => "http://example/manifest.ttl#testeval00",
175
+ "@type" => %w(earl:TestCriterion earl:TestCase),
176
+ title: "subm-test-00",
177
+ description: "Blank subject",
178
+ testAction: "http://example/test-00.ttl",
179
+ testResult: "http://example/test-00.out",
180
+ }.each do |prop, value|
181
+ specify(prop) {tc[prop.to_s].should == value}
182
+ end
183
+
184
+ context "assertion" do
185
+ let(:as) {tc['http://rubygems.org/gems/rdf-turtle']}
186
+ specify {as.should be_a(Hash)}
187
+ {
188
+ "@type" => %(earl:Assertion),
189
+ assertedBy: "http://greggkellogg.net/foaf#me",
190
+ mode: "earl:automatic",
191
+ subject: "http://rubygems.org/gems/rdf-turtle",
192
+ test: "http://example/manifest.ttl#testeval00",
193
+ }.each do |prop, value|
194
+ specify(prop) {as[prop.to_s].should == value}
195
+ end
196
+
197
+ context "result" do
198
+ let(:rs) {as['result']}
199
+ specify {rs.should be_a(Hash)}
200
+ {
201
+ "@type" => %(earl:TestResult),
202
+ outcome: "earl:passed",
203
+ }.each do |prop, value|
204
+ specify(prop) {rs[prop.to_s].should == value}
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
210
+
211
+
212
+ describe "#test_subject_turtle" do
213
+ context "test subject" do
214
+ let(:desc) {{
215
+ "@id" => "http://rubygems.org/gems/rdf-turtle",
216
+ "@type" => %w(earl:TestSubject doap:Project),
217
+ 'doap_desc' => "RDF::Turtle is an Turtle reader/writer for the RDF.rb library suite.",
218
+ 'homepage' => "http://ruby-rdf.github.com/rdf-turtle",
219
+ 'language' => "Ruby",
220
+ 'name' => "RDF::Turtle",
221
+ 'developer' => {
222
+ '@id' => "http://greggkellogg.net/foaf#me",
223
+ '@type' => %w(foaf:Person earl:Assertor),
224
+ 'foaf:name' => "Gregg Kellogg"
225
+ }
226
+ }}
227
+ let(:ttl) {subject.send(:test_subject_turtle, desc)}
228
+ specify {ttl.length.should > 0}
229
+ it "has subject subject" do
230
+ ttl.should match(/<#{desc['@id']}> a/)
231
+ end
232
+ it "has types" do
233
+ ttl.should match(/ a #{desc['@type'].join(', ')};$/)
234
+ end
235
+ it "has name" do
236
+ ttl.should match(/ doap:name "#{desc['name']}";$/)
237
+ end
238
+ it "has description" do
239
+ ttl.should match(/ doap:description """#{desc['doap_desc']}""";$/)
240
+ end
241
+ it "has doap:programming-language" do
242
+ ttl.should match(/ doap:programming-language "#{desc['language']}";$/)
243
+ end
244
+ it "has doap:developer" do
245
+ ttl.should match(/ doap:developer <#{desc['developer']['@id']}>/)
246
+ end
247
+
248
+ context "developer" do
249
+ let(:dev) {desc['developer']}
250
+ it "has subject subject" do
251
+ ttl.should match(/<#{dev['@id']}> a/)
252
+ end
253
+ it "has types" do
254
+ ttl.should match(/ a #{dev['@type'].join(', ')};$/)
255
+ end
256
+ it "has name" do
257
+ ttl.should match(/ foaf:name "#{dev['foaf:name']}" .$/)
258
+ end
259
+ end
260
+ end
261
+ end
262
+
263
+ describe "#tc_turtle" do
264
+ context "test case" do
265
+ let(:tc) {{
266
+ "@id" => "http://example/manifest.ttl#testeval00",
267
+ "@type" => %w(earl:TestCriterion earl:TestCase),
268
+ 'title' => "subm-test-00",
269
+ 'description' => "Blank subject",
270
+ 'testAction' => "http://example/test-00.ttl",
271
+ 'testResult' => "http://example/test-00.out",
272
+ }}
273
+ let(:ttl) {subject.send(:tc_turtle, tc)}
274
+ specify {ttl.length.should > 0}
275
+ it "has subject subject" do
276
+ ttl.should match(/<#{tc['@id']}> a/)
277
+ end
278
+ it "has types" do
279
+ ttl.should match(/ a #{tc['@type'].join(', ')};$/)
280
+ end
281
+ it "has dc:title" do
282
+ ttl.should match(/ dc:title "#{tc['title']}";$/)
283
+ end
284
+ it "has dc:description" do
285
+ ttl.should match(/ dc:description """#{tc['description']}""";$/)
286
+ end
287
+ it "has mf:action" do
288
+ ttl.should match(/ mf:action <#{tc['testAction']}>;$/)
289
+ end
290
+ it "has mf:result" do
291
+ ttl.should match(/ mf:result <#{tc['testResult']}>;$/)
292
+ end
293
+ end
294
+ end
295
+
296
+ describe "#as_turtle" do
297
+ context "assertion" do
298
+ let(:as) {{
299
+ "@type" => %w(earl:Assertion),
300
+ 'assertedBy' => "http://greggkellogg.net/foaf#me",
301
+ 'mode' => "earl:automatic",
302
+ 'subject' => "http://rubygems.org/gems/rdf-turtle",
303
+ 'test' => "http://example/manifest.ttl#testeval00",
304
+ 'result' => {
305
+ '@type' => 'earl:TestResult',
306
+ 'outcome' => 'earl:passed'
307
+ }
308
+ }}
309
+ let(:ttl) {subject.send(:as_turtle, as)}
310
+ specify {ttl.length.should > 0}
311
+ it "has type" do
312
+ ttl.should match(/ a #{as['@type'].join(', ')};$/)
313
+ end
314
+ it "has earl:assertedBy" do
315
+ ttl.should match(/ earl:assertedBy <#{as['assertedBy']}>;$/)
316
+ end
317
+ it "has earl:test" do
318
+ ttl.should match(/ earl:test <#{as['test']}>;$/)
319
+ end
320
+ it "has earl:subject" do
321
+ ttl.should match(/ earl:subject <#{as['subject']}>;$/)
322
+ end
323
+ it "has earl:mode" do
324
+ ttl.should match(/ earl:mode #{as['mode']};$/)
325
+ end
326
+ it "has earl:result" do
327
+ ttl.should match(/ earl:result \[ a #{as['result']['@type']}; earl:outcome #{as['result']['outcome']}\]/)
328
+ end
329
+ end
330
+ end
331
+
332
+ describe "#earl_turtle" do
333
+ let(:results) {
334
+ @results ||= JSON.parse(File.read(File.expand_path("../test-files/results.jsonld", __FILE__)))
335
+ }
336
+ let(:output) {
337
+ @output ||= begin
338
+ sio = StringIO.new
339
+ subject.send(:earl_turtle, {json_hash: results, io: sio})
340
+ sio.rewind
341
+ sio.read
342
+ end
343
+ }
344
+ let(:ts) {results['testSubjects'].first}
345
+ let(:tc) {results['tests'].first}
346
+ let(:as) {tc[ts['@id']]}
347
+
348
+ context "prefixes" do
349
+ %w(dc doap earl foaf mf owl rdf rdfs xsd).each do |pfx|
350
+ it "should have prefix #{pfx}" do
351
+ output.should match(/@prefix #{pfx}: </)
352
+ end
353
+ end
354
+ end
355
+
356
+ context "earl:Software" do
357
+ specify {output.should match(/<> a earl:Software, doap:Project;/)}
358
+ specify {output.should match(/ doap:name "#{results['name']}"\./)}
359
+ end
360
+
361
+ context "Subject Definitions" do
362
+ specify {output.should match(/<#{ts['@id']}> a #{ts['@type'].join(', ')};/)}
363
+ end
364
+
365
+ context "Test Case Definitions" do
366
+ specify {output.should match(/<#{tc['@id']}> a #{tc['@type'].join(', ')};/)}
367
+ end
368
+
369
+ context "Assertion" do
370
+ specify {output.should match(/\[ a #{as['@type']};/)}
371
+ end
372
+ end
373
+ end
@@ -0,0 +1,19 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $:.unshift File.dirname(__FILE__)
3
+
4
+ #require "bundler/setup"
5
+ require 'rspec'
6
+ require 'earl_report'
7
+
8
+ JSON_STATE = JSON::State.new(
9
+ :indent => " ",
10
+ :space => " ",
11
+ :space_before => "",
12
+ :object_nl => "\n",
13
+ :array_nl => "\n"
14
+ )
15
+
16
+ ::RSpec.configure do |c|
17
+ c.filter_run :focus => true
18
+ c.run_all_when_everything_filtered = true
19
+ end
@@ -0,0 +1,33 @@
1
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
3
+ @prefix dc: <http://purl.org/dc/terms/> .
4
+ @prefix earl: <http://www.w3.org/ns/earl#> .
5
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
6
+ @prefix doap: <http://usefulinc.com/ns/doap#> .
7
+ @prefix ex: <http://example.org/> .
8
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
9
+
10
+ <http://rubygems.org/gems/rdf-turtle> a doap:Project, earl:TestSubject, earl:Software ;
11
+ doap:name "RDF::Turtle" ;
12
+ doap:homepage <http://ruby-rdf.github.com/rdf-turtle> ;
13
+ doap:license <http://creativecommons.org/licenses/publicdomain/> ;
14
+ doap:shortdesc "Turtle reader/writer for Ruby."@en ;
15
+ doap:description "RDF::Turtle is an Turtle reader/writer for the RDF.rb library suite."@en ;
16
+ doap:created "2011-08-29"^^xsd:date;
17
+ doap:programming-language "Ruby" ;
18
+ doap:implements <http://www.w3.org/TR/turtle/> ;
19
+ doap:category <http://dbpedia.org/resource/Resource_Description_Framework>,
20
+ <http://dbpedia.org/resource/Ruby_(programming_language)> ;
21
+ doap:download-page <http://rubygems.org/gems/rdf-turtle> ;
22
+ doap:mailing-list <http://lists.w3.org/Archives/Public/public-rdf-ruby/> ;
23
+ doap:bug-database <http://github.com/ruby-rdf/rdf-turtle/issues> ;
24
+ doap:blog <http://greggkellogg.net/> ;
25
+ doap:developer <http://greggkellogg.net/foaf#me> ;
26
+ doap:maintainer <http://greggkellogg.net/foaf#me> ;
27
+ doap:documenter <http://greggkellogg.net/foaf#me> ;
28
+ foaf:maker <http://greggkellogg.net/foaf#me> ;
29
+ dc:title "RDF::Turtle" ;
30
+ dc:description "RDF::Turtle is an Turtle reader/writer for the RDF.rb library suite."@en ;
31
+ dc:date "2011-08-29"^^xsd:date;
32
+ dc:creator <http://greggkellogg.net/foaf#me>
33
+ dc:isPartOf <http://rubygems.org/gems/rdf> .
@@ -0,0 +1,4 @@
1
+ <http://greggkellogg.net/foaf#me> a foaf:Person, earl:Assertor;
2
+ foaf:name "Gregg Kellogg";
3
+ foaf:title "Implementor";
4
+ foaf:homepage <http://greggkellogg.net/> .
@@ -0,0 +1,26 @@
1
+ # Exmple teset manifest
2
+ @base <http://example/manifest.ttl> .
3
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
4
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
5
+ @prefix mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
6
+ @prefix qt: <http://www.w3.org/2001/sw/DataAccess/tests/test-query#> .
7
+ @prefix rdft: <http://www.w3.org/ns/rdftest#> .
8
+
9
+ <> a mf:Manifest ;
10
+ rdfs:comment "Example Test Cases" ;
11
+ mf:entries (
12
+ <#testeval00>
13
+ [ a rdft:TestTurtleEval ;
14
+ mf:name "subm-test-01" ;
15
+ rdfs:comment "@prefix and qnames" ;
16
+ mf:action <test-01.ttl> ;
17
+ mf:result <test-01.out>
18
+ ]
19
+ ) .
20
+
21
+ <#testeval00> a rdft:TestTurtleEval ;
22
+ mf:name "subm-test-00" ;
23
+ rdfs:comment "Blank subject" ;
24
+ mf:action <test-00.ttl> ;
25
+ mf:result <test-00.out>
26
+ .