rdf-spec 1.0.9 → 1.1.0.p1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,33 +9,32 @@ module RDF_Format
9
9
  end
10
10
 
11
11
  describe RDF::Format do
12
- subject {@format_class}
13
12
  describe ".for" do
14
13
  RDF::Format.file_extensions.each do |ext, formats|
15
14
  it "detects #{formats.first} using file path foo.#{ext}" do
16
- expect(RDF::Format.for("foo.#{ext}")).to eq formats.first
15
+ RDF::Format.for("foo.#{ext}").should == formats.first
17
16
  end
18
17
 
19
18
  it "detects #{formats.first} using file_name foo.#{ext}" do
20
- expect(RDF::Format.for(:file_name => "foo.#{ext}")).to eq formats.first
19
+ RDF::Format.for(:file_name => "foo.#{ext}").should == formats.first
21
20
  end
22
21
 
23
22
  it "detects #{formats.first} using file_extension #{ext}" do
24
- expect(RDF::Format.for(:file_extension => ext)).to eq formats.first
23
+ RDF::Format.for(:file_extension => ext).should == formats.first
25
24
  end
26
25
  end
27
26
 
28
27
  RDF::Format.content_types.each do |content_type, formats|
29
28
  it "detects #{formats.first} using content_type #{content_type}" do
30
- expect(RDF::Format.for(:content_type => content_type)).to eq formats.first
29
+ RDF::Format.for(:content_type => content_type).should == formats.first
31
30
  end
32
31
  end
33
32
  end
34
33
 
35
34
  describe ".reader" do
36
35
  it "returns a reader" do
37
- subject.each do |f|
38
- expect(f.reader).not_to be_nil
36
+ @format_class.each do |f|
37
+ f.reader.should_not be_nil
39
38
  end
40
39
  end
41
40
  end
@@ -44,9 +43,9 @@ module RDF_Format
44
43
  ##
45
44
  # May not return a writer, only does if one is defined by the format
46
45
  it "returns a writer" do
47
- subject.each do |f|
46
+ @format_class.each do |f|
48
47
  format_namespace = f.name.split('::')[0..-2].inject(Kernel) {|base, const| base.const_get(const)}
49
- expect(f.writer).not_to be_nil if format_namespace.const_defined?(:Writer)
48
+ f.writer.should_not be_nil if format_namespace.const_defined?(:Writer)
50
49
  end
51
50
  end
52
51
  end
@@ -9,17 +9,24 @@ module RDF_Indexable
9
9
  end
10
10
 
11
11
  describe RDF::Indexable do
12
- subject {@indexable}
13
- it {should respond_to(:indexed?)}
14
- its(:indexed?) {should == subject.indexed?}
15
- it {should respond_to(:index!)}
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
16
23
 
17
24
  it "does not raise error on #index! if #indexed?" do
18
- expect {subject.index!}.not_to raise_error if subject.indexed?
25
+ lambda {@indexable.index!}.should_not raise_error if @indexable.indexed?
19
26
  end
20
27
 
21
28
  it "raises error on #index! if not #indexed?" do
22
- expect {subject.index!}.to raise_error unless subject.indexed?
29
+ lambda {@indexable.index!}.should raise_error unless @indexable.indexed?
23
30
  end
24
31
  end
25
32
  end
@@ -8,113 +8,113 @@ module RDF; module Spec
8
8
  module Matchers
9
9
  RSpec::Matchers.define :be_countable do
10
10
  match do |countable|
11
- expect(countable).to be_a_kind_of(RDF::Countable)
11
+ countable.should be_a_kind_of(RDF::Countable)
12
12
  true
13
13
  end
14
14
  end
15
15
 
16
16
  RSpec::Matchers.define :be_enumerable do
17
17
  match do |enumerable|
18
- expect(enumerable).to be_a_kind_of(RDF::Enumerable)
18
+ enumerable.should be_a_kind_of(RDF::Enumerable)
19
19
  true
20
20
  end
21
21
  end
22
22
 
23
23
  RSpec::Matchers.define :be_an_enumerator do
24
24
  match do |enumerator|
25
- expect(enumerator).to be_a_kind_of(RDF::Enumerator)
25
+ enumerator.should be_a_kind_of(Enumerator)
26
26
  true
27
27
  end
28
28
  end
29
29
 
30
30
  RSpec::Matchers.define :be_queryable do
31
31
  match do |enumerable|
32
- expect(enumerable).to be_a_kind_of(RDF::Queryable)
32
+ enumerable.should be_a_kind_of(RDF::Queryable)
33
33
  true
34
34
  end
35
35
  end
36
36
 
37
37
  RSpec::Matchers.define :be_mutable do
38
38
  match do |enumerable|
39
- expect(enumerable).to be_a_kind_of(RDF::Mutable)
39
+ enumerable.should be_a_kind_of(RDF::Mutable)
40
40
  true
41
41
  end
42
42
  end
43
43
 
44
44
  RSpec::Matchers.define :be_a_statement do
45
45
  match do |statement|
46
- expect(statement).to be_instance_of(RDF::Statement)
47
- expect(statement.subject).to be_a_kind_of(RDF::Resource)
48
- expect(statement.predicate).to be_a_kind_of(RDF::URI)
49
- expect(statement.object).to be_a_kind_of(RDF::Value)
46
+ statement.should be_instance_of(RDF::Statement)
47
+ statement.subject.should be_a_kind_of(RDF::Resource)
48
+ statement.predicate.should be_a_kind_of(RDF::URI)
49
+ statement.object.should be_a_kind_of(RDF::Value)
50
50
  true
51
51
  end
52
52
  end
53
53
 
54
54
  RSpec::Matchers.define :be_a_triple do
55
55
  match do |triple|
56
- expect(triple).to be_instance_of(Array)
57
- expect(triple.size).to eq 3
58
- expect(triple[0]).to be_a_kind_of(RDF::Resource)
59
- expect(triple[1]).to be_a_kind_of(RDF::URI)
60
- expect(triple[2]).to be_a_kind_of(RDF::Value)
56
+ triple.should be_instance_of(Array)
57
+ triple.size.should == 3
58
+ triple[0].should be_a_kind_of(RDF::Resource)
59
+ triple[1].should be_a_kind_of(RDF::URI)
60
+ triple[2].should be_a_kind_of(RDF::Value)
61
61
  true
62
62
  end
63
63
  end
64
64
 
65
65
  RSpec::Matchers.define :be_a_quad do
66
66
  match do |quad|
67
- expect(quad).to be_instance_of(Array)
68
- expect(quad.size).to eq 4
69
- expect(quad[0]).to be_a_kind_of(RDF::Resource)
70
- expect(quad[1]).to be_a_kind_of(RDF::URI)
71
- expect(quad[2]).to be_a_kind_of(RDF::Value)
72
- expect(quad[3]).to be_a_kind_of(RDF::Resource) unless quad[3].nil?
67
+ quad.should be_instance_of(Array)
68
+ quad.size.should == 4
69
+ quad[0].should be_a_kind_of(RDF::Resource)
70
+ quad[1].should be_a_kind_of(RDF::URI)
71
+ quad[2].should be_a_kind_of(RDF::Value)
72
+ quad[3].should be_a_kind_of(RDF::Resource) unless quad[3].nil?
73
73
  true
74
74
  end
75
75
  end
76
76
 
77
77
  RSpec::Matchers.define :be_a_resource do
78
78
  match do |value|
79
- expect(value).to be_a_kind_of(RDF::Resource)
79
+ value.should be_a_kind_of(RDF::Resource)
80
80
  true
81
81
  end
82
82
  end
83
83
 
84
84
  RSpec::Matchers.define :be_a_node do
85
85
  match do |value|
86
- expect(value).to be_a_kind_of(RDF::Node)
86
+ value.should be_a_kind_of(RDF::Node)
87
87
  true
88
88
  end
89
89
  end
90
90
 
91
91
  RSpec::Matchers.define :be_a_uri do
92
92
  match do |value|
93
- expect(value).to be_a_kind_of(RDF::URI)
93
+ value.should be_a_kind_of(RDF::URI)
94
94
  true
95
95
  end
96
96
  end
97
97
 
98
98
  RSpec::Matchers.define :be_a_value do
99
99
  match do |value|
100
- expect(value).to be_a_kind_of(RDF::Value)
100
+ value.should be_a_kind_of(RDF::Value)
101
101
  true
102
102
  end
103
103
  end
104
104
 
105
105
  RSpec::Matchers.define :be_a_list do
106
106
  match do |value|
107
- expect(value).to be_an(RDF::List)
107
+ value.should be_an(RDF::List)
108
108
  true
109
109
  end
110
110
  end
111
111
 
112
112
  RSpec::Matchers.define :be_a_vocabulary do |base_uri|
113
113
  match do |vocabulary|
114
- expect(vocabulary).to be_a_kind_of(Module)
115
- expect(vocabulary).to respond_to(:to_uri)
116
- expect(vocabulary.to_uri.to_s).to eq base_uri
117
- expect(vocabulary).to respond_to(:[])
114
+ vocabulary.should be_a_kind_of(Module)
115
+ vocabulary.should respond_to(:to_uri)
116
+ vocabulary.to_uri.to_s.should == base_uri
117
+ vocabulary.should respond_to(:[])
118
118
  true
119
119
  end
120
120
  end
@@ -122,13 +122,13 @@ module RDF; module Spec
122
122
  RSpec::Matchers.define :have_properties do |base_uri, properties|
123
123
  match do |vocabulary|
124
124
  properties.map { |p| p.to_sym }.each do |property|
125
- expect(vocabulary[property]).to be_a_uri
126
- expect(vocabulary[property].to_s).to eq "#{base_uri}#{property}"
127
- expect(vocabulary).to respond_to(property)
128
- expect { vocabulary.send(property) }.not_to raise_error
129
- expect(vocabulary.send(property)).to be_a_uri
130
- expect(vocabulary.send(property.to_s)).to be_a_uri
131
- expect(vocabulary.send(property).to_s).to eq "#{base_uri}#{property}"
125
+ vocabulary[property].should be_a_uri
126
+ vocabulary[property].to_s.should == "#{base_uri}#{property}"
127
+ vocabulary.should respond_to(property)
128
+ lambda { vocabulary.send(property) }.should_not raise_error
129
+ vocabulary.send(property).should be_a_uri
130
+ vocabulary.send(property.to_s).should be_a_uri
131
+ vocabulary.send(property).to_s.should == "#{base_uri}#{property}"
132
132
  end
133
133
  true
134
134
  end
@@ -145,14 +145,14 @@ module RDF; module Spec
145
145
 
146
146
  RSpec::Matchers.define :be_a_repository do
147
147
  match do |repository|
148
- expect(repository).to be_a_kind_of(RDF::Repository)
148
+ repository.should be_a_kind_of(RDF::Repository)
149
149
  true
150
150
  end
151
151
  end
152
152
 
153
153
  RSpec::Matchers.define :be_a_repository_of_size do |size|
154
154
  match do |repository|
155
- expect(repository).to be_a_repository
155
+ repository.should be_a_repository
156
156
  repository.size == size
157
157
  end
158
158
  end
@@ -8,14 +8,15 @@ 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
+
11
16
  @supports_context = @mutable.respond_to?(:supports?) && @mutable.supports?(:context)
12
17
  end
13
- let(:resource) {RDF::URI('http://rubygems.org/gems/rdf')}
14
- let(:context) {RDF::URI('http://example.org/context')}
15
18
 
16
19
  describe RDF::Mutable do
17
- subject {@mutable}
18
-
19
20
  context "readability" do
20
21
  require 'rdf/spec/readable'
21
22
 
@@ -36,123 +37,119 @@ module RDF_Mutable
36
37
  include RDF_Writable
37
38
  end
38
39
 
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)}
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
47
57
 
48
- its(:count) {should be_zero}
58
+ it "should support #load" do
59
+ @mutable.respond_to?(:load).should be_true
60
+ end
49
61
 
50
62
  context "#load" do
51
63
  it "should require an argument" do
52
- expect { subject.load }.to raise_error(ArgumentError)
64
+ lambda { @mutable.load }.should raise_error(ArgumentError)
53
65
  end
54
66
 
55
67
  it "should accept a string filename argument" do
56
- pending("mutability", :unless => subject.mutable?) do
57
- expect { subject.load(RDF::Spec::TRIPLES_FILE) }.not_to raise_error
58
- end
68
+ lambda { @mutable.load(@filename) }.should_not raise_error(ArgumentError)
59
69
  end
60
70
 
61
71
  it "should accept an optional hash argument" do
62
- pending("mutability", :unless => subject.mutable?) do
63
- expect { subject.load(RDF::Spec::TRIPLES_FILE, {}) }.not_to raise_error
64
- end
72
+ lambda { @mutable.load(@filename,{}) }.should_not raise_error(ArgumentError)
65
73
  end
66
74
 
67
75
  it "should load statements" do
68
- pending("mutability", :unless => subject.mutable?) do
69
- subject.load RDF::Spec::TRIPLES_FILE
70
- expect(subject.size).to eq File.readlines(RDF::Spec::TRIPLES_FILE).size
71
- expect(subject).to have_subject(resource)
72
- end
76
+ @mutable.load @filename
77
+ @mutable.size.should == File.readlines(@filename).size
78
+ @mutable.should have_subject(@subject)
73
79
  end
74
80
 
75
81
  it "should load statements with a context override" do
76
- pending("mutability and contextuality", :unless => (subject.mutable? && @supports_context)) do
77
- subject.load RDF::Spec::TRIPLES_FILE, :context => context
78
- expect(subject).to have_context(context)
79
- expect(subject.query(:context => context).size).to eq subject.size
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
80
86
  end
81
87
  end
82
88
  end
83
89
 
84
- context "#from_{reader}" do
85
- it "should instantiate a reader" do
86
- reader = double("reader")
87
- expect(reader).to receive(:new).and_return(RDF::NTriples::Reader.new(""))
88
- expect(RDF::Reader).to receive(:for).with(:a_reader).and_return(reader)
89
- subject.send(:from_a_reader)
90
- end
91
- end
92
-
93
90
  context "when deleting statements" do
94
91
  before :each do
95
- @statements = RDF::NTriples::Reader.new(File.open(RDF::Spec::TRIPLES_FILE)).to_a
96
- subject.insert(*@statements)
92
+ @statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
93
+ @mutable.insert(*@statements)
94
+ end
95
+
96
+ it "should support #delete" do
97
+ @mutable.should respond_to(:delete)
97
98
  end
98
99
 
99
100
  it "should not raise errors" do
100
- pending("mutability", :unless => subject.mutable?) do
101
- expect { subject.delete(@statements.first) }.not_to raise_error
102
- end
101
+ lambda { @mutable.delete(@statements.first) }.should_not raise_error
103
102
  end
104
103
 
105
104
  it "should support deleting one statement at a time" do
106
- pending("mutability", :unless => subject.mutable?) do
107
- subject.delete(@statements.first)
108
- expect(subject).not_to have_statement(@statements.first)
109
- end
105
+ @mutable.delete(@statements.first)
106
+ @mutable.should_not have_statement(@statements.first)
110
107
  end
111
108
 
112
109
  it "should support deleting multiple statements at a time" do
113
- pending("mutability", :unless => subject.mutable?) do
114
- subject.delete(*@statements)
115
- expect(subject.find { |s| subject.has_statement?(s) }).to be_false
116
- end
110
+ @mutable.delete(*@statements)
111
+ @statements.find { |s| @mutable.has_statement?(s) }.should be_false
117
112
  end
118
113
 
119
114
  it "should support wildcard deletions" do
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
- expect(subject).not_to be_empty
126
- expect(subject.count).to eq count
127
-
128
- # everything deleted
129
- subject.delete([nil, nil, nil])
130
- expect(subject).to be_empty
131
- end
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
132
125
  end
133
126
 
134
127
  it "should only delete statements when the context matches" do
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
- expect(subject.count).to eq count
147
-
148
- # Delete one by one
149
- subject.delete(s1)
150
- expect(subject.count).to eq count - (@supports_context ? 1 : 1)
151
- subject.delete(s2)
152
- expect(subject.count).to eq count - (@supports_context ? 2 : 1)
153
- subject.delete(s3)
154
- expect(subject.count).to eq count - (@supports_context ? 3 : 1)
155
- end
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)
156
153
  end
157
154
  end
158
155
  end