redlander 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,96 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Parser do
4
-
5
- it "should be created with default values" do
6
- lambda {
7
- Parser.new
8
- }.should_not raise_exception
9
- end
10
-
11
- describe "string source" do
12
-
13
- it "should be parsed into the model" do
14
- parser = Parser.new
15
- model = Model.new
16
- lambda {
17
- parser.from_string(model, content[:rdfxml], :base_uri => base_uri[:rdfxml])
18
- }.should change(model.statements, :size).by(1)
19
- end
20
-
21
- end
22
-
23
- describe "file source" do
24
-
25
- before :each do
26
- reference_model = Model.new
27
- reference_model.from_rdfxml(content[:rdfxml], :base_uri => base_uri[:rdfxml])
28
- reference_model.to_file(filename)
29
- end
30
-
31
- after :each do
32
- cleanup
33
- end
34
-
35
- it "should be parsed into the model" do
36
- parser = Parser.new
37
- model = Model.new
38
- lambda {
39
- parser.from_file(model, filename, :base_uri => base_uri[:rdfxml])
40
- }.should change(model.statements, :size).by(1)
41
- end
42
-
43
- end
44
-
45
-
46
- describe "statements" do
47
-
48
- it do
49
- Parser.new(:ntriples).statements(content[:ntriples]).should be_an_instance_of(ParserProxy)
50
- end
51
-
52
- [:rdfxml, :turtle, :ntriples].each do |format|
53
- it "should parse #{format} content" do
54
- parser = Parser.new(format)
55
- statements = []
56
- lambda {
57
- parser.statements(content[format], :base_uri => base_uri[format]).each do |st|
58
- statements << st
59
- end
60
- }.should change(statements, :size).by(1)
61
- end
62
- end
63
-
64
- end
65
-
66
-
67
- private
68
-
69
- def cleanup
70
- File.delete(filename) if File.exists?(filename)
71
- end
72
-
73
- def filename
74
- "test_model.rdf"
75
- end
76
-
77
- def content
78
- {
79
- :ntriples => '<http://example.org/ns/a2> <http://example.org/ns/b2> <http://example.org/ns/c2> .',
80
- :turtle => '# this is a complete turtle document
81
- @prefix foo: <http://example.org/ns#> .
82
- @prefix : <http://other.example.org/ns#> .
83
- foo:bar foo: : .',
84
- :rdfxml => '<?xml version="1.0" encoding="utf-8"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="http://example.com/concepts#two-dimensional_seismic_imaging"><ns0:label xmlns:ns0="http://www.w3.org/2000/01/rdf-schema#" xml:lang="en">2-D seismic imaging</ns0:label></rdf:Description></rdf:RDF>'
85
- }
86
- end
87
-
88
- def base_uri
89
- {
90
- :ntriples => nil,
91
- :turtle => 'http://example.com/concepts',
92
- :rdfxml => 'http://example.com/concepts'
93
- }
94
- end
95
-
96
- end
@@ -1,52 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Serializer do
4
-
5
- it "should be created with default values" do
6
- lambda {
7
- Serializer.new
8
- }.should_not raise_exception
9
- end
10
-
11
- describe "model" do
12
-
13
- before :each do
14
- @model = Model.new
15
- s = URI.parse("http://example.com/concepts#two-dimensional_seismic_imaging")
16
- p = URI.parse("http://www.w3.org/2000/01/rdf-schema#label")
17
- o = "2-D seismic imaging@en"
18
- @model.statements.create(:subject => s, :predicate => p, :object => o)
19
- end
20
-
21
- [:rdfxml, :ntriples, :turtle, :dot, :json].each do |format|
22
- it "should be serialized into a #{format} string" do
23
- serializer = Serializer.new(format)
24
- output = serializer.to_string(@model)
25
- output.should be_an_instance_of(String)
26
- output.should_not be_empty
27
- end
28
- end
29
-
30
- it "should be serialized into a file" do
31
- cleanup
32
- serializer = Serializer.new(:ntriples)
33
- serializer.to_file(@model, filename)
34
- File.should be_exists(filename)
35
- File.size(filename).should_not be_zero
36
- cleanup
37
- end
38
-
39
-
40
- private
41
-
42
- def cleanup
43
- File.delete(filename) if File.exists?(filename)
44
- end
45
-
46
- def filename
47
- "test_model.nt"
48
- end
49
-
50
- end
51
-
52
- end
@@ -1,77 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Statement do
4
-
5
- it "should be created with default values" do
6
- statement = nil
7
- lambda { statement = Statement.new }.should_not raise_exception
8
- statement.subject.should be_nil
9
- statement.predicate.should be_nil
10
- statement.object.should be_nil
11
- end
12
-
13
- it "should be created with the given values" do
14
- statement = create_statement
15
- statement.subject.should be_an_instance_of(Node)
16
- statement.predicate.should be_an_instance_of(Node)
17
- statement.object.should be_an_instance_of(Node)
18
- end
19
-
20
- it "should have proper attributes" do
21
- statement = create_statement
22
- statement.subject.value.to_s.should eql('http://example.com/concepts#subject')
23
- statement.predicate.value.to_s.should eql('http://example.com/concepts#label')
24
- statement.object.value.should eql('subject!')
25
- end
26
-
27
- it do
28
- statement = Statement.new
29
- lambda {
30
- statement.should_not be_valid
31
- }.should change(statement.errors, :size).by(1)
32
- end
33
-
34
- it do
35
- create_statement.should be_valid
36
- end
37
-
38
- [:subject, :predicate, :object].each do |attribute|
39
- it "should be assigned a #{attribute}" do
40
- statement = Statement.new
41
- attr = Node.new(statement_attributes[attribute])
42
- lambda {
43
- statement.send("#{attribute}=", attr)
44
- }.should change(statement, attribute).from(nil).to(attr)
45
- end
46
- end
47
-
48
- it "should not be assigned the same attribute twice" do
49
- statement = Statement.new
50
- object = "object!"
51
- lambda {
52
- 2.times do
53
- statement.object = object
54
- end
55
- }.should raise_exception
56
- object.should be_frozen
57
- end
58
-
59
-
60
- private
61
-
62
- def create_statement
63
- Statement.new(statement_attributes)
64
- end
65
-
66
- def statement_attributes
67
- s = URI.parse('http://example.com/concepts#subject')
68
- p = URI.parse('http://example.com/concepts#label')
69
- o = "subject!"
70
- {
71
- :subject => s,
72
- :predicate => p,
73
- :object => o
74
- }
75
- end
76
-
77
- end