rdf-spec 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rdf/spec/node.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'rdf/spec'
2
-
3
- share_as :RDF_Node do
4
- before :each do
5
- raise '+@new+ must be defined in a before(:each) block' unless instance_variable_get('@new')
6
- end
7
-
8
- it "should be instantiable" do
9
- lambda { @new.call }.should_not raise_error
10
- end
11
- end
@@ -1,7 +0,0 @@
1
- require 'rdf/spec'
2
-
3
- share_as :RDF_Resource do
4
- include RDF::Spec::Matchers
5
-
6
- # TODO
7
- end
@@ -1,214 +0,0 @@
1
- require 'rdf/spec'
2
-
3
- share_as :RDF_Statement do
4
- include RDF::Spec::Matchers
5
-
6
- before :each do
7
- raise '+@n3+ must be defined in a before(:each) block' unless instance_variable_get('@n3')
8
- raise '+@s+ must be defined in a before(:each) block' unless instance_variable_get('@s')
9
- raise '+@p+ must be defined in a before(:each) block' unless instance_variable_get('@p')
10
- raise '+@o+ must be defined in a before(:each) block' unless instance_variable_get('@o')
11
- raise '+@stmt+ must be defined in a before(:each) block' unless instance_variable_get('@stmt')
12
- end
13
-
14
- context "when initializing" do
15
- it "should be instantiable with a hash argument" do
16
- lambda { RDF::Statement.new(:subject => @s,
17
- :predicate => @p,
18
- :object => @o) }.should_not raise_error(ArgumentError)
19
-
20
- end
21
-
22
- it "should not alter a hash argument" do
23
- hash = { :subject => @s, :predicate => @p, :object => @o }
24
- original_hash = hash.dup
25
- stmt = RDF::Statement.new(hash)
26
- original_hash.should == hash
27
- end
28
-
29
- it "should not alter its options argument" do
30
- options = { :context => RDF::DOAP.name }
31
- original_options = options.dup
32
- stmt = RDF::Statement.new(@s, @p, @o, options)
33
- options.should == original_options
34
- end
35
- end
36
-
37
- context "when created" do
38
- it "should not require arguments" do
39
- lambda { RDF::Statement.new }.should_not raise_error(ArgumentError)
40
- end
41
-
42
- it "should have a subject" do
43
- @stmt.has_subject?.should be_true
44
- @stmt.subject.should_not be_nil
45
- end
46
-
47
- it "should have a predicate" do
48
- @stmt.has_predicate?.should be_true
49
- @stmt.predicate.should_not be_nil
50
- end
51
-
52
- it "should have an object" do
53
- @stmt.has_object?.should be_true
54
- @stmt.object.should_not be_nil
55
- end
56
-
57
- it "should be asserted" do
58
- @stmt.asserted?.should be_true
59
- end
60
-
61
- it "should not be quoted" do
62
- @stmt.quoted?.should be_false
63
- end
64
-
65
- it "should be statement" do
66
- @stmt.statement?.should be_true
67
- end
68
- end
69
-
70
- context "when created with a blank node subject" do
71
- before :each do
72
- @stmt = RDF::Statement.new(RDF::Node.new, @p, @o)
73
- end
74
-
75
- it "should have a blank node" do
76
- @stmt.has_blank_nodes?.should be_true
77
- end
78
- end
79
-
80
- context "when created with a blank node object" do
81
- before :each do
82
- @stmt = RDF::Statement.new(@s, @p, RDF::Node.new)
83
- end
84
-
85
- it "should have a blank node" do
86
- @stmt.has_blank_nodes?.should be_true
87
- end
88
- end
89
-
90
- context "when created without a context" do
91
- it "should not have a context" do
92
- @stmt = RDF::Statement.new(@s, @p, @o, :context => nil)
93
- @stmt.context.should be_nil
94
- @stmt.has_context?.should be_false
95
- end
96
- end
97
-
98
- context "when created with a context" do
99
- it "should have a context" do
100
- @stmt = RDF::Statement.new(@s, @p, @o, :context => @s)
101
- @stmt.has_context?.should be_true
102
- @stmt.context.should_not be_nil
103
- end
104
- end
105
-
106
- context "when used like an Array" do
107
- it "should respond to #to_a" do
108
- @stmt.should respond_to(:to_a)
109
- end
110
-
111
- it "should respond to #[]" do
112
- @stmt.should respond_to(:[])
113
- end
114
-
115
- it "should respond to #[]=" do
116
- @stmt.should respond_to(:[]=)
117
- end
118
-
119
- it "should support #to_a" do
120
- @stmt.to_a.should eql([@stmt.subject, @stmt.predicate, @stmt.object])
121
- end
122
-
123
- it "should support #[] for the subject" do
124
- @stmt[0].should equal(@stmt.subject)
125
- end
126
-
127
- it "should support #[] for the predicate" do
128
- @stmt[1].should equal(@stmt.predicate)
129
- end
130
-
131
- it "should support #[] for the object" do
132
- @stmt[2].should equal(@stmt.object)
133
- end
134
-
135
- it "should support #[] for the context" do
136
- @stmt[3].should equal(@stmt.context)
137
- end
138
-
139
- it "should support #[]= for the subject" do
140
- stmt = @stmt.dup
141
- stmt[0] = s = RDF::URI("http://example.org/subject")
142
- stmt.subject.should == s
143
- end
144
-
145
- it "should support #[]= for the predicate" do
146
- stmt = @stmt.dup
147
- stmt[1] = p = RDF::URI("http://example.org/predicate")
148
- stmt.predicate.should == p
149
- end
150
-
151
- it "should support #[]= for the object" do
152
- stmt = @stmt.dup
153
- stmt[2] = o = RDF::URI("http://example.org/object")
154
- stmt.object.should == o
155
- end
156
-
157
- it "should support #[]= for the context" do
158
- stmt = @stmt.dup
159
- stmt[3] = c = RDF::URI("http://example.org/context")
160
- stmt.context.should == c
161
- end
162
- end
163
-
164
- context "when used like a Hash" do
165
- it "should support #to_hash" do
166
- @stmt.should respond_to(:to_hash)
167
- @stmt.to_hash.should eql({
168
- :subject => @stmt.subject,
169
- :predicate => @stmt.predicate,
170
- :object => @stmt.object,
171
- :context => @stmt.context,
172
- })
173
- end
174
- end
175
-
176
- context "when used like a String" do
177
- it "should support #to_s" do
178
- @stmt.should respond_to(:to_s)
179
- end
180
-
181
- it "should have an N-Triples representation" do
182
- @stmt.to_s.should eql(@n3)
183
- end
184
- end
185
-
186
- context "when comparing equality" do
187
- before :each do
188
- @c = RDF::URI.parse("http://example.org/context")
189
- @other_stmt = RDF::Statement.new(@s, @p, @o, :context => @c)
190
- end
191
-
192
- it "should == regardless of context" do
193
- @stmt.should == @other_stmt
194
- end
195
-
196
- it "should not be eql? with differing contexts" do
197
- @stmt.should_not be_eql(@other_stmt)
198
- end
199
-
200
- it "should match (===) a statement with a missing component to one with that component" do
201
- @stmt.should === @other_stmt
202
- end
203
-
204
- it "should not match (===) a statement with a component to one which is missing that component" do
205
- @other_stmt.should_not === @stmt
206
- end
207
-
208
- it "should only equals? with object equality" do
209
- @same_stmt = RDF::Statement.new @s, @p, @o
210
- @stmt.should_not equal(@same_stmt)
211
- @stmt.should equal(@stmt)
212
- end
213
- end
214
- end
data/lib/rdf/spec/term.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'rdf/spec'
2
-
3
- share_as :RDF_Term do
4
- include RDF::Spec::Matchers
5
-
6
- # TODO
7
- end
data/lib/rdf/spec/uri.rb DELETED
@@ -1,198 +0,0 @@
1
- require 'rdf/spec'
2
-
3
- share_as :RDF_URI do
4
- before :each do
5
- raise '+@new+ must be defined in a before(:each) block' unless instance_variable_get('@new')
6
- end
7
-
8
- it "should be instantiable" do
9
- lambda { @new.call('http://rdf.rubyforge.org/') }.should_not raise_error
10
- end
11
-
12
- it "should recognize URNs" do
13
- urns = %w(urn:isbn:0451450523 urn:isan:0000-0000-9E59-0000-O-0000-0000-2 urn:issn:0167-6423 urn:ietf:rfc:2648 urn:mpeg:mpeg7:schema:2001 urn:oid:2.16.840 urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66 urn:uci:I001+SBSi-B10000083052)
14
- urns.each do |urn|
15
- uri = @new.call(urn)
16
- uri.should be_a_uri
17
- uri.should respond_to(:urn?)
18
- uri.should be_a_urn
19
- uri.should_not be_a_url
20
- end
21
- end
22
-
23
- it "should recognize URLs" do
24
- urls = %w(mailto:jhacker@example.org http://example.org/ ftp://example.org/)
25
- urls.each do |url|
26
- uri = @new.call(url)
27
- uri.should be_a_uri
28
- uri.should respond_to(:url?)
29
- uri.should be_a_url
30
- uri.should_not be_a_urn
31
- end
32
- end
33
-
34
- it "should return the root URI" do
35
- uri = @new.call('http://rdf.rubyforge.org/RDF/URI.html')
36
- uri.should respond_to(:root)
37
- uri.root.should be_a_uri
38
- uri.root.should == @new.call('http://rdf.rubyforge.org/')
39
- end
40
-
41
- it "should find the parent URI" do
42
- uri = @new.call('http://rdf.rubyforge.org/RDF/URI.html')
43
- uri.should respond_to(:parent)
44
- uri.parent.should be_a_uri
45
- uri.parent.should == @new.call('http://rdf.rubyforge.org/RDF/')
46
- uri.parent.parent.should == @new.call('http://rdf.rubyforge.org/')
47
- uri.parent.parent.parent.should be_nil
48
- end
49
-
50
- it "should have a consistent hash code" do
51
- hash1 = @new.call('http://rdf.rubyforge.org/').hash
52
- hash2 = @new.call('http://rdf.rubyforge.org/').hash
53
- hash1.should == hash2
54
- end
55
-
56
- it "should be duplicable" do
57
- url = Addressable::URI.parse('http://rdf.rubyforge.org/')
58
- uri2 = (uri1 = @new.call(url)).dup
59
-
60
- uri1.should_not be_equal(uri2)
61
- uri1.should be_eql(uri2)
62
- uri1.should == uri2
63
-
64
- url.path = '/rdf/'
65
- uri1.should_not be_equal(uri2)
66
- uri1.should_not be_eql(uri2)
67
- uri1.should_not == uri2
68
- end
69
-
70
- it "should not be #anonymous?" do
71
- @new.call('http://example.org').should_not be_anonymous
72
- end
73
-
74
- context "using the smart separator (/)" do
75
- {
76
- # #!! means that I'm not sure I like the semantics, but they are cases for
77
- # arguably invalid input, probably without 'correct' answers.
78
-
79
- %w(http://foo a) => "http://foo/a",
80
- %w(http://foo /a) => "http://foo/a",
81
- %w(http://foo #a) => "http://foo#a",
82
-
83
- %w(http://foo/ a) => "http://foo/a",
84
- %w(http://foo/ /a) => "http://foo/a",
85
- %w(http://foo/ #a) => "http://foo#a", #!!
86
-
87
- %w(http://foo# a) => "http://foo#a",
88
- %w(http://foo# /a) => "http://foo/a", #!!
89
- %w(http://foo# #a) => "http://foo#a",
90
-
91
- %w(http://foo/bar a) => "http://foo/bar/a",
92
- %w(http://foo/bar /a) => "http://foo/bar/a",
93
- %w(http://foo/bar #a) => "http://foo/bar#a",
94
-
95
- %w(http://foo/bar/ a) => "http://foo/bar/a",
96
- %w(http://foo/bar/ /a) => "http://foo/bar/a",
97
- %w(http://foo/bar/ #a) => "http://foo/bar#a", #!!
98
-
99
- %w(http://foo/bar# a) => "http://foo/bar#a",
100
- %w(http://foo/bar# /a) => "http://foo/bar/a", #!!
101
- %w(http://foo/bar# #a) => "http://foo/bar#a",
102
-
103
- %w(urn:isbn: 0451450523) => "urn:isbn:0451450523",
104
- %w(urn:isbn: :0451450523) => "urn:isbn:0451450523",
105
-
106
- %w(urn:isbn 0451450523) => "urn:isbn:0451450523",
107
- %w(urn:isbn :0451450523) => "urn:isbn:0451450523",
108
- }.each_pair do |input, result|
109
- it "should create <#{result}> from <#{input[0]}> and '#{input[1]}'" do
110
- (RDF::URI.new(input[0]) / input[1]).to_s.should == result
111
- (RDF::URI.new(input[0]) / RDF::URI.new(input[1])).to_s.should == result
112
- end
113
- end
114
-
115
- it "should raise an ArgumentError when receiving an absolute URI as a fragment" do
116
- lambda { RDF::URI.new('http://example.org') / RDF::URI.new('http://example.com') }.should raise_error ArgumentError
117
- end
118
- end
119
-
120
- context "using concatenation (#+)" do
121
- {
122
- %w(http://foo/ a) => "http://foo/a",
123
- %w(http://foo/ /a) => "http://foo//a",
124
- %w(http://foo/ #a) => "http://foo/#a",
125
-
126
- %w(urn:isbn :0451450523) => "urn:isbn:0451450523",
127
- %w(urn:isbn 0451450523) => "urn:isbn0451450523",
128
-
129
- %w(http://example.org/test test) => "http://example.org/testtest",
130
- }.each_pair do |input, result|
131
- it "should create <#{result}> from <#{input[0]}> and '#{input[1]}'" do
132
- (RDF::URI.new(input[0]) + input[1]).to_s.should == result
133
- (RDF::URI.new(input[0]) + RDF::URI.new(input[1])).to_s.should == result
134
- end
135
- end
136
- end
137
-
138
- context "using normalized merging (#join)" do
139
-
140
- before :all do
141
- @writer = RDF::Writer.for(:ntriples)
142
- end
143
-
144
- before :each do
145
- @subject = RDF::URI.new("http://example.org")
146
- end
147
-
148
- it "appends fragment to uri" do
149
- @subject.join("foo").to_s.should == "http://example.org/foo"
150
- end
151
-
152
- it "appends another fragment" do
153
- @subject.join("foo#bar").to_s.should == "http://example.org/foo#bar"
154
- end
155
-
156
- it "appends another URI" do
157
- @subject.join(RDF::URI.new("foo#bar")).to_s.should == "http://example.org/foo#bar"
158
- end
159
-
160
- {
161
- %w(http://foo ) => "<http://foo>",
162
- %w(http://foo a) => "<http://foo/a>",
163
- %w(http://foo /a) => "<http://foo/a>",
164
- %w(http://foo #a) => "<http://foo#a>",
165
-
166
- %w(http://foo/ ) => "<http://foo/>",
167
- %w(http://foo/ a) => "<http://foo/a>",
168
- %w(http://foo/ /a) => "<http://foo/a>",
169
- %w(http://foo/ #a) => "<http://foo/#a>",
170
-
171
- %w(http://foo# ) => "<http://foo#>",
172
- %w(http://foo# a) => "<http://foo/a>",
173
- %w(http://foo# /a) => "<http://foo/a>",
174
- %w(http://foo# #a) => "<http://foo#a>",
175
-
176
- %w(http://foo/bar ) => "<http://foo/bar>",
177
- %w(http://foo/bar a) => "<http://foo/a>",
178
- %w(http://foo/bar /a) => "<http://foo/a>",
179
- %w(http://foo/bar #a) => "<http://foo/bar#a>",
180
-
181
- %w(http://foo/bar/ ) => "<http://foo/bar/>",
182
- %w(http://foo/bar/ a) => "<http://foo/bar/a>",
183
- %w(http://foo/bar/ /a) => "<http://foo/a>",
184
- %w(http://foo/bar/ #a) => "<http://foo/bar/#a>",
185
-
186
- %w(http://foo/bar# ) => "<http://foo/bar#>",
187
- %w(http://foo/bar# a) => "<http://foo/a>",
188
- %w(http://foo/bar# /a) => "<http://foo/a>",
189
- %w(http://foo/bar# #a) => "<http://foo/bar#a>",
190
-
191
- }.each_pair do |input, result|
192
- it "creates #{result} from <#{input[0]}> and '#{input[1]}'" do
193
- @writer.serialize(RDF::URI.new(input[0]).join(input[1].to_s)).should == result
194
- end
195
- end
196
- end
197
-
198
- end
@@ -1,28 +0,0 @@
1
- require 'rdf/spec'
2
-
3
- share_as :RDF_Value do
4
- before :each do
5
- raise '+@value+ must be defined in a before(:each) block' unless instance_variable_get('@value')
6
- raise '+@resource+ must be defined in a before(:each) block' unless instance_variable_get('@resource')
7
- end
8
-
9
- describe RDF::Value do
10
- it "should not be instantiable" do
11
- lambda { @value.call }.should raise_error(NoMethodError)
12
- end
13
- end
14
-
15
- describe RDF::Resource do
16
- it "should instantiate blank nodes" do
17
- resource = @resource.call('_:foobar')
18
- resource.class.should == RDF::Node
19
- resource.id.should == 'foobar'
20
- end
21
-
22
- it "should instantiate URIs" do
23
- resource = @resource.call('http://rdf.rubyforge.org/')
24
- resource.class.should == RDF::URI
25
- resource.to_s.should == 'http://rdf.rubyforge.org/'
26
- end
27
- end
28
- end