rdf-spec 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,49 +1,52 @@
1
1
  require 'rdf/spec'
2
2
 
3
- share_as :RDF_Format do
3
+ module RDF_Format
4
+ extend RSpec::SharedContext
4
5
  include RDF::Spec::Matchers
5
6
 
6
7
  before(:each) do
7
8
  raise raise '+@format_class+ must be defined in a before(:each) block' unless instance_variable_get('@format_class')
8
9
  end
9
10
 
10
- describe ".for" do
11
- RDF::Format.file_extensions.each do |ext, formats|
12
- it "detects #{formats.first} using file path foo.#{ext}" do
13
- RDF::Format.for("foo.#{ext}").should == formats.first
14
- end
11
+ describe RDF::Format do
12
+ describe ".for" do
13
+ RDF::Format.file_extensions.each do |ext, formats|
14
+ it "detects #{formats.first} using file path foo.#{ext}" do
15
+ RDF::Format.for("foo.#{ext}").should == formats.first
16
+ end
15
17
 
16
- it "detects #{formats.first} using file_name foo.#{ext}" do
17
- RDF::Format.for(:file_name => "foo.#{ext}").should == formats.first
18
- end
18
+ it "detects #{formats.first} using file_name foo.#{ext}" do
19
+ RDF::Format.for(:file_name => "foo.#{ext}").should == formats.first
20
+ end
19
21
 
20
- it "detects #{formats.first} using file_extension #{ext}" do
21
- RDF::Format.for(:file_extension => ext).should == formats.first
22
+ it "detects #{formats.first} using file_extension #{ext}" do
23
+ RDF::Format.for(:file_extension => ext).should == formats.first
24
+ end
22
25
  end
23
- end
24
26
 
25
- RDF::Format.content_types.each do |content_type, formats|
26
- it "detects #{formats.first} using content_type #{content_type}" do
27
- RDF::Format.for(:content_type => content_type).should == formats.first
27
+ RDF::Format.content_types.each do |content_type, formats|
28
+ it "detects #{formats.first} using content_type #{content_type}" do
29
+ RDF::Format.for(:content_type => content_type).should == formats.first
30
+ end
28
31
  end
29
32
  end
30
- end
31
33
 
32
- describe ".reader" do
33
- it "returns a reader" do
34
- @format_class.each do |f|
35
- f.reader.should_not be_nil
34
+ describe ".reader" do
35
+ it "returns a reader" do
36
+ @format_class.each do |f|
37
+ f.reader.should_not be_nil
38
+ end
36
39
  end
37
40
  end
38
- end
39
41
 
40
- describe ".writer" do
41
- ##
42
- # May not return a writer, only does if one is defined by the format
43
- it "returns a writer" do
44
- @format_class.each do |f|
45
- format_namespace = f.name.split('::')[0..-2].inject(Kernel) {|base, const| base.const_get(const)}
46
- f.writer.should_not be_nil if format_namespace.const_defined?(:Writer)
42
+ describe ".writer" do
43
+ ##
44
+ # May not return a writer, only does if one is defined by the format
45
+ it "returns a writer" do
46
+ @format_class.each do |f|
47
+ format_namespace = f.name.split('::')[0..-2].inject(Kernel) {|base, const| base.const_get(const)}
48
+ f.writer.should_not be_nil if format_namespace.const_defined?(:Writer)
49
+ end
47
50
  end
48
51
  end
49
52
  end
@@ -1,29 +1,32 @@
1
1
  require 'rdf/spec'
2
2
 
3
- share_as :RDF_Indexable do
3
+ module RDF_Indexable
4
+ extend RSpec::SharedContext
4
5
  include RDF::Spec::Matchers
5
6
 
6
7
  before :each do
7
8
  raise '+@indexable+ must be defined in a before(:each) block' unless instance_variable_get('@indexable')
8
9
  end
10
+
11
+ describe RDF::Indexable do
12
+ it "responds to #indexed?" do
13
+ @indexable.respond_to?(:indexed?)
14
+ end
9
15
 
10
- it "responds to #indexed?" do
11
- @indexable.respond_to?(:indexed?)
12
- end
13
-
14
- it "implements #indexed?" do
15
- !!@indexable.indexed?.should == @indexable.indexed?
16
- end
16
+ it "implements #indexed?" do
17
+ !!@indexable.indexed?.should == @indexable.indexed?
18
+ end
17
19
 
18
- it "responds to #index!" do
19
- @indexable.respond_to?(:index!)
20
- end
20
+ it "responds to #index!" do
21
+ @indexable.respond_to?(:index!)
22
+ end
21
23
 
22
- it "does not raise error on #index! if #indexed?" do
23
- lambda {@indexable.index!}.should_not raise_error if @indexable.indexed?
24
- end
24
+ it "does not raise error on #index! if #indexed?" do
25
+ lambda {@indexable.index!}.should_not raise_error if @indexable.indexed?
26
+ end
25
27
 
26
- it "raises error on #index! if not #indexed?" do
27
- lambda {@indexable.index!}.should raise_error unless @indexable.indexed?
28
+ it "raises error on #index! if not #indexed?" do
29
+ lambda {@indexable.index!}.should raise_error unless @indexable.indexed?
30
+ end
28
31
  end
29
32
  end
@@ -1,7 +1,10 @@
1
1
  require 'rdf/spec'
2
2
 
3
- share_as :RDF_Inferable do
3
+ module RDF_Inferable
4
+ extend RSpec::SharedContext
4
5
  include RDF::Spec::Matchers
5
6
 
6
- # TODO
7
+ describe RDF::Inferable do
8
+ it "should implement specs" #TODO
9
+ end
7
10
  end
@@ -46,7 +46,7 @@ module RDF; module Spec
46
46
  statement.should be_instance_of(RDF::Statement)
47
47
  statement.subject.should be_a_kind_of(RDF::Resource)
48
48
  statement.predicate.should be_a_kind_of(RDF::URI)
49
- statement.object.should be_a_kind_of(RDF::Value) unless statement.object.is_a?(String) # FIXME
49
+ statement.object.should be_a_kind_of(RDF::Value)
50
50
  true
51
51
  end
52
52
  end
@@ -57,7 +57,7 @@ module RDF; module Spec
57
57
  triple.size.should == 3
58
58
  triple[0].should be_a_kind_of(RDF::Resource)
59
59
  triple[1].should be_a_kind_of(RDF::URI)
60
- triple[2].should be_a_kind_of(RDF::Value) unless triple[2].is_a?(String) # FIXME
60
+ triple[2].should be_a_kind_of(RDF::Value)
61
61
  true
62
62
  end
63
63
  end
@@ -68,7 +68,7 @@ module RDF; module Spec
68
68
  quad.size.should == 4
69
69
  quad[0].should be_a_kind_of(RDF::Resource)
70
70
  quad[1].should be_a_kind_of(RDF::URI)
71
- quad[2].should be_a_kind_of(RDF::Value) unless quad[2].is_a?(String) # FIXME
71
+ quad[2].should be_a_kind_of(RDF::Value)
72
72
  quad[3].should be_a_kind_of(RDF::Resource) unless quad[3].nil?
73
73
  true
74
74
  end
@@ -97,7 +97,7 @@ module RDF; module Spec
97
97
 
98
98
  RSpec::Matchers.define :be_a_value do
99
99
  match do |value|
100
- value.should be_a_kind_of(RDF::Value) unless value.is_a?(String) # FIXME
100
+ value.should be_a_kind_of(RDF::Value)
101
101
  true
102
102
  end
103
103
  end
@@ -124,7 +124,7 @@ module RDF; module Spec
124
124
  properties.map { |p| p.to_sym }.each do |property|
125
125
  vocabulary[property].should be_a_uri
126
126
  vocabulary[property].to_s.should == "#{base_uri}#{property}"
127
- #vocabulary.should respond_to(property) # FIXME
127
+ vocabulary.should respond_to(property)
128
128
  lambda { vocabulary.send(property) }.should_not raise_error
129
129
  vocabulary.send(property).should be_a_uri
130
130
  vocabulary.send(property.to_s).should be_a_uri
@@ -137,7 +137,7 @@ module RDF; module Spec
137
137
  RSpec::Matchers.define :have_subclasses do |base_uri, klasses|
138
138
  match do |vocabulary|
139
139
  klasses.map { |k| k.to_sym }.each do |klass|
140
- # TODO
140
+ pending "checks that #{base_uri} has subClassOf for #{klass}"
141
141
  end
142
142
  true
143
143
  end
@@ -1,7 +1,8 @@
1
1
  require 'rdf/spec'
2
2
  require 'rdf/ntriples'
3
3
 
4
- share_as :RDF_Mutable do
4
+ module RDF_Mutable
5
+ extend RSpec::SharedContext
5
6
  include RDF::Spec::Matchers
6
7
 
7
8
  before :each do
@@ -15,139 +16,141 @@ share_as :RDF_Mutable do
15
16
  @supports_context = @mutable.respond_to?(:supports?) && @mutable.supports?(:context)
16
17
  end
17
18
 
18
- context "readability" do
19
- require 'rdf/spec/readable'
19
+ describe RDF::Mutable do
20
+ context "readability" do
21
+ require 'rdf/spec/readable'
20
22
 
21
- before :each do
22
- @readable = @mutable
23
- end
24
-
25
- it_should_behave_like RDF_Readable
26
- end
27
-
28
- context "writability" do
29
- require 'rdf/spec/writable'
23
+ before :each do
24
+ @readable = @mutable
25
+ end
30
26
 
31
- before :each do
32
- @writable = @mutable
27
+ include RDF_Readable
33
28
  end
34
29
 
35
- it_should_behave_like RDF_Writable
36
- end
37
-
38
- it "should be empty initially" do
39
- @mutable.empty?.should be_true
40
- @mutable.count.should be_zero
41
- end
42
-
43
- it "should be readable" do
44
- @mutable.readable?.should be_true
45
- end
30
+ context "writability" do
31
+ require 'rdf/spec/writable'
46
32
 
47
- it "should be writable" do
48
- @mutable.writable?.should be_true
49
- end
33
+ before :each do
34
+ @writable = @mutable
35
+ end
50
36
 
51
- it "should be mutable" do
52
- @mutable.immutable?.should be_false
53
- @mutable.mutable?.should be_true
54
- end
37
+ include RDF_Writable
38
+ end
55
39
 
56
- it "should support #load" do
57
- @mutable.respond_to?(:load).should be_true
58
- end
40
+ it "should be empty initially" do
41
+ @mutable.empty?.should be_true
42
+ @mutable.count.should be_zero
43
+ end
59
44
 
60
- context "#load" do
61
- it "should require an argument" do
62
- lambda { @mutable.load }.should raise_error(ArgumentError)
45
+ it "should be readable" do
46
+ @mutable.readable?.should be_true
63
47
  end
64
48
 
65
- it "should accept a string filename argument" do
66
- lambda { @mutable.load(@filename) }.should_not raise_error(ArgumentError)
49
+ it "should be writable" do
50
+ @mutable.writable?.should be_true
67
51
  end
68
52
 
69
- it "should accept an optional hash argument" do
70
- lambda { @mutable.load(@filename,{}) }.should_not raise_error(ArgumentError)
53
+ it "should be mutable" do
54
+ @mutable.immutable?.should be_false
55
+ @mutable.mutable?.should be_true
71
56
  end
72
57
 
73
- it "should load statements" do
74
- @mutable.load @filename
75
- @mutable.size.should == File.readlines(@filename).size
76
- @mutable.should have_subject(@subject)
58
+ it "should support #load" do
59
+ @mutable.respond_to?(:load).should be_true
77
60
  end
78
61
 
79
- it "should load statements with a context override" do
80
- if @supports_context
81
- @mutable.load @filename, :context => @context
82
- @mutable.should have_context(@context)
83
- @mutable.query(:context => @context).size.should == @mutable.size
62
+ context "#load" do
63
+ it "should require an argument" do
64
+ lambda { @mutable.load }.should raise_error(ArgumentError)
84
65
  end
85
- end
86
- end
87
66
 
88
- context "when deleting statements" do
89
- before :each do
90
- @statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
91
- @mutable.insert(*@statements)
92
- end
67
+ it "should accept a string filename argument" do
68
+ lambda { @mutable.load(@filename) }.should_not raise_error(ArgumentError)
69
+ end
93
70
 
94
- it "should support #delete" do
95
- @mutable.should respond_to(:delete)
96
- end
71
+ it "should accept an optional hash argument" do
72
+ lambda { @mutable.load(@filename,{}) }.should_not raise_error(ArgumentError)
73
+ end
97
74
 
98
- it "should not raise errors" do
99
- lambda { @mutable.delete(@statements.first) }.should_not raise_error
100
- end
75
+ it "should load statements" do
76
+ @mutable.load @filename
77
+ @mutable.size.should == File.readlines(@filename).size
78
+ @mutable.should have_subject(@subject)
79
+ end
101
80
 
102
- it "should support deleting one statement at a time" do
103
- @mutable.delete(@statements.first)
104
- @mutable.should_not have_statement(@statements.first)
81
+ it "should load statements with a context override" do
82
+ if @supports_context
83
+ @mutable.load @filename, :context => @context
84
+ @mutable.should have_context(@context)
85
+ @mutable.query(:context => @context).size.should == @mutable.size
86
+ end
87
+ end
105
88
  end
106
89
 
107
- it "should support deleting multiple statements at a time" do
108
- @mutable.delete(*@statements)
109
- @statements.find { |s| @mutable.has_statement?(s) }.should be_false
110
- end
90
+ context "when deleting statements" do
91
+ before :each do
92
+ @statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
93
+ @mutable.insert(*@statements)
94
+ end
111
95
 
112
- it "should support wildcard deletions" do
113
- # nothing deleted
114
- require 'digest/sha1'
115
- count = @mutable.count
116
- @mutable.delete([nil, nil, random = Digest::SHA1.hexdigest(File.read(__FILE__))])
117
- @mutable.should_not be_empty
118
- @mutable.count.should == count
119
-
120
- # everything deleted
121
- @mutable.delete([nil, nil, nil])
122
- @mutable.should be_empty
123
- end
96
+ it "should support #delete" do
97
+ @mutable.should respond_to(:delete)
98
+ end
99
+
100
+ it "should not raise errors" do
101
+ lambda { @mutable.delete(@statements.first) }.should_not raise_error
102
+ end
103
+
104
+ it "should support deleting one statement at a time" do
105
+ @mutable.delete(@statements.first)
106
+ @mutable.should_not have_statement(@statements.first)
107
+ end
108
+
109
+ it "should support deleting multiple statements at a time" do
110
+ @mutable.delete(*@statements)
111
+ @statements.find { |s| @mutable.has_statement?(s) }.should be_false
112
+ end
124
113
 
125
- it "should only delete statements when the context matches" do
126
- # Setup three statements identical except for context
127
- count = @mutable.count + (@supports_context ? 3 : 1)
128
- s1 = RDF::Statement.new(@subject, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:1"))
129
- s2 = s1.dup
130
- s2.context = RDF::URI.new("urn:context:1")
131
- s3 = s1.dup
132
- s3.context = RDF::URI.new("urn:context:2")
133
- @mutable.insert(s1)
134
- @mutable.insert(s2)
135
- @mutable.insert(s3)
136
- @mutable.count.should == count
137
-
138
- # Delete one by one
139
- @mutable.delete(s1)
140
- @mutable.count.should == count - (@supports_context ? 1 : 1)
141
- @mutable.delete(s2)
142
- @mutable.count.should == count - (@supports_context ? 2 : 1)
143
- @mutable.delete(s3)
144
- @mutable.count.should == count - (@supports_context ? 3 : 1)
114
+ it "should support wildcard deletions" do
115
+ # nothing deleted
116
+ require 'digest/sha1'
117
+ count = @mutable.count
118
+ @mutable.delete([nil, nil, random = Digest::SHA1.hexdigest(File.read(__FILE__))])
119
+ @mutable.should_not be_empty
120
+ @mutable.count.should == count
121
+
122
+ # everything deleted
123
+ @mutable.delete([nil, nil, nil])
124
+ @mutable.should be_empty
125
+ end
126
+
127
+ it "should only delete statements when the context matches" do
128
+ # Setup three statements identical except for context
129
+ count = @mutable.count + (@supports_context ? 3 : 1)
130
+ s1 = RDF::Statement.new(@subject, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:1"))
131
+ s2 = s1.dup
132
+ s2.context = RDF::URI.new("urn:context:1")
133
+ s3 = s1.dup
134
+ s3.context = RDF::URI.new("urn:context:2")
135
+ @mutable.insert(s1)
136
+ @mutable.insert(s2)
137
+ @mutable.insert(s3)
138
+ @mutable.count.should == count
139
+
140
+ # Delete one by one
141
+ @mutable.delete(s1)
142
+ @mutable.count.should == count - (@supports_context ? 1 : 1)
143
+ @mutable.delete(s2)
144
+ @mutable.count.should == count - (@supports_context ? 2 : 1)
145
+ @mutable.delete(s3)
146
+ @mutable.count.should == count - (@supports_context ? 3 : 1)
147
+ end
145
148
  end
146
- end
147
149
 
148
- context "when clearing all statements" do
149
- it "should support #clear" do
150
- @mutable.should respond_to(:clear)
150
+ context "when clearing all statements" do
151
+ it "should support #clear" do
152
+ @mutable.should respond_to(:clear)
153
+ end
151
154
  end
152
155
  end
153
156
  end