rdf-spec 1.1.5 → 1.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CREDITS +1 -0
- data/README +1 -0
- data/VERSION +1 -1
- data/lib/rdf/spec/countable.rb +34 -11
- data/lib/rdf/spec/durable.rb +38 -20
- data/lib/rdf/spec/enumerable.rb +365 -345
- data/lib/rdf/spec/format.rb +58 -37
- data/lib/rdf/spec/http_adapter.rb +293 -0
- data/lib/rdf/spec/indexable.rb +36 -14
- data/lib/rdf/spec/inferable.rb +15 -2
- data/lib/rdf/spec/literal.rb +143 -0
- data/lib/rdf/spec/mutable.rb +36 -19
- data/lib/rdf/spec/queryable.rb +68 -33
- data/lib/rdf/spec/readable.rb +29 -6
- data/lib/rdf/spec/reader.rb +183 -157
- data/lib/rdf/spec/repository.rb +59 -38
- data/lib/rdf/spec/transaction.rb +92 -90
- data/lib/rdf/spec/writable.rb +109 -97
- data/lib/rdf/spec/writer.rb +153 -131
- metadata +22 -6
data/lib/rdf/spec/transaction.rb
CHANGED
@@ -2,109 +2,111 @@ require 'rdf/spec'
|
|
2
2
|
|
3
3
|
# Pass in an instance of RDF::Transaction as follows:
|
4
4
|
#
|
5
|
-
# it_behaves_like "
|
6
|
-
shared_examples "
|
5
|
+
# it_behaves_like "RDF::Transaction", RDF::Transaction
|
6
|
+
shared_examples "an RDF::Transaction" do |klass|
|
7
7
|
include RDF::Spec::Matchers
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
expect(this.inserts).to eq g
|
35
|
-
end
|
36
|
-
|
37
|
-
it "accepts deletes" do
|
38
|
-
g = double("deletes")
|
39
|
-
this = subject.new(:delete => g)
|
40
|
-
expect(this.deletes).to eq g
|
41
|
-
end
|
9
|
+
subject {klass.new(:context => RDF::URI("name"), :insert => RDF::Graph.new, :delete => RDF::Graph.new)}
|
10
|
+
|
11
|
+
describe "#initialize" do
|
12
|
+
subject {klass}
|
13
|
+
it "accepts a graph" do
|
14
|
+
g = double("graph")
|
15
|
+
this = subject.new(:graph => g)
|
16
|
+
expect(this.graph).to eq g
|
17
|
+
end
|
18
|
+
|
19
|
+
it "accepts a context" do
|
20
|
+
c = double("context")
|
21
|
+
this = subject.new(:graph => c)
|
22
|
+
expect(this.graph).to eq c
|
23
|
+
expect(this.context).to eq c
|
24
|
+
|
25
|
+
this = subject.new(:context => c)
|
26
|
+
expect(this.graph).to eq c
|
27
|
+
expect(this.context).to eq c
|
28
|
+
end
|
29
|
+
|
30
|
+
it "accepts inserts" do
|
31
|
+
g = double("inserts")
|
32
|
+
this = subject.new(:insert => g)
|
33
|
+
expect(this.inserts).to eq g
|
42
34
|
end
|
43
35
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
36
|
+
it "accepts deletes" do
|
37
|
+
g = double("deletes")
|
38
|
+
this = subject.new(:delete => g)
|
39
|
+
expect(this.deletes).to eq g
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
its(:deletes) {should be_a(RDF::Enumerable)}
|
44
|
+
its(:inserts) {should be_a(RDF::Enumerable)}
|
45
|
+
it {should be_mutable}
|
46
|
+
it {should_not be_readable}
|
47
|
+
|
48
|
+
it "does not respond to #load" do
|
49
|
+
expect {subject.load("http://example/")}.to raise_error(NoMethodError)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "does not respond to #update" do
|
53
|
+
expect {subject.update(RDF::Statement.new)}.to raise_error(NoMethodError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "does not respond to #clear" do
|
57
|
+
expect {subject.clear}.to raise_error(NoMethodError)
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#execute" do
|
61
|
+
let(:s) {RDF::Statement.new(RDF::URI("s"), RDF::URI("p"), RDF::URI("o"))}
|
62
|
+
let(:r) {double("repository")}
|
48
63
|
|
49
|
-
it "
|
50
|
-
expect
|
64
|
+
it "deletes statements" do
|
65
|
+
expect(r).to receive(:delete).with(s)
|
66
|
+
expect(r).not_to receive(:insert)
|
67
|
+
subject.delete(s)
|
68
|
+
subject.execute(r)
|
51
69
|
end
|
52
70
|
|
53
|
-
it "
|
54
|
-
expect
|
71
|
+
it "inserts statements" do
|
72
|
+
expect(r).not_to receive(:delete)
|
73
|
+
expect(r).to receive(:insert).with(s)
|
74
|
+
subject.insert(s)
|
75
|
+
subject.execute(r)
|
55
76
|
end
|
56
77
|
|
57
|
-
it "
|
58
|
-
expect
|
78
|
+
it "calls before_execute" do
|
79
|
+
expect(subject).to receive(:before_execute).with(r, {})
|
80
|
+
subject.execute(r)
|
59
81
|
end
|
60
82
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
it "deletes statements" do
|
66
|
-
expect(r).to receive(:delete).with(s)
|
67
|
-
expect(r).not_to receive(:insert)
|
68
|
-
subject.delete(s)
|
69
|
-
subject.execute(r)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "inserts statements" do
|
73
|
-
expect(r).not_to receive(:delete)
|
74
|
-
expect(r).to receive(:insert).with(s)
|
75
|
-
subject.insert(s)
|
76
|
-
subject.execute(r)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "calls before_execute" do
|
80
|
-
expect(subject).to receive(:before_execute).with(r, {})
|
81
|
-
subject.execute(r)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "calls after_execute" do
|
85
|
-
expect(subject).to receive(:after_execute).with(r, {})
|
86
|
-
subject.execute(r)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "returns self" do
|
90
|
-
expect(subject.execute(r)).to eq subject
|
91
|
-
end
|
83
|
+
it "calls after_execute" do
|
84
|
+
expect(subject).to receive(:after_execute).with(r, {})
|
85
|
+
subject.execute(r)
|
92
86
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
it "adds statement to #deletes" do
|
97
|
-
subject.delete(s)
|
98
|
-
expect(subject.deletes.to_a).to eq [s]
|
99
|
-
end
|
87
|
+
|
88
|
+
it "returns self" do
|
89
|
+
expect(subject.execute(r)).to eq subject
|
100
90
|
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#delete_statement" do
|
94
|
+
let(:s) {RDF::Statement.new(RDF::URI("s"), RDF::URI("p"), RDF::URI("o"))}
|
95
|
+
it "adds statement to #deletes" do
|
96
|
+
subject.delete(s)
|
97
|
+
expect(subject.deletes.to_a).to eq [s]
|
108
98
|
end
|
109
99
|
end
|
100
|
+
|
101
|
+
describe "#insert_statement" do
|
102
|
+
let(:s) {RDF::Statement.new(RDF::URI("s"), RDF::URI("p"), RDF::URI("o"))}
|
103
|
+
it "adds statement to #inserts" do
|
104
|
+
subject.insert(s)
|
105
|
+
expect(subject.inserts.to_a).to eq [s]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
shared_examples "RDF_Transaction" do |klass|
|
111
|
+
it_behaves_like 'an RDF::Transaction', klass
|
110
112
|
end
|
data/lib/rdf/spec/writable.rb
CHANGED
@@ -1,124 +1,136 @@
|
|
1
1
|
require 'rdf/spec'
|
2
2
|
|
3
|
-
|
4
|
-
extend RSpec::SharedContext
|
3
|
+
RSpec.shared_examples 'an RDF::Writable' do
|
5
4
|
include RDF::Spec::Matchers
|
6
5
|
|
7
6
|
before :each do
|
8
|
-
raise '
|
7
|
+
raise 'writable must be defined in with let(:readable)' unless
|
8
|
+
defined? writable
|
9
9
|
|
10
10
|
@filename = RDF::Spec::TRIPLES_FILE
|
11
11
|
@statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
|
12
12
|
|
13
|
-
@supports_context =
|
13
|
+
@supports_context = writable.respond_to?(:supports?) && writable.supports?(:context)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
let(:count) {@statements.size}
|
20
|
-
|
21
|
-
it {should respond_to(:writable?)}
|
22
|
-
its(:writable?) {should == !!subject.writable?}
|
23
|
-
|
24
|
-
describe "#<<" do
|
25
|
-
it "inserts a reader" do
|
26
|
-
skip("writability") unless subject.writable?
|
27
|
-
reader = RDF::NTriples::Reader.new(File.open(@filename)).to_a
|
28
|
-
subject << reader
|
29
|
-
expect(subject).to have_statement(statement)
|
30
|
-
expect(subject.count).to eq count
|
31
|
-
end
|
16
|
+
subject { writable }
|
17
|
+
let(:statement) {@statements.detect {|s| s.to_a.all? {|r| r.uri?}}}
|
18
|
+
let(:count) {@statements.size}
|
32
19
|
|
33
|
-
|
34
|
-
|
35
|
-
graph = RDF::Graph.new << @statements
|
36
|
-
subject << graph
|
37
|
-
expect(subject).to have_statement(statement)
|
38
|
-
expect(subject.count).to eq count
|
39
|
-
end
|
20
|
+
it {should respond_to(:writable?)}
|
21
|
+
its(:writable?) {should == !!subject.writable?}
|
40
22
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
23
|
+
describe "#<<" do
|
24
|
+
it "inserts a reader" do
|
25
|
+
skip("writability") unless subject.writable?
|
26
|
+
reader = RDF::NTriples::Reader.new(File.open(@filename)).to_a
|
27
|
+
subject << reader
|
28
|
+
expect(subject).to have_statement(statement)
|
29
|
+
expect(subject.count).to eq count
|
30
|
+
end
|
48
31
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
32
|
+
it "inserts a graph" do
|
33
|
+
skip("writability") unless subject.writable?
|
34
|
+
graph = RDF::Graph.new << @statements
|
35
|
+
subject << graph
|
36
|
+
expect(subject).to have_statement(statement)
|
37
|
+
expect(subject.count).to eq count
|
38
|
+
end
|
57
39
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
40
|
+
it "inserts an enumerable" do
|
41
|
+
skip("writability") unless subject.writable?
|
42
|
+
enumerable = @statements.dup.extend(RDF::Enumerable)
|
43
|
+
subject << enumerable
|
44
|
+
expect(subject).to have_statement(statement)
|
45
|
+
expect(subject.count).to eq count
|
46
|
+
end
|
64
47
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
48
|
+
it "inserts data responding to #to_rdf" do
|
49
|
+
skip("writability") unless subject.writable?
|
50
|
+
mock = double('mock')
|
51
|
+
allow(mock).to receive(:to_rdf).and_return(@statements)
|
52
|
+
subject << mock
|
53
|
+
expect(subject).to have_statement(statement)
|
54
|
+
expect(subject.count).to eq count
|
72
55
|
end
|
73
56
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
57
|
+
it "inserts a statement" do
|
58
|
+
skip("writability") unless subject.writable?
|
59
|
+
subject << statement
|
60
|
+
expect(subject).to have_statement(statement)
|
61
|
+
expect(subject.count).to eq 1
|
62
|
+
end
|
63
|
+
end
|
79
64
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
65
|
+
context "when inserting statements" do
|
66
|
+
it "should support #insert" do
|
67
|
+
skip("writability") unless subject.writable?
|
68
|
+
expect(subject).to respond_to(:insert)
|
69
|
+
end
|
84
70
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
71
|
+
it "should not raise errors" do
|
72
|
+
skip("writability") unless subject.writable?
|
73
|
+
expect { subject.insert(statement) }.not_to raise_error
|
74
|
+
end
|
90
75
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
76
|
+
it "should support inserting one statement at a time" do
|
77
|
+
skip("writability") unless subject.writable?
|
78
|
+
subject.insert(statement)
|
79
|
+
expect(subject).to have_statement(statement)
|
80
|
+
end
|
95
81
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
82
|
+
it "should support inserting multiple statements at a time" do
|
83
|
+
skip("writability") unless subject.writable?
|
84
|
+
subject.insert(*@statements)
|
85
|
+
end
|
101
86
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
87
|
+
it "should insert statements successfully" do
|
88
|
+
skip("writability") unless subject.writable?
|
89
|
+
subject.insert(*@statements)
|
90
|
+
expect(subject.count).to eq count
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should not insert a statement twice" do
|
94
|
+
skip("writability") unless subject.writable?
|
95
|
+
subject.insert(statement)
|
96
|
+
subject.insert(statement)
|
97
|
+
expect(subject.count).to eq 1
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should treat statements with a different context as distinct" do
|
101
|
+
skip("writability") unless subject.writable?
|
102
|
+
s1 = statement.dup
|
103
|
+
s1.context = nil
|
104
|
+
s2 = statement.dup
|
105
|
+
s2.context = RDF::URI.new("urn:context:1")
|
106
|
+
s3 = statement.dup
|
107
|
+
s3.context = RDF::URI.new("urn:context:2")
|
108
|
+
subject.insert(s1)
|
109
|
+
subject.insert(s2)
|
110
|
+
subject.insert(s3)
|
111
|
+
# If contexts are not suported, all three are redundant
|
112
|
+
expect(subject.count).to eq (@supports_context ? 3 : 1)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# @deprecated use `it_behaves_like "an RDF::Writable"` instead
|
119
|
+
module RDF_Writable
|
120
|
+
extend RSpec::SharedContext
|
121
|
+
include RDF::Spec::Matchers
|
122
|
+
|
123
|
+
def self.included(mod)
|
124
|
+
warn "[DEPRECATION] `RDF_Writable` is deprecated. "\
|
125
|
+
"Please use `it_behaves_like 'an RDF::Writable'`"
|
126
|
+
end
|
127
|
+
|
128
|
+
describe 'examples for' do
|
129
|
+
include_examples 'an RDF::Writable' do
|
130
|
+
let(:writable) { @writable }
|
108
131
|
|
109
|
-
|
110
|
-
|
111
|
-
s1 = statement.dup
|
112
|
-
s1.context = nil
|
113
|
-
s2 = statement.dup
|
114
|
-
s2.context = RDF::URI.new("urn:context:1")
|
115
|
-
s3 = statement.dup
|
116
|
-
s3.context = RDF::URI.new("urn:context:2")
|
117
|
-
subject.insert(s1)
|
118
|
-
subject.insert(s2)
|
119
|
-
subject.insert(s3)
|
120
|
-
# If contexts are not suported, all three are redundant
|
121
|
-
expect(subject.count).to eq (@supports_context ? 3 : 1)
|
132
|
+
before do
|
133
|
+
raise '@writable must be defined' unless defined?(writable)
|
122
134
|
end
|
123
135
|
end
|
124
136
|
end
|
data/lib/rdf/spec/writer.rb
CHANGED
@@ -2,175 +2,197 @@ require 'rdf/spec'
|
|
2
2
|
require 'fileutils'
|
3
3
|
require 'tmpdir'
|
4
4
|
|
5
|
-
|
5
|
+
RSpec.shared_examples 'an RDF::Writer' do
|
6
6
|
extend RSpec::SharedContext
|
7
|
-
include RDF::Spec::Matchers
|
8
7
|
|
9
8
|
before(:each) do
|
10
|
-
raise '
|
11
|
-
|
9
|
+
raise 'writer must be defined with let(:writer)' unless
|
10
|
+
defined? writer
|
12
11
|
end
|
12
|
+
let(:writer_class) { writer.class }
|
13
13
|
|
14
|
-
describe
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
expect(r).not_to be_nil
|
19
|
-
end
|
14
|
+
describe ".each" do
|
15
|
+
it "yields each writer" do
|
16
|
+
writer_class.each do |r|
|
17
|
+
expect(r).not_to be_nil
|
20
18
|
end
|
21
19
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".buffer" do
|
23
|
+
it "calls .new with buffer and other arguments" do
|
24
|
+
expect(writer_class).to receive(:new)
|
25
|
+
writer_class.buffer do |r|
|
26
|
+
expect(r).to be_a(writer_class)
|
29
27
|
end
|
30
28
|
end
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
after(:each) do
|
40
|
-
FileUtils.rm_rf(@dir)
|
41
|
-
end
|
31
|
+
describe ".open" do
|
32
|
+
before(:each) do
|
33
|
+
allow(RDF::Util::File).to receive(:open_file).and_yield(StringIO.new("foo"))
|
34
|
+
@dir = Dir.mktmpdir
|
35
|
+
@basename = File.join(@dir, "foo")
|
36
|
+
end
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
writer_mock = double("writer")
|
47
|
-
expect(writer_mock).to receive(:got_here)
|
48
|
-
expect(@writer_class).to receive(:for).with(:file_name => "#{@basename}.#{sym}").and_return(@writer_class)
|
49
|
-
@writer_class.open("#{@basename}.#{sym}") do |r|
|
50
|
-
expect(r).to be_a(RDF::Writer)
|
51
|
-
writer_mock.got_here
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
38
|
+
after(:each) do
|
39
|
+
FileUtils.rm_rf(@dir)
|
40
|
+
end
|
56
41
|
|
57
|
-
|
58
|
-
|
59
|
-
|
42
|
+
it "yields writer given file_name" do
|
43
|
+
writer_class.format.each do |f|
|
44
|
+
f.file_extensions.each_pair do |sym, content_type|
|
60
45
|
writer_mock = double("writer")
|
61
46
|
expect(writer_mock).to receive(:got_here)
|
62
|
-
expect(
|
63
|
-
|
47
|
+
expect(writer_class).to receive(:for).with(:file_name => "#{@basename}.#{sym}").and_return(writer_class)
|
48
|
+
writer_class.open("#{@basename}.#{sym}") do |r|
|
64
49
|
expect(r).to be_a(RDF::Writer)
|
65
50
|
writer_mock.got_here
|
66
51
|
end
|
67
52
|
end
|
68
53
|
end
|
54
|
+
end
|
69
55
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
56
|
+
it "yields writer given symbol" do
|
57
|
+
writer_class.format.each do |f|
|
58
|
+
sym = f.to_sym # Like RDF::NTriples::Format => :ntriples
|
59
|
+
writer_mock = double("writer")
|
60
|
+
expect(writer_mock).to receive(:got_here)
|
61
|
+
expect(writer_class).to receive(:for).with(sym).and_return(writer_class)
|
62
|
+
writer_class.open("#{@basename}.#{sym}", :format => sym) do |r|
|
63
|
+
expect(r).to be_a(RDF::Writer)
|
64
|
+
writer_mock.got_here
|
81
65
|
end
|
82
66
|
end
|
67
|
+
end
|
83
68
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
69
|
+
it "yields writer given {:file_name => file_name}" do
|
70
|
+
writer_class.format.each do |f|
|
71
|
+
f.file_extensions.each_pair do |sym, content_type|
|
72
|
+
writer_mock = double("writer")
|
73
|
+
expect(writer_mock).to receive(:got_here)
|
74
|
+
expect(writer_class).to receive(:for).with(:file_name => "#{@basename}.#{sym}").and_return(writer_class)
|
75
|
+
writer_class.open("#{@basename}.#{sym}", :file_name => "#{@basename}.#{sym}") do |r|
|
76
|
+
expect(r).to be_a(RDF::Writer)
|
77
|
+
writer_mock.got_here
|
94
78
|
end
|
95
79
|
end
|
96
80
|
end
|
97
81
|
end
|
98
82
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
83
|
+
it "yields writer given {:content_type => 'a/b'}" do
|
84
|
+
writer_class.format.each do |f|
|
85
|
+
f.content_types.each_pair do |content_type, formats|
|
86
|
+
writer_mock = double("writer")
|
87
|
+
expect(writer_mock).to receive(:got_here)
|
88
|
+
expect(writer_class).to receive(:for).with(:content_type => content_type, :file_name => @basename).and_return(writer_class)
|
89
|
+
writer_class.open(@basename, :content_type => content_type) do |r|
|
90
|
+
expect(r).to be_a(RDF::Writer)
|
91
|
+
writer_mock.got_here
|
92
|
+
end
|
93
|
+
end
|
103
94
|
end
|
104
95
|
end
|
96
|
+
end
|
105
97
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
98
|
+
describe ".format" do
|
99
|
+
it "returns itself even if given explicit format" do
|
100
|
+
other_format = writer_class == RDF::NTriples::Writer ? :nquads : :ntriples
|
101
|
+
expect(writer_class.for(other_format)).to eq writer_class
|
102
|
+
end
|
103
|
+
end
|
111
104
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
105
|
+
describe ".new" do
|
106
|
+
it "sets @output to $stdout by default" do
|
107
|
+
writer_mock = double("writer")
|
108
|
+
expect(writer_mock).to receive(:got_here)
|
109
|
+
save, $stdout = $stdout, StringIO.new
|
110
|
+
|
111
|
+
writer_class.new do |r|
|
112
|
+
writer_mock.got_here
|
113
|
+
expect(r.instance_variable_get(:@output)).to eq $stdout
|
117
114
|
end
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
115
|
+
$stdout = save
|
116
|
+
end
|
117
|
+
|
118
|
+
it "sets @output to file given something other than a string" do
|
119
|
+
writer_mock = double("writer")
|
120
|
+
expect(writer_mock).to receive(:got_here)
|
121
|
+
file = StringIO.new
|
122
|
+
writer_class.new(file) do |r|
|
123
|
+
writer_mock.got_here
|
124
|
+
expect(r.instance_variable_get(:@output)).to eq file
|
127
125
|
end
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
126
|
+
end
|
127
|
+
|
128
|
+
it "sets prefixes given :prefixes => {}" do
|
129
|
+
writer_mock = double("writer")
|
130
|
+
expect(writer_mock).to receive(:got_here)
|
131
|
+
writer_class.new(StringIO.new, :prefixes => {:a => "b"}) do |r|
|
132
|
+
writer_mock.got_here
|
133
|
+
expect(r.prefixes).to eq({:a => "b"})
|
136
134
|
end
|
137
|
-
|
138
|
-
#it "calls #write_prologue" do
|
139
|
-
# writer_mock = double("writer")
|
140
|
-
# writer_mock.should_receive(:got_here)
|
141
|
-
# @writer_class.any_instance.should_receive(:write_prologue)
|
142
|
-
# @writer_class.new(StringIO.new) do |r|
|
143
|
-
# writer_mock.got_here
|
144
|
-
# end
|
145
|
-
#end
|
146
|
-
#
|
147
|
-
#it "calls #write_epilogue" do
|
148
|
-
# writer_mock = double("writer")
|
149
|
-
# writer_mock.should_receive(:got_here)
|
150
|
-
# @writer_class.any_instance.should_receive(:write_epilogue)
|
151
|
-
# @writer_class.new(StringIO.new) do |r|
|
152
|
-
# writer_mock.got_here
|
153
|
-
# end
|
154
|
-
#end
|
155
135
|
end
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
136
|
+
|
137
|
+
#it "calls #write_prologue" do
|
138
|
+
# writer_mock = double("writer")
|
139
|
+
# writer_mock.should_receive(:got_here)
|
140
|
+
# writer_class.any_instance.should_receive(:write_prologue)
|
141
|
+
# writer_class.new(StringIO.new) do |r|
|
142
|
+
# writer_mock.got_here
|
143
|
+
# end
|
144
|
+
#end
|
145
|
+
#
|
146
|
+
#it "calls #write_epilogue" do
|
147
|
+
# writer_mock = double("writer")
|
148
|
+
# writer_mock.should_receive(:got_here)
|
149
|
+
# writer_class.any_instance.should_receive(:write_epilogue)
|
150
|
+
# writer_class.new(StringIO.new) do |r|
|
151
|
+
# writer_mock.got_here
|
152
|
+
# end
|
153
|
+
#end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "#prefixes=" do
|
157
|
+
it "sets prefixes from hash" do
|
158
|
+
writer.prefixes = {:a => "b"}
|
159
|
+
expect(writer.prefixes).to eq({:a => "b"})
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "#prefix" do
|
164
|
+
{
|
165
|
+
nil => "nil",
|
166
|
+
:a => "b",
|
167
|
+
"foo" => "bar",
|
168
|
+
}.each_pair do |pfx, uri|
|
169
|
+
it "sets prefix(#{pfx}) to #{uri}" do
|
170
|
+
expect(writer.prefix(pfx, uri)).to eq uri
|
171
|
+
expect(writer.prefix(pfx)).to eq uri
|
161
172
|
end
|
162
173
|
end
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
##
|
178
|
+
# @deprecated use `it_behaves_like "an RDF::Writer"` instead
|
179
|
+
module RDF_Writer
|
180
|
+
extend RSpec::SharedContext
|
181
|
+
include RDF::Spec::Matchers
|
182
|
+
|
183
|
+
def self.included(mod)
|
184
|
+
warn "[DEPRECATION] `RDF_Writer` is deprecated. "\
|
185
|
+
"Please use `it_behaves_like 'an RDF::Writer'`"
|
186
|
+
end
|
187
|
+
|
188
|
+
describe 'examples for' do
|
189
|
+
include_examples 'an RDF::Writer' do
|
190
|
+
let(:writer_class) { @writer_class }
|
191
|
+
let(:writer) { @writer }
|
192
|
+
|
193
|
+
before do
|
194
|
+
raise '@writer_class must be defined' unless defined?(writer_class)
|
195
|
+
raise '@writer must be defined' unless defined?(writer)
|
174
196
|
end
|
175
197
|
end
|
176
198
|
end
|