rdf-spec 1.0.9 → 1.1.0.p1

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,8 +9,12 @@ module RDF_Readable
9
9
  end
10
10
 
11
11
  describe RDF::Readable do
12
- subject {@readable}
13
- it {should respond_to(:readable?)}
14
- its(:readable?) {should == subject.readable?}
12
+ it "responds to #readable?" do
13
+ @readable.respond_to?(:readable?)
14
+ end
15
+
16
+ it "implements #readable?" do
17
+ !!@readable.readable?.should == @readable.readable?
18
+ end
15
19
  end
16
20
  end
@@ -13,25 +13,25 @@ module RDF_Reader
13
13
  describe ".each" do
14
14
  it "yields each reader" do
15
15
  @reader_class.each do |r|
16
- expect(r).not_to be_nil
16
+ r.should_not be_nil
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
21
  describe ".open" do
22
22
  before(:each) do
23
- RDF::Util::File.stub(:open_file).and_yield(StringIO.new("foo"))
23
+ RDF::Util::File.stub!(:open_file).and_yield(StringIO.new("foo"))
24
24
  end
25
25
 
26
26
  it "yields reader given file_name" do
27
27
  @reader_class.format.each do |f|
28
- RDF::Util::File.stub(:open_file).and_yield(StringIO.new("foo"))
28
+ RDF::Util::File.stub!(:open_file).and_yield(StringIO.new("foo"))
29
29
  f.file_extensions.each_pair do |sym, content_type|
30
- reader_mock = double("reader")
31
- expect(reader_mock).to receive(:got_here)
32
- expect(@reader_class).to receive(:for).with(:file_name => "foo.#{sym}").and_return(@reader_class)
30
+ reader_mock = mock("reader")
31
+ reader_mock.should_receive(:got_here)
32
+ @reader_class.should_receive(:for).with(:file_name => "foo.#{sym}").and_return(@reader_class)
33
33
  @reader_class.open("foo.#{sym}") do |r|
34
- expect(r).to be_a(RDF::Reader)
34
+ r.should be_a(RDF::Reader)
35
35
  reader_mock.got_here
36
36
  end
37
37
  end
@@ -40,13 +40,13 @@ module RDF_Reader
40
40
 
41
41
  it "yields reader given symbol" do
42
42
  @reader_class.format.each do |f|
43
- RDF::Util::File.stub(:open_file).and_yield(StringIO.new("foo"))
43
+ RDF::Util::File.stub!(:open_file).and_yield(StringIO.new("foo"))
44
44
  sym = f.to_sym # Like RDF::NTriples::Format => :ntriples
45
- reader_mock = double("reader")
46
- expect(reader_mock).to receive(:got_here)
47
- expect(@reader_class).to receive(:for).with(sym).and_return(@reader_class)
45
+ reader_mock = mock("reader")
46
+ reader_mock.should_receive(:got_here)
47
+ @reader_class.should_receive(:for).with(sym).and_return(@reader_class)
48
48
  @reader_class.open("foo.#{sym}", :format => sym) do |r|
49
- expect(r).to be_a(RDF::Reader)
49
+ r.should be_a(RDF::Reader)
50
50
  reader_mock.got_here
51
51
  end
52
52
  end
@@ -54,13 +54,13 @@ module RDF_Reader
54
54
 
55
55
  it "yields reader given {:file_name => file_name}" do
56
56
  @reader_class.format.each do |f|
57
- RDF::Util::File.stub(:open_file).and_yield(StringIO.new("foo"))
57
+ RDF::Util::File.stub!(:open_file).and_yield(StringIO.new("foo"))
58
58
  f.file_extensions.each_pair do |sym, content_type|
59
- reader_mock = double("reader")
60
- expect(reader_mock).to receive(:got_here)
61
- expect(@reader_class).to receive(:for).with(:file_name => "foo.#{sym}").and_return(@reader_class)
59
+ reader_mock = mock("reader")
60
+ reader_mock.should_receive(:got_here)
61
+ @reader_class.should_receive(:for).with(:file_name => "foo.#{sym}").and_return(@reader_class)
62
62
  @reader_class.open("foo.#{sym}", :file_name => "foo.#{sym}") do |r|
63
- expect(r).to be_a(RDF::Reader)
63
+ r.should be_a(RDF::Reader)
64
64
  reader_mock.got_here
65
65
  end
66
66
  end
@@ -69,13 +69,13 @@ module RDF_Reader
69
69
 
70
70
  it "yields reader given {:content_type => 'a/b'}" do
71
71
  @reader_class.format.each do |f|
72
- RDF::Util::File.stub(:open_file).and_yield(StringIO.new("foo"))
72
+ RDF::Util::File.stub!(:open_file).and_yield(StringIO.new("foo"))
73
73
  f.content_types.each_pair do |content_type, formats|
74
- reader_mock = double("reader")
75
- expect(reader_mock).to receive(:got_here)
76
- expect(@reader_class).to receive(:for).with(:content_type => content_type, :file_name => "foo").and_return(@reader_class)
74
+ reader_mock = mock("reader")
75
+ reader_mock.should_receive(:got_here)
76
+ @reader_class.should_receive(:for).with(:content_type => content_type, :file_name => "foo").and_return(@reader_class)
77
77
  @reader_class.open("foo", :content_type => content_type) do |r|
78
- expect(r).to be_a(RDF::Reader)
78
+ r.should be_a(RDF::Reader)
79
79
  reader_mock.got_here
80
80
  end
81
81
  end
@@ -86,27 +86,27 @@ module RDF_Reader
86
86
  describe ".format" do
87
87
  it "returns itself even if given explicit format" do
88
88
  other_format = @reader_class == RDF::NTriples::Reader ? :nquads : :ntriples
89
- expect(@reader_class.for(other_format)).to eq @reader_class
89
+ @reader_class.for(other_format).should == @reader_class
90
90
  end
91
91
  end
92
92
 
93
93
  describe ".new" do
94
94
  it "sets @input to StringIO given a string" do
95
- reader_mock = double("reader")
96
- expect(reader_mock).to receive(:got_here)
95
+ reader_mock = mock("reader")
96
+ reader_mock.should_receive(:got_here)
97
97
  @reader_class.new("string") do |r|
98
98
  reader_mock.got_here
99
- expect(r.instance_variable_get(:@input)).to be_a(StringIO)
99
+ r.instance_variable_get(:@input).should be_a(StringIO)
100
100
  end
101
101
  end
102
102
 
103
103
  it "sets @input to input given something other than a string" do
104
- reader_mock = double("reader")
105
- expect(reader_mock).to receive(:got_here)
104
+ reader_mock = mock("reader")
105
+ reader_mock.should_receive(:got_here)
106
106
  file = StringIO.new("")
107
107
  @reader_class.new(file) do |r|
108
108
  reader_mock.got_here
109
- expect(r.instance_variable_get(:@input)).to eq file
109
+ r.instance_variable_get(:@input).should == file
110
110
  end
111
111
  end
112
112
 
@@ -114,37 +114,37 @@ module RDF_Reader
114
114
  # Either set validate, or through error, due to invalid input (null input may be invalid)
115
115
  begin
116
116
  @reader_class.new("string", :validate => true) do |r|
117
- expect(r).to be_valid
117
+ r.send(:validate?).should be_true
118
118
  end
119
119
  rescue
120
- expect($!).to be_a(RDF::ReaderError) # An error is acceptable
120
+ $!.should be_a(RDF::ReaderError) # An error is acceptable
121
121
  end
122
122
  end
123
123
 
124
124
  it "sets canonicalize given :canonicalize => true" do
125
- reader_mock = double("reader")
126
- expect(reader_mock).to receive(:got_here)
125
+ reader_mock = mock("reader")
126
+ reader_mock.should_receive(:got_here)
127
127
  @reader_class.new("string", :canonicalize => true) do |r|
128
128
  reader_mock.got_here
129
- expect(r).to be_canonicalize
129
+ r.send(:canonicalize?).should be_true
130
130
  end
131
131
  end
132
132
 
133
133
  it "sets intern given :intern => true" do
134
- reader_mock = double("reader")
135
- expect(reader_mock).to receive(:got_here)
134
+ reader_mock = mock("reader")
135
+ reader_mock.should_receive(:got_here)
136
136
  @reader_class.new("string", :intern => true) do |r|
137
137
  reader_mock.got_here
138
- expect(r).to be_intern
138
+ r.send(:intern?).should be_true
139
139
  end
140
140
  end
141
141
 
142
142
  it "sets prefixes given :prefixes => {}" do
143
- reader_mock = double("reader")
144
- expect(reader_mock).to receive(:got_here)
143
+ reader_mock = mock("reader")
144
+ reader_mock.should_receive(:got_here)
145
145
  @reader_class.new("string", :prefixes => {:a => "b"}) do |r|
146
146
  reader_mock.got_here
147
- expect(r.prefixes).to eq({:a => "b"})
147
+ r.prefixes.should == {:a => "b"}
148
148
  end
149
149
  end
150
150
  end
@@ -152,7 +152,7 @@ module RDF_Reader
152
152
  describe "#prefixes=" do
153
153
  it "sets prefixes from hash" do
154
154
  @reader.prefixes = {:a => "b"}
155
- expect(@reader.prefixes).to eq({:a => "b"})
155
+ @reader.prefixes.should == {:a => "b"}
156
156
  end
157
157
  end
158
158
 
@@ -163,8 +163,8 @@ module RDF_Reader
163
163
  "foo" => "bar",
164
164
  }.each_pair do |pfx, uri|
165
165
  it "sets prefix(#{pfx}) to #{uri}" do
166
- expect(@reader.prefix(pfx, uri)).to eq uri
167
- expect(@reader.prefix(pfx)).to eq uri
166
+ @reader.prefix(pfx, uri).should == uri
167
+ @reader.prefix(pfx).should == uri
168
168
  end
169
169
  end
170
170
  end
@@ -6,50 +6,61 @@ module RDF_Repository
6
6
 
7
7
  before :each do
8
8
  raise '+@repository+ must be defined in a before(:each) block' unless instance_variable_get('@repository')
9
- @statements = RDF::Spec.quads
10
- if @repository.empty? && @repository.writable?
11
- @repository.insert(*@statements)
12
- elsif @repository.empty?
13
- raise "+@repository+ must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
14
- end
15
- @countable = @repository
9
+ @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
10
+ @statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
16
11
  @enumerable = @repository
17
- @queryable = @repository
18
- @mutable = @repository
19
12
  end
20
13
 
21
14
  describe RDF::Repository do
22
-
23
15
  context "when counting statements" do
24
16
  require 'rdf/spec/countable'
17
+
18
+ before :each do
19
+ @countable = @repository
20
+ @countable.insert(*@statements)
21
+ end
22
+
25
23
  include RDF_Countable
26
24
  end
27
25
 
28
26
  context "when enumerating statements" do
29
27
  require 'rdf/spec/enumerable'
28
+
29
+ before :each do
30
+ @enumerable = @repository
31
+ @enumerable.insert(*@statements)
32
+ end
33
+
30
34
  include RDF_Enumerable
31
35
  end
32
36
 
33
37
  context "when querying statements" do
34
38
  require 'rdf/spec/queryable'
39
+
40
+ before :each do
41
+ @queryable = @repository
42
+ @subject = RDF::URI.new('http://rubygems.org/gems/rdf')
43
+ end
44
+
35
45
  include RDF_Queryable
36
46
  end
37
47
 
38
- # FIXME: This should be condition on the repository being mutable
39
48
  context "when updating" do
40
49
  require 'rdf/spec/mutable'
41
- before(:each) do
42
- @mutable.clear
50
+
51
+ before :each do
52
+ @mutable = @repository
53
+ @subject = RDF::URI.new('http://rubygems.org/gems/rdf')
54
+ @context = RDF::URI.new('http://example.org/context')
43
55
  end
56
+
44
57
  include RDF_Mutable
45
58
  end
46
59
 
47
- # FIXME: This should be condition on the repository being mutable
48
60
  context "as a durable repository" do
49
61
  require 'rdf/spec/durable'
50
62
 
51
63
  before :each do
52
- @repository.clear
53
64
  @load_durable ||= lambda { @repository }
54
65
  end
55
66
 
@@ -1,62 +1,110 @@
1
1
  require 'rdf/spec'
2
2
 
3
- module RDF_Transaction
4
- extend RSpec::SharedContext
3
+ # Pass in an instance of RDF::Transaction as follows:
4
+ #
5
+ # it_behaves_like "RDF_Transaction", RDF::Transaction
6
+ shared_examples "RDF_Transaction" do |klass|
5
7
  include RDF::Spec::Matchers
6
8
 
7
- before :each do
8
- raise '+@transaction+ must be defined in a before(:each) block' unless instance_variable_get('@transaction')
9
- end
10
-
11
9
  describe RDF::Transaction do
12
- #TODO
10
+ subject {klass.new(:context => RDF::URI("name"), :insert => RDF::Graph.new, :delete => RDF::Graph.new)}
11
+
13
12
  describe "#initialize" do
14
- it "accepts a graph"
15
- it "accepts a context"
16
- it "accepts inserts"
17
- it "accepts deletes"
18
- end
19
-
20
- describe "#graph" do
21
- it "is mutable"
13
+ subject {klass}
14
+ it "accepts a graph" do
15
+ g = mock("graph")
16
+ this = subject.new(:graph => g)
17
+ this.graph.should == g
18
+ end
19
+
20
+ it "accepts a context" do
21
+ c = mock("context")
22
+ this = subject.new(:graph => c)
23
+ this.graph.should == c
24
+ this.context.should == c
25
+
26
+ this = subject.new(:context => c)
27
+ this.graph.should == c
28
+ this.context.should == c
29
+ end
30
+
31
+ it "accepts inserts" do
32
+ g = mock("inserts")
33
+ this = subject.new(:insert => g)
34
+ this.inserts.should == g
35
+ end
36
+
37
+ it "accepts deletes" do
38
+ g = mock("deletes")
39
+ this = subject.new(:delete => g)
40
+ this.deletes.should == g
41
+ end
22
42
  end
23
-
24
- describe "#deletes" do
25
- it "is mutable"
43
+
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}
48
+
49
+ it "does not respond to #load" do
50
+ lambda {subject.load("http://example/")}.should raise_error(NoMethodError)
26
51
  end
27
-
28
- describe "#inserts" do
29
- it "is mutable"
52
+
53
+ it "does not respond to #update" do
54
+ lambda {subject.update(RDF::Statement.new)}.should raise_error(NoMethodError)
30
55
  end
31
-
32
- describe "#readable?" do
33
- it "returns false" do
34
- expect(@transaction.readable?).to be_false
35
- end
56
+
57
+ it "does not respond to #clear" do
58
+ lambda {subject.clear}.should raise_error(NoMethodError)
36
59
  end
37
-
60
+
38
61
  describe "#execute" do
39
- it "deletes statements"
40
- it "inserts statements"
41
- it "calls before_execute"
42
- it "calls after_execute"
43
- it "returns self"
44
- it "does not delete statements on failures"
45
- it "does not insert statements on failures"
62
+ let(:s) {RDF::Statement.new(RDF::URI("s"), RDF::URI("p"), RDF::URI("o"))}
63
+ let(:r) {mock("repository")}
64
+
65
+ it "deletes statements" do
66
+ r.should_receive(:delete).with(s)
67
+ r.should_not_receive(:insert)
68
+ subject.delete(s)
69
+ subject.execute(r)
70
+ end
71
+
72
+ it "inserts statements" do
73
+ r.should_not_receive(:delete)
74
+ r.should_receive(:insert).with(s)
75
+ subject.insert(s)
76
+ subject.execute(r)
77
+ end
78
+
79
+ it "calls before_execute" do
80
+ subject.should_receive(:before_execute).with(r, {})
81
+ subject.execute(r)
82
+ end
83
+
84
+ it "calls after_execute" do
85
+ subject.should_receive(:after_execute).with(r, {})
86
+ subject.execute(r)
87
+ end
88
+
89
+ it "returns self" do
90
+ subject.execute(r).should == subject
91
+ end
46
92
  end
47
93
 
48
94
  describe "#delete_statement" do
49
- it "adds statement to #deletes"
50
- it "does not remove statement from graph"
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
+ subject.deletes.to_a.should == [s]
99
+ end
51
100
  end
52
101
 
53
102
  describe "#insert_statement" do
54
- it "adds statement to #inserts"
55
- it "does not add statement to graph"
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
+ subject.inserts.to_a.should == [s]
107
+ end
56
108
  end
57
-
58
- it "does not respond to #load"
59
- it "does not respond to #update"
60
- it "does not respond to #clear"
61
109
  end
62
110
  end
@@ -7,130 +7,117 @@ module RDF_Writable
7
7
  before :each do
8
8
  raise '+@writable+ must be defined in a before(:each) block' unless instance_variable_get('@writable')
9
9
 
10
- @filename = RDF::Spec::TRIPLES_FILE
10
+ @filename = File.expand_path("../../../../etc/doap.nt", __FILE__)
11
11
  @statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
12
12
 
13
13
  @supports_context = @writable.respond_to?(:supports?) && @writable.supports?(:context)
14
14
  end
15
15
 
16
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?}
17
+ it "responds to #writable?" do
18
+ @writable.respond_to?(:readable?)
19
+ end
23
20
 
21
+ it "implements #writable?" do
22
+ !!@writable.writable?.should == @writable.writable?
23
+ end
24
+
24
25
  describe "#<<" do
25
26
  it "inserts a reader" do
26
- pending("writability", :unless => subject.writable?) do
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
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
32
31
  end
33
32
 
34
33
  it "inserts a graph" do
35
- pending("writability", :unless => subject.writable?) do
36
- graph = RDF::Graph.new << @statements
37
- subject << graph
38
- expect(subject).to have_statement(statement)
39
- expect(subject.count).to eq count
40
- end
34
+ graph = RDF::Graph.new << @statements
35
+ @writable << graph
36
+ @writable.should have_statement(@statements.first)
37
+ @writable.count.should == @statements.size
41
38
  end
42
39
 
43
40
  it "inserts an enumerable" do
44
- pending("writability", :unless => subject.writable?) do
45
- enumerable = @statements.dup.extend(RDF::Enumerable)
46
- subject << enumerable
47
- expect(subject).to have_statement(statement)
48
- expect(subject.count).to eq count
49
- end
41
+ enumerable = @statements.dup.extend(RDF::Enumerable)
42
+ @writable << enumerable
43
+ @writable.should have_statement(@statements.first)
44
+ @writable.count.should == @statements.size
50
45
  end
51
46
 
52
47
  it "inserts data responding to #to_rdf" do
53
- pending("writability", :unless => subject.writable?) do
54
- mock = double('mock')
55
- mock.stub(:to_rdf).and_return(@statements)
56
- subject << mock
57
- expect(subject).to have_statement(statement)
58
- expect(subject.count).to eq count
59
- end
48
+ mock = double('mock')
49
+ mock.stub(:to_rdf).and_return(@statements)
50
+ @writable << mock
51
+ @writable.should have_statement(@statements.first)
52
+ @writable.count.should == @statements.size
60
53
  end
61
54
 
62
55
  it "inserts a statement" do
63
- pending("writability", :unless => subject.writable?) do
64
- subject << statement
65
- expect(subject).to have_statement(statement)
66
- expect(subject.count).to eq 1
67
- end
56
+ @writable << @statements.first
57
+ @writable.should have_statement(@statements.first)
58
+ @writable.count.should == 1
68
59
  end
69
60
 
70
61
  it "inserts an invalid statement" do
71
- pending("writability", :unless => subject.writable?) do
72
- s = RDF::Statement.from([nil, nil, nil])
73
- expect(s).not_to be_valid
74
- subject << s
75
- expect(subject.count).to eq 1
76
- end
62
+ s = RDF::Statement.from([nil, nil, nil])
63
+ s.should_not be_valid
64
+ @writable << s
65
+ @writable.count.should == 1
77
66
  end
78
67
  end
79
68
 
80
69
  context "when inserting statements" do
81
70
  it "should support #insert" do
82
- pending("writability", :unless => subject.writable?) do
83
- expect(subject).to respond_to(:insert)
84
- end
71
+ @writable.should respond_to(:insert)
85
72
  end
86
73
 
87
74
  it "should not raise errors" do
88
- pending("writability", :unless => subject.writable?) do
89
- expect { subject.insert(statement) }.not_to raise_error
75
+ if @writable.writable?
76
+ lambda { @writable.insert(@statements.first) }.should_not raise_error
90
77
  end
91
78
  end
92
79
 
93
80
  it "should support inserting one statement at a time" do
94
- pending("writability", :unless => subject.writable?) do
95
- subject.insert(statement)
96
- expect(subject).to have_statement(statement)
81
+ if @writable.writable?
82
+ @writable.insert(@statements.first)
83
+ @writable.should have_statement(@statements.first)
97
84
  end
98
85
  end
99
86
 
100
87
  it "should support inserting multiple statements at a time" do
101
- pending("writability", :unless => subject.writable?) do
102
- subject.insert(*@statements)
88
+ if @writable.writable?
89
+ @writable.insert(*@statements)
103
90
  end
104
91
  end
105
92
 
106
93
  it "should insert statements successfully" do
107
- pending("writability", :unless => subject.writable?) do
108
- subject.insert(*@statements)
109
- expect(subject.count).to eq count
94
+ if @writable.writable?
95
+ @writable.insert(*@statements)
96
+ @writable.count.should == @statements.size
110
97
  end
111
98
  end
112
99
 
113
100
  it "should not insert a statement twice" do
114
- pending("writability", :unless => subject.writable?) do
115
- subject.insert(statement)
116
- subject.insert(statement)
117
- expect(subject.count).to eq 1
101
+ if @writable.writable?
102
+ @writable.insert(@statements.first)
103
+ @writable.insert(@statements.first)
104
+ @writable.count.should == 1
118
105
  end
119
106
  end
120
107
 
121
108
  it "should treat statements with a different context as distinct" do
122
- pending("writability", :unless => subject.writable?) do
123
- s1 = statement.dup
109
+ if @writable.writable?
110
+ s1 = @statements.first.dup
124
111
  s1.context = nil
125
- s2 = statement.dup
112
+ s2 = @statements.first.dup
126
113
  s2.context = RDF::URI.new("urn:context:1")
127
- s3 = statement.dup
114
+ s3 = @statements.first.dup
128
115
  s3.context = RDF::URI.new("urn:context:2")
129
- subject.insert(s1)
130
- subject.insert(s2)
131
- subject.insert(s3)
116
+ @writable.insert(s1)
117
+ @writable.insert(s2)
118
+ @writable.insert(s3)
132
119
  # If contexts are not suported, all three are redundant
133
- expect(subject.count).to eq (@supports_context ? 3 : 1)
120
+ @writable.count.should == (@supports_context ? 3 : 1)
134
121
  end
135
122
  end
136
123
  end