rdf-spec 1.1.0.p1 → 1.1.0.p2

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,7 @@ module RDF_Format
9
9
  end
10
10
 
11
11
  describe RDF::Format do
12
+ subject {@format_class}
12
13
  describe ".for" do
13
14
  RDF::Format.file_extensions.each do |ext, formats|
14
15
  it "detects #{formats.first} using file path foo.#{ext}" do
@@ -33,7 +34,7 @@ module RDF_Format
33
34
 
34
35
  describe ".reader" do
35
36
  it "returns a reader" do
36
- @format_class.each do |f|
37
+ subject.each do |f|
37
38
  f.reader.should_not be_nil
38
39
  end
39
40
  end
@@ -43,7 +44,7 @@ module RDF_Format
43
44
  ##
44
45
  # May not return a writer, only does if one is defined by the format
45
46
  it "returns a writer" do
46
- @format_class.each do |f|
47
+ subject.each do |f|
47
48
  format_namespace = f.name.split('::')[0..-2].inject(Kernel) {|base, const| base.const_get(const)}
48
49
  f.writer.should_not be_nil if format_namespace.const_defined?(:Writer)
49
50
  end
@@ -9,24 +9,17 @@ module RDF_Indexable
9
9
  end
10
10
 
11
11
  describe RDF::Indexable do
12
- it "responds to #indexed?" do
13
- @indexable.respond_to?(:indexed?)
14
- end
15
-
16
- it "implements #indexed?" do
17
- !!@indexable.indexed?.should == @indexable.indexed?
18
- end
19
-
20
- it "responds to #index!" do
21
- @indexable.respond_to?(:index!)
22
- end
12
+ subject {@indexable}
13
+ it {should respond_to(:indexed?)}
14
+ its(:indexed?) {should == subject.indexed?}
15
+ it {should respond_to(:index!)}
23
16
 
24
17
  it "does not raise error on #index! if #indexed?" do
25
- lambda {@indexable.index!}.should_not raise_error if @indexable.indexed?
18
+ lambda {subject.index!}.should_not raise_error if subject.indexed?
26
19
  end
27
20
 
28
21
  it "raises error on #index! if not #indexed?" do
29
- lambda {@indexable.index!}.should raise_error unless @indexable.indexed?
22
+ lambda {subject.index!}.should raise_error unless subject.indexed?
30
23
  end
31
24
  end
32
25
  end
@@ -8,15 +8,14 @@ module RDF_Mutable
8
8
  before :each do
9
9
  raise '+@mutable+ must be defined in a before(:each) block' unless instance_variable_get('@mutable')
10
10
 
11
- @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
12
-
13
- @subject = RDF::URI('http://rubygems.org/gems/rdf')
14
- @context = RDF::URI('http://example.org/context')
15
-
16
11
  @supports_context = @mutable.respond_to?(:supports?) && @mutable.supports?(:context)
17
12
  end
13
+ let(:resource) {RDF::URI('http://rubygems.org/gems/rdf')}
14
+ let(:context) {RDF::URI('http://example.org/context')}
18
15
 
19
16
  describe RDF::Mutable do
17
+ subject {@mutable}
18
+
20
19
  context "readability" do
21
20
  require 'rdf/spec/readable'
22
21
 
@@ -37,119 +36,123 @@ module RDF_Mutable
37
36
  include RDF_Writable
38
37
  end
39
38
 
40
- it "should be empty initially" do
41
- @mutable.empty?.should be_true
42
- @mutable.count.should be_zero
43
- end
44
-
45
- it "should be readable" do
46
- @mutable.readable?.should be_true
47
- end
48
-
49
- it "should be writable" do
50
- @mutable.writable?.should be_true
51
- end
52
-
53
- it "should be mutable" do
54
- @mutable.immutable?.should be_false
55
- @mutable.mutable?.should be_true
56
- end
39
+ it {should be_empty}
40
+ it {should be_readable}
41
+ it {should be_writable}
42
+ it {should be_mutable}
43
+ it {should_not be_immutable}
44
+ it {should respond_to(:load)}
45
+ it {should respond_to(:clear)}
46
+ it {should respond_to(:delete)}
57
47
 
58
- it "should support #load" do
59
- @mutable.respond_to?(:load).should be_true
60
- end
48
+ its(:count) {should be_zero}
61
49
 
62
50
  context "#load" do
63
51
  it "should require an argument" do
64
- lambda { @mutable.load }.should raise_error(ArgumentError)
52
+ lambda { subject.load }.should raise_error(ArgumentError)
65
53
  end
66
54
 
67
55
  it "should accept a string filename argument" do
68
- lambda { @mutable.load(@filename) }.should_not raise_error(ArgumentError)
56
+ pending("mutability", :unless => subject.mutable?) do
57
+ lambda { subject.load(RDF::Spec::TRIPLES_FILE) }.should_not raise_error(ArgumentError)
58
+ end
69
59
  end
70
60
 
71
61
  it "should accept an optional hash argument" do
72
- lambda { @mutable.load(@filename,{}) }.should_not raise_error(ArgumentError)
62
+ pending("mutability", :unless => subject.mutable?) do
63
+ lambda { subject.load(RDF::Spec::TRIPLES_FILE, {}) }.should_not raise_error(ArgumentError)
64
+ end
73
65
  end
74
66
 
75
67
  it "should load statements" do
76
- @mutable.load @filename
77
- @mutable.size.should == File.readlines(@filename).size
78
- @mutable.should have_subject(@subject)
68
+ pending("mutability", :unless => subject.mutable?) do
69
+ subject.load RDF::Spec::TRIPLES_FILE
70
+ subject.size.should == File.readlines(RDF::Spec::TRIPLES_FILE).size
71
+ subject.should have_subject(resource)
72
+ end
79
73
  end
80
74
 
81
75
  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
76
+ pending("mutability and contextuality", :unless => (subject.mutable? && @supports_context)) do
77
+ subject.load RDF::Spec::TRIPLES_FILE, :context => context
78
+ subject.should have_context(context)
79
+ subject.query(:context => context).size.should == subject.size
86
80
  end
87
81
  end
88
82
  end
89
83
 
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)
84
+ context "#from_{reader}" do
85
+ it "should instantiate a reader" do
86
+ reader = mock("reader")
87
+ reader.should_receive(:new).and_return(RDF::NTriples::Reader.new(""))
88
+ RDF::Reader.should_receive(:for).with(:a_reader).and_return(reader)
89
+ subject.send(:from_a_reader)
94
90
  end
91
+ end
95
92
 
96
- it "should support #delete" do
97
- @mutable.should respond_to(:delete)
93
+ context "when deleting statements" do
94
+ before :each do
95
+ @statements = RDF::NTriples::Reader.new(File.open(RDF::Spec::TRIPLES_FILE)).to_a
96
+ subject.insert(*@statements)
98
97
  end
99
98
 
100
99
  it "should not raise errors" do
101
- lambda { @mutable.delete(@statements.first) }.should_not raise_error
100
+ pending("mutability", :unless => subject.mutable?) do
101
+ lambda { subject.delete(@statements.first) }.should_not raise_error
102
+ end
102
103
  end
103
104
 
104
105
  it "should support deleting one statement at a time" do
105
- @mutable.delete(@statements.first)
106
- @mutable.should_not have_statement(@statements.first)
106
+ pending("mutability", :unless => subject.mutable?) do
107
+ subject.delete(@statements.first)
108
+ subject.should_not have_statement(@statements.first)
109
+ end
107
110
  end
108
111
 
109
112
  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
113
+ pending("mutability", :unless => subject.mutable?) do
114
+ subject.delete(*@statements)
115
+ subject.find { |s| subject.has_statement?(s) }.should be_false
116
+ end
112
117
  end
113
118
 
114
119
  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
120
+ pending("mutability", :unless => subject.mutable?) do
121
+ # nothing deleted
122
+ require 'digest/sha1'
123
+ count = subject.count
124
+ subject.delete([nil, nil, random = Digest::SHA1.hexdigest(File.read(__FILE__))])
125
+ subject.should_not be_empty
126
+ subject.count.should == count
127
+
128
+ # everything deleted
129
+ subject.delete([nil, nil, nil])
130
+ subject.should be_empty
131
+ end
125
132
  end
126
133
 
127
134
  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
148
- end
149
-
150
- context "when clearing all statements" do
151
- it "should support #clear" do
152
- @mutable.should respond_to(:clear)
135
+ pending("mutability", :unless => subject.mutable?) do
136
+ # Setup three statements identical except for context
137
+ count = subject.count + (@supports_context ? 3 : 1)
138
+ s1 = RDF::Statement.new(resource, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:1"))
139
+ s2 = s1.dup
140
+ s2.context = RDF::URI.new("urn:context:1")
141
+ s3 = s1.dup
142
+ s3.context = RDF::URI.new("urn:context:2")
143
+ subject.insert(s1)
144
+ subject.insert(s2)
145
+ subject.insert(s3)
146
+ subject.count.should == count
147
+
148
+ # Delete one by one
149
+ subject.delete(s1)
150
+ subject.count.should == count - (@supports_context ? 1 : 1)
151
+ subject.delete(s2)
152
+ subject.count.should == count - (@supports_context ? 2 : 1)
153
+ subject.delete(s3)
154
+ subject.count.should == count - (@supports_context ? 3 : 1)
155
+ end
153
156
  end
154
157
  end
155
158
  end
@@ -7,69 +7,67 @@ module RDF_Queryable
7
7
  before :each do
8
8
  raise '+@queryable+ must be defined in a before(:each) block' unless instance_variable_get('@queryable')
9
9
 
10
- @doap = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nq'))
11
- @doaps = RDF::NQuads::Reader.new(File.open(@doap)).to_a
12
- @statements = @doaps
10
+ @doap = RDF::Spec::QUADS_FILE
11
+ @statements = RDF::Spec.quads
13
12
 
14
13
  if @queryable.empty?
15
- if @queryable.respond_to?(:<<)
16
- @doaps.each { |statement| @queryable << statement }
14
+ if @queryable.respond_to?(:<<) && (@queryable.writable? rescue true)
15
+ @statements.each { |statement| @queryable << statement }
17
16
  else
18
17
  raise "@queryable must respond to #<< or be pre-populated with the statements in #{@doap} in a before(:each) block"
19
18
  end
20
19
  end
21
-
22
- @subject = RDF::URI('http://rubygems.org/gems/rdf')
23
20
  end
21
+ let(:resource) {RDF::URI('http://rubygems.org/gems/rdf')}
22
+ let(:literal) {RDF::Literal.new('J. Random Hacker')}
24
23
 
25
24
  describe RDF::Queryable do
25
+ subject {@queryable}
26
26
  ##
27
27
  # @see RDF::Queryable#query
28
28
  describe "#query" do
29
- it "should respond to #query" do
30
- @queryable.should respond_to(:query)
31
- end
29
+ it {should respond_to(:query)}
32
30
 
33
31
  context "when called" do
34
32
  it "requires an argument" do
35
- lambda { @queryable.query }.should raise_error(ArgumentError)
33
+ lambda { subject.query }.should raise_error(ArgumentError)
36
34
  end
37
35
 
38
36
  it "accepts a pattern argument" do
39
- lambda { @queryable.query(RDF::Query::Pattern.new(nil, nil, nil)) }.should_not raise_error(ArgumentError)
40
- lambda { @queryable.query(RDF::Query::Pattern.new(:s, :p, :o)) }.should_not raise_error(ArgumentError)
37
+ lambda { subject.query(RDF::Query::Pattern.new(nil, nil, nil)) }.should_not raise_error(ArgumentError)
38
+ lambda { subject.query(RDF::Query::Pattern.new(:s, :p, :o)) }.should_not raise_error(ArgumentError)
41
39
  end
42
40
 
43
41
  it "accepts a statement argument" do
44
- lambda { @queryable.query(RDF::Statement.new(nil, nil, nil)) }.should_not raise_error(ArgumentError)
42
+ lambda { subject.query(RDF::Statement.new(nil, nil, nil)) }.should_not raise_error(ArgumentError)
45
43
  end
46
44
 
47
45
  it "accepts a triple argument" do
48
- lambda { @queryable.query([nil, nil, nil]) }.should_not raise_error(ArgumentError)
46
+ lambda { subject.query([nil, nil, nil]) }.should_not raise_error(ArgumentError)
49
47
  end
50
48
 
51
49
  it "accepts a quad argument" do
52
- lambda { @queryable.query([nil, nil, nil, nil]) }.should_not raise_error(ArgumentError)
50
+ lambda { subject.query([nil, nil, nil, nil]) }.should_not raise_error(ArgumentError)
53
51
  end
54
52
 
55
53
  it "accepts a hash argument" do
56
- lambda { @queryable.query({}) }.should_not raise_error(ArgumentError)
54
+ lambda { subject.query({}) }.should_not raise_error(ArgumentError)
57
55
  end
58
56
 
59
57
  it "does not alter a given hash argument" do
60
- query = {:subject => @subject, :predicate => RDF::DOAP.name, :object => RDF::FOAF.Person}
58
+ query = {:subject => resource, :predicate => RDF::DOAP.name, :object => RDF::FOAF.Person}
61
59
  original_query = query.dup
62
- @queryable.query(query)
60
+ subject.query(query)
63
61
  query.should == original_query
64
62
  end
65
63
 
66
64
  it "rejects other kinds of arguments" do
67
- lambda { @queryable.query(nil) }.should raise_error(ArgumentError)
65
+ lambda { subject.query(nil) }.should raise_error(ArgumentError)
68
66
  end
69
67
 
70
68
  context "with a block" do
71
69
  it "yields statements" do
72
- @queryable.query([nil, nil, nil]) do |statement|
70
+ subject.query([nil, nil, nil]) do |statement|
73
71
  statement.should be_a_statement
74
72
  end
75
73
  end
@@ -77,48 +75,48 @@ module RDF_Queryable
77
75
 
78
76
  context "without a block" do
79
77
  it "returns an enumerator" do
80
- @queryable.query([nil, nil, nil]).should be_an_enumerator
78
+ subject.query([nil, nil, nil]).should be_an_enumerator
81
79
  end
82
80
 
83
81
  it "returns an enumerable enumerator" do
84
- @queryable.query([nil, nil, nil]).should be_enumerable
82
+ subject.query([nil, nil, nil]).should be_enumerable
85
83
  end
86
84
 
87
85
  it "returns a queryable enumerator" do
88
- @queryable.query([nil, nil, nil]).should be_queryable
86
+ subject.query([nil, nil, nil]).should be_queryable
89
87
  end
90
88
 
91
89
  it "returns statements" do
92
- @queryable.query([nil, nil, nil]).each do |statement|
90
+ subject.query([nil, nil, nil]).each do |statement|
93
91
  statement.should be_a_statement
94
92
  end
95
93
  end
96
94
 
97
95
  it "returns the correct number of results for array queries" do
98
- @queryable.query([nil, nil, nil]).size.should == @statements.size
99
- @queryable.query([@subject, nil, nil]).size.should == File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
100
- @queryable.query([RDF::URI("http://ar.to/#self"), nil, nil]).size.should == File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
101
- @queryable.query([@subject, RDF::DOAP.name, nil]).size.should == 1
102
- @queryable.query([nil, nil, RDF::DOAP.Project]).size.should == 1
96
+ subject.query([nil, nil, nil]).size.should == @statements.size
97
+ subject.query([resource, nil, nil]).size.should == File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
98
+ subject.query([RDF::URI("http://ar.to/#self"), nil, nil]).size.should == File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
99
+ subject.query([resource, RDF::DOAP.name, nil]).size.should == 1
100
+ subject.query([nil, nil, RDF::DOAP.Project]).size.should == 1
103
101
  end
104
102
 
105
103
  it "returns the correct number of results for hash queries" do
106
- @queryable.query({}).size.should == @statements.size
107
- @queryable.query(:subject => @subject) .size.should == File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
108
- @queryable.query(:subject => @subject, :predicate => RDF::DOAP.name).size.should == 1
109
- @queryable.query(:object => RDF::DOAP.Project).size.should == 1
104
+ subject.query({}).size.should == @statements.size
105
+ subject.query(:subject => resource) .size.should == File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
106
+ subject.query(:subject => resource, :predicate => RDF::DOAP.name).size.should == 1
107
+ subject.query(:object => RDF::DOAP.Project).size.should == 1
110
108
  end
111
109
  end
112
110
 
113
111
  context "with specific patterns from SPARQL" do
114
112
  context "triple pattern combinations" do
115
113
  it "?s p o" do
116
- @queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal.new(1)).to_a.should ==
114
+ subject.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal.new(1)).to_a.should ==
117
115
  [RDF::Statement.new(RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1), RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
118
116
  end
119
117
 
120
118
  it "s ?p o" do
121
- @queryable.query(:subject => RDF::URI("http://example.org/xi2"), :object => RDF::Literal.new(1)).to_a.should ==
119
+ subject.query(:subject => RDF::URI("http://example.org/xi2"), :object => RDF::Literal.new(1)).to_a.should ==
122
120
  [RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
123
121
  end
124
122
  end
@@ -126,35 +124,24 @@ module RDF_Queryable
126
124
  # From data-r2/expr-equals
127
125
  context "data/r2/expr-equals" do
128
126
  context "graph-1" do
129
- before(:each) do
130
- @solutions = @queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Integer.new(1)).to_a
131
- end
127
+ subject {@queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Integer.new(1)).to_a}
128
+ its(:count) {should == 2}
132
129
 
133
130
  it "has two solutions" do
134
- @solutions.count.should == 2
135
- end
136
-
137
- it "has xi1 as a solution" do
138
- @solutions.any? {|s| s.subject == RDF::URI("http://example.org/xi1")}.should be_true
131
+ subject.any? {|s| s.subject == RDF::URI("http://example.org/xi1")}.should be_true
139
132
  end
140
133
 
141
134
  it "has xi2 as a solution" do
142
- @solutions.any? {|s| s.subject == RDF::URI("http://example.org/xi2")}.should be_true
135
+ subject.any? {|s| s.subject == RDF::URI("http://example.org/xi2")}.should be_true
143
136
  end
144
137
  end
145
138
 
146
-
147
139
  context "graph-2" do
148
- before(:each) do
149
- @solutions = @queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Double.new("1.0e0")).to_a
150
- end
151
-
152
- it "has one solution" do
153
- @solutions.count.should == 1
154
- end
140
+ subject {@queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Double.new("1.0e0")).to_a}
141
+ its(:count) {should == 1}
155
142
 
156
143
  it "has xd1 as a solution" do
157
- @solutions.any? {|s| s.subject == RDF::URI("http://example.org/xd1")}.should be_true
144
+ subject.any? {|s| s.subject == RDF::URI("http://example.org/xd1")}.should be_true
158
145
  end
159
146
  end
160
147
  end
@@ -166,17 +153,17 @@ module RDF_Queryable
166
153
  # @see RDF::Queryable#query_pattern
167
154
  describe "#query_pattern" do
168
155
  it "defines a protected #query_pattern method" do
169
- @queryable.class.protected_method_defined?(:query_pattern).should be_true
156
+ subject.class.protected_method_defined?(:query_pattern).should be_true
170
157
  end
171
158
 
172
159
  context "when called" do
173
160
  it "requires an argument" do
174
- lambda { @queryable.send(:query_pattern) }.should raise_error(ArgumentError)
161
+ lambda { subject.send(:query_pattern) }.should raise_error(ArgumentError)
175
162
  end
176
163
 
177
164
  it "yields to the given block" do
178
165
  called = false
179
- @queryable.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
166
+ subject.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
180
167
  called = true
181
168
  break
182
169
  end
@@ -184,7 +171,7 @@ module RDF_Queryable
184
171
  end
185
172
 
186
173
  it "yields statements" do
187
- @queryable.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
174
+ subject.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
188
175
  statement.should be_a_statement
189
176
  end
190
177
  end
@@ -202,7 +189,7 @@ module RDF_Queryable
202
189
  pattern = RDF::Query::Pattern.from(pattern)
203
190
  it "returns #{result.inspect} given #{pattern.inspect}" do
204
191
  solutions = []
205
- @queryable.send(:query_pattern, pattern) {|s| solutions << s}
192
+ subject.send(:query_pattern, pattern) {|s| solutions << s}
206
193
  solutions.should == result
207
194
  end
208
195
  end
@@ -212,33 +199,33 @@ module RDF_Queryable
212
199
  it "returns statements from all contexts with no context" do
213
200
  pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => nil)
214
201
  solutions = []
215
- @queryable.send(:query_pattern, pattern) {|s| solutions << s}
202
+ subject.send(:query_pattern, pattern) {|s| solutions << s}
216
203
  solutions.size.should == @statements.size
217
204
  end
218
205
 
219
206
  it "returns statements from unnamed contexts with false context" do
220
207
  pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => false)
221
208
  solutions = []
222
- @queryable.send(:query_pattern, pattern) {|s| solutions << s}
223
- context_statements = @queryable.statements.reject {|st| st.has_context?}.length
209
+ subject.send(:query_pattern, pattern) {|s| solutions << s}
210
+ context_statements = subject.statements.reject {|st| st.has_context?}.length
224
211
  solutions.size.should == context_statements
225
212
  end
226
213
 
227
214
  it "returns statements from named contexts with variable context" do
228
- unless @queryable.contexts.to_a.empty?
215
+ unless subject.contexts.to_a.empty?
229
216
  pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => :c)
230
217
  solutions = []
231
- @queryable.send(:query_pattern, pattern) {|s| solutions << s}
232
- context_statements = @queryable.statements.select {|st| st.has_context?}.length
218
+ subject.send(:query_pattern, pattern) {|s| solutions << s}
219
+ context_statements = subject.statements.select {|st| st.has_context?}.length
233
220
  solutions.size.should == context_statements
234
221
  end
235
222
  end
236
223
 
237
224
  it "returns statements from specific context with URI context" do
238
- unless @queryable.contexts.to_a.empty?
225
+ unless subject.contexts.to_a.empty?
239
226
  pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => RDF::URI("http://ar.to/#self"))
240
227
  solutions = []
241
- @queryable.send(:query_pattern, pattern) {|s| solutions << s}
228
+ subject.send(:query_pattern, pattern) {|s| solutions << s}
242
229
  solutions.size.should == File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
243
230
  end
244
231
  end
@@ -249,68 +236,64 @@ module RDF_Queryable
249
236
  ##
250
237
  # @see RDF::Queryable#first
251
238
  describe "#first" do
252
- before :all do
253
- @failing_pattern = [RDF::Node.new] * 3
254
- end
239
+ let(:failing_pattern) {[RDF::Node.new] * 3}
255
240
 
256
241
  it "should respond to #first" do
257
- @queryable.should respond_to(:first)
242
+ subject.should respond_to(:first)
258
243
  end
259
244
 
260
245
  it "returns enumerator without a pattern" do
261
- lambda { @queryable.first }.should_not raise_error(ArgumentError)
262
- @queryable.first.should == @queryable.each.first # uses an Enumerator
246
+ lambda { subject.first }.should_not raise_error(ArgumentError)
247
+ subject.first.should == subject.each.first # uses an Enumerator
263
248
  end
264
249
 
265
250
  it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
266
- matching_patterns = [[nil, nil, nil], @queryable.each.first]
251
+ matching_patterns = [[nil, nil, nil], subject.each.first]
267
252
  matching_patterns.each do |matching_pattern|
268
- @queryable.first(matching_pattern).should == @queryable.query(matching_pattern).each.first
253
+ subject.first(matching_pattern).should == subject.query(matching_pattern).each.first
269
254
  end
270
255
  end
271
256
 
272
257
  it "returns nil when the pattern fails to match anything" do
273
- @queryable.first(@failing_pattern).should be_nil
258
+ subject.first(failing_pattern).should be_nil
274
259
  end
275
260
 
276
261
  it "returns nil when self is empty" do
277
262
  queryable = [].extend(RDF::Queryable)
278
263
  queryable.first.should be_nil
279
- queryable.first(@failing_pattern).should be_nil
264
+ queryable.first(failing_pattern).should be_nil
280
265
  end
281
266
  end
282
267
 
283
268
  ##
284
269
  # @see RDF::Queryable#first_subject
285
270
  describe "#first_subject" do
286
- before :all do
287
- @failing_pattern = [RDF::Node.new, nil, nil]
288
- end
271
+ let(:failing_pattern) {[RDF::Node.new, nil, nil]}
289
272
 
290
273
  it "should respond to #first_subject" do
291
- @queryable.should respond_to(:first_subject)
274
+ subject.should respond_to(:first_subject)
292
275
  end
293
276
 
294
277
  it "returns enumerator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
295
- lambda { @queryable.first_subject }.should_not raise_error(ArgumentError)
296
- @queryable.first_subject.should == @queryable.first.subject
278
+ lambda { subject.first_subject }.should_not raise_error(ArgumentError)
279
+ subject.first_subject.should == subject.first.subject
297
280
  end
298
281
 
299
282
  it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
300
- matching_patterns = [[nil, nil, nil], [@queryable.first.subject, nil, nil]]
283
+ matching_patterns = [[nil, nil, nil], [subject.first.subject, nil, nil]]
301
284
  matching_patterns.each do |matching_pattern|
302
- @queryable.first_subject(matching_pattern).should == @queryable.query(matching_pattern).first.subject
285
+ subject.first_subject(matching_pattern).should == subject.query(matching_pattern).first.subject
303
286
  end
304
287
  end
305
288
 
306
289
  it "returns nil when the pattern fails to match anything" do
307
- @queryable.first_subject(@failing_pattern).should be_nil
290
+ subject.first_subject(failing_pattern).should be_nil
308
291
  end
309
292
 
310
293
  it "returns nil when self is empty" do
311
294
  queryable = [].extend(RDF::Queryable)
312
295
  queryable.first_subject.should be_nil
313
- queryable.first_subject(@failing_pattern).should be_nil
296
+ queryable.first_subject(failing_pattern).should be_nil
314
297
  end
315
298
  end
316
299
 
@@ -318,34 +301,30 @@ module RDF_Queryable
318
301
  # @see RDF::Queryable#first_predicate
319
302
 
320
303
  describe "#first_predicate" do
321
- before :all do
322
- @failing_pattern = [nil, RDF::Node.new, nil]
323
- end
304
+ let(:failing_pattern) {[nil, RDF::Node.new, nil]}
324
305
 
325
- it "should respond to #first_predicate" do
326
- @queryable.should respond_to(:first_predicate)
327
- end
306
+ it {should respond_to(:first_predicate)}
328
307
 
329
308
  it "returns enumerator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
330
- lambda { @queryable.first_predicate }.should_not raise_error(ArgumentError)
331
- @queryable.first_predicate.should == @queryable.first.predicate
309
+ lambda { subject.first_predicate }.should_not raise_error(ArgumentError)
310
+ subject.first_predicate.should == subject.first.predicate
332
311
  end
333
312
 
334
313
  it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
335
- matching_patterns = [[nil, nil, nil], [nil, @queryable.first.predicate, nil]]
314
+ matching_patterns = [[nil, nil, nil], [nil, subject.first.predicate, nil]]
336
315
  matching_patterns.each do |matching_pattern|
337
- @queryable.first_predicate(matching_pattern).should == @queryable.query(matching_pattern).first.predicate
316
+ subject.first_predicate(matching_pattern).should == subject.query(matching_pattern).first.predicate
338
317
  end
339
318
  end
340
319
 
341
320
  it "returns nil when the pattern fails to match anything" do
342
- @queryable.first_predicate(@failing_pattern).should be_nil
321
+ subject.first_predicate(failing_pattern).should be_nil
343
322
  end
344
323
 
345
324
  it "returns nil when self is empty" do
346
325
  queryable = [].extend(RDF::Queryable)
347
326
  queryable.first_predicate.should be_nil
348
- queryable.first_predicate(@failing_pattern).should be_nil
327
+ queryable.first_predicate(failing_pattern).should be_nil
349
328
  end
350
329
  end
351
330
 
@@ -353,76 +332,67 @@ module RDF_Queryable
353
332
  # @see RDF::Queryable#first_object
354
333
 
355
334
  describe "#first_object" do
356
- before :all do
357
- @failing_pattern = [nil, nil, RDF::Node.new]
358
- end
359
-
360
- it "should respond to #first_object" do
361
- @queryable.should respond_to(:first_object)
362
- end
335
+ let(:failing_pattern) {[nil, nil, RDF::Node.new]}
336
+ it {should respond_to(:first_object)}
363
337
 
364
338
  it "returns enurator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
365
- lambda { @queryable.first_object }.should_not raise_error(ArgumentError)
366
- @queryable.first_object.should == @queryable.first.object
339
+ lambda { subject.first_object }.should_not raise_error(ArgumentError)
340
+ subject.first_object.should == subject.first.object
367
341
  end
368
342
 
369
343
  it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
370
- matching_patterns = [[nil, nil, nil], [nil, nil, @queryable.first.object]]
344
+ matching_patterns = [[nil, nil, nil], [nil, nil, subject.first.object]]
371
345
  matching_patterns.each do |matching_pattern|
372
- @queryable.first_object(matching_pattern).should == @queryable.query(matching_pattern).first.object
346
+ subject.first_object(matching_pattern).should == subject.query(matching_pattern).first.object
373
347
  end
374
348
  end
375
349
 
376
350
  it "returns nil when the pattern fails to match anything" do
377
- @queryable.first_object(@failing_pattern).should be_nil
351
+ subject.first_object(failing_pattern).should be_nil
378
352
  end
379
353
 
380
354
  it "returns nil when self is empty" do
381
355
  queryable = [].extend(RDF::Queryable)
382
356
  queryable.first_object.should be_nil
383
- queryable.first_object(@failing_pattern).should be_nil
357
+ queryable.first_object(failing_pattern).should be_nil
384
358
  end
385
359
  end
386
360
 
387
361
  ##
388
362
  # @see RDF::Queryable#first_literal
389
363
 
390
- it "returns to #first_literal" do
391
- @queryable.should respond_to(:first_literal)
392
- end
393
-
394
364
  describe "#first_literal" do
395
- before :each do
396
- # FIXME: these tests should be using the provided @queryable, if possible.
397
- @queryable = RDF::Graph.new do |graph|
398
- @subject = RDF::Node.new
399
- graph << [@subject, RDF.type, RDF::DOAP.Project]
400
- graph << [@subject, RDF::DC.creator, RDF::URI.new('http://example.org/#jhacker')]
401
- graph << [@subject, RDF::DC.creator, @literal = RDF::Literal.new('J. Random Hacker')]
365
+ let(:failing_pattern) {[nil, nil, RDF::Node.new]}
366
+ let(:resource) {RDF::Node.new}
367
+ subject {
368
+ RDF::Graph.new do |graph|
369
+ graph << [resource, RDF.type, RDF::DOAP.Project]
370
+ graph << [resource, RDF::DC.creator, RDF::URI.new('http://example.org/#jhacker')]
371
+ graph << [resource, RDF::DC.creator, literal]
402
372
  end
403
- @failing_pattern = [nil, nil, RDF::Node.new]
404
- end
373
+ }
374
+ it {should respond_to(:first_literal)}
405
375
 
406
376
  it "returns a literal without a pattern" do
407
- lambda { @queryable.first_literal }.should_not raise_error(ArgumentError)
408
- @queryable.first_literal.should == @literal
377
+ lambda { subject.first_literal }.should_not raise_error(ArgumentError)
378
+ subject.first_literal.should == literal
409
379
  end
410
380
 
411
381
  it "returns the correct value when the pattern matches" do
412
- matching_patterns = [[nil, nil, nil], [@subject, nil, nil], [nil, RDF::DC.creator, nil], [nil, nil, @literal]]
382
+ matching_patterns = [[nil, nil, nil], [resource, nil, nil], [nil, RDF::DC.creator, nil], [nil, nil, literal]]
413
383
  matching_patterns.each do |matching_pattern|
414
- @queryable.first_literal(matching_pattern).should == @literal
384
+ subject.first_literal(matching_pattern).should == literal
415
385
  end
416
386
  end
417
387
 
418
388
  it "returns nil when the pattern fails to match anything" do
419
- @queryable.first_literal(@failing_pattern).should be_nil
389
+ subject.first_literal(failing_pattern).should be_nil
420
390
  end
421
391
 
422
392
  it "returns nil when self is empty" do
423
393
  queryable = [].extend(RDF::Queryable)
424
394
  queryable.first_literal.should be_nil
425
- queryable.first_literal(@failing_pattern).should be_nil
395
+ queryable.first_literal(failing_pattern).should be_nil
426
396
  end
427
397
  end
428
398
 
@@ -430,40 +400,35 @@ module RDF_Queryable
430
400
  # @see RDF::Queryable#first_value
431
401
 
432
402
  describe "#first_value" do
433
- before :all do
434
- @failing_pattern = [nil, nil, RDF::Node.new]
435
- end
436
-
437
- it "should respond to #first_value" do
438
- @queryable.should respond_to(:first_value)
439
- end
403
+ let(:failing_pattern) {[nil, nil, RDF::Node.new]}
404
+ it {should respond_to(:first_value)}
440
405
 
441
406
  it "returns first literal without a pattern" do
442
- lambda { @queryable.first_value }.should_not raise_error(ArgumentError)
443
- @queryable.first_value.should == @queryable.first_literal.value
407
+ lambda { subject.first_value }.should_not raise_error(ArgumentError)
408
+ subject.first_value.should == subject.first_literal.value
444
409
  end
445
410
 
446
411
  it "returns the correct value when the pattern matches" do
447
412
  matching_patterns = []
448
- @queryable.each do |statement|
413
+ subject.each do |statement|
449
414
  if statement.object.is_a?(RDF::Literal)
450
415
  matching_pattern = [statement.subject, statement.predicate, nil]
451
416
  unless matching_patterns.include?(matching_pattern)
452
417
  matching_patterns << matching_pattern
453
- @queryable.first_value(matching_pattern).should == @queryable.first_literal(matching_pattern).value
418
+ subject.first_value(matching_pattern).should == subject.first_literal(matching_pattern).value
454
419
  end
455
420
  end
456
421
  end
457
422
  end
458
423
 
459
424
  it "returns nil when the pattern fails to match anything" do
460
- @queryable.first_value(@failing_pattern).should be_nil
425
+ subject.first_value(failing_pattern).should be_nil
461
426
  end
462
427
 
463
428
  it "returns nil when self is empty" do
464
429
  queryable = [].extend(RDF::Queryable)
465
430
  queryable.first_value.should be_nil
466
- queryable.first_value(@failing_pattern).should be_nil
431
+ queryable.first_value(failing_pattern).should be_nil
467
432
  end
468
433
  end
469
434
  end