dbd 0.0.9 → 0.0.10
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.
- checksums.yaml +4 -4
- data/Guardfile +2 -2
- data/HISTORY.txt +11 -0
- data/README.md +24 -5
- data/bin/test_4.rb +2 -2
- data/bin/test_6.rb +2 -2
- data/docs/test.rb +1 -1
- data/lib/dbd/fact.rb +35 -67
- data/lib/dbd/fact/factory.rb +90 -0
- data/lib/dbd/fact/id.rb +2 -2
- data/lib/dbd/fact/subject.rb +2 -2
- data/lib/dbd/graph.rb +4 -6
- data/lib/dbd/helpers/uuid.rb +2 -2
- data/lib/dbd/resource.rb +1 -1
- data/lib/dbd/time_stamp.rb +16 -7
- data/lib/dbd/version.rb +1 -1
- data/spec/lib/dbd/fact/collection/collection_spec.rb +59 -59
- data/spec/lib/dbd/fact/factory/factory_spec.rb +109 -0
- data/spec/lib/dbd/fact/id/id_spec.rb +4 -4
- data/spec/lib/dbd/fact/id/test_factories_spec.rb +14 -0
- data/spec/lib/dbd/fact/methods_spec.rb +53 -57
- data/spec/lib/dbd/fact/new_spec.rb +32 -55
- data/spec/lib/dbd/fact/subject/subject_spec.rb +3 -3
- data/spec/lib/dbd/fact/subject/test_factories_spec.rb +23 -0
- data/spec/lib/dbd/fact/test_factories_spec.rb +82 -0
- data/spec/lib/dbd/graph/add_to_graph_spec.rb +31 -31
- data/spec/lib/dbd/graph/from_csv_spec.rb +47 -20
- data/spec/lib/dbd/graph/test_factories_spec.rb +58 -0
- data/spec/lib/dbd/graph/to_csv_spec.rb +46 -45
- data/spec/lib/dbd/helpers/ordered_set_collection/ordered_set_collection_spec.rb +17 -17
- data/spec/lib/dbd/helpers/uuid/uuid_spec.rb +11 -5
- data/spec/lib/dbd/performance_spec.rb +6 -6
- data/spec/lib/dbd/provenance_fact/methods_spec.rb +19 -19
- data/spec/lib/dbd/provenance_fact/new_spec.rb +17 -17
- data/spec/lib/dbd/provenance_fact/test_factories_spec.rb +24 -0
- data/spec/lib/dbd/provenance_resource/provenance_resource_spec.rb +24 -24
- data/spec/lib/dbd/rdf_base/rdf_base_spec.rb +7 -7
- data/spec/lib/dbd/resource/collection_spec.rb +34 -34
- data/spec/lib/dbd/resource/new_spec.rb +12 -12
- data/spec/lib/dbd/resource/test_factories_spec.rb +25 -0
- data/spec/lib/dbd/time_stamp/comparisons_spec.rb +31 -30
- data/spec/lib/dbd/time_stamp/methods_spec.rb +17 -13
- data/spec/lib/dbd/time_stamp/new_spec.rb +40 -14
- data/spec/lib/dbd/time_stamp/test_factories_spec.rb +18 -0
- data/spec/spec_helper.rb +2 -6
- data/spec/{factories → test_factories}/fact.rb +32 -25
- data/spec/{factories → test_factories}/fact/id.rb +2 -2
- data/spec/{factories → test_factories}/fact/subject.rb +3 -3
- data/spec/test_factories/graph.rb +25 -0
- data/spec/{factories → test_factories}/provenance_fact.rb +8 -10
- data/spec/{factories → test_factories}/provenance_resource.rb +3 -3
- data/spec/{factories → test_factories}/resource.rb +10 -4
- data/spec/{factories → test_factories}/time_stamp.rb +2 -2
- metadata +35 -32
- data/spec/factories/graph.rb +0 -23
- data/spec/lib/dbd/fact/factory_spec.rb +0 -82
- data/spec/lib/dbd/fact/id/factory_spec.rb +0 -16
- data/spec/lib/dbd/fact/subject/factory_spec.rb +0 -25
- data/spec/lib/dbd/graph/factory_spec.rb +0 -33
- data/spec/lib/dbd/provenance_fact/factory_spec.rb +0 -24
- data/spec/lib/dbd/resource/factory_spec.rb +0 -18
- data/spec/lib/dbd/time_stamp/factory_spec.rb +0 -18
@@ -4,53 +4,53 @@ module Dbd
|
|
4
4
|
describe Graph do
|
5
5
|
|
6
6
|
def new_subject
|
7
|
-
Fact.new_subject
|
7
|
+
Fact.factory.new_subject
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:data_fact) {
|
11
|
-
let(:fact_no_subject) {
|
12
|
-
let(:fact_no_provenance) {
|
10
|
+
let(:data_fact) { TestFactories::Fact.data_fact(new_subject, new_subject) }
|
11
|
+
let(:fact_no_subject) { TestFactories::Fact.data_fact(new_subject, nil) }
|
12
|
+
let(:fact_no_provenance) { TestFactories::Fact.data_fact(nil, new_subject) }
|
13
13
|
|
14
|
-
let(:provenance_facts) {
|
14
|
+
let(:provenance_facts) { TestFactories::Fact::Collection.provenance_facts(new_subject) }
|
15
15
|
let(:provenance_fact_1) { provenance_facts.first }
|
16
16
|
|
17
17
|
let(:subject_regexp) { Fact::Subject.regexp }
|
18
18
|
|
19
|
-
let(:provenance_resource) {
|
20
|
-
let(:resource) {
|
19
|
+
let(:provenance_resource) { TestFactories::ProvenanceResource.provenance_resource }
|
20
|
+
let(:resource) { TestFactories::Resource.facts_resource(provenance_resource.subject) }
|
21
21
|
let(:resource_array) { [provenance_resource, resource]}
|
22
22
|
|
23
|
-
describe
|
24
|
-
it
|
23
|
+
describe 'create a graph' do
|
24
|
+
it 'does not fail' do
|
25
25
|
described_class.new # should_not raise_error
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe
|
30
|
-
describe
|
31
|
-
it
|
29
|
+
describe '<< ' do
|
30
|
+
describe 'a Fact' do
|
31
|
+
it 'a data_fact does not fail' do
|
32
32
|
subject << data_fact
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'a provenance_fact does not fail' do
|
36
36
|
subject << provenance_fact_1
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it 'two facts does not fail' do
|
40
40
|
subject << provenance_fact_1
|
41
41
|
subject << data_fact
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'fact with missing subject raises FactError' do
|
45
45
|
lambda { subject << fact_no_subject } . should raise_error FactError
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it 'fact with missing provenance raises FactError' do
|
49
49
|
lambda { subject << fact_no_provenance } . should raise_error FactError
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
describe
|
53
|
+
describe 'sets the time_stamp and adds a random time (1..999 nanoseconds) if needed' do
|
54
54
|
|
55
55
|
# NOTE: reduced the far_future from 2500 to 2250 as work around for
|
56
56
|
# http://jira.codehaus.org/browse/JRUBY-7095
|
@@ -62,7 +62,7 @@ module Dbd
|
|
62
62
|
subject.first.time_stamp.should == far_future
|
63
63
|
end
|
64
64
|
|
65
|
-
describe
|
65
|
+
describe 'sets the time_stamp if not yet set' do
|
66
66
|
|
67
67
|
let(:near_future) { Time.now.utc + 100}
|
68
68
|
let(:fake_time_stamp) { TimeStamp.new(time: near_future) }
|
@@ -72,14 +72,14 @@ module Dbd
|
|
72
72
|
fake_time_stamp # get this before setting the stub
|
73
73
|
end
|
74
74
|
|
75
|
-
it
|
75
|
+
it 'sets it (to TimeStamp.new)' do
|
76
76
|
TimeStamp.stub(:new).and_return(fake_time_stamp)
|
77
77
|
data_fact.time_stamp.should be_nil # assert pre-condition
|
78
78
|
subject << data_fact
|
79
79
|
subject.first.time_stamp.should == fake_time_stamp
|
80
80
|
end
|
81
81
|
|
82
|
-
it
|
82
|
+
it 'sends a slightly higher time_stamp than newest_time_stamp if Time.now <= newest_time_stamp' do
|
83
83
|
subject.stub(:newest_time_stamp).and_return(fake_time_stamp)
|
84
84
|
subject << data_fact
|
85
85
|
subject.first.time_stamp.should > fake_time_stamp
|
@@ -88,18 +88,18 @@ module Dbd
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
describe
|
91
|
+
describe 'a ProvenanceResource and a Resource' do
|
92
92
|
|
93
|
-
it
|
93
|
+
it 'does not fail' do
|
94
94
|
subject << provenance_resource
|
95
95
|
end
|
96
96
|
|
97
|
-
it
|
97
|
+
it 'Adds the facts from the provenance_resource to the graph' do
|
98
98
|
subject << provenance_resource
|
99
99
|
subject.size.should == 2
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
102
|
+
it 'Adds the facts from the provenance_resource and the resource to the graph' do
|
103
103
|
subject << provenance_resource
|
104
104
|
subject << resource
|
105
105
|
subject.size.should == 4
|
@@ -108,31 +108,31 @@ module Dbd
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
describe
|
112
|
-
it
|
111
|
+
describe 'an array of Resources' do
|
112
|
+
it 'does not fail' do
|
113
113
|
subject << resource_array
|
114
114
|
end
|
115
115
|
|
116
|
-
it
|
116
|
+
it 'Adds the facts from the provenance_resource and the resource to the graph' do
|
117
117
|
subject << resource_array
|
118
118
|
subject.first.class.should == ProvenanceFact
|
119
119
|
subject.last.class.should == Fact
|
120
120
|
subject.size.should == 4
|
121
121
|
end
|
122
122
|
|
123
|
-
it
|
123
|
+
it 'goes 3 levels over collection deep' do
|
124
124
|
subject << [resource_array]
|
125
125
|
subject.size.should == 4
|
126
126
|
end
|
127
127
|
|
128
|
-
it
|
128
|
+
it 'works with different levels deep in 1 collection' do
|
129
129
|
subject << [provenance_resource, [[resource]]]
|
130
130
|
subject.size.should == 4
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
it
|
135
|
-
(subject <<
|
134
|
+
it 'returns self' do
|
135
|
+
(subject << TestFactories::Fact::Collection.provenance_facts(new_subject)).should be_a(described_class)
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
@@ -5,60 +5,87 @@ module Dbd
|
|
5
5
|
describe Graph do
|
6
6
|
|
7
7
|
def round_tripped_graph(graph)
|
8
|
-
|
8
|
+
described_class.new.from_CSV(StringIO.new(graph.to_CSV))
|
9
9
|
end
|
10
10
|
|
11
11
|
def validate_round_trip(graph)
|
12
12
|
graph_from_CSV = round_tripped_graph(graph)
|
13
|
-
# temporarily use to_csv as the
|
13
|
+
# temporarily use to_csv as the 'identity function' for Graph
|
14
14
|
# TODO define a proper Equality for Graph and Fact
|
15
15
|
graph_from_CSV.to_CSV.should == graph.to_CSV
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
18
|
+
describe '#from_CSV reads back a csv exported graph correctly' do
|
19
|
+
describe 'for a graph with only provenance_facts' do
|
19
20
|
|
20
|
-
|
21
|
+
let(:graph) { TestFactories::Graph.only_provenance }
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
it "round_trip validates" do
|
23
|
+
it 'round_trip validates' do
|
25
24
|
validate_round_trip(graph)
|
26
25
|
end
|
27
26
|
|
28
|
-
it
|
27
|
+
it 'for a provenance_fact, the provenance_subject must be equal (nil)' do
|
29
28
|
graph_from_CSV = round_tripped_graph(graph)
|
30
29
|
provenance_fact = graph_from_CSV.first
|
31
30
|
provenance_fact.provenance_subject.should be_nil
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
describe
|
34
|
+
describe 'for a graph with facts and provenance_facts' do
|
36
35
|
|
37
|
-
let(:graph) {
|
36
|
+
let(:graph) { TestFactories::Graph.full }
|
38
37
|
|
39
|
-
it
|
38
|
+
it 'round_trip validates' do
|
40
39
|
validate_round_trip(graph)
|
41
40
|
end
|
42
41
|
|
43
|
-
it
|
44
|
-
imported_graph =
|
42
|
+
it 'the short export of a graph is correct after a round trip' do
|
43
|
+
imported_graph = described_class.new.from_CSV(graph.to_CSV)
|
45
44
|
imported_graph.map(&:short).should == (graph.map(&:short))
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
describe
|
49
|
+
describe '#from_CSV reads back _two_ csv exported graphs correctly' do
|
50
|
+
describe 'for a graph with facts and provenance_facts' do
|
51
|
+
|
52
|
+
let(:graph_provenance) { TestFactories::Graph.only_provenance }
|
53
|
+
let(:graph_facts) { TestFactories::Graph.only_facts(graph_provenance.first.subject) }
|
54
|
+
let(:graph_provenance_csv) { graph_provenance.to_CSV }
|
55
|
+
let(:graph_facts_csv) { graph_facts.to_CSV }
|
56
|
+
|
57
|
+
let(:graph_from_2_csv_s) do
|
58
|
+
stream_1 = StringIO.new(graph_provenance_csv)
|
59
|
+
stream_2 = StringIO.new(graph_facts_csv)
|
60
|
+
graph = described_class.new
|
61
|
+
graph.from_CSV(stream_1)
|
62
|
+
graph.from_CSV(stream_2)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'round_trip validates' do
|
66
|
+
# we do not have full graph equivalence yet
|
67
|
+
graph_from_2_csv_s.first.should be_equivalent(graph_provenance.first)
|
68
|
+
graph_from_2_csv_s.last.should be_equivalent(graph_facts.last)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'a string concat of 2 CSV files works to logically concat them' do
|
72
|
+
graph_from_2_csv_s.to_CSV.should == (graph_provenance_csv + graph_facts_csv)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#from_CSV reads special cases correctly' do
|
51
78
|
|
52
|
-
let(:provenance_subject) {
|
53
|
-
let(:resource) {
|
54
|
-
let(:special_fact) {
|
79
|
+
let(:provenance_subject) { TestFactories::Fact::Subject.fixed_provenance_subject }
|
80
|
+
let(:resource) { TestFactories::Resource.empty(provenance_subject) }
|
81
|
+
let(:special_fact) { TestFactories::Fact.fact_with_special_chars(provenance_subject, resource.subject) }
|
55
82
|
|
56
|
-
it
|
83
|
+
it 'as object' do
|
57
84
|
resource << special_fact
|
58
85
|
graph = described_class.new << resource
|
59
86
|
csv = graph.to_CSV
|
60
|
-
csv.should match(%r{A long story\nreally with a comma, a double quote "" and a non-ASCII char éà Über.})
|
61
|
-
graph_from_CSV = described_class.from_CSV(csv)
|
87
|
+
csv.should match(%r{A long story with a newline\nreally with a comma, a double quote "" and a non-ASCII char éà Über.})
|
88
|
+
graph_from_CSV = described_class.new.from_CSV(csv)
|
62
89
|
graph_from_CSV.first.should be_equivalent(graph.first)
|
63
90
|
end
|
64
91
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module TestFactories
|
4
|
+
describe Graph do
|
5
|
+
describe 'with only provenance facts' do
|
6
|
+
|
7
|
+
let(:only_provenance) { described_class.only_provenance }
|
8
|
+
|
9
|
+
it 'is a Graph' do
|
10
|
+
only_provenance.should be_a(described_class.factory_for)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has some facts' do
|
14
|
+
only_provenance.size.should >= 2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'with only facts' do
|
19
|
+
|
20
|
+
let(:subject) { described_class.new_subject }
|
21
|
+
let(:only_facts_without_provenance_subject) { described_class.only_facts }
|
22
|
+
let(:only_facts_with_provenance_subject) { described_class.only_facts(subject) }
|
23
|
+
|
24
|
+
describe 'only_facts_without_provenance_subject' do
|
25
|
+
it 'is a Graph' do
|
26
|
+
only_facts_without_provenance_subject.should be_a(described_class.factory_for)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'has some facts' do
|
30
|
+
only_facts_without_provenance_subject.size.should >= 2
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'only_facts_with_subject' do
|
35
|
+
it 'is a Graph' do
|
36
|
+
only_facts_with_provenance_subject.should be_a(described_class.factory_for)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'has the set subject' do
|
40
|
+
only_facts_with_provenance_subject.first.provenance_subject.should == subject
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'full' do
|
46
|
+
|
47
|
+
let(:full) { described_class.full }
|
48
|
+
|
49
|
+
it 'is a Graph' do
|
50
|
+
full.should be_a(described_class.factory_for)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'full has many facts' do
|
54
|
+
full.size.should >= 4
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -5,18 +5,19 @@ module Dbd
|
|
5
5
|
describe Graph do
|
6
6
|
|
7
7
|
def new_subject
|
8
|
-
Fact.new_subject
|
8
|
+
Fact.factory.new_subject
|
9
9
|
end
|
10
10
|
|
11
|
-
let(:provenance_facts) {
|
11
|
+
let(:provenance_facts) { TestFactories::Fact::Collection.provenance_facts(new_subject) }
|
12
12
|
let(:provenance_fact_1) { provenance_facts.first }
|
13
|
-
let(:fact_2_3) {
|
14
|
-
let(:fact_special_characters) {
|
13
|
+
let(:fact_2_3) { TestFactories::Fact::Collection.fact_2_3(provenance_fact_1.subject) }
|
14
|
+
let(:fact_special_characters) { TestFactories::Fact::fact_with_special_chars(provenance_fact_1.subject, new_subject) }
|
15
15
|
|
16
|
-
let(:
|
17
|
-
let(:
|
16
|
+
let(:subject_valid_regexp) { Fact::Subject.valid_regexp }
|
17
|
+
let(:id_valid_regexp) { Fact::ID.valid_regexp }
|
18
|
+
let(:time_stamp_valid_regexp) { TimeStamp.valid_regexp }
|
18
19
|
|
19
|
-
describe
|
20
|
+
describe '#to_CSV with only provenance_facts' do
|
20
21
|
before do
|
21
22
|
provenance_facts.each_with_index do |provenance_fact, index|
|
22
23
|
subject << provenance_fact
|
@@ -27,7 +28,7 @@ module Dbd
|
|
27
28
|
subject.to_CSV.should be_a(String)
|
28
29
|
end
|
29
30
|
|
30
|
-
it
|
31
|
+
it 'returns a string in UTF-8 encoding' do
|
31
32
|
subject.to_CSV.encoding.should == Encoding::UTF_8
|
32
33
|
end
|
33
34
|
|
@@ -35,66 +36,66 @@ module Dbd
|
|
35
36
|
subject.to_CSV.should match(/\A"[^",]+","[^",]+","[^",]*","[^",]+"/)
|
36
37
|
end
|
37
38
|
|
38
|
-
describe
|
39
|
-
it
|
39
|
+
describe 'with a single provenance_fact collection' do
|
40
|
+
it 'has three logical lines (but one with embedded newline)' do
|
40
41
|
subject.to_CSV.lines.count.should == 4
|
41
42
|
end
|
42
43
|
|
43
|
-
it
|
44
|
+
it 'ends with a newline' do
|
44
45
|
subject.to_CSV.lines.to_a.last[-1].should == "\n"
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
describe
|
49
|
+
describe 'has all attributes of the provenance_fact_collection' do
|
49
50
|
|
50
51
|
let(:first_line) do
|
51
52
|
subject.to_CSV.lines.to_a.first.chomp
|
52
53
|
end
|
53
54
|
|
54
|
-
it
|
55
|
-
first_line.split(',')[0].gsub(/"/, '').should match(
|
55
|
+
it 'has id (a Fact::ID) as first value' do
|
56
|
+
first_line.split(',')[0].gsub(/"/, '').should match(id_valid_regexp)
|
56
57
|
end
|
57
58
|
|
58
|
-
it
|
59
|
-
first_line.split(',')[1].should match(
|
59
|
+
it 'has time_stamp as second value' do
|
60
|
+
first_line.split(',')[1][1..-2].should match(time_stamp_valid_regexp)
|
60
61
|
end
|
61
62
|
|
62
|
-
it
|
63
|
-
first_line.split(',')[2].should == "
|
63
|
+
it 'has an empty third value (signature of a provenance_fact)' do
|
64
|
+
first_line.split(',')[2].should == '""'
|
64
65
|
end
|
65
66
|
|
66
|
-
it
|
67
|
-
first_line.split(',')[3].gsub(/"/, '').should match(
|
67
|
+
it 'has subject as 4th value' do
|
68
|
+
first_line.split(',')[3].gsub(/"/, '').should match(subject_valid_regexp)
|
68
69
|
end
|
69
70
|
|
70
|
-
it
|
71
|
+
it 'has data_predicate as 5th value' do
|
71
72
|
first_line.split(',')[4].should == '"https://data.vandenabeele.com/ontologies/provenance#context"'
|
72
73
|
end
|
73
74
|
|
74
|
-
it
|
75
|
+
it 'has object as 6th value' do
|
75
76
|
first_line.split(',')[5].should == '"public"'
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
79
|
-
describe
|
80
|
-
it
|
80
|
+
describe 'handles comma, double quote and newline correctly' do
|
81
|
+
it 'has original_source with special characters and double quote escaped' do
|
81
82
|
subject.to_CSV.should match(/"this has a comma , a newline \n and a double quote """/)
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
86
|
-
describe
|
87
|
+
describe '#to_CSV with only facts' do
|
87
88
|
before do
|
88
89
|
fact_2_3.each_with_index do |fact, index|
|
89
90
|
subject << fact
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
|
-
it
|
94
|
+
it 'returns a string' do
|
94
95
|
subject.to_CSV.should be_a(String)
|
95
96
|
end
|
96
97
|
|
97
|
-
it
|
98
|
+
it 'returns a string in UTF-8 encoding' do
|
98
99
|
subject.to_CSV.encoding.should == Encoding::UTF_8
|
99
100
|
end
|
100
101
|
|
@@ -102,49 +103,49 @@ module Dbd
|
|
102
103
|
subject.to_CSV.should match(/\A"[^",]+","[^",]+","[^",]+"/)
|
103
104
|
end
|
104
105
|
|
105
|
-
describe
|
106
|
-
it
|
106
|
+
describe 'with a single fact collection' do
|
107
|
+
it 'has two lines' do
|
107
108
|
subject.to_CSV.lines.count.should == 2
|
108
109
|
end
|
109
110
|
|
110
|
-
it
|
111
|
+
it 'ends with a newline' do
|
111
112
|
subject.to_CSV.lines.to_a.last[-1].should == "\n"
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
115
|
-
describe
|
116
|
+
describe 'has all attributes of the fact_collection' do
|
116
117
|
|
117
118
|
let(:first_line) do
|
118
119
|
subject.to_CSV.lines.to_a.first.chomp
|
119
120
|
end
|
120
121
|
|
121
|
-
it
|
122
|
-
first_line.split(',')[0].gsub(/"/, '').should match(
|
122
|
+
it 'has id (a Fact::ID) as first value' do
|
123
|
+
first_line.split(',')[0].gsub(/"/, '').should match(id_valid_regexp)
|
123
124
|
end
|
124
125
|
|
125
|
-
it
|
126
|
-
first_line.split(',')[1].should match(
|
126
|
+
it 'has time_stamp as second value' do
|
127
|
+
first_line.split(',')[1][1..-2].should match(time_stamp_valid_regexp)
|
127
128
|
end
|
128
129
|
|
129
|
-
it
|
130
|
+
it 'has provenance_fact_1.subject as third value' do
|
130
131
|
first_line.split(',')[2].should == "\"#{provenance_fact_1.subject.to_s}\""
|
131
132
|
end
|
132
133
|
|
133
|
-
it
|
134
|
-
first_line.split(',')[3].gsub(/"/, '').should match(
|
134
|
+
it 'has subject as 4th value' do
|
135
|
+
first_line.split(',')[3].gsub(/"/, '').should match(subject_valid_regexp)
|
135
136
|
end
|
136
137
|
|
137
|
-
it
|
138
|
+
it 'has data_predicate as 5th value' do
|
138
139
|
first_line.split(',')[4].should == '"http://example.org/test/name"'
|
139
140
|
end
|
140
141
|
|
141
|
-
it
|
142
|
+
it 'has object as 6th value' do
|
142
143
|
first_line.split(',')[5].should == '"Mandela"'
|
143
144
|
end
|
144
145
|
end
|
145
146
|
end
|
146
147
|
|
147
|
-
describe
|
148
|
+
describe '#to_CSV with provenance_facts and facts' do
|
148
149
|
|
149
150
|
before do
|
150
151
|
provenance_facts.each do |provenance_fact|
|
@@ -155,12 +156,12 @@ module Dbd
|
|
155
156
|
end
|
156
157
|
end
|
157
158
|
|
158
|
-
it
|
159
|
+
it 'has six lines' do
|
159
160
|
subject.to_CSV.lines.count.should == 6
|
160
161
|
end
|
161
162
|
end
|
162
163
|
|
163
|
-
describe
|
164
|
+
describe '#to_CSV_file' do
|
164
165
|
|
165
166
|
before do
|
166
167
|
provenance_facts.each do |provenance_fact|
|
@@ -172,7 +173,7 @@ module Dbd
|
|
172
173
|
subject << fact_special_characters
|
173
174
|
end
|
174
175
|
|
175
|
-
it
|
176
|
+
it 'has eight lines' do
|
176
177
|
filename = 'data/foo.csv'
|
177
178
|
subject.to_CSV_file(filename)
|
178
179
|
File.open(filename) do |f|
|
@@ -180,7 +181,7 @@ module Dbd
|
|
180
181
|
end
|
181
182
|
end
|
182
183
|
|
183
|
-
it
|
184
|
+
it 'reads back UTF-8 characters correctly' do
|
184
185
|
filename = 'data/foo.csv'
|
185
186
|
subject.to_CSV_file(filename)
|
186
187
|
File.open(filename) do |f|
|