rdf-spec 0.1.0 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -15,7 +15,7 @@ Documentation
15
15
  Dependencies
16
16
  ------------
17
17
 
18
- * [RDF.rb](http://gemcutter.org/gems/rdf) (>= 0.1.0)
18
+ * [RDF.rb](http://gemcutter.org/gems/rdf) (>= 0.1.4)
19
19
  * [RSpec](http://gemcutter.org/gems/rspec) (>= 1.3.0)
20
20
 
21
21
  Installation
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.4
@@ -0,0 +1,50 @@
1
+ require 'rdf/spec'
2
+ require 'spec'
3
+
4
+ # To use RDF::Durable to check that a repository maintains information between
5
+ # instantiations, add a Proc that creates a repository before each item, and
6
+ # clean that up after every run. Example:
7
+ #describe RDF::DataObjects::Repository do
8
+ # context "The SQLite adapter" do
9
+ # before :each do
10
+ # @repository = RDF::DataObjects::Repository.new "sqlite3://:memory:"
11
+ # @load_durable = lambda { RDF::DataObjects::Repository.new "sqlite3:test.db" }
12
+ # end
13
+ #
14
+ # after :each do
15
+ # File.delete('test.db') if File.exists?('test.db')
16
+ # end
17
+ #
18
+ # it_should_behave_like RDF_Repository
19
+ # end
20
+ #end
21
+ share_as :RDF_Durable do
22
+ include RDF::Spec::Matchers
23
+
24
+ before :each do
25
+ raise '+@load_durable+ must be defined in a before(:each) block' unless instance_variable_get('@load_durable')
26
+ # RDF::Queryable cares about the contents of this file too much to let someone set it
27
+ @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
28
+ end
29
+
30
+
31
+ it "should support #durable?" do
32
+ @load_durable.call.should respond_to(:durable?)
33
+ [true,false].member?(@load_durable.call.durable?).should be_true
34
+ end
35
+
36
+ it "should support #nondurable?" do
37
+ @load_durable.call.should respond_to(:nondurable?)
38
+ [true,false].member?(@load_durable.call.nondurable?).should be_true
39
+ end
40
+
41
+ it "should not be both durable and nondurable" do
42
+ @load_durable.call.nondurable?.should_not == @load_durable.call.durable?
43
+ end
44
+
45
+ it "should save contents between instantiations" do
46
+ @load_durable.call.load(@filename)
47
+ @load_durable.call.count.should == File.readlines(@filename).size
48
+ end
49
+ end
50
+
@@ -57,6 +57,13 @@ module RDF; module Spec
57
57
  end
58
58
  end
59
59
 
60
+ define :be_a_node do
61
+ match do |value|
62
+ value.should be_a_kind_of(RDF::Node)
63
+ true
64
+ end
65
+ end
66
+
60
67
  define :be_a_uri do
61
68
  match do |value|
62
69
  value.should be_a_kind_of(RDF::URI)
@@ -0,0 +1,132 @@
1
+ require 'rdf'
2
+ require 'rdf/spec'
3
+ require 'rdf/ntriples'
4
+
5
+ share_as :RDF_Mutable do
6
+
7
+ include RDF::Spec::Matchers
8
+
9
+ before :each do
10
+ raise '+@filename+ must be defined in a before(:each) block' unless instance_variable_get('@filename')
11
+ raise '+@repository+ must be defined in a before(:each) block' unless instance_variable_get('@repository')
12
+ raise '+@subject+ must be defined in a before(:each) block' unless instance_variable_get('@subject')
13
+ raise '+@context+ must be defined in a before(:each) block' unless instance_variable_get('@context')
14
+ end
15
+
16
+ it "should be empty initially" do
17
+ @repository.empty?.should be_true
18
+ @repository.count.should be_zero
19
+ end
20
+
21
+ it "should be readable" do
22
+ @repository.readable?.should be_true
23
+ end
24
+
25
+ it "should be writable" do
26
+ @repository.writable?.should be_true
27
+ end
28
+
29
+ it "should be mutable" do
30
+ @repository.immutable?.should be_false
31
+ @repository.mutable?.should be_true
32
+ end
33
+
34
+ it "should support #load" do
35
+ @repository.respond_to?(:load).should be_true
36
+ end
37
+
38
+ context "#load" do
39
+ it "should require an argument" do
40
+ lambda { @repository.load }.should raise_error(ArgumentError)
41
+ end
42
+
43
+ it "should accept a string filename argument" do
44
+ lambda { @repository.load(@filename) }.should_not raise_error(ArgumentError)
45
+ end
46
+
47
+ it "should accept an optional hash argument" do
48
+ lambda { @repository.load(@filename,{}) }.should_not raise_error(ArgumentError)
49
+ end
50
+
51
+ it "should load statements" do
52
+ @repository.load @filename
53
+ @repository.size.should == File.readlines(@filename).size
54
+ @repository.should have_subject @subject
55
+ end
56
+
57
+ it "should load statements with a context override" do
58
+ @repository.load @filename, :context => @context
59
+ @repository.should have_context @context
60
+ @repository.query(:context => @context).size.should == @repository.size
61
+ end
62
+
63
+ end
64
+
65
+ context "when inserting statements" do
66
+
67
+ before :each do
68
+ @statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
69
+ end
70
+
71
+ it "should support #insert" do
72
+ @repository.should respond_to(:insert)
73
+ end
74
+
75
+ it "should not raise errors" do
76
+ lambda { @repository.insert(@statements.first) }.should_not raise_error
77
+ end
78
+
79
+ it "should support inserting one statement at a time" do
80
+ @repository.insert(@statements.first)
81
+ @repository.should have_statement(@statements.first)
82
+ end
83
+
84
+ it "should support inserting multiple statements at a time" do
85
+ @repository.insert(*@statements)
86
+ end
87
+
88
+ it "should insert statements successfully" do
89
+ @repository.insert(*@statements)
90
+ @repository.count.should == @statements.size
91
+ end
92
+
93
+ it "should not insert a statement twice" do
94
+ @repository.insert(@statements.first)
95
+ @repository.insert(@statements.first)
96
+ @repository.count.should == 1
97
+ end
98
+ end
99
+
100
+ context "when deleting statements" do
101
+
102
+ before :each do
103
+ @statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
104
+ @repository.insert(*@statements)
105
+ end
106
+
107
+ it "should support #delete" do
108
+ @repository.should respond_to(:delete)
109
+ end
110
+
111
+ it "should not raise errors" do
112
+ lambda { @repository.delete(@statements.first) }.should_not raise_error
113
+ end
114
+
115
+ it "should support deleting one statement at a time" do
116
+ @repository.delete(@statements.first)
117
+ @repository.should_not have_statement(@statements.first)
118
+ end
119
+
120
+ it "should support deleting multiple statements at a time" do
121
+ @repository.delete(*@statements)
122
+ @statements.find { |s| @repository.has_statement?(s) }.should be_false
123
+ end
124
+
125
+ end
126
+
127
+ context "when clearing all statements" do
128
+ it "should support #clear" do
129
+ @repository.should respond_to(:clear)
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,80 @@
1
+ require 'rdf/spec'
2
+ require 'spec'
3
+
4
+ share_as :RDF_Queryable do
5
+ include RDF::Spec::Matchers
6
+
7
+ before :each do
8
+ # RDF::Queryable cares about the contents of this file too much to let someone set it
9
+ @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
10
+ raise '+@queryable+ must be defined in a before(:each) block' unless instance_variable_get('@queryable')
11
+ raise '+@subject+ must be defined in a before(:each) block' unless instance_variable_get('@subject')
12
+ if @queryable.empty?
13
+ if @queryable.respond_to?(:insert)
14
+ @queryable.insert(*(RDF::NTriples::Reader.new(File.open(@filename)).to_a))
15
+ else
16
+ raise "@queryable must be mutable or pre-populated with the statements in #{@filename} in a before(:each)"
17
+ end
18
+ end
19
+ end
20
+
21
+ it "should support #query" do
22
+ @queryable.respond_to?(:query).should be_true
23
+ end
24
+
25
+ context "#query" do
26
+ it "should require an argument" do
27
+ lambda { @queryable.query }.should raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should accept a triple argument" do
31
+ lambda { @queryable.query([nil, nil, nil]) }.should_not raise_error(ArgumentError)
32
+ end
33
+
34
+ it "should accept a hash argument" do
35
+ lambda { @queryable.query({}) }.should_not raise_error(ArgumentError)
36
+ end
37
+
38
+ it "should accept a statement argument" do
39
+ lambda { @queryable.query(RDF::Statement.new(nil, nil, nil)) }.should_not raise_error(ArgumentError)
40
+ end
41
+
42
+ it "should accept a pattern argument" do
43
+ lambda { @queryable.query(RDF::Query::Pattern.new(nil, nil, nil)) }.should_not raise_error(ArgumentError)
44
+ lambda { @queryable.query(RDF::Query::Pattern.new(:s, :p, :o)) }.should_not raise_error(ArgumentError)
45
+ end
46
+
47
+ it "should reject other arguments" do
48
+ lambda { @queryable.query(nil) }.should raise_error(ArgumentError)
49
+ end
50
+
51
+ it "should return RDF statements" do
52
+ @queryable.query([nil, nil, nil]).each do |statement|
53
+ statement.should be_a_statement
54
+ end
55
+ end
56
+
57
+ it "should return the correct number of results for array queries" do
58
+ @queryable.query([nil, nil, nil]).size.should == File.readlines(@filename).size
59
+ @queryable.query([@subject, nil, nil]).size.should == File.readlines(@filename).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
60
+ @queryable.query([@subject, RDF::DOAP.name, nil]).size.should == 1
61
+ @queryable.query([@subject, RDF::DOAP.developer, nil]).size.should == @queryable.query([nil, nil, RDF::FOAF.Person]).size
62
+ @queryable.query([nil, nil, RDF::DOAP.Project]).size.should == 1
63
+ end
64
+
65
+ it "should return the correct number of results for hash queries" do
66
+ @queryable.query({}).size.should == File.readlines(@filename).size
67
+ @queryable.query(:subject => @subject) .size.should == File.readlines(@filename).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
68
+ @queryable.query(:subject => @subject, :predicate => RDF::DOAP.name).size.should == 1
69
+ @queryable.query(:subject => @subject, :predicate => RDF::DOAP.developer).size.should == @queryable.query(:object => RDF::FOAF.Person).size
70
+ @queryable.query(:object => RDF::DOAP.Project).size.should == 1
71
+ end
72
+
73
+ it "should not alter a given hash argument" do
74
+ query = { :subject => @subject, :predicate => RDF::DOAP.name, :object => RDF::FOAF.Person }
75
+ original_query = query.dup
76
+ result = @queryable.query(query)
77
+ query.should == original_query
78
+ end
79
+ end
80
+ end
@@ -11,52 +11,16 @@ share_as :RDF_Repository do
11
11
  @enumerable = @repository
12
12
  end
13
13
 
14
- it "should be empty initially" do
15
- @repository.empty?.should be_true
16
- @repository.count.should be_zero
17
- end
18
-
19
- it "should be readable" do
20
- @repository.readable?.should be_true
21
- end
22
-
23
- it "should be mutable" do
24
- @repository.immutable?.should be_false
25
- @repository.mutable?.should be_true
26
- end
27
-
28
- context "when inserting statements" do
29
- it "should support #insert" do
30
- @repository.should respond_to(:insert)
31
- end
32
-
33
- it "should not raise errors" do
34
- lambda { @repository.insert(@statements.first) }.should_not raise_error
35
- end
36
-
37
- it "should support inserting one statement at a time" do
38
- @repository.insert(@statements.first)
39
- end
40
-
41
- it "should support inserting multiple statements at a time" do
42
- @repository.insert(*@statements)
43
- end
14
+ context "when updating" do
15
+ require 'rdf/spec/mutable'
44
16
 
45
- it "should insert statements successfully" do
46
- @repository.insert(*@statements)
47
- @repository.count.should == @statements.size
17
+ before :each do
18
+ @subject = RDF::URI.new("http://rubygems.org/gems/rdf")
19
+ @context = RDF::URI.new("http://example.org/context")
48
20
  end
49
- end
50
21
 
51
- context "when deleting statements" do
52
- it "should support #delete" do
53
- @repository.should respond_to(:delete)
54
- end
22
+ it_should_behave_like RDF_Mutable
55
23
 
56
- it "should not raise errors"
57
- it "should support deleting one statement at a time"
58
- it "should support deleting multiple statements at a time"
59
- it "should delete statements successfully"
60
24
  end
61
25
 
62
26
  context "when enumerating statements" do
@@ -70,9 +34,24 @@ share_as :RDF_Repository do
70
34
  it_should_behave_like RDF_Enumerable
71
35
  end
72
36
 
73
- context "when clearing all statements" do
74
- it "should support #clear" do
75
- @repository.should respond_to(:clear)
37
+ context "when querying statements, " do
38
+ require 'rdf/spec/queryable'
39
+
40
+ before :each do
41
+ @subject = RDF::URI.new("http://rubygems.org/gems/rdf")
42
+ @queryable = @repository
76
43
  end
44
+
45
+ it_should_behave_like RDF_Queryable
46
+ end
47
+
48
+ context "as a durable repository, " do
49
+ require 'rdf/spec/durable'
50
+
51
+ before :each do
52
+ @load_durable ||= lambda { @repository }
53
+ end
54
+
55
+ it_should_behave_like RDF_Durable
77
56
  end
78
57
  end
@@ -2,15 +2,15 @@ module RDF; module Spec
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 4
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
- STRING << "-#{EXTRA}" if EXTRA
9
+ STRING << ".#{EXTRA}" if EXTRA
10
10
 
11
11
  ##
12
12
  # @return [String]
13
- def self.to_s() STRING end
13
+ def self.to_s() STRING end
14
14
 
15
15
  ##
16
16
  # @return [String]
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+ require 'rdf/spec/queryable'
3
+
4
+ describe RDF::Queryable do
5
+ before :each do
6
+ @file = "etc/doap.nt"
7
+ @statements = RDF::NTriples::Reader.new(File.open(@file)).to_a
8
+ @queryable = @statements.extend(RDF::Queryable)
9
+ @subject = RDF::URI.new("http://rubygems.org/gems/rdf")
10
+ end
11
+
12
+ it_should_behave_like RDF_Queryable
13
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Arto Bendiken
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-03-11 00:00:00 +01:00
18
+ date: 2010-04-03 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -28,8 +28,8 @@ dependencies:
28
28
  segments:
29
29
  - 0
30
30
  - 1
31
- - 0
32
- version: 0.1.0
31
+ - 4
32
+ version: 0.1.4
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -88,12 +88,16 @@ files:
88
88
  - UNLICENSE
89
89
  - VERSION
90
90
  - etc/doap.nt
91
+ - lib/rdf/spec/durable.rb
91
92
  - lib/rdf/spec/enumerable.rb
92
93
  - lib/rdf/spec/matchers.rb
94
+ - lib/rdf/spec/mutable.rb
95
+ - lib/rdf/spec/queryable.rb
93
96
  - lib/rdf/spec/repository.rb
94
97
  - lib/rdf/spec/version.rb
95
98
  - lib/rdf/spec.rb
96
99
  - spec/enumerable_spec.rb
100
+ - spec/queryable_spec.rb
97
101
  - spec/repository_spec.rb
98
102
  - spec/spec_helper.rb
99
103
  has_rdoc: false