rdf-spec 1.0.7 → 1.0.9
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.
- checksums.yaml +6 -14
- data/VERSION +1 -1
- data/lib/rdf/spec/countable.rb +1 -1
- data/lib/rdf/spec/durable.rb +3 -3
- data/lib/rdf/spec/enumerable.rb +66 -66
- data/lib/rdf/spec/format.rb +6 -6
- data/lib/rdf/spec/indexable.rb +2 -2
- data/lib/rdf/spec/matchers.rb +38 -38
- data/lib/rdf/spec/mutable.rb +20 -20
- data/lib/rdf/spec/queryable.rb +147 -85
- data/lib/rdf/spec/reader.rb +43 -43
- data/lib/rdf/spec/transaction.rb +1 -1
- data/lib/rdf/spec/writable.rb +18 -18
- data/lib/rdf/spec/writer.rb +35 -36
- data/spec/version_spec.rb +1 -1
- metadata +28 -29
data/lib/rdf/spec/indexable.rb
CHANGED
@@ -15,11 +15,11 @@ module RDF_Indexable
|
|
15
15
|
it {should respond_to(:index!)}
|
16
16
|
|
17
17
|
it "does not raise error on #index! if #indexed?" do
|
18
|
-
|
18
|
+
expect {subject.index!}.not_to raise_error if subject.indexed?
|
19
19
|
end
|
20
20
|
|
21
21
|
it "raises error on #index! if not #indexed?" do
|
22
|
-
|
22
|
+
expect {subject.index!}.to raise_error unless subject.indexed?
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/rdf/spec/matchers.rb
CHANGED
@@ -8,113 +8,113 @@ module RDF; module Spec
|
|
8
8
|
module Matchers
|
9
9
|
RSpec::Matchers.define :be_countable do
|
10
10
|
match do |countable|
|
11
|
-
countable.
|
11
|
+
expect(countable).to be_a_kind_of(RDF::Countable)
|
12
12
|
true
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
RSpec::Matchers.define :be_enumerable do
|
17
17
|
match do |enumerable|
|
18
|
-
enumerable.
|
18
|
+
expect(enumerable).to be_a_kind_of(RDF::Enumerable)
|
19
19
|
true
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
RSpec::Matchers.define :be_an_enumerator do
|
24
24
|
match do |enumerator|
|
25
|
-
enumerator.
|
25
|
+
expect(enumerator).to be_a_kind_of(RDF::Enumerator)
|
26
26
|
true
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
RSpec::Matchers.define :be_queryable do
|
31
31
|
match do |enumerable|
|
32
|
-
enumerable.
|
32
|
+
expect(enumerable).to be_a_kind_of(RDF::Queryable)
|
33
33
|
true
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
RSpec::Matchers.define :be_mutable do
|
38
38
|
match do |enumerable|
|
39
|
-
enumerable.
|
39
|
+
expect(enumerable).to be_a_kind_of(RDF::Mutable)
|
40
40
|
true
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
RSpec::Matchers.define :be_a_statement do
|
45
45
|
match do |statement|
|
46
|
-
statement.
|
47
|
-
statement.subject.
|
48
|
-
statement.predicate.
|
49
|
-
statement.object.
|
46
|
+
expect(statement).to be_instance_of(RDF::Statement)
|
47
|
+
expect(statement.subject).to be_a_kind_of(RDF::Resource)
|
48
|
+
expect(statement.predicate).to be_a_kind_of(RDF::URI)
|
49
|
+
expect(statement.object).to be_a_kind_of(RDF::Value)
|
50
50
|
true
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
RSpec::Matchers.define :be_a_triple do
|
55
55
|
match do |triple|
|
56
|
-
triple.
|
57
|
-
triple.size.
|
58
|
-
triple[0].
|
59
|
-
triple[1].
|
60
|
-
triple[2].
|
56
|
+
expect(triple).to be_instance_of(Array)
|
57
|
+
expect(triple.size).to eq 3
|
58
|
+
expect(triple[0]).to be_a_kind_of(RDF::Resource)
|
59
|
+
expect(triple[1]).to be_a_kind_of(RDF::URI)
|
60
|
+
expect(triple[2]).to be_a_kind_of(RDF::Value)
|
61
61
|
true
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
RSpec::Matchers.define :be_a_quad do
|
66
66
|
match do |quad|
|
67
|
-
quad.
|
68
|
-
quad.size.
|
69
|
-
quad[0].
|
70
|
-
quad[1].
|
71
|
-
quad[2].
|
72
|
-
quad[3].
|
67
|
+
expect(quad).to be_instance_of(Array)
|
68
|
+
expect(quad.size).to eq 4
|
69
|
+
expect(quad[0]).to be_a_kind_of(RDF::Resource)
|
70
|
+
expect(quad[1]).to be_a_kind_of(RDF::URI)
|
71
|
+
expect(quad[2]).to be_a_kind_of(RDF::Value)
|
72
|
+
expect(quad[3]).to be_a_kind_of(RDF::Resource) unless quad[3].nil?
|
73
73
|
true
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
RSpec::Matchers.define :be_a_resource do
|
78
78
|
match do |value|
|
79
|
-
value.
|
79
|
+
expect(value).to be_a_kind_of(RDF::Resource)
|
80
80
|
true
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
RSpec::Matchers.define :be_a_node do
|
85
85
|
match do |value|
|
86
|
-
value.
|
86
|
+
expect(value).to be_a_kind_of(RDF::Node)
|
87
87
|
true
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
RSpec::Matchers.define :be_a_uri do
|
92
92
|
match do |value|
|
93
|
-
value.
|
93
|
+
expect(value).to be_a_kind_of(RDF::URI)
|
94
94
|
true
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
RSpec::Matchers.define :be_a_value do
|
99
99
|
match do |value|
|
100
|
-
value.
|
100
|
+
expect(value).to be_a_kind_of(RDF::Value)
|
101
101
|
true
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
RSpec::Matchers.define :be_a_list do
|
106
106
|
match do |value|
|
107
|
-
value.
|
107
|
+
expect(value).to be_an(RDF::List)
|
108
108
|
true
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
112
|
RSpec::Matchers.define :be_a_vocabulary do |base_uri|
|
113
113
|
match do |vocabulary|
|
114
|
-
vocabulary.
|
115
|
-
vocabulary.
|
116
|
-
vocabulary.to_uri.to_s.
|
117
|
-
vocabulary.
|
114
|
+
expect(vocabulary).to be_a_kind_of(Module)
|
115
|
+
expect(vocabulary).to respond_to(:to_uri)
|
116
|
+
expect(vocabulary.to_uri.to_s).to eq base_uri
|
117
|
+
expect(vocabulary).to respond_to(:[])
|
118
118
|
true
|
119
119
|
end
|
120
120
|
end
|
@@ -122,13 +122,13 @@ module RDF; module Spec
|
|
122
122
|
RSpec::Matchers.define :have_properties do |base_uri, properties|
|
123
123
|
match do |vocabulary|
|
124
124
|
properties.map { |p| p.to_sym }.each do |property|
|
125
|
-
vocabulary[property].
|
126
|
-
vocabulary[property].to_s.
|
127
|
-
vocabulary.
|
128
|
-
|
129
|
-
vocabulary.send(property).
|
130
|
-
vocabulary.send(property.to_s).
|
131
|
-
vocabulary.send(property).to_s.
|
125
|
+
expect(vocabulary[property]).to be_a_uri
|
126
|
+
expect(vocabulary[property].to_s).to eq "#{base_uri}#{property}"
|
127
|
+
expect(vocabulary).to respond_to(property)
|
128
|
+
expect { vocabulary.send(property) }.not_to raise_error
|
129
|
+
expect(vocabulary.send(property)).to be_a_uri
|
130
|
+
expect(vocabulary.send(property.to_s)).to be_a_uri
|
131
|
+
expect(vocabulary.send(property).to_s).to eq "#{base_uri}#{property}"
|
132
132
|
end
|
133
133
|
true
|
134
134
|
end
|
@@ -145,14 +145,14 @@ module RDF; module Spec
|
|
145
145
|
|
146
146
|
RSpec::Matchers.define :be_a_repository do
|
147
147
|
match do |repository|
|
148
|
-
repository.
|
148
|
+
expect(repository).to be_a_kind_of(RDF::Repository)
|
149
149
|
true
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
153
|
RSpec::Matchers.define :be_a_repository_of_size do |size|
|
154
154
|
match do |repository|
|
155
|
-
repository.
|
155
|
+
expect(repository).to be_a_repository
|
156
156
|
repository.size == size
|
157
157
|
end
|
158
158
|
end
|
data/lib/rdf/spec/mutable.rb
CHANGED
@@ -49,43 +49,43 @@ module RDF_Mutable
|
|
49
49
|
|
50
50
|
context "#load" do
|
51
51
|
it "should require an argument" do
|
52
|
-
|
52
|
+
expect { subject.load }.to raise_error(ArgumentError)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should accept a string filename argument" do
|
56
56
|
pending("mutability", :unless => subject.mutable?) do
|
57
|
-
|
57
|
+
expect { subject.load(RDF::Spec::TRIPLES_FILE) }.not_to raise_error
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should accept an optional hash argument" do
|
62
62
|
pending("mutability", :unless => subject.mutable?) do
|
63
|
-
|
63
|
+
expect { subject.load(RDF::Spec::TRIPLES_FILE, {}) }.not_to raise_error
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should load statements" do
|
68
68
|
pending("mutability", :unless => subject.mutable?) do
|
69
69
|
subject.load RDF::Spec::TRIPLES_FILE
|
70
|
-
subject.size.
|
71
|
-
subject.
|
70
|
+
expect(subject.size).to eq File.readlines(RDF::Spec::TRIPLES_FILE).size
|
71
|
+
expect(subject).to have_subject(resource)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should load statements with a context override" do
|
76
76
|
pending("mutability and contextuality", :unless => (subject.mutable? && @supports_context)) do
|
77
77
|
subject.load RDF::Spec::TRIPLES_FILE, :context => context
|
78
|
-
subject.
|
79
|
-
subject.query(:context => context).size.
|
78
|
+
expect(subject).to have_context(context)
|
79
|
+
expect(subject.query(:context => context).size).to eq subject.size
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
context "#from_{reader}" do
|
85
85
|
it "should instantiate a reader" do
|
86
|
-
reader =
|
87
|
-
reader.
|
88
|
-
RDF::Reader.
|
86
|
+
reader = double("reader")
|
87
|
+
expect(reader).to receive(:new).and_return(RDF::NTriples::Reader.new(""))
|
88
|
+
expect(RDF::Reader).to receive(:for).with(:a_reader).and_return(reader)
|
89
89
|
subject.send(:from_a_reader)
|
90
90
|
end
|
91
91
|
end
|
@@ -98,21 +98,21 @@ module RDF_Mutable
|
|
98
98
|
|
99
99
|
it "should not raise errors" do
|
100
100
|
pending("mutability", :unless => subject.mutable?) do
|
101
|
-
|
101
|
+
expect { subject.delete(@statements.first) }.not_to raise_error
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
it "should support deleting one statement at a time" do
|
106
106
|
pending("mutability", :unless => subject.mutable?) do
|
107
107
|
subject.delete(@statements.first)
|
108
|
-
subject.
|
108
|
+
expect(subject).not_to have_statement(@statements.first)
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should support deleting multiple statements at a time" do
|
113
113
|
pending("mutability", :unless => subject.mutable?) do
|
114
114
|
subject.delete(*@statements)
|
115
|
-
subject.find { |s| subject.has_statement?(s) }.
|
115
|
+
expect(subject.find { |s| subject.has_statement?(s) }).to be_false
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -122,12 +122,12 @@ module RDF_Mutable
|
|
122
122
|
require 'digest/sha1'
|
123
123
|
count = subject.count
|
124
124
|
subject.delete([nil, nil, random = Digest::SHA1.hexdigest(File.read(__FILE__))])
|
125
|
-
subject.
|
126
|
-
subject.count.
|
125
|
+
expect(subject).not_to be_empty
|
126
|
+
expect(subject.count).to eq count
|
127
127
|
|
128
128
|
# everything deleted
|
129
129
|
subject.delete([nil, nil, nil])
|
130
|
-
subject.
|
130
|
+
expect(subject).to be_empty
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -143,15 +143,15 @@ module RDF_Mutable
|
|
143
143
|
subject.insert(s1)
|
144
144
|
subject.insert(s2)
|
145
145
|
subject.insert(s3)
|
146
|
-
subject.count.
|
146
|
+
expect(subject.count).to eq count
|
147
147
|
|
148
148
|
# Delete one by one
|
149
149
|
subject.delete(s1)
|
150
|
-
subject.count.
|
150
|
+
expect(subject.count).to eq count - (@supports_context ? 1 : 1)
|
151
151
|
subject.delete(s2)
|
152
|
-
subject.count.
|
152
|
+
expect(subject.count).to eq count - (@supports_context ? 2 : 1)
|
153
153
|
subject.delete(s3)
|
154
|
-
subject.count.
|
154
|
+
expect(subject.count).to eq count - (@supports_context ? 3 : 1)
|
155
155
|
end
|
156
156
|
end
|
157
157
|
end
|
data/lib/rdf/spec/queryable.rb
CHANGED
@@ -23,6 +23,8 @@ module RDF_Queryable
|
|
23
23
|
|
24
24
|
describe RDF::Queryable do
|
25
25
|
subject {@queryable}
|
26
|
+
let(:query) {RDF::Query.new {pattern [:s, :p, :o]}}
|
27
|
+
|
26
28
|
##
|
27
29
|
# @see RDF::Queryable#query
|
28
30
|
describe "#query" do
|
@@ -30,94 +32,135 @@ module RDF_Queryable
|
|
30
32
|
|
31
33
|
context "when called" do
|
32
34
|
it "requires an argument" do
|
33
|
-
|
35
|
+
expect { subject.query }.to raise_error(ArgumentError)
|
34
36
|
end
|
35
37
|
|
36
38
|
it "accepts a pattern argument" do
|
37
|
-
|
38
|
-
|
39
|
+
expect { subject.query(RDF::Query::Pattern.new(nil, nil, nil)) }.not_to raise_error
|
40
|
+
expect { subject.query(RDF::Query::Pattern.new(:s, :p, :o)) }.not_to raise_error
|
39
41
|
end
|
40
42
|
|
41
43
|
it "accepts a statement argument" do
|
42
|
-
|
44
|
+
expect { subject.query(RDF::Statement.new(nil, nil, nil)) }.not_to raise_error
|
43
45
|
end
|
44
46
|
|
45
47
|
it "accepts a triple argument" do
|
46
|
-
|
48
|
+
expect { subject.query([nil, nil, nil]) }.not_to raise_error
|
47
49
|
end
|
48
50
|
|
49
51
|
it "accepts a quad argument" do
|
50
|
-
|
52
|
+
expect { subject.query([nil, nil, nil, nil]) }.not_to raise_error
|
51
53
|
end
|
52
54
|
|
53
55
|
it "accepts a hash argument" do
|
54
|
-
|
56
|
+
expect { subject.query({}) }.not_to raise_error
|
57
|
+
end
|
58
|
+
|
59
|
+
it "accepts an RDF::Query argument" do
|
60
|
+
expect { subject.query(RDF::Query.new) }.not_to raise_error
|
55
61
|
end
|
56
62
|
|
57
63
|
it "does not alter a given hash argument" do
|
58
64
|
query = {:subject => resource, :predicate => RDF::DOAP.name, :object => RDF::FOAF.Person}
|
59
65
|
original_query = query.dup
|
60
66
|
subject.query(query)
|
61
|
-
query.
|
67
|
+
expect(query).to eq original_query
|
62
68
|
end
|
63
69
|
|
64
70
|
it "rejects other kinds of arguments" do
|
65
|
-
|
71
|
+
expect { subject.query(nil) }.to raise_error(ArgumentError)
|
66
72
|
end
|
67
73
|
|
68
74
|
context "with a block" do
|
69
|
-
|
70
|
-
|
71
|
-
|
75
|
+
context "with a triple argument" do
|
76
|
+
it "yields statements" do
|
77
|
+
subject.query([nil, nil, nil]) do |statement|
|
78
|
+
expect(statement).to be_a_statement
|
79
|
+
expect(statement).not_to be_a RDF::Query::Solution
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "calls #query_pattern" do
|
84
|
+
expect(subject).to receive(:query_pattern)
|
85
|
+
expect(subject).not_to receive(:query_execute)
|
86
|
+
subject.query([:s, :p, :o]) {}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
context "with a Query argument" do
|
90
|
+
it "yields statements" do
|
91
|
+
subject.query(query) do |solution|
|
92
|
+
expect(solution).not_to be_a_statement
|
93
|
+
expect(solution).to be_a RDF::Query::Solution
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "calls #query_execute" do
|
98
|
+
expect(subject).to receive(:query_execute)
|
99
|
+
expect(subject).not_to receive(:query_pattern)
|
100
|
+
subject.query(query) {}
|
72
101
|
end
|
73
102
|
end
|
74
103
|
end
|
75
104
|
|
76
105
|
context "without a block" do
|
77
106
|
it "returns an enumerator" do
|
78
|
-
subject.query([nil, nil, nil]).
|
107
|
+
expect(subject.query([nil, nil, nil])).to be_an_enumerator
|
79
108
|
end
|
80
109
|
|
81
110
|
it "returns an enumerable enumerator" do
|
82
|
-
subject.query([nil, nil, nil]).
|
111
|
+
expect(subject.query([nil, nil, nil])).to be_enumerable
|
83
112
|
end
|
84
113
|
|
85
114
|
it "returns a queryable enumerator" do
|
86
|
-
subject.query([nil, nil, nil]).
|
115
|
+
expect(subject.query([nil, nil, nil])).to be_queryable
|
87
116
|
end
|
88
117
|
|
89
|
-
it "returns statements" do
|
118
|
+
it "returns statements given a triple" do
|
90
119
|
subject.query([nil, nil, nil]).each do |statement|
|
91
|
-
statement.
|
120
|
+
expect(statement).to be_a_statement
|
121
|
+
expect(statement).not_to be_a RDF::Query::Solution
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "returns solutions given a query" do
|
126
|
+
subject.query(query).each do |solution|
|
127
|
+
expect(solution).not_to be_a_statement
|
128
|
+
expect(solution).to be_a RDF::Query::Solution
|
92
129
|
end
|
93
130
|
end
|
94
131
|
|
95
132
|
it "returns the correct number of results for array queries" do
|
96
|
-
subject.query([nil, nil, nil]).size.
|
97
|
-
subject.query([resource, nil, nil]).size.
|
98
|
-
subject.query([RDF::URI("http://ar.to/#self"), nil, nil]).size.
|
99
|
-
subject.query([resource, RDF::DOAP.name, nil]).size.
|
100
|
-
subject.query([nil, nil, RDF::DOAP.Project]).size.
|
133
|
+
expect(subject.query([nil, nil, nil]).size).to eq @statements.size
|
134
|
+
expect(subject.query([resource, nil, nil]).size).to eq File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
|
135
|
+
expect(subject.query([RDF::URI("http://ar.to/#self"), nil, nil]).size).to eq File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
|
136
|
+
expect(subject.query([resource, RDF::DOAP.name, nil]).size).to eq 1
|
137
|
+
expect(subject.query([nil, nil, RDF::DOAP.Project]).size).to eq 1
|
101
138
|
end
|
102
139
|
|
103
140
|
it "returns the correct number of results for hash queries" do
|
104
|
-
subject.query({}).size.
|
105
|
-
subject.query(:subject => resource)
|
106
|
-
subject.query(:subject => resource, :predicate => RDF::DOAP.name).size.
|
107
|
-
subject.query(:object => RDF::DOAP.Project).size.
|
141
|
+
expect(subject.query({}).size).to eq @statements.size
|
142
|
+
expect(subject.query(:subject => resource).size).to eq File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
|
143
|
+
expect(subject.query(:subject => resource, :predicate => RDF::DOAP.name).size).to eq 1
|
144
|
+
expect(subject.query(:object => RDF::DOAP.Project).size).to eq 1
|
145
|
+
end
|
146
|
+
|
147
|
+
it "returns the correct number of results for query queries" do
|
148
|
+
expect(subject.query(query).size).to eq @statements.size
|
108
149
|
end
|
109
150
|
end
|
110
151
|
|
111
152
|
context "with specific patterns from SPARQL" do
|
112
153
|
context "triple pattern combinations" do
|
113
154
|
it "?s p o" do
|
114
|
-
subject.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal.new(1)).to_a.
|
115
|
-
[RDF::Statement.new(RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1), RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
|
155
|
+
expect(subject.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal.new(1)).to_a).to(
|
156
|
+
include *[RDF::Statement.new(RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1), RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
|
157
|
+
)
|
116
158
|
end
|
117
159
|
|
118
160
|
it "s ?p o" do
|
119
|
-
subject.query(:subject => RDF::URI("http://example.org/xi2"), :object => RDF::Literal.new(1)).to_a.
|
120
|
-
[RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
|
161
|
+
expect(subject.query(:subject => RDF::URI("http://example.org/xi2"), :object => RDF::Literal.new(1)).to_a).to(
|
162
|
+
include *[RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
|
163
|
+
)
|
121
164
|
end
|
122
165
|
end
|
123
166
|
|
@@ -128,11 +171,11 @@ module RDF_Queryable
|
|
128
171
|
its(:count) {should == 2}
|
129
172
|
|
130
173
|
it "has two solutions" do
|
131
|
-
subject.any? {|s| s.subject == RDF::URI("http://example.org/xi1")}.
|
174
|
+
expect(subject.any? {|s| s.subject == RDF::URI("http://example.org/xi1")}).to be_true
|
132
175
|
end
|
133
176
|
|
134
177
|
it "has xi2 as a solution" do
|
135
|
-
subject.any? {|s| s.subject == RDF::URI("http://example.org/xi2")}.
|
178
|
+
expect(subject.any? {|s| s.subject == RDF::URI("http://example.org/xi2")}).to be_true
|
136
179
|
end
|
137
180
|
end
|
138
181
|
|
@@ -141,7 +184,7 @@ module RDF_Queryable
|
|
141
184
|
its(:count) {should == 1}
|
142
185
|
|
143
186
|
it "has xd1 as a solution" do
|
144
|
-
subject.any? {|s| s.subject == RDF::URI("http://example.org/xd1")}.
|
187
|
+
expect(subject.any? {|s| s.subject == RDF::URI("http://example.org/xd1")}).to be_true
|
145
188
|
end
|
146
189
|
end
|
147
190
|
end
|
@@ -149,30 +192,49 @@ module RDF_Queryable
|
|
149
192
|
end
|
150
193
|
end
|
151
194
|
|
195
|
+
##
|
196
|
+
# @see RDF::Queryable#query_execute
|
197
|
+
describe "#query_execute" do
|
198
|
+
it "defines a protected #query_execute method" do
|
199
|
+
expect(subject.class.protected_method_defined?(:query_execute)).to be_true
|
200
|
+
end
|
201
|
+
|
202
|
+
context "when called" do
|
203
|
+
it "requires an argument" do
|
204
|
+
expect { subject.send(:query_execute) }.to raise_error(ArgumentError)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "yields to the given block" do
|
208
|
+
expect {|b| subject.send(:query_execute, query, &b)}.to yield_control.exactly(@queryable.count).times
|
209
|
+
end
|
210
|
+
|
211
|
+
it "yields solutions" do
|
212
|
+
subject.send(:query_execute, query) do |solution|
|
213
|
+
expect(solution).to be_a RDF::Query::Solution
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
152
219
|
##
|
153
220
|
# @see RDF::Queryable#query_pattern
|
154
221
|
describe "#query_pattern" do
|
155
222
|
it "defines a protected #query_pattern method" do
|
156
|
-
subject.class.protected_method_defined?(:query_pattern).
|
223
|
+
expect(subject.class.protected_method_defined?(:query_pattern)).to be_true
|
157
224
|
end
|
158
225
|
|
159
226
|
context "when called" do
|
160
227
|
it "requires an argument" do
|
161
|
-
|
228
|
+
expect { subject.send(:query_pattern) }.to raise_error(ArgumentError)
|
162
229
|
end
|
163
230
|
|
164
231
|
it "yields to the given block" do
|
165
|
-
|
166
|
-
subject.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
|
167
|
-
called = true
|
168
|
-
break
|
169
|
-
end
|
170
|
-
called.should be_true
|
232
|
+
expect {|b| subject.send(:query_pattern, RDF::Query::Pattern.new, &b)}.to yield_control.exactly(@queryable.count).times
|
171
233
|
end
|
172
234
|
|
173
235
|
it "yields statements" do
|
174
236
|
subject.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
|
175
|
-
statement.
|
237
|
+
expect(statement).to be_a_statement
|
176
238
|
end
|
177
239
|
end
|
178
240
|
|
@@ -190,7 +252,7 @@ module RDF_Queryable
|
|
190
252
|
it "returns #{result.inspect} given #{pattern.inspect}" do
|
191
253
|
solutions = []
|
192
254
|
subject.send(:query_pattern, pattern) {|s| solutions << s}
|
193
|
-
solutions.
|
255
|
+
expect(solutions).to eq result
|
194
256
|
end
|
195
257
|
end
|
196
258
|
end
|
@@ -200,7 +262,7 @@ module RDF_Queryable
|
|
200
262
|
pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => nil)
|
201
263
|
solutions = []
|
202
264
|
subject.send(:query_pattern, pattern) {|s| solutions << s}
|
203
|
-
solutions.size.
|
265
|
+
expect(solutions.size).to eq @statements.size
|
204
266
|
end
|
205
267
|
|
206
268
|
it "returns statements from unnamed contexts with false context" do
|
@@ -208,7 +270,7 @@ module RDF_Queryable
|
|
208
270
|
solutions = []
|
209
271
|
subject.send(:query_pattern, pattern) {|s| solutions << s}
|
210
272
|
context_statements = subject.statements.reject {|st| st.has_context?}.length
|
211
|
-
solutions.size.
|
273
|
+
expect(solutions.size).to eq context_statements
|
212
274
|
end
|
213
275
|
|
214
276
|
it "returns statements from named contexts with variable context" do
|
@@ -217,7 +279,7 @@ module RDF_Queryable
|
|
217
279
|
solutions = []
|
218
280
|
subject.send(:query_pattern, pattern) {|s| solutions << s}
|
219
281
|
context_statements = subject.statements.select {|st| st.has_context?}.length
|
220
|
-
solutions.size.
|
282
|
+
expect(solutions.size).to eq context_statements
|
221
283
|
end
|
222
284
|
end
|
223
285
|
|
@@ -226,7 +288,7 @@ module RDF_Queryable
|
|
226
288
|
pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => RDF::URI("http://ar.to/#self"))
|
227
289
|
solutions = []
|
228
290
|
subject.send(:query_pattern, pattern) {|s| solutions << s}
|
229
|
-
solutions.size.
|
291
|
+
expect(solutions.size).to eq File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
|
230
292
|
end
|
231
293
|
end
|
232
294
|
end
|
@@ -239,29 +301,29 @@ module RDF_Queryable
|
|
239
301
|
let(:failing_pattern) {[RDF::Node.new] * 3}
|
240
302
|
|
241
303
|
it "should respond to #first" do
|
242
|
-
subject.
|
304
|
+
expect(subject).to respond_to(:first)
|
243
305
|
end
|
244
306
|
|
245
307
|
it "returns enumerator without a pattern" do
|
246
|
-
|
247
|
-
subject.first.
|
308
|
+
expect { subject.first }.not_to raise_error
|
309
|
+
expect(subject.first).to eq subject.each.first # uses an Enumerator
|
248
310
|
end
|
249
311
|
|
250
312
|
it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
251
313
|
matching_patterns = [[nil, nil, nil], subject.each.first]
|
252
314
|
matching_patterns.each do |matching_pattern|
|
253
|
-
subject.first(matching_pattern).
|
315
|
+
expect(subject.first(matching_pattern)).to eq subject.query(matching_pattern).each.first
|
254
316
|
end
|
255
317
|
end
|
256
318
|
|
257
319
|
it "returns nil when the pattern fails to match anything" do
|
258
|
-
subject.first(failing_pattern).
|
320
|
+
expect(subject.first(failing_pattern)).to be_nil
|
259
321
|
end
|
260
322
|
|
261
323
|
it "returns nil when self is empty" do
|
262
324
|
queryable = [].extend(RDF::Queryable)
|
263
|
-
queryable.first.
|
264
|
-
queryable.first(failing_pattern).
|
325
|
+
expect(queryable.first).to be_nil
|
326
|
+
expect(queryable.first(failing_pattern)).to be_nil
|
265
327
|
end
|
266
328
|
end
|
267
329
|
|
@@ -271,29 +333,29 @@ module RDF_Queryable
|
|
271
333
|
let(:failing_pattern) {[RDF::Node.new, nil, nil]}
|
272
334
|
|
273
335
|
it "should respond to #first_subject" do
|
274
|
-
subject.
|
336
|
+
expect(subject).to respond_to(:first_subject)
|
275
337
|
end
|
276
338
|
|
277
339
|
it "returns enumerator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
278
|
-
|
279
|
-
subject.first_subject.
|
340
|
+
expect { subject.first_subject }.not_to raise_error
|
341
|
+
expect(subject.first_subject).to eq subject.first.subject
|
280
342
|
end
|
281
343
|
|
282
344
|
it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
283
345
|
matching_patterns = [[nil, nil, nil], [subject.first.subject, nil, nil]]
|
284
346
|
matching_patterns.each do |matching_pattern|
|
285
|
-
subject.first_subject(matching_pattern).
|
347
|
+
expect(subject.first_subject(matching_pattern)).to eq subject.query(matching_pattern).first.subject
|
286
348
|
end
|
287
349
|
end
|
288
350
|
|
289
351
|
it "returns nil when the pattern fails to match anything" do
|
290
|
-
subject.first_subject(failing_pattern).
|
352
|
+
expect(subject.first_subject(failing_pattern)).to be_nil
|
291
353
|
end
|
292
354
|
|
293
355
|
it "returns nil when self is empty" do
|
294
356
|
queryable = [].extend(RDF::Queryable)
|
295
|
-
queryable.first_subject.
|
296
|
-
queryable.first_subject(failing_pattern).
|
357
|
+
expect(queryable.first_subject).to be_nil
|
358
|
+
expect(queryable.first_subject(failing_pattern)).to be_nil
|
297
359
|
end
|
298
360
|
end
|
299
361
|
|
@@ -306,25 +368,25 @@ module RDF_Queryable
|
|
306
368
|
it {should respond_to(:first_predicate)}
|
307
369
|
|
308
370
|
it "returns enumerator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
309
|
-
|
310
|
-
subject.first_predicate.
|
371
|
+
expect { subject.first_predicate }.not_to raise_error
|
372
|
+
expect(subject.first_predicate).to eq subject.first.predicate
|
311
373
|
end
|
312
374
|
|
313
375
|
it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
314
376
|
matching_patterns = [[nil, nil, nil], [nil, subject.first.predicate, nil]]
|
315
377
|
matching_patterns.each do |matching_pattern|
|
316
|
-
subject.first_predicate(matching_pattern).
|
378
|
+
expect(subject.first_predicate(matching_pattern)).to eq subject.query(matching_pattern).first.predicate
|
317
379
|
end
|
318
380
|
end
|
319
381
|
|
320
382
|
it "returns nil when the pattern fails to match anything" do
|
321
|
-
subject.first_predicate(failing_pattern).
|
383
|
+
expect(subject.first_predicate(failing_pattern)).to be_nil
|
322
384
|
end
|
323
385
|
|
324
386
|
it "returns nil when self is empty" do
|
325
387
|
queryable = [].extend(RDF::Queryable)
|
326
|
-
queryable.first_predicate.
|
327
|
-
queryable.first_predicate(failing_pattern).
|
388
|
+
expect(queryable.first_predicate).to be_nil
|
389
|
+
expect(queryable.first_predicate(failing_pattern)).to be_nil
|
328
390
|
end
|
329
391
|
end
|
330
392
|
|
@@ -336,25 +398,25 @@ module RDF_Queryable
|
|
336
398
|
it {should respond_to(:first_object)}
|
337
399
|
|
338
400
|
it "returns enurator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
339
|
-
|
340
|
-
subject.first_object.
|
401
|
+
expect { subject.first_object }.not_to raise_error
|
402
|
+
expect(subject.first_object).to eq subject.first.object
|
341
403
|
end
|
342
404
|
|
343
405
|
it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
|
344
406
|
matching_patterns = [[nil, nil, nil], [nil, nil, subject.first.object]]
|
345
407
|
matching_patterns.each do |matching_pattern|
|
346
|
-
subject.first_object(matching_pattern).
|
408
|
+
expect(subject.first_object(matching_pattern)).to eq subject.query(matching_pattern).first.object
|
347
409
|
end
|
348
410
|
end
|
349
411
|
|
350
412
|
it "returns nil when the pattern fails to match anything" do
|
351
|
-
subject.first_object(failing_pattern).
|
413
|
+
expect(subject.first_object(failing_pattern)).to be_nil
|
352
414
|
end
|
353
415
|
|
354
416
|
it "returns nil when self is empty" do
|
355
417
|
queryable = [].extend(RDF::Queryable)
|
356
|
-
queryable.first_object.
|
357
|
-
queryable.first_object(failing_pattern).
|
418
|
+
expect(queryable.first_object).to be_nil
|
419
|
+
expect(queryable.first_object(failing_pattern)).to be_nil
|
358
420
|
end
|
359
421
|
end
|
360
422
|
|
@@ -374,25 +436,25 @@ module RDF_Queryable
|
|
374
436
|
it {should respond_to(:first_literal)}
|
375
437
|
|
376
438
|
it "returns a literal without a pattern" do
|
377
|
-
|
378
|
-
subject.first_literal.
|
439
|
+
expect { subject.first_literal }.not_to raise_error
|
440
|
+
expect(subject.first_literal).to eq literal
|
379
441
|
end
|
380
442
|
|
381
443
|
it "returns the correct value when the pattern matches" do
|
382
444
|
matching_patterns = [[nil, nil, nil], [resource, nil, nil], [nil, RDF::DC.creator, nil], [nil, nil, literal]]
|
383
445
|
matching_patterns.each do |matching_pattern|
|
384
|
-
subject.first_literal(matching_pattern).
|
446
|
+
expect(subject.first_literal(matching_pattern)).to eq literal
|
385
447
|
end
|
386
448
|
end
|
387
449
|
|
388
450
|
it "returns nil when the pattern fails to match anything" do
|
389
|
-
subject.first_literal(failing_pattern).
|
451
|
+
expect(subject.first_literal(failing_pattern)).to be_nil
|
390
452
|
end
|
391
453
|
|
392
454
|
it "returns nil when self is empty" do
|
393
455
|
queryable = [].extend(RDF::Queryable)
|
394
|
-
queryable.first_literal.
|
395
|
-
queryable.first_literal(failing_pattern).
|
456
|
+
expect(queryable.first_literal).to be_nil
|
457
|
+
expect(queryable.first_literal(failing_pattern)).to be_nil
|
396
458
|
end
|
397
459
|
end
|
398
460
|
|
@@ -404,8 +466,8 @@ module RDF_Queryable
|
|
404
466
|
it {should respond_to(:first_value)}
|
405
467
|
|
406
468
|
it "returns first literal without a pattern" do
|
407
|
-
|
408
|
-
subject.first_value.
|
469
|
+
expect { subject.first_value }.not_to raise_error
|
470
|
+
expect(subject.first_value).to eq subject.first_literal.value
|
409
471
|
end
|
410
472
|
|
411
473
|
it "returns the correct value when the pattern matches" do
|
@@ -415,20 +477,20 @@ module RDF_Queryable
|
|
415
477
|
matching_pattern = [statement.subject, statement.predicate, nil]
|
416
478
|
unless matching_patterns.include?(matching_pattern)
|
417
479
|
matching_patterns << matching_pattern
|
418
|
-
subject.first_value(matching_pattern).
|
480
|
+
expect(subject.first_value(matching_pattern)).to eq subject.first_literal(matching_pattern).value
|
419
481
|
end
|
420
482
|
end
|
421
483
|
end
|
422
484
|
end
|
423
485
|
|
424
486
|
it "returns nil when the pattern fails to match anything" do
|
425
|
-
subject.first_value(failing_pattern).
|
487
|
+
expect(subject.first_value(failing_pattern)).to be_nil
|
426
488
|
end
|
427
489
|
|
428
490
|
it "returns nil when self is empty" do
|
429
491
|
queryable = [].extend(RDF::Queryable)
|
430
|
-
queryable.first_value.
|
431
|
-
queryable.first_value(failing_pattern).
|
492
|
+
expect(queryable.first_value).to be_nil
|
493
|
+
expect(queryable.first_value(failing_pattern)).to be_nil
|
432
494
|
end
|
433
495
|
end
|
434
496
|
end
|