rdf-spec 0.3.8 → 0.3.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.
- data/VERSION +1 -1
- data/lib/rdf/spec.rb +2 -2
- data/lib/rdf/spec/countable.rb +3 -2
- data/lib/rdf/spec/durable.rb +20 -18
- data/lib/rdf/spec/enumerable.rb +337 -314
- data/lib/rdf/spec/format.rb +31 -28
- data/lib/rdf/spec/indexable.rb +19 -16
- data/lib/rdf/spec/inferable.rb +5 -2
- data/lib/rdf/spec/matchers.rb +6 -6
- data/lib/rdf/spec/mutable.rb +110 -107
- data/lib/rdf/spec/queryable.rb +331 -330
- data/lib/rdf/spec/readable.rb +10 -7
- data/lib/rdf/spec/reader.rb +119 -116
- data/lib/rdf/spec/repository.rb +39 -36
- data/lib/rdf/spec/transaction.rb +44 -40
- data/lib/rdf/spec/writable.rb +86 -57
- data/lib/rdf/spec/writer.rb +126 -123
- metadata +4 -6
- data/lib/rdf/spec/query.rb +0 -7
- data/lib/rdf/spec/vocab.rb +0 -7
data/lib/rdf/spec/writable.rb
CHANGED
@@ -1,88 +1,117 @@
|
|
1
1
|
require 'rdf/spec'
|
2
2
|
|
3
|
-
|
3
|
+
module RDF_Writable
|
4
|
+
extend RSpec::SharedContext
|
4
5
|
include RDF::Spec::Matchers
|
5
6
|
|
6
7
|
before :each do
|
7
8
|
raise '+@writable+ must be defined in a before(:each) block' unless instance_variable_get('@writable')
|
8
9
|
|
9
|
-
@filename = File.expand_path(
|
10
|
+
@filename = File.expand_path("../../../../etc/doap.nt", __FILE__)
|
11
|
+
@statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
|
10
12
|
|
11
13
|
@supports_context = @writable.respond_to?(:supports?) && @writable.supports?(:context)
|
12
14
|
end
|
13
|
-
|
14
|
-
it "responds to #writable?" do
|
15
|
-
@writable.respond_to?(:readable?)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "implements #writable?" do
|
19
|
-
!!@writable.writable?.should == @writable.writable?
|
20
|
-
end
|
21
15
|
|
22
|
-
describe
|
23
|
-
it "
|
24
|
-
|
25
|
-
it "inserts an enumerable"
|
26
|
-
it "inserts data responding to #to_rdf"
|
27
|
-
it "inserts a statement"
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when inserting statements" do
|
31
|
-
before :each do
|
32
|
-
@statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
|
16
|
+
describe RDF::Writable do
|
17
|
+
it "responds to #writable?" do
|
18
|
+
@writable.respond_to?(:readable?)
|
33
19
|
end
|
34
|
-
|
35
|
-
it "
|
36
|
-
|
20
|
+
|
21
|
+
it "implements #writable?" do
|
22
|
+
!!@writable.writable?.should == @writable.writable?
|
37
23
|
end
|
38
24
|
|
39
|
-
|
40
|
-
|
41
|
-
|
25
|
+
describe "#<<" do
|
26
|
+
it "inserts a reader" do
|
27
|
+
reader = RDF::NTriples::Reader.new(File.open(@filename)).to_a
|
28
|
+
@writable << reader
|
29
|
+
@writable.should have_statement(@statements.first)
|
30
|
+
@writable.count.should == @statements.size
|
42
31
|
end
|
43
|
-
end
|
44
32
|
|
45
|
-
|
46
|
-
|
47
|
-
@writable
|
33
|
+
it "inserts a graph" do
|
34
|
+
graph = RDF::Graph.new << @statements
|
35
|
+
@writable << graph
|
48
36
|
@writable.should have_statement(@statements.first)
|
37
|
+
@writable.count.should == @statements.size
|
49
38
|
end
|
50
|
-
end
|
51
39
|
|
52
|
-
|
53
|
-
|
54
|
-
@writable
|
40
|
+
it "inserts an enumerable" do
|
41
|
+
enumerable = @statements.dup.extend(RDF::Enumerable)
|
42
|
+
@writable << enumerable
|
43
|
+
@writable.should have_statement(@statements.first)
|
44
|
+
@writable.count.should == @statements.size
|
55
45
|
end
|
56
|
-
end
|
57
46
|
|
58
|
-
|
59
|
-
|
60
|
-
|
47
|
+
it "inserts data responding to #to_rdf" do
|
48
|
+
mock = double('mock')
|
49
|
+
mock.stub(:to_rdf).and_return(@statements)
|
50
|
+
@writable << mock
|
51
|
+
@writable.should have_statement(@statements.first)
|
61
52
|
@writable.count.should == @statements.size
|
62
53
|
end
|
63
|
-
end
|
64
54
|
|
65
|
-
|
66
|
-
|
67
|
-
@writable.
|
68
|
-
@writable.insert(@statements.first)
|
55
|
+
it "inserts a statement" do
|
56
|
+
@writable << @statements.first
|
57
|
+
@writable.should have_statement(@statements.first)
|
69
58
|
@writable.count.should == 1
|
70
59
|
end
|
71
60
|
end
|
72
61
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
@writable.
|
62
|
+
context "when inserting statements" do
|
63
|
+
it "should support #insert" do
|
64
|
+
@writable.should respond_to(:insert)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not raise errors" do
|
68
|
+
if @writable.writable?
|
69
|
+
lambda { @writable.insert(@statements.first) }.should_not raise_error
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should support inserting one statement at a time" do
|
74
|
+
if @writable.writable?
|
75
|
+
@writable.insert(@statements.first)
|
76
|
+
@writable.should have_statement(@statements.first)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should support inserting multiple statements at a time" do
|
81
|
+
if @writable.writable?
|
82
|
+
@writable.insert(*@statements)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should insert statements successfully" do
|
87
|
+
if @writable.writable?
|
88
|
+
@writable.insert(*@statements)
|
89
|
+
@writable.count.should == @statements.size
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should not insert a statement twice" do
|
94
|
+
if @writable.writable?
|
95
|
+
@writable.insert(@statements.first)
|
96
|
+
@writable.insert(@statements.first)
|
97
|
+
@writable.count.should == 1
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should treat statements with a different context as distinct" do
|
102
|
+
if @writable.writable?
|
103
|
+
s1 = @statements.first.dup
|
104
|
+
s1.context = nil
|
105
|
+
s2 = @statements.first.dup
|
106
|
+
s2.context = RDF::URI.new("urn:context:1")
|
107
|
+
s3 = @statements.first.dup
|
108
|
+
s3.context = RDF::URI.new("urn:context:2")
|
109
|
+
@writable.insert(s1)
|
110
|
+
@writable.insert(s2)
|
111
|
+
@writable.insert(s3)
|
112
|
+
# If contexts are not suported, all three are redundant
|
113
|
+
@writable.count.should == (@supports_context ? 3 : 1)
|
114
|
+
end
|
86
115
|
end
|
87
116
|
end
|
88
117
|
end
|
data/lib/rdf/spec/writer.rb
CHANGED
@@ -2,7 +2,8 @@ require 'rdf/spec'
|
|
2
2
|
require 'fileutils'
|
3
3
|
require 'tmpdir'
|
4
4
|
|
5
|
-
|
5
|
+
module RDF_Writer
|
6
|
+
extend RSpec::SharedContext
|
6
7
|
include RDF::Spec::Matchers
|
7
8
|
|
8
9
|
before(:each) do
|
@@ -10,165 +11,167 @@ share_as :RDF_Writer do
|
|
10
11
|
@writer_class = @writer.class
|
11
12
|
end
|
12
13
|
|
13
|
-
describe
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
describe RDF::Writer do
|
15
|
+
describe ".each" do
|
16
|
+
it "yields each writer" do
|
17
|
+
@writer_class.each do |r|
|
18
|
+
r.should_not be_nil
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
19
|
-
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
describe ".buffer" do
|
24
|
+
it "calls .new with buffer and other arguments" do
|
25
|
+
@writer_class.should_receive(:new)
|
26
|
+
@writer_class.buffer do |r|
|
27
|
+
r.should be_a(@writer_class)
|
28
|
+
end
|
26
29
|
end
|
27
30
|
end
|
28
|
-
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
describe ".open" do
|
33
|
+
before(:each) do
|
34
|
+
RDF::Util::File.stub!(:open_file).and_yield(StringIO.new("foo"))
|
35
|
+
@dir = Dir.mktmpdir
|
36
|
+
@basename = File.join(@dir, "foo")
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
it "yields writer given file_name" do
|
42
|
-
@writer_class.format.each do |f|
|
43
|
-
f.file_extensions.each_pair do |sym, content_type|
|
44
|
-
writer_mock = mock("writer")
|
45
|
-
writer_mock.should_receive(:got_here)
|
46
|
-
@writer_class.should_receive(:for).with(:file_name => "#{@basename}.#{sym}").and_return(@writer_class)
|
47
|
-
@writer_class.open("#{@basename}.#{sym}") do |r|
|
48
|
-
r.should be_a(RDF::Writer)
|
49
|
-
writer_mock.got_here
|
50
|
-
end
|
51
|
-
end
|
39
|
+
after(:each) do
|
40
|
+
FileUtils.rm_rf(@dir)
|
52
41
|
end
|
53
|
-
end
|
54
42
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
43
|
+
it "yields writer given file_name" do
|
44
|
+
@writer_class.format.each do |f|
|
45
|
+
f.file_extensions.each_pair do |sym, content_type|
|
46
|
+
writer_mock = mock("writer")
|
47
|
+
writer_mock.should_receive(:got_here)
|
48
|
+
@writer_class.should_receive(:for).with(:file_name => "#{@basename}.#{sym}").and_return(@writer_class)
|
49
|
+
@writer_class.open("#{@basename}.#{sym}") do |r|
|
50
|
+
r.should be_a(RDF::Writer)
|
51
|
+
writer_mock.got_here
|
52
|
+
end
|
53
|
+
end
|
64
54
|
end
|
65
55
|
end
|
66
|
-
end
|
67
56
|
|
68
|
-
|
69
|
-
|
70
|
-
|
57
|
+
it "yields writer given symbol" do
|
58
|
+
@writer_class.format.each do |f|
|
59
|
+
sym = f.to_sym # Like RDF::NTriples::Format => :ntriples
|
71
60
|
writer_mock = mock("writer")
|
72
61
|
writer_mock.should_receive(:got_here)
|
73
|
-
@writer_class.should_receive(:for).with(
|
74
|
-
@writer_class.open("#{@basename}.#{sym}", :
|
62
|
+
@writer_class.should_receive(:for).with(sym).and_return(@writer_class)
|
63
|
+
@writer_class.open("#{@basename}.#{sym}", :format => sym) do |r|
|
75
64
|
r.should be_a(RDF::Writer)
|
76
65
|
writer_mock.got_here
|
77
66
|
end
|
78
67
|
end
|
79
68
|
end
|
80
|
-
end
|
81
69
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
70
|
+
it "yields writer given {:file_name => file_name}" do
|
71
|
+
@writer_class.format.each do |f|
|
72
|
+
f.file_extensions.each_pair do |sym, content_type|
|
73
|
+
writer_mock = mock("writer")
|
74
|
+
writer_mock.should_receive(:got_here)
|
75
|
+
@writer_class.should_receive(:for).with(:file_name => "#{@basename}.#{sym}").and_return(@writer_class)
|
76
|
+
@writer_class.open("#{@basename}.#{sym}", :file_name => "#{@basename}.#{sym}") do |r|
|
77
|
+
r.should be_a(RDF::Writer)
|
78
|
+
writer_mock.got_here
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it "yields writer given {:content_type => 'a/b'}" do
|
85
|
+
@writer_class.format.each do |f|
|
86
|
+
f.content_types.each_pair do |content_type, formats|
|
87
|
+
writer_mock = mock("writer")
|
88
|
+
writer_mock.should_receive(:got_here)
|
89
|
+
@writer_class.should_receive(:for).with(:content_type => content_type, :file_name => @basename).and_return(@writer_class)
|
90
|
+
@writer_class.open(@basename, :content_type => content_type) do |r|
|
91
|
+
r.should be_a(RDF::Writer)
|
92
|
+
writer_mock.got_here
|
93
|
+
end
|
91
94
|
end
|
92
95
|
end
|
93
96
|
end
|
94
97
|
end
|
95
|
-
end
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
99
|
+
describe ".format" do
|
100
|
+
it "returns itself even if given explicit format" do
|
101
|
+
other_format = @writer_class == RDF::NTriples::Writer ? :nquads : :ntriples
|
102
|
+
@writer_class.for(other_format).should == @writer_class
|
103
|
+
end
|
101
104
|
end
|
102
|
-
end
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
describe ".new" do
|
107
|
+
it "sets @output to $stdout by default" do
|
108
|
+
writer_mock = mock("writer")
|
109
|
+
writer_mock.should_receive(:got_here)
|
110
|
+
save, $stdout = $stdout, StringIO.new
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
|
112
|
+
@writer_class.new do |r|
|
113
|
+
writer_mock.got_here
|
114
|
+
r.instance_variable_get(:@output).should == $stdout
|
115
|
+
end
|
116
|
+
$stdout = save
|
113
117
|
end
|
114
|
-
$stdout = save
|
115
|
-
end
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
119
|
+
it "sets @output to file given something other than a string" do
|
120
|
+
writer_mock = mock("writer")
|
121
|
+
writer_mock.should_receive(:got_here)
|
122
|
+
file = StringIO.new
|
123
|
+
file.should_receive(:write).any_number_of_times
|
124
|
+
@writer_class.new(file) do |r|
|
125
|
+
writer_mock.got_here
|
126
|
+
r.instance_variable_get(:@output).should == file
|
127
|
+
end
|
125
128
|
end
|
126
|
-
end
|
127
129
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
130
|
+
it "sets prefixes given :prefixes => {}" do
|
131
|
+
writer_mock = mock("writer")
|
132
|
+
writer_mock.should_receive(:got_here)
|
133
|
+
@writer_class.new(StringIO.new, :prefixes => {:a => "b"}) do |r|
|
134
|
+
writer_mock.got_here
|
135
|
+
r.prefixes.should == {:a => "b"}
|
136
|
+
end
|
134
137
|
end
|
135
|
-
end
|
136
138
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
139
|
+
#it "calls #write_prologue" do
|
140
|
+
# writer_mock = mock("writer")
|
141
|
+
# writer_mock.should_receive(:got_here)
|
142
|
+
# @writer_class.any_instance.should_receive(:write_prologue)
|
143
|
+
# @writer_class.new(StringIO.new) do |r|
|
144
|
+
# writer_mock.got_here
|
145
|
+
# end
|
146
|
+
#end
|
147
|
+
#
|
148
|
+
#it "calls #write_epilogue" do
|
149
|
+
# writer_mock = mock("writer")
|
150
|
+
# writer_mock.should_receive(:got_here)
|
151
|
+
# @writer_class.any_instance.should_receive(:write_epilogue)
|
152
|
+
# @writer_class.new(StringIO.new) do |r|
|
153
|
+
# writer_mock.got_here
|
154
|
+
# end
|
155
|
+
#end
|
156
|
+
end
|
155
157
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
158
|
+
describe "#prefixes=" do
|
159
|
+
it "sets prefixes from hash" do
|
160
|
+
@writer.prefixes = {:a => "b"}
|
161
|
+
@writer.prefixes.should == {:a => "b"}
|
162
|
+
end
|
160
163
|
end
|
161
|
-
end
|
162
164
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
165
|
+
describe "#prefix" do
|
166
|
+
{
|
167
|
+
nil => "nil",
|
168
|
+
:a => "b",
|
169
|
+
"foo" => "bar",
|
170
|
+
}.each_pair do |pfx, uri|
|
171
|
+
it "sets prefix(#{pfx}) to #{uri}" do
|
172
|
+
@writer.prefix(pfx, uri).should == uri
|
173
|
+
@writer.prefix(pfx).should == uri
|
174
|
+
end
|
172
175
|
end
|
173
176
|
end
|
174
177
|
end
|