rdf-spec 1.0.9 → 1.1.0.p1

Sign up to get free protection for your applications and to get access to all the features.
data/etc/doap.ttl ADDED
@@ -0,0 +1,79 @@
1
+ @base <http://rubygems.org/gems/rdf> .
2
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
3
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
4
+ @prefix dc: <http://purl.org/dc/terms/> .
5
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
6
+ @prefix doap: <http://usefulinc.com/ns/doap#> .
7
+
8
+ <> a doap:Project ;
9
+ doap:name "RDF.rb" ;
10
+ doap:homepage <http://rubygems.org/gems/rdf> ;
11
+ doap:license <http://creativecommons.org/licenses/publicdomain/> ;
12
+ doap:shortdesc "A Ruby library for working with Resource Description Framework (RDF) data."@en ;
13
+ doap:description "RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data."@en ;
14
+ doap:created "2007-10-23" ;
15
+ doap:platform "Ruby" ;
16
+ doap:category <http://dbpedia.org/resource/Resource_Description_Framework>,
17
+ <http://dbpedia.org/resource/Ruby_(programming_language)> ;
18
+ doap:implements <http://www.w3.org/TR/rdf-concepts/>,
19
+ <http://sw.deri.org/2008/07/n-quads/>,
20
+ <http://www.w3.org/2001/sw/RDFCore/ntriples/> ;
21
+ doap:download-page <http://rubyforge.org/projects/rdf/> ;
22
+ doap:bug-database <http://github.com/ruby-rdf/rdf/issues> ;
23
+ doap:blog <http://ar.to/>, <http://blog.datagraph.org/> ;
24
+ doap:vendor <http://datagraph.org/> ;
25
+ doap:developer <http://ar.to/#self>, <http://bhuga.net/#ben>, <http://greggkellogg.net/foaf#me> ;
26
+ doap:maintainer <http://ar.to/#self>, <http://bhuga.net/#ben>, <http://greggkellogg.net/foaf#me> ;
27
+ doap:documenter <http://ar.to/#self>, <http://bhuga.net/#ben>, <http://greggkellogg.net/foaf#me> ;
28
+ doap:helper [a foaf:Person ;
29
+ foaf:name "Călin Ardelean" ;
30
+ foaf:mbox_sha1sum "274bd18402fc773ffc0606996aa1fb90b603aa29"] ;
31
+ doap:helper [a foaf:Person ;
32
+ foaf:name "Danny Gagne" ;
33
+ foaf:mbox_sha1sum "6de43e9cf7de53427fea9765706703e4d957c17b"] ;
34
+ doap:helper [a foaf:Person ;
35
+ foaf:name "Joey Geiger" ;
36
+ foaf:mbox_sha1sum "f412d743150d7b27b8468d56e69ca147917ea6fc"] ;
37
+ doap:helper [a foaf:Person ;
38
+ foaf:name "Fumihiro Kato" ;
39
+ foaf:mbox_sha1sum "d31fdd6af7a279a89bf09fdc9f7c44d9d08bb930"] ;
40
+ doap:helper [a foaf:Person ;
41
+ foaf:name "Naoki Kawamukai" ;
42
+ foaf:mbox_sha1sum "5bdcd8e2af4f5952aaeeffbdd371c41525ec761d"] ;
43
+ doap:helper [a foaf:Person ;
44
+ foaf:name "Hellekin O. Wolf" ;
45
+ foaf:mbox_sha1sum "c69f3255ff0639543cc5edfd8116eac8df16fab8"] ;
46
+ doap:helper [a foaf:Person ;
47
+ foaf:name "John Fieber" ;
48
+ foaf:mbox_sha1sum "f7653fc1ac0e82ebb32f092389bd5fc728eaae12"] ;
49
+ doap:helper [a foaf:Person ;
50
+ foaf:name "Keita Urashima" ;
51
+ foaf:mbox_sha1sum "2b4247b6fd5bb4a1383378f325784318680d5ff9"] ;
52
+ doap:helper [a foaf:Person ;
53
+ foaf:name "Pius Uzamere" ;
54
+ foaf:mbox_sha1sum "bedbbf2451e5beb38d59687c0460032aff92cd3c"] ;
55
+ foaf:maker <http://ar.to/#self> ;
56
+ dc:creator <http://ar.to/#self> .
57
+
58
+ <http://ar.to/#self> a foaf:Person ;
59
+ foaf:name "Arto Bendiken" ;
60
+ foaf:mbox <mailto:arto.bendiken@gmail.com> ;
61
+ foaf:mbox_sha1sum "d0737cceb55eb7d740578d2db1bc0727e3ed49ce",
62
+ "a033f652c84a4d73b8c26d318c2395699dd2bdfb" ;
63
+ foaf:homepage <http://ar.to/> ;
64
+ foaf:made <> ;
65
+ rdfs:isDefinedBy <http://datagraph.org/bendiken/foaf> .
66
+
67
+ <http://bhuga.net/#ben> a foaf:Person ;
68
+ foaf:name "Ben Lavender" ;
69
+ foaf:mbox <mailto:blavender@gmail.com> ;
70
+ foaf:mbox_sha1sum "dbf45f4ffbd27b67aa84f02a6a31c144727d10af" ;
71
+ foaf:homepage <http://bhuga.net/> ;
72
+ rdfs:isDefinedBy <http://datagraph.org/bhuga/foaf> .
73
+
74
+ <http://greggkellogg.net/foaf#me> a foaf:Person ;
75
+ foaf:name "Gregg Kellogg" ;
76
+ foaf:mbox <mailto:gregg@greggkellogg.net> ;
77
+ foaf:mbox_sha1sum "35bc44e6d0070e5ad50ccbe0d24403c96af2b9bd" ;
78
+ foaf:homepage <http://greggkellogg.net/>;
79
+ rdfs:isDefinedBy <http://greggkellogg.net/foaf> .
data/etc/gkellogg.nq CHANGED
@@ -1,6 +1,5 @@
1
- <http://greggkellogg.net/foaf#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://greggkellogg.net/foaf#me> .
2
- <http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/name> "Gregg Kellogg" <http://greggkellogg.net/foaf#me> .
3
- <http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/mbox> <mailto:gregg@greggkellogg.net> <http://greggkellogg.net/foaf#me> .
4
- <http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/mbox_sha1sum> "35bc44e6d0070e5ad50ccbe0d24403c96af2b9bd" <http://greggkellogg.net/foaf#me> .
5
- <http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/homepage> <http://greggkellogg.net/> <http://greggkellogg.net/foaf#me> .
6
- <http://greggkellogg.net/foaf#me> <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> <http://greggkellogg.net/foaf> <http://greggkellogg.net/foaf#me> .
1
+ <http://greggkellogg.net/#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://greggkellogg.net/#me> .
2
+ <http://greggkellogg.net/#me> <http://xmlns.com/foaf/0.1/name> "Gregg Kellogg" <http://greggkellogg.net/#me> .
3
+ <http://greggkellogg.net/#me> <http://xmlns.com/foaf/0.1/mbox> <mailto:gregg@greggkellogg.net> <http://greggkellogg.net/#me> .
4
+ <http://greggkellogg.net/#me> <http://xmlns.com/foaf/0.1/mbox_sha1sum> "b7a856d39fc3f02573271d9901f1f9107147f657" <http://greggkellogg.net/#me> .
5
+ <http://greggkellogg.net/#me> <http://xmlns.com/foaf/0.1/homepage> <http://greggkellogg.net/> <http://greggkellogg.net/#me> .
data/etc/gkellogg.nt ADDED
@@ -0,0 +1,5 @@
1
+ <http://greggkellogg.net/#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
2
+ <http://greggkellogg.net/#me> <http://xmlns.com/foaf/0.1/name> "Gregg Kellogg" .
3
+ <http://greggkellogg.net/#me> <http://xmlns.com/foaf/0.1/mbox> <mailto:gregg@greggkellogg.net> .
4
+ <http://greggkellogg.net/#me> <http://xmlns.com/foaf/0.1/mbox_sha1sum> "b7a856d39fc3f02573271d9901f1f9107147f657" .
5
+ <http://greggkellogg.net/#me> <http://xmlns.com/foaf/0.1/homepage> <http://greggkellogg.net/> .
data/etc/gkellogg.ttl ADDED
@@ -0,0 +1,14 @@
1
+ @base <http://rubygems.org/gems/rdf> .
2
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
3
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
4
+ @prefix dc: <http://purl.org/dc/terms/> .
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://greggkellogg.net/#me> a foaf:Person ;
11
+ foaf:name "Gregg Kellogg" ;
12
+ foaf:mbox <mailto:gregg@greggkellogg.net> ;
13
+ foaf:mbox_sha1sum "b7a856d39fc3f02573271d9901f1f9107147f657" ;
14
+ foaf:homepage <http://greggkellogg.net/> .
data/etc/test-data.nt CHANGED
@@ -1,3 +1,4 @@
1
+ # Test data from SPARQLdata-r2/expr-equals
1
2
  <http://example.org/xi1> <http://example.org/p> "1"^^<http://www.w3.org/2001/XMLSchema#integer> .
2
3
  <http://example.org/xi2> <http://example.org/p> "1"^^<http://www.w3.org/2001/XMLSchema#integer> .
3
4
  <http://example.org/xi3> <http://example.org/p> "01"^^<http://www.w3.org/2001/XMLSchema#integer> .
data/lib/rdf/spec.rb CHANGED
@@ -46,25 +46,5 @@ module RDF
46
46
  module Spec
47
47
  autoload :Matchers, 'rdf/spec/matchers'
48
48
  autoload :VERSION, 'rdf/spec/version'
49
- TRIPLES_FILE = File.expand_path("../../../etc/triples.nt", __FILE__)
50
- QUADS_FILE = File.expand_path("../../../etc/quads.nq", __FILE__)
51
-
52
- ##
53
- # Return quads for tests
54
- #
55
- # @return [Array<RDF::Statement>]
56
- def self.quads
57
- require 'rdf/nquads'
58
- (@quads ||= RDF::NQuads::Reader.new(File.open(QUADS_FILE)).to_a).dup
59
- end
60
-
61
- ##
62
- # Return triples for tests
63
- #
64
- # @return [Array<RDF::Statement>]
65
- def self.triples
66
- require 'rdf/ntriples'
67
- (@triples ||= RDF::NTriples::Reader.new(File.open(TRIPLES_FILE)).to_a).dup
68
- end
69
49
  end # Spec
70
50
  end # RDF
@@ -7,38 +7,43 @@ module RDF_Countable
7
7
  before :each do
8
8
  raise '+@countable+ must be defined in a before(:each) block' unless instance_variable_get('@countable')
9
9
 
10
- @statements = RDF::Spec.quads
10
+ @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
11
+ @statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
11
12
 
12
13
  if @countable.empty?
13
- if @countable.respond_to?(:<<) && (@countable.writable? rescue true)
14
+ if @countable.respond_to?(:<<)
14
15
  @statements.each { |statement| @countable << statement }
15
16
  else
16
- raise "+@countable+ must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
17
+ raise "+@countable+ must respond to #<< or be pre-populated with the statements in #{@filename} in a before(:each) block"
17
18
  end
18
19
  end
19
20
  end
20
21
 
21
22
  describe RDF::Countable do
22
- subject {@countable}
23
-
24
- it {should respond_to(:empty?)}
25
- it {should_not be_empty}
26
- it {should respond_to(:count)}
27
- its(:count) {should == @statements.size}
28
- it {should respond_to(:size)}
29
- its(:size) {should == @statements.size}
30
-
31
- context "when empty" do
32
- subject {[].extend(RDF::Countable)}
33
- it {should be_empty}
34
- its(:count) {should == 0}
35
- its(:size) {should == 0}
23
+ it "responds to #empty?" do
24
+ @countable.should respond_to(:empty?)
36
25
  end
37
26
 
38
- its(:to_enum) {should be_countable}
39
- its(:enum_for) {should be_countable}
40
- it "#enum_for(:each)" do
41
- expect(subject.enum_for(:each)).to be_countable
27
+ it "responds to #count and #size" do
28
+ @countable.should respond_to(:count, :size)
29
+ end
30
+
31
+ it "implements #empty?" do
32
+ ([].extend(RDF::Countable)).empty?.should be_true
33
+ ([42].extend(RDF::Countable)).empty?.should be_false
34
+ @countable.empty?.should be_false
35
+ end
36
+
37
+ it "implements #count and #size" do
38
+ %w(count size).each do |method|
39
+ @countable.send(method).should >= @statements.size
40
+ end
41
+ end
42
+
43
+ it "returns countable enumerators" do
44
+ @countable.to_enum.should be_countable
45
+ @countable.enum_for.should be_countable
46
+ @countable.enum_for(:each).should be_countable
42
47
  end
43
48
  end
44
49
  end
@@ -23,25 +23,29 @@ module RDF_Durable
23
23
 
24
24
  before :each do
25
25
  raise '+@load_durable+ must be defined in a before(:each) block' unless instance_variable_get('@load_durable')
26
+ # RDF::Queryable cares about the contents of this file too much to let someone set it
27
+ @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
26
28
  end
27
29
 
28
30
  describe RDF::Durable do
29
- subject {@load_durable.call}
30
- it {should respond_to(:durable?)}
31
31
  it "should support #durable?" do
32
- expect([true,false]).to be_member(subject.durable?)
32
+ @load_durable.call.should respond_to(:durable?)
33
+ [true,false].member?(@load_durable.call.durable?).should be_true
33
34
  end
34
35
 
35
- it {should respond_to(:nondurable?)}
36
36
  it "should support #nondurable?" do
37
- expect([true,false]).to be_member(@load_durable.call.nondurable?)
37
+ @load_durable.call.should respond_to(:nondurable?)
38
+ [true,false].member?(@load_durable.call.nondurable?).should be_true
39
+ end
40
+
41
+ it "should not be both durable and nondurable" do
42
+ @load_durable.call.nondurable?.should_not == @load_durable.call.durable?
38
43
  end
39
- its(:nondurable?) {should_not == subject.durable?}
40
44
 
41
45
  it "should save contents between instantiations" do
42
- if subject.durable?
43
- subject.load(RDF::Spec::TRIPLES_FILE)
44
- expect(subject.count).to eq File.readlines(RDF::Spec::TRIPLES_FILE).size
46
+ if @load_durable.call.durable?
47
+ @load_durable.call.load(@filename)
48
+ @load_durable.call.count.should == File.readlines(@filename).size
45
49
  end
46
50
  end
47
51
  end
@@ -7,36 +7,38 @@ module RDF_Enumerable
7
7
  before :each do
8
8
  raise '+@enumerable+ must be defined in a before(:each) block' unless instance_variable_get('@enumerable')
9
9
 
10
- @statements ||= RDF::Spec.quads
10
+ @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
11
+ @statements ||= RDF::NTriples::Reader.new(File.open(@filename)).to_a
11
12
 
12
13
  if @enumerable.empty?
13
- if @enumerable.respond_to?(:<<) && (@enumerable.writable? rescue true)
14
+ if @enumerable.respond_to?(:<<)
14
15
  @statements.each { |statement| @enumerable << statement }
15
16
  else
16
- raise "@enumerable must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
17
+ raise "@enumerable must respond to #<< or be pre-populated with the statements in #{@filename} in a before(:each) block"
17
18
  end
18
19
  end
19
20
 
20
- @supports_context = @enumerable.supports?(:context) rescue true
21
+ @supports_context = @enumerable.respond_to?(:supports?) && @enumerable.supports?(:context)
21
22
  end
22
23
 
23
24
  describe RDF::Enumerable do
24
- let(:subject_count) {@statements.map(&:subject).uniq.length}
25
- let(:bnode_subject_count) {@statements.map(&:subject).uniq.select(&:node?).length}
26
- let(:non_bnode_statements) {@statements.reject {|s| s.subject.node? || s.object.node?}}
27
-
28
- subject {@enumerable}
29
- it {should respond_to(:supports?)}
25
+ describe "#supports?" do
26
+ it "responds to #supports?" do
27
+ @enumerable.respond_to?(:support?)
28
+ end
29
+ end
30
30
 
31
31
  describe "valid?" do
32
- it {should be_valid}
32
+ it "returns true if all statements are valid" do
33
+ @enumerable.should be_valid
34
+ end
33
35
 
34
36
  it "returns false if any statement is invalid" do
35
- if subject.respond_to?(:<<) && (subject.writable? rescue true)
37
+ if @enumerable.respond_to?(:<<)
36
38
  s = RDF::Statement.from([nil, nil, nil])
37
- expect(s).not_to be_valid
38
- subject << s
39
- expect(subject).not_to be_valid
39
+ s.should_not be_valid
40
+ @enumerable << s
41
+ @enumerable.should_not be_valid
40
42
  else
41
43
  pending("can't add statement to immutable enumerable")
42
44
  end
@@ -44,383 +46,431 @@ module RDF_Enumerable
44
46
  end
45
47
 
46
48
  context "when counting statements" do
47
- it {should respond_to(:empty?)}
48
- it {should_not be_empty}
49
- it {should respond_to(:count)}
50
- its(:count) {should == @statements.size}
51
- it {should respond_to(:size)}
52
- its(:size) {should == @statements.size}
53
-
54
- context "and empty" do
55
- subject {[].extend(RDF::Enumerable)}
56
- it {should be_empty}
57
- its(:count) {should == 0}
58
- its(:size) {should == 0}
49
+ it "should respond to #empty?" do
50
+ @enumerable.should respond_to(:empty?)
51
+ end
52
+
53
+ it "should respond to #count and #size" do
54
+ @enumerable.should respond_to(*%w(count size))
55
+ end
56
+
57
+ it "should implement #empty?" do
58
+ ([].extend(RDF::Enumerable)).empty?.should be_true
59
+ @enumerable.empty?.should be_false
60
+ end
61
+
62
+ it "should implement #count and #size" do
63
+ %w(count size).each do |method|
64
+ @enumerable.send(method).should == @statements.size
65
+ end
59
66
  end
60
67
  end
61
68
 
62
69
  context "when enumerating statements" do
63
- it {should respond_to(:statements)}
64
- its(:statements) {should be_an_enumerator}
70
+ it "should respond to #statements" do
71
+ @enumerable.should respond_to(:statements)
72
+ end
65
73
 
66
- context "#statements" do
67
- specify {expect(subject.statements.to_a.size).to eq @statements.size}
68
- specify {subject.statements.each { |statement| expect(statement).to be_a_statement }}
74
+ it "should respond to #has_statement?" do
75
+ @enumerable.should respond_to(:has_statement?)
69
76
  end
70
77
 
71
- it {should respond_to(:has_statement?)}
72
- context "#has_statement?" do
73
- let(:unknown_statement) {RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)}
74
- it "should have all statements" do
75
- # Don't check for BNodes, as equivalence depends on their being exactly the same, not just the same identifier. If subject is loaded separately, these won't match.
76
- non_bnode_statements.each do |statement|
77
- expect(subject).to have_statement(statement)
78
- end
78
+ it "should respond to #each_statement" do
79
+ @enumerable.should respond_to(:each_statement)
80
+ end
81
+
82
+ it "should respond to #enum_statement" do
83
+ @enumerable.should respond_to(:enum_statement)
84
+ end
85
+
86
+ it "should implement #statements" do
87
+ @enumerable.statements.should be_an_enumerator
88
+ @enumerable.statements.to_a.size.should == @statements.size
89
+ @enumerable.statements.each { |statement| statement.should be_a_statement }
90
+ end
91
+
92
+ it "should implement #has_statement?" do
93
+ @statements.each do |statement|
94
+ @enumerable.has_statement?(statement).should be_true
79
95
  end
80
96
 
81
- it "does not have statement in different context" do
82
- if @supports_context
83
- context = RDF::URI.new("urn:context:1")
84
- non_bnode_statements.each do |statement|
85
- s = statement.dup
86
- s.context = context
87
- expect(subject).not_to have_statement(s)
88
- end
97
+ if @supports_context
98
+ context = RDF::URI.new("urn:context:1")
99
+ @statements.each do |statement|
100
+ s = statement.dup
101
+ s.context = context
102
+ @enumerable.has_statement?(s).should be_false
89
103
  end
90
104
  end
91
105
 
92
- it "does not have an unknown statement" do
93
- expect(subject).not_to have_statement(unknown_statement)
94
- end
106
+ unknown_statement = RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)
107
+ @enumerable.has_statement?(unknown_statement).should be_false
95
108
  end
96
109
 
97
- it {should respond_to(:each_statement)}
98
- its(:each_statement) {should be_an_enumerator}
99
110
  it "should implement #each_statement" do
100
- subject.each_statement { |statement| expect(statement).to be_a_statement }
111
+ @enumerable.each_statement.should be_an_enumerator
112
+ @enumerable.each_statement { |statement| statement.should be_a_statement }
101
113
  end
102
114
 
103
- it {should respond_to(:enum_statement)}
104
- its(:enum_statement) {should be_an_enumerator}
105
- its(:enum_statement) {should be_countable}
106
- its(:enum_statement) {should be_enumerable}
107
- its(:enum_statement) {should be_queryable}
108
- context "#enum_statement" do
109
- it "should enumerate all statements" do
110
- expect(subject.enum_statement.to_a).to include(*@enumerable.each_statement.to_a)
111
- end
115
+ it "should implement #enum_statement" do
116
+ @enumerable.enum_statement.should be_an_enumerator
117
+ @enumerable.enum_statement.should be_countable
118
+ @enumerable.enum_statement.should be_enumerable
119
+ @enumerable.enum_statement.should be_queryable
120
+ @enumerable.enum_statement.to_a.should == @enumerable.each_statement.to_a
112
121
  end
113
122
  end
114
123
 
115
124
  context "when enumerating triples" do
116
- it {should respond_to(:triples)}
117
- it {should respond_to(:has_triple?)}
118
- it {should respond_to(:each_triple)}
119
- it {should respond_to(:enum_triple)}
125
+ it "should respond to #triples" do
126
+ @enumerable.should respond_to(:triples)
127
+ end
120
128
 
121
- its(:triples) {should be_an_enumerator}
122
- context "#triples" do
123
- specify {expect(subject.triples.to_a.size).to eq @statements.size}
124
- specify {subject.triples.each { |triple| expect(triple).to be_a_triple }}
129
+ it "should respond to #has_triple?" do
130
+ @enumerable.should respond_to(:has_triple?)
125
131
  end
126
132
 
127
- context "#has_triple?" do
128
- specify do
129
- non_bnode_statements.each do |statement|
130
- expect(subject).to have_triple(statement.to_triple)
131
- end
132
- end
133
+ it "should respond to #each_triple" do
134
+ @enumerable.should respond_to(:each_triple)
133
135
  end
134
136
 
135
- its(:each_triple) {should be_an_enumerator}
136
- context "#each_triple" do
137
- specify {subject.each_triple { |*triple| expect(triple).to be_a_triple }}
137
+ it "should respond to #enum_triple" do
138
+ @enumerable.should respond_to(:enum_triple)
138
139
  end
139
140
 
140
- its(:enum_triple) {should be_an_enumerator}
141
- its(:enum_triple) {should be_countable}
142
- context "#enum_triple" do
143
- it "should enumerate all triples" do
144
- expect(subject.enum_triple.to_a).to include(*@enumerable.each_triple.to_a)
141
+ it "should implement #triples" do
142
+ @enumerable.triples.should be_an_enumerator
143
+ @enumerable.triples.to_a.size.should == @statements.size
144
+ @enumerable.triples.each { |triple| triple.should be_a_triple }
145
+ end
146
+
147
+ it "should implement #has_triple?" do
148
+ @statements.each do |statement|
149
+ @enumerable.has_triple?(statement.to_triple).should be_true
145
150
  end
146
151
  end
152
+
153
+ it "should implement #each_triple" do
154
+ @enumerable.each_triple.should be_an_enumerator
155
+ @enumerable.each_triple { |*triple| triple.should be_a_triple }
156
+ end
157
+
158
+ it "should implement #enum_triple" do
159
+ @enumerable.enum_triple.should be_an_enumerator
160
+ @enumerable.enum_triple.should be_countable
161
+ @enumerable.enum_triple.to_a.should == @enumerable.each_triple.to_a
162
+ end
147
163
  end
148
164
 
149
165
  context "when enumerating quads" do
150
- it {should respond_to(:quads)}
151
- it {should respond_to(:has_quad?)}
152
- it {should respond_to(:each_quad)}
153
- it {should respond_to(:enum_quad)}
154
-
155
- its(:quads) {should be_an_enumerator}
156
- context "#quads" do
157
- specify {expect(subject.quads.to_a.size).to eq @statements.size}
158
- specify {subject.quads.each { |quad| expect(quad).to be_a_quad }}
159
- end
160
-
161
- context "#has_quad?" do
162
- specify do
163
- if @supports_context
164
- non_bnode_statements.each do |statement|
165
- expect(subject).to have_quad(statement.to_quad)
166
- end
167
- end
168
- end
166
+ it "should respond to #quads" do
167
+ @enumerable.should respond_to(:quads)
168
+ end
169
+
170
+ it "should respond to #has_quad?" do
171
+ @enumerable.should respond_to(:has_quad?)
172
+ end
173
+
174
+ it "should respond to #each_quad" do
175
+ @enumerable.should respond_to(:each_quad)
176
+ end
177
+
178
+ it "should respond to #enum_quad" do
179
+ @enumerable.should respond_to(:enum_quad)
169
180
  end
170
181
 
171
- its(:each_quad) {should be_an_enumerator}
172
- context "#each_quad" do
173
- specify {subject.each_quad {|*quad| expect(quad).to be_a_quad }}
182
+ it "should implement #quads" do
183
+ @enumerable.quads.should be_an_enumerator
184
+ @enumerable.quads.to_a.size.should == @statements.size
185
+ @enumerable.quads.each { |quad| quad.should be_a_quad }
174
186
  end
175
187
 
176
- its(:enum_quad) {should be_an_enumerator}
177
- its(:enum_quad) {should be_countable}
178
- context "#enum_quad" do
179
- it "should enumerate all quads" do
180
- expect(subject.enum_quad.to_a).to include(*@enumerable.each_quad.to_a)
188
+ it "should implement #has_quad?" do
189
+ @statements.each do |statement|
190
+ @enumerable.has_quad?(statement.to_quad).should be_true
181
191
  end
182
192
  end
193
+
194
+ it "should implement #each_quad" do
195
+ @enumerable.each_quad.should be_an_enumerator
196
+ @enumerable.each_quad { |*quad| quad.should be_a_quad }
197
+ end
198
+
199
+ it "should implement #enum_quad" do
200
+ @enumerable.enum_quad.should be_an_enumerator
201
+ @enumerable.enum_quad.should be_countable
202
+ @enumerable.enum_quad.to_a.should == @enumerable.each_quad.to_a
203
+ end
183
204
  end
184
205
 
185
206
  context "when enumerating subjects" do
186
- let(:subjects) {subject.map { |s| s.subject }.reject(&:node?).uniq}
187
- it {should respond_to(:subjects)}
188
- it {should respond_to(:has_subject?)}
189
- it {should respond_to(:each_subject)}
190
- it {should respond_to(:enum_subject)}
191
-
192
- its(:subjects) {should be_an_enumerator}
193
- context "#subjects" do
207
+ it "should respond to #subjects" do
208
+ @enumerable.should respond_to(:subjects)
209
+ end
210
+
211
+ it "should respond to #has_subject?" do
212
+ @enumerable.should respond_to(:has_subject?)
213
+ end
214
+
215
+ it "should respond to #each_subject" do
216
+ @enumerable.should respond_to(:each_subject)
217
+ end
218
+
219
+ it "should respond to #enum_subject" do
220
+ @enumerable.should respond_to(:enum_subject)
221
+ end
222
+
223
+ describe "#subjects" do
194
224
  subject {@enumerable.subjects}
195
- specify {expect(subject).to be_an_enumerator}
196
- specify {subject.each { |value| expect(value).to be_a_resource }}
225
+ specify {subject.should be_an_enumerator}
226
+ specify {subject.each { |value| value.should be_a_resource }}
197
227
  context ":unique => false" do
198
228
  subject {@enumerable.subjects(:unique => false)}
199
- specify {expect(subject).to be_an_enumerator}
200
- specify {subject.each { |value| expect(value).to be_a_resource }}
229
+ specify {subject.should be_an_enumerator}
230
+ specify {subject.each { |value| value.should be_a_resource }}
201
231
  end
202
232
  end
203
233
 
204
- context "#has_subject?" do
205
- specify do
206
- checked = []
207
- non_bnode_statements.each do |statement|
208
- expect(@enumerable).to have_subject(statement.subject) unless checked.include?(statement.subject)
209
- checked << statement.subject
210
- end
211
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
212
- expect(@enumerable).not_to have_subject(uri)
234
+ it "should implement #has_subject?" do
235
+ checked = []
236
+ @statements.each do |statement|
237
+ @enumerable.has_subject?(statement.subject).should be_true unless checked.include?(statement.subject)
238
+ checked << statement.subject
213
239
  end
240
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
241
+ @enumerable.has_predicate?(uri).should be_false
214
242
  end
215
243
 
216
- its(:each_subject) {should be_an_enumerator}
217
- context "#each_subject" do
218
- specify {expect(subject.each_subject.reject(&:node?).size).to eq subjects.size}
219
- specify {subject.each_subject {|value| expect(value).to be_a_resource}}
220
- specify {subject.each_subject {|value| expect(subjects).to include(value) unless value.node?}}
244
+ it "should implement #each_subject" do
245
+ @enumerable.each_subject.should be_an_enumerator
246
+ subjects = @statements.map { |s| s.subject }.uniq
247
+ @enumerable.each_subject.to_a.size.should == subjects.size
248
+ @enumerable.each_subject do |value|
249
+ value.should be_a_value
250
+ subjects.should include(value)
251
+ end
221
252
  end
222
253
 
223
- its(:enum_subject) {should be_an_enumerator}
224
- its(:enum_subject) {should be_countable}
225
- context "#enum_subject" do
226
- it "should enumerate all subjects" do
227
- expect(subject.enum_subject.reject(&:node?)).to include(*subjects)
228
- end
254
+ it "should implement #enum_subject" do
255
+ @enumerable.enum_subject.should be_an_enumerator
256
+ @enumerable.enum_subject.should be_countable
257
+ @enumerable.enum_subject.to_a.should == @enumerable.each_subject.to_a
229
258
  end
230
259
  end
231
260
 
232
261
  context "when enumerating predicates" do
233
- let(:predicates) {@statements.map { |s| s.predicate }.uniq}
234
- it {should respond_to(:predicates)}
235
- it {should respond_to(:has_predicate?)}
236
- it {should respond_to(:each_predicate)}
237
- it {should respond_to(:enum_predicate)}
238
-
239
- its(:predicates) {should be_an_enumerator}
240
- context "#predicates" do
262
+ it "should respond to #predicates" do
263
+ @enumerable.should respond_to(:predicates)
264
+ end
265
+
266
+ it "should respond to #has_predicate?" do
267
+ @enumerable.should respond_to(:has_predicate?)
268
+ end
269
+
270
+ it "should respond to #each_predicate" do
271
+ @enumerable.should respond_to(:each_predicate)
272
+ end
273
+
274
+ it "should respond to #enum_predicate" do
275
+ @enumerable.should respond_to(:enum_predicate)
276
+ end
277
+
278
+ describe "#predicates" do
241
279
  subject {@enumerable.predicates}
242
- specify {expect(subject).to be_an_enumerator}
243
- specify {subject.each { |value| expect(value).to be_a_uri }}
280
+ specify {subject.should be_an_enumerator}
281
+ specify {subject.each { |value| value.should be_a_uri }}
244
282
  context ":unique => false" do
245
283
  subject {@enumerable.predicates(:unique => false)}
246
- specify {expect(subject).to be_an_enumerator}
247
- specify {subject.each { |value| expect(value).to be_a_uri }}
284
+ specify {subject.should be_an_enumerator}
285
+ specify {subject.each { |value| value.should be_a_resource }}
248
286
  end
249
287
  end
250
288
 
251
- context "#has_predicate?" do
252
- specify do
253
- checked = []
254
- @statements.each do |statement|
255
- expect(@enumerable).to have_predicate(statement.predicate) unless checked.include?(statement.predicate)
256
- checked << statement.predicate
257
- end
258
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
259
- expect(@enumerable).not_to have_predicate(uri)
289
+ it "should implement #has_predicate?" do
290
+ checked = []
291
+ @statements.each do |statement|
292
+ @enumerable.has_predicate?(statement.predicate).should be_true unless checked.include?(statement.object)
293
+ checked << statement.predicate
260
294
  end
295
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
296
+ @enumerable.has_predicate?(uri).should be_false
261
297
  end
262
298
 
263
- its(:each_predicate) {should be_an_enumerator}
264
- context "#each_predicate" do
265
- specify {expect(subject.each_predicate.to_a.size).to eq predicates.size}
266
- specify {subject.each_predicate {|value| expect(value).to be_a_uri}}
267
- specify {subject.each_predicate {|value| expect(predicates).to include(value)}}
299
+ it "should implement #each_predicate" do
300
+ predicates = @statements.map { |s| s.predicate }.uniq
301
+ @enumerable.each_predicate.should be_an_enumerator
302
+ @enumerable.each_predicate.to_a.size.should == predicates.size
303
+ @enumerable.each_predicate do |value|
304
+ value.should be_a_uri
305
+ predicates.should include(value)
306
+ end
268
307
  end
269
308
 
270
- its(:enum_predicate) {should be_an_enumerator}
271
- its(:enum_predicate) {should be_countable}
272
- context "#enum_predicate" do
273
- it "should enumerate all predicates" do
274
- expect(subject.enum_predicate.to_a).to include(*predicates)
275
- end
309
+ it "should implement #enum_predicate" do
310
+ @enumerable.enum_predicate.should be_an_enumerator
311
+ @enumerable.enum_predicate.should be_countable
312
+ @enumerable.enum_predicate.to_a.should == @enumerable.each_predicate.to_a
276
313
  end
277
314
  end
278
315
 
279
316
  context "when enumerating objects" do
280
- let(:objects) {subject.map(&:object).reject(&:node?).uniq}
281
- it {should respond_to(:objects)}
282
- it {should respond_to(:has_object?)}
283
- it {should respond_to(:each_object)}
284
- it {should respond_to(:enum_object)}
285
-
286
- its(:objects) {should be_an_enumerator}
287
- context "#objects" do
317
+ it "should respond to #objects" do
318
+ @enumerable.should respond_to(:objects)
319
+ end
320
+
321
+ it "should respond to #has_object?" do
322
+ @enumerable.should respond_to(:has_object?)
323
+ end
324
+
325
+ it "should respond to #each_object" do
326
+ @enumerable.should respond_to(:each_object)
327
+ end
328
+
329
+ it "should respond to #enum_object" do
330
+ @enumerable.should respond_to(:enum_object)
331
+ end
332
+
333
+ describe "#objects" do
288
334
  subject {@enumerable.objects}
289
- specify {expect(subject).to be_an_enumerator}
290
- specify {subject.each { |value| expect(value).to be_a_term }}
335
+ specify {subject.should be_an_enumerator}
336
+ specify {subject.each { |value| value.should be_a_value }}
291
337
  context ":unique => false" do
292
338
  subject {@enumerable.objects(:unique => false)}
293
- specify {expect(subject).to be_an_enumerator}
294
- specify {subject.each { |value| expect(value).to be_a_term }}
339
+ specify {subject.should be_an_enumerator}
340
+ specify {subject.each { |value| value.should be_a_value }}
295
341
  end
296
342
  end
297
343
 
298
- context "#has_object?" do
299
- specify do
300
- checked = []
301
- non_bnode_statements.each do |statement|
302
- expect(@enumerable).to have_object(statement.object) unless checked.include?(statement.object)
303
- checked << statement.object
304
- end
305
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
306
- expect(@enumerable).not_to have_object(uri)
344
+ it "should implement #has_object?" do
345
+ checked = []
346
+ @statements.each do |statement|
347
+ @enumerable.has_object?(statement.object).should be_true unless checked.include?(statement.object)
348
+ checked << statement.object
307
349
  end
350
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
351
+ @enumerable.has_object?(uri).should be_false
308
352
  end
309
353
 
310
- its(:each_object) {should be_an_enumerator}
311
- context "#each_object" do
312
- specify {expect(subject.each_object.reject(&:node?).size).to eq objects.size}
313
- specify {subject.each_object {|value| expect(value).to be_a_term}}
314
- specify {subject.each_object {|value| expect(objects).to include(value) unless value.node?}}
354
+ it "should implement #each_object" do
355
+ objects = @statements.map { |s| s.object }.uniq
356
+ @enumerable.each_object.should be_an_enumerator
357
+ @enumerable.each_object.to_a.size.should == objects.size
358
+ @enumerable.each_object do |value|
359
+ value.should be_a_value
360
+ objects.should include(value)
361
+ end
315
362
  end
316
363
 
317
- its(:enum_object) {should be_an_enumerator}
318
- its(:enum_object) {should be_countable}
319
- context "#enum_object" do
320
- it "should enumerate all objects" do
321
- expect(subject.enum_object.reject(&:node?)).to include(*objects)
322
- end
364
+ it "should implement #enum_object" do
365
+ @enumerable.enum_object.should be_an_enumerator
366
+ @enumerable.enum_object.should be_countable
367
+ @enumerable.enum_object.to_a.should == @enumerable.each_object.to_a
323
368
  end
324
369
  end
325
370
 
326
371
  context "when enumerating contexts" do
327
- it {should respond_to(:contexts)}
328
- it {should respond_to(:has_context?)}
329
- it {should respond_to(:each_context)}
330
- it {should respond_to(:enum_context)}
372
+ it "should respond to #contexts" do
373
+ @enumerable.should respond_to(:contexts)
374
+ end
375
+
376
+ it "should respond to #has_context?" do
377
+ @enumerable.should respond_to(:has_context?)
378
+ end
379
+
380
+ it "should respond to #each_context" do
381
+ @enumerable.should respond_to(:each_context)
382
+ end
383
+
384
+ it "should respond to #enum_context" do
385
+ @enumerable.should respond_to(:enum_context)
386
+ end
331
387
 
332
- its(:contexts) {should be_an_enumerator}
333
388
  describe "#contexts" do
334
389
  subject {@enumerable.contexts}
335
- specify {expect(subject).to be_an_enumerator}
336
- it "values should be resources" do
337
- subject.each { |value| expect(value).to be_a_resource }
338
- end
390
+ specify {subject.should be_an_enumerator}
391
+ specify {subject.each { |value| value.should be_a_resource }}
339
392
  context ":unique => false" do
340
393
  subject {@enumerable.contexts(:unique => false)}
341
- specify {expect(subject).to be_an_enumerator}
342
- it "values should be resources" do
343
- subject.each { |value| expect(value).to be_a_resource }
344
- end
394
+ specify {subject.should be_an_enumerator}
395
+ specify {subject.each { |value| value.should be_a_resource }}
345
396
  end
346
397
  end
347
398
 
348
399
  it "should implement #has_context?" do
349
- if @supports_context
350
- @statements.each do |statement|
351
- if statement.has_context?
352
- expect(@enumerable).to have_context(statement.context)
353
- end
400
+ @statements.each do |statement|
401
+ if statement.has_context?
402
+ @enumerable.has_context?(statement.context).should be_true
354
403
  end
355
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
356
- expect(@enumerable).not_to have_context(uri)
357
404
  end
358
- end
359
-
360
- its(:each_context) {should be_an_enumerator}
361
- context "#each_context" do
362
- let(:contexts) {@statements.map { |s| s.context }.uniq.compact}
363
- it "has appropriate number of contexts" do
364
- if @supports_context
365
- expect(subject.each_context.to_a.size).to eq contexts.size
366
- end
367
- end
368
- it "values should be resources" do
369
- subject.each_context {|value| expect(value).to be_a_resource}
370
- end
371
- it "should have all contexts" do
372
- subject.each_context {|value| expect(contexts).to include(value)}
405
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
406
+ @enumerable.has_context?(uri).should be_false
407
+ end
408
+
409
+ it "should implement #each_context" do
410
+ contexts = @statements.map { |s| s.context }.uniq
411
+ contexts.delete nil
412
+ @enumerable.each_context.should be_an_enumerator
413
+ @enumerable.each_context.to_a.size.should == contexts.size
414
+ @enumerable.each_context do |value|
415
+ value.should be_a_resource
416
+ contexts.should include(value)
373
417
  end
374
418
  end
375
419
 
376
- its(:enum_context) {should be_an_enumerator}
377
- its(:enum_context) {should be_countable}
378
- context "#enum_context" do
379
- it "should enumerate all contexts" do
380
- expect(subject.enum_context.to_a).to include(*@enumerable.each_context.to_a)
381
- end
420
+ it "should implement #enum_context" do
421
+ @enumerable.enum_context.should be_an_enumerator
422
+ @enumerable.enum_context.should be_countable
423
+ @enumerable.enum_context.to_a.should == @enumerable.each_context.to_a
382
424
  end
383
425
  end
384
426
 
385
427
  context "when enumerating graphs" do
386
- it {should respond_to(:each_graph)}
387
- it {should respond_to(:enum_graph)}
428
+ it "should respond to #each_graph" do
429
+ @enumerable.should respond_to(:enum_graph)
430
+ end
431
+
432
+ it "should respond to #enum_graph" do
433
+ @enumerable.should respond_to(:enum_graph)
434
+ end
388
435
 
389
436
  describe "#each_graph" do
390
437
  subject {@enumerable.each_graph}
391
438
  it {should be_an_enumerator}
392
- specify {subject.each { |value| expect(value).to be_a_graph }}
439
+ specify {subject.each { |value| value.should be_a_graph }}
393
440
  end
394
441
 
395
442
  describe "#enum_graph" do
396
443
  subject {@enumerable.enum_graph}
397
- it {should be_an_enumerator}
398
- it {should be_countable}
444
+ it {subject.should be_an_enumerator}
445
+ it {subject.should be_countable}
399
446
  it "enumerates the same as #each_graph" do
400
- subject.to_a.should =~ @enumerable.each_graph.to_a # expect with match problematic
447
+ subject.to_a.should == @enumerable.each_graph.to_a
401
448
  end
402
449
  end
403
450
  end
404
451
 
405
452
  context "when converting" do
406
- it {should respond_to(:to_hash)}
407
- its(:to_hash) {should be_instance_of(Hash)}
408
- context "#to_hash" do
409
- it "should have as many keys as subjects" do
410
- expect(subject.to_hash.keys.size).to eq @enumerable.subjects.to_a.size
411
- end
453
+ it "should respond to #to_hash" do
454
+ @enumerable.should respond_to(:to_hash)
455
+ end
456
+
457
+ it "should implement #to_hash" do
458
+ @enumerable.to_hash.should be_instance_of(Hash)
459
+ @enumerable.to_hash.keys.size.should == @enumerable.subjects.to_a.size
412
460
  end
413
461
  end
414
462
 
415
463
  context "when dumping" do
416
- it {should respond_to(:dump)}
464
+ it "should respond to #dump" do
465
+ @enumerable.should respond_to(:dump)
466
+ end
417
467
 
418
468
  it "should implement #dump" do
419
- expect(subject.dump(:ntriples)).to eq RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
469
+ @enumerable.dump(:ntriples).should == RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
420
470
  end
421
471
 
422
472
  it "raises error on unknown format" do
423
- expect {subject.dump(:foobar)}.to raise_error(RDF::WriterError, /No writer found/)
473
+ lambda {@enumerable.dump(:foobar)}.should raise_error(RDF::WriterError, /No writer found/)
424
474
  end
425
475
  end
426
476
  end