rdf-spec 1.1.5 → 1.1.13

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.
@@ -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 "RDF_Transaction", RDF::Transaction
6
- shared_examples "RDF_Transaction" do |klass|
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
- describe RDF::Transaction do
10
- subject {klass.new(:context => RDF::URI("name"), :insert => RDF::Graph.new, :delete => RDF::Graph.new)}
11
-
12
- describe "#initialize" do
13
- subject {klass}
14
- it "accepts a graph" do
15
- g = double("graph")
16
- this = subject.new(:graph => g)
17
- expect(this.graph).to eq g
18
- end
19
-
20
- it "accepts a context" do
21
- c = double("context")
22
- this = subject.new(:graph => c)
23
- expect(this.graph).to eq c
24
- expect(this.context).to eq c
25
-
26
- this = subject.new(:context => c)
27
- expect(this.graph).to eq c
28
- expect(this.context).to eq c
29
- end
30
-
31
- it "accepts inserts" do
32
- g = double("inserts")
33
- this = subject.new(:insert => g)
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
- its(:deletes) {should be_a(RDF::Enumerable)}
45
- its(:inserts) {should be_a(RDF::Enumerable)}
46
- it {should be_mutable}
47
- it {should_not be_readable}
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 "does not respond to #load" do
50
- expect {subject.load("http://example/")}.to raise_error(NoMethodError)
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 "does not respond to #update" do
54
- expect {subject.update(RDF::Statement.new)}.to raise_error(NoMethodError)
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 "does not respond to #clear" do
58
- expect {subject.clear}.to raise_error(NoMethodError)
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
- describe "#execute" do
62
- let(:s) {RDF::Statement.new(RDF::URI("s"), RDF::URI("p"), RDF::URI("o"))}
63
- let(:r) {double("repository")}
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
- describe "#delete_statement" do
95
- let(:s) {RDF::Statement.new(RDF::URI("s"), RDF::URI("p"), RDF::URI("o"))}
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
- describe "#insert_statement" do
103
- let(:s) {RDF::Statement.new(RDF::URI("s"), RDF::URI("p"), RDF::URI("o"))}
104
- it "adds statement to #inserts" do
105
- subject.insert(s)
106
- expect(subject.inserts.to_a).to eq [s]
107
- end
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
@@ -1,124 +1,136 @@
1
1
  require 'rdf/spec'
2
2
 
3
- module RDF_Writable
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 '+@writable+ must be defined in a before(:each) block' unless instance_variable_get('@writable')
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 = @writable.respond_to?(:supports?) && @writable.supports?(:context)
13
+ @supports_context = writable.respond_to?(:supports?) && writable.supports?(:context)
14
14
  end
15
15
 
16
- describe RDF::Writable do
17
- subject {@writable}
18
- let(:statement) {@statements.detect {|s| s.to_a.all? {|r| r.uri?}}}
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
- it "inserts a graph" do
34
- skip("writability") unless subject.writable?
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
- it "inserts an enumerable" do
42
- skip("writability") unless subject.writable?
43
- enumerable = @statements.dup.extend(RDF::Enumerable)
44
- subject << enumerable
45
- expect(subject).to have_statement(statement)
46
- expect(subject.count).to eq count
47
- end
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
- it "inserts data responding to #to_rdf" do
50
- skip("writability") unless subject.writable?
51
- mock = double('mock')
52
- allow(mock).to receive(:to_rdf).and_return(@statements)
53
- subject << mock
54
- expect(subject).to have_statement(statement)
55
- expect(subject.count).to eq count
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
- it "inserts a statement" do
59
- skip("writability") unless subject.writable?
60
- subject << statement
61
- expect(subject).to have_statement(statement)
62
- expect(subject.count).to eq 1
63
- end
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
- it "inserts an invalid statement" do
66
- skip("writability") unless subject.writable?
67
- s = RDF::Statement.from([nil, nil, nil])
68
- expect(s).not_to be_valid
69
- subject << s
70
- expect(subject.count).to eq 1
71
- end
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
- context "when inserting statements" do
75
- it "should support #insert" do
76
- skip("writability") unless subject.writable?
77
- expect(subject).to respond_to(:insert)
78
- end
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
- it "should not raise errors" do
81
- skip("writability") unless subject.writable?
82
- expect { subject.insert(statement) }.not_to raise_error
83
- end
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
- it "should support inserting one statement at a time" do
86
- skip("writability") unless subject.writable?
87
- subject.insert(statement)
88
- expect(subject).to have_statement(statement)
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
- it "should support inserting multiple statements at a time" do
92
- skip("writability") unless subject.writable?
93
- subject.insert(*@statements)
94
- end
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
- it "should insert statements successfully" do
97
- skip("writability") unless subject.writable?
98
- subject.insert(*@statements)
99
- expect(subject.count).to eq count
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
- it "should not insert a statement twice" do
103
- skip("writability") unless subject.writable?
104
- subject.insert(statement)
105
- subject.insert(statement)
106
- expect(subject.count).to eq 1
107
- end
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
- it "should treat statements with a different context as distinct" do
110
- skip("writability") unless subject.writable?
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
@@ -2,175 +2,197 @@ require 'rdf/spec'
2
2
  require 'fileutils'
3
3
  require 'tmpdir'
4
4
 
5
- module RDF_Writer
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 '+@writer+ must be defined in a before(:each) block' unless instance_variable_get('@writer')
11
- @writer_class = @writer.class
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 RDF::Writer do
15
- describe ".each" do
16
- it "yields each writer" do
17
- @writer_class.each do |r|
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
- describe ".buffer" do
24
- it "calls .new with buffer and other arguments" do
25
- expect(@writer_class).to receive(:new)
26
- @writer_class.buffer do |r|
27
- expect(r).to be_a(@writer_class)
28
- end
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
- describe ".open" do
33
- before(:each) do
34
- allow(RDF::Util::File).to receive(:open_file).and_yield(StringIO.new("foo"))
35
- @dir = Dir.mktmpdir
36
- @basename = File.join(@dir, "foo")
37
- end
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
- 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 = 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
- it "yields writer given symbol" do
58
- @writer_class.format.each do |f|
59
- sym = f.to_sym # Like RDF::NTriples::Format => :ntriples
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(@writer_class).to receive(:for).with(sym).and_return(@writer_class)
63
- @writer_class.open("#{@basename}.#{sym}", :format => sym) do |r|
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
- 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 = double("writer")
74
- expect(writer_mock).to receive(:got_here)
75
- expect(@writer_class).to receive(:for).with(:file_name => "#{@basename}.#{sym}").and_return(@writer_class)
76
- @writer_class.open("#{@basename}.#{sym}", :file_name => "#{@basename}.#{sym}") do |r|
77
- expect(r).to be_a(RDF::Writer)
78
- writer_mock.got_here
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
- 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 = double("writer")
88
- expect(writer_mock).to receive(:got_here)
89
- expect(@writer_class).to 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
- expect(r).to be_a(RDF::Writer)
92
- writer_mock.got_here
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
- describe ".format" do
100
- it "returns itself even if given explicit format" do
101
- other_format = @writer_class == RDF::NTriples::Writer ? :nquads : :ntriples
102
- expect(@writer_class.for(other_format)).to eq @writer_class
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
- describe ".new" do
107
- it "sets @output to $stdout by default" do
108
- writer_mock = double("writer")
109
- expect(writer_mock).to receive(:got_here)
110
- save, $stdout = $stdout, StringIO.new
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
- @writer_class.new do |r|
113
- writer_mock.got_here
114
- expect(r.instance_variable_get(:@output)).to eq $stdout
115
- end
116
- $stdout = save
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
- it "sets @output to file given something other than a string" do
120
- writer_mock = double("writer")
121
- expect(writer_mock).to receive(:got_here)
122
- file = StringIO.new
123
- @writer_class.new(file) do |r|
124
- writer_mock.got_here
125
- expect(r.instance_variable_get(:@output)).to eq file
126
- end
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
- it "sets prefixes given :prefixes => {}" do
130
- writer_mock = double("writer")
131
- expect(writer_mock).to receive(:got_here)
132
- @writer_class.new(StringIO.new, :prefixes => {:a => "b"}) do |r|
133
- writer_mock.got_here
134
- expect(r.prefixes).to eq({:a => "b"})
135
- end
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
- describe "#prefixes=" do
158
- it "sets prefixes from hash" do
159
- @writer.prefixes = {:a => "b"}
160
- expect(@writer.prefixes).to eq({:a => "b"})
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
- describe "#prefix" do
165
- {
166
- nil => "nil",
167
- :a => "b",
168
- "foo" => "bar",
169
- }.each_pair do |pfx, uri|
170
- it "sets prefix(#{pfx}) to #{uri}" do
171
- expect(@writer.prefix(pfx, uri)).to eq uri
172
- expect(@writer.prefix(pfx)).to eq uri
173
- end
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