dbd 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +2 -2
  3. data/HISTORY.txt +11 -0
  4. data/README.md +24 -5
  5. data/bin/test_4.rb +2 -2
  6. data/bin/test_6.rb +2 -2
  7. data/docs/test.rb +1 -1
  8. data/lib/dbd/fact.rb +35 -67
  9. data/lib/dbd/fact/factory.rb +90 -0
  10. data/lib/dbd/fact/id.rb +2 -2
  11. data/lib/dbd/fact/subject.rb +2 -2
  12. data/lib/dbd/graph.rb +4 -6
  13. data/lib/dbd/helpers/uuid.rb +2 -2
  14. data/lib/dbd/resource.rb +1 -1
  15. data/lib/dbd/time_stamp.rb +16 -7
  16. data/lib/dbd/version.rb +1 -1
  17. data/spec/lib/dbd/fact/collection/collection_spec.rb +59 -59
  18. data/spec/lib/dbd/fact/factory/factory_spec.rb +109 -0
  19. data/spec/lib/dbd/fact/id/id_spec.rb +4 -4
  20. data/spec/lib/dbd/fact/id/test_factories_spec.rb +14 -0
  21. data/spec/lib/dbd/fact/methods_spec.rb +53 -57
  22. data/spec/lib/dbd/fact/new_spec.rb +32 -55
  23. data/spec/lib/dbd/fact/subject/subject_spec.rb +3 -3
  24. data/spec/lib/dbd/fact/subject/test_factories_spec.rb +23 -0
  25. data/spec/lib/dbd/fact/test_factories_spec.rb +82 -0
  26. data/spec/lib/dbd/graph/add_to_graph_spec.rb +31 -31
  27. data/spec/lib/dbd/graph/from_csv_spec.rb +47 -20
  28. data/spec/lib/dbd/graph/test_factories_spec.rb +58 -0
  29. data/spec/lib/dbd/graph/to_csv_spec.rb +46 -45
  30. data/spec/lib/dbd/helpers/ordered_set_collection/ordered_set_collection_spec.rb +17 -17
  31. data/spec/lib/dbd/helpers/uuid/uuid_spec.rb +11 -5
  32. data/spec/lib/dbd/performance_spec.rb +6 -6
  33. data/spec/lib/dbd/provenance_fact/methods_spec.rb +19 -19
  34. data/spec/lib/dbd/provenance_fact/new_spec.rb +17 -17
  35. data/spec/lib/dbd/provenance_fact/test_factories_spec.rb +24 -0
  36. data/spec/lib/dbd/provenance_resource/provenance_resource_spec.rb +24 -24
  37. data/spec/lib/dbd/rdf_base/rdf_base_spec.rb +7 -7
  38. data/spec/lib/dbd/resource/collection_spec.rb +34 -34
  39. data/spec/lib/dbd/resource/new_spec.rb +12 -12
  40. data/spec/lib/dbd/resource/test_factories_spec.rb +25 -0
  41. data/spec/lib/dbd/time_stamp/comparisons_spec.rb +31 -30
  42. data/spec/lib/dbd/time_stamp/methods_spec.rb +17 -13
  43. data/spec/lib/dbd/time_stamp/new_spec.rb +40 -14
  44. data/spec/lib/dbd/time_stamp/test_factories_spec.rb +18 -0
  45. data/spec/spec_helper.rb +2 -6
  46. data/spec/{factories → test_factories}/fact.rb +32 -25
  47. data/spec/{factories → test_factories}/fact/id.rb +2 -2
  48. data/spec/{factories → test_factories}/fact/subject.rb +3 -3
  49. data/spec/test_factories/graph.rb +25 -0
  50. data/spec/{factories → test_factories}/provenance_fact.rb +8 -10
  51. data/spec/{factories → test_factories}/provenance_resource.rb +3 -3
  52. data/spec/{factories → test_factories}/resource.rb +10 -4
  53. data/spec/{factories → test_factories}/time_stamp.rb +2 -2
  54. metadata +35 -32
  55. data/spec/factories/graph.rb +0 -23
  56. data/spec/lib/dbd/fact/factory_spec.rb +0 -82
  57. data/spec/lib/dbd/fact/id/factory_spec.rb +0 -16
  58. data/spec/lib/dbd/fact/subject/factory_spec.rb +0 -25
  59. data/spec/lib/dbd/graph/factory_spec.rb +0 -33
  60. data/spec/lib/dbd/provenance_fact/factory_spec.rb +0 -24
  61. data/spec/lib/dbd/resource/factory_spec.rb +0 -18
  62. data/spec/lib/dbd/time_stamp/factory_spec.rb +0 -18
@@ -13,36 +13,36 @@ module Dbd
13
13
  o
14
14
  end
15
15
 
16
- describe "create an elements collection" do
17
- it "the collection is not an array" do
16
+ describe 'create an elements collection' do
17
+ it 'the collection is not an array' do
18
18
  # do not derive from Ruby standard classes
19
19
  subject.should_not be_a(Array)
20
20
  end
21
21
  end
22
22
 
23
- describe "accessor functions" do
24
- it "the collection has Enumerable methods" do
23
+ describe 'accessor functions' do
24
+ it 'the collection has Enumerable methods' do
25
25
  subject.map #should_not raise_exception
26
26
  subject.first #should_not raise_exception
27
27
  end
28
28
 
29
- it "<< adds the element" do
29
+ it '<< adds the element' do
30
30
  subject << element_1
31
31
  subject.count.should == 1
32
32
  end
33
33
 
34
- it "returns self to allow chaining" do
34
+ it 'returns self to allow chaining' do
35
35
  (subject << element_1).should == subject
36
36
  end
37
37
 
38
- it "other functions (e.g. pop) do not work" do
38
+ it 'other functions (e.g. pop) do not work' do
39
39
  lambda {subject.pop} . should raise_exception NoMethodError
40
40
  end
41
41
 
42
- describe "add_and_return_index returns the index of the inserted element" do
42
+ describe 'add_and_return_index returns the index of the inserted element' do
43
43
 
44
44
  let(:internal_collection) do
45
- subject.instance_variable_get("@internal_collection")
45
+ subject.instance_variable_get('@internal_collection')
46
46
  end
47
47
 
48
48
  let(:index) do
@@ -51,26 +51,26 @@ module Dbd
51
51
 
52
52
  before(:each) { index }
53
53
 
54
- it "works for 1 element" do
54
+ it 'works for 1 element' do
55
55
  index.should == 0
56
56
  end
57
57
 
58
- it "works for 2 elements" do
58
+ it 'works for 2 elements' do
59
59
  index_2 = described_class.add_and_return_index(element_2, internal_collection)
60
60
  index_2.should == 1
61
61
  end
62
62
  end
63
63
 
64
- describe "last" do
65
- it "returns the last element" do
64
+ describe 'last' do
65
+ it 'returns the last element' do
66
66
  subject << element_1
67
67
  subject << element_2
68
68
  subject.last.should == element_2
69
69
  end
70
70
  end
71
71
 
72
- describe "size" do
73
- it "returns the last element" do
72
+ describe 'size' do
73
+ it 'returns the last element' do
74
74
  subject << element_1
75
75
  subject << element_2
76
76
  subject.size.should == 2
@@ -78,8 +78,8 @@ module Dbd
78
78
  end
79
79
  end
80
80
 
81
- describe "on empty collection" do
82
- it "#last returns nil" do
81
+ describe 'on empty collection' do
82
+ it '#last returns nil' do
83
83
  subject.last.should be_nil
84
84
  end
85
85
  end
@@ -3,15 +3,21 @@ require 'spec_helper'
3
3
  module Dbd
4
4
  module Helpers
5
5
  describe UUID do
6
- it ".regex" do
7
- '12345678-abcd-4567-89ab-0123456789ab'.should match(UUID.regexp)
6
+ describe '.valid_regex' do
7
+ it 'matches correct uuid' do
8
+ '12345678-abcd-4567-89ab-0123456789ab'.should match(UUID.valid_regexp)
9
+ end
10
+
11
+ it 'does not match incorrect uuid' do
12
+ '012345678-abcd-4567-89ab-0123456789ab'.should_not match(UUID.valid_regexp)
13
+ end
8
14
  end
9
15
 
10
- it ".new creates a new random UUID" do
11
- described_class.new.to_s.should match(UUID.regexp)
16
+ it '.new creates a new random UUID' do
17
+ described_class.new.to_s.should match(UUID.valid_regexp)
12
18
  end
13
19
 
14
- it ".new creates a new random UUID with UTF-8 encoding" do
20
+ it '.new creates a new random UUID with UTF-8 encoding' do
15
21
  described_class.new.to_s.encoding.should == Encoding::UTF_8
16
22
  end
17
23
  end
@@ -2,32 +2,32 @@ require 'spec_helper'
2
2
  require 'benchmark'
3
3
 
4
4
  module Dbd
5
- describe "performance" do
5
+ describe 'performance' do
6
6
 
7
7
  include Benchmark
8
8
 
9
9
  # no let because we do not want memoized
10
10
  def new_subject
11
- Fact.new_subject
11
+ Fact.factory.new_subject
12
12
  end
13
13
 
14
- let(:provenance_fact_1) { Factories::ProvenanceFact.context(new_subject) }
14
+ let(:provenance_fact_1) { TestFactories::ProvenanceFact.context(new_subject) }
15
15
 
16
16
  NUMBER_OF_FACTS = 10_000
17
17
 
18
18
  describe "#{NUMBER_OF_FACTS} facts" do
19
- it "reports and checks the used time" do
19
+ it 'reports and checks the used time' do
20
20
  graph = Graph.new
21
21
  graph << provenance_fact_1
22
22
  # Rehearsal
23
23
  NUMBER_OF_FACTS.times do |counter|
24
- data_fact = Factories::Fact.data_fact(provenance_fact_1, new_subject)
24
+ data_fact = TestFactories::Fact.data_fact(provenance_fact_1, new_subject)
25
25
  graph << data_fact
26
26
  end
27
27
  # Actual
28
28
  start = Time.now
29
29
  NUMBER_OF_FACTS.times do |counter|
30
- data_fact = Factories::Fact.data_fact(provenance_fact_1, new_subject)
30
+ data_fact = TestFactories::Fact.data_fact(provenance_fact_1, new_subject)
31
31
  graph << data_fact
32
32
  end
33
33
  duration = Time.now - start
@@ -3,74 +3,74 @@ require 'spec_helper'
3
3
  module Dbd
4
4
  describe ProvenanceFact do
5
5
 
6
- let(:subject) { described_class.new_subject }
6
+ let(:subject) { described_class.factory.new_subject }
7
7
 
8
8
  let(:provenance_fact_1) do
9
- Factories::ProvenanceFact.context(subject)
9
+ TestFactories::ProvenanceFact.context(subject)
10
10
  end
11
11
 
12
12
  let(:provenance_fact_created) do
13
- Factories::ProvenanceFact.created(subject)
13
+ TestFactories::ProvenanceFact.created(subject)
14
14
  end
15
15
 
16
- describe "short" do
17
- it "for a provenance fact shows [ prov ], subj, predicate, object" do
16
+ describe 'short' do
17
+ it 'for a provenance fact shows [ prov ], subj, predicate, object' do
18
18
  provenance_fact_1.short.should match(/^\[ prov \] : [0-9a-f]{8} : https:\/\/data\.vandenabeel : public$/)
19
19
  end
20
20
 
21
- it "for a provenance fact with non string object also works" do
21
+ it 'for a provenance fact with non string object also works' do
22
22
  provenance_fact_created.short.should match(/^\[ prov \] : [0-9a-f]{8} : dcterms:created : \d{4}/)
23
23
  end
24
24
  end
25
25
 
26
- describe "errors" do
27
- it "the factory has no errors" do
26
+ describe 'errors' do
27
+ it 'the factory has no errors' do
28
28
  provenance_fact_1.errors.should be_empty
29
29
  end
30
30
 
31
- describe "with a provenance_subject" do
31
+ describe 'with a provenance_subject' do
32
32
 
33
33
  before(:each) do
34
34
  provenance_fact_1.stub(:provenance_subject).and_return(subject)
35
35
  end
36
36
 
37
- it "errors returns an array with 1 error message" do
37
+ it 'errors returns an array with 1 error message' do
38
38
  provenance_fact_1.errors.single.should match(/Provenance subject should not be present in Provenance Fact/)
39
39
  end
40
40
  end
41
41
 
42
- describe "without subject" do
42
+ describe 'without subject' do
43
43
 
44
44
  before(:each) do
45
45
  provenance_fact_1.stub(:subject).and_return(nil)
46
46
  end
47
47
 
48
- it "errors returns an array with an error message" do
48
+ it 'errors returns an array with an error message' do
49
49
  provenance_fact_1.errors.single.should match(/Subject is missing/)
50
50
  end
51
51
  end
52
52
  end
53
53
 
54
- describe "update_used_provenance_subjects" do
55
- it "does nothing for a provenance_fact" do
54
+ describe 'update_used_provenance_subjects' do
55
+ it 'does nothing for a provenance_fact' do
56
56
  h = {}
57
57
  provenance_fact_1.update_used_provenance_subjects(h)
58
58
  h.should be_empty
59
59
  end
60
60
  end
61
61
 
62
- describe "attributes and values" do
63
- it "there are 6 attributes" do
62
+ describe 'attributes and values' do
63
+ it 'there are 6 attributes' do
64
64
  described_class.attributes.size.should == 6
65
65
  end
66
66
 
67
- it "there are 6 values" do
67
+ it 'there are 6 values' do
68
68
  provenance_fact_1.values.size.should == 6
69
69
  end
70
70
  end
71
71
 
72
- describe "provenance_fact?" do
73
- it "is true for ProvenanceFact or derived from it" do
72
+ describe 'provenance_fact?' do
73
+ it 'is true for ProvenanceFact or derived from it' do
74
74
  provenance_fact_1.provenance_fact?.should be_true
75
75
  end
76
76
  end
@@ -3,47 +3,47 @@ require 'spec_helper'
3
3
  module Dbd
4
4
  describe ProvenanceFact do
5
5
 
6
- let(:subject) { described_class.new_subject }
7
- let(:id_class) { described_class.new_id.class }
6
+ let(:subject) { described_class.factory.new_subject }
7
+ let(:id_class) { described_class.factory.new_id.class }
8
8
 
9
9
  let(:provenance_fact_1) do
10
- Factories::ProvenanceFact.context(subject)
10
+ TestFactories::ProvenanceFact.context(subject)
11
11
  end
12
12
 
13
13
  let(:provenance_fact_2) do
14
- Factories::ProvenanceFact.created_by(subject)
14
+ TestFactories::ProvenanceFact.created_by(subject)
15
15
  end
16
16
 
17
- describe "#new" do
18
- it "has a unique id (new_id.class)" do
17
+ describe '#new' do
18
+ it 'has a unique id (new_id.class)' do
19
19
  provenance_fact_1.id.should be_a(id_class)
20
20
  end
21
21
 
22
- it "two provenance_facts have different id" do
22
+ it 'two provenance_facts have different id' do
23
23
  provenance_fact_1.id.should_not == provenance_fact_2.id
24
24
  end
25
25
 
26
- it "has nil provenance_subject" do
26
+ it 'has nil provenance_subject' do
27
27
  provenance_fact_1.provenance_subject.should be_nil
28
28
  end
29
29
 
30
- it "has correct subject" do
30
+ it 'has correct subject' do
31
31
  provenance_fact_1.subject.should == subject
32
32
  end
33
33
 
34
- it "has correct predicate" do
35
- provenance_fact_1.predicate.should == "https://data.vandenabeele.com/ontologies/provenance#context"
34
+ it 'has correct predicate' do
35
+ provenance_fact_1.predicate.should == 'https://data.vandenabeele.com/ontologies/provenance#context'
36
36
  end
37
37
 
38
- it "has correct object" do
39
- provenance_fact_1.object.should == "public"
38
+ it 'has correct object' do
39
+ provenance_fact_1.object.should == 'public'
40
40
  end
41
41
 
42
- it "raises an ProvenanceError when provenance_subject is present in options hash" do
42
+ it 'raises an ProvenanceError when provenance_subject is present in options hash' do
43
43
  lambda { described_class.new(
44
- provenance_subject: described_class.new_subject,
45
- predicate: "test",
46
- object: "test") } .
44
+ provenance_subject: subject,
45
+ predicate: 'test',
46
+ object: 'test') } .
47
47
  should raise_error ProvenanceError
48
48
  end
49
49
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module TestFactories
4
+ describe ProvenanceFact do
5
+
6
+ describe 'TestFactories do not fail' do
7
+ it 'TestFactories::ProvenanceFact.context is OK' do
8
+ described_class.context.should_not be_nil
9
+ end
10
+
11
+ it 'TestFactories::ProvenanceFact.created_by is OK' do
12
+ described_class.created_by.should_not be_nil
13
+ end
14
+
15
+ it 'TestFactories::ProvenanceFact.original_source is OK' do
16
+ described_class.original_source.should_not be_nil
17
+ end
18
+
19
+ it 'TestFactories::ProvenanceFact.new_subject is OK' do
20
+ described_class.new_subject.should be_a(ProvenanceFact.new_subject.class)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -6,66 +6,66 @@ module Dbd
6
6
  let(:provenance_resource) { described_class.new }
7
7
  let(:provenance_resource_subject) { provenance_resource.subject }
8
8
 
9
- describe ".new" do
10
- describe "without a subject argument" do
11
- it "has created a new subject" do
9
+ describe '.new' do
10
+ describe 'without a subject argument' do
11
+ it 'has created a new subject' do
12
12
  provenance_resource.subject.should be_a(described_class.new_subject.class)
13
13
  end
14
14
  end
15
15
 
16
- describe "with a subject argument" do
17
- it "has stored the resource_subject" do
16
+ describe 'with a subject argument' do
17
+ it 'has stored the resource_subject' do
18
18
  described_class.new(subject: provenance_resource_subject).subject.
19
19
  should == provenance_resource_subject
20
20
  end
21
21
  end
22
22
 
23
- describe "with a provenance_subject argument" do
24
- it "raises an ProvenanceError" do
23
+ describe 'with a provenance_subject argument' do
24
+ it 'raises an ProvenanceError' do
25
25
  lambda{ described_class.new(provenance_subject: provenance_resource_subject) }.
26
26
  should raise_error(ArgumentError)
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
- describe "provenance_subject" do
32
- it "raises NoMethodError when called" do
31
+ describe 'provenance_subject' do
32
+ it 'raises NoMethodError when called' do
33
33
  lambda{ provenance_resource.provenance_subject }.should raise_error(NoMethodError)
34
34
  end
35
35
  end
36
36
 
37
- describe "Factories::Resource" do
38
- it ".provenance_resource works" do
39
- Factories::ProvenanceResource.provenance_resource
37
+ describe 'TestFactories::Resource' do
38
+ it '.provenance_resource works' do
39
+ TestFactories::ProvenanceResource.provenance_resource
40
40
  end
41
41
  end
42
42
 
43
- describe "the collection" do
43
+ describe 'the collection' do
44
44
 
45
- let(:provenance_fact_context) { Factories::ProvenanceFact.context }
46
- let(:provenance_fact_context_with_incorrect_subject) { Factories::ProvenanceFact.context(Factories::ProvenanceFact.new_subject) }
47
- let(:provenance_fact_context_with_correct_subject) { Factories::ProvenanceFact.context(provenance_resource_subject) }
48
- let(:fact_1) { Factories::Fact.fact_1(provenance_resource_subject) }
45
+ let(:provenance_fact_context) { TestFactories::ProvenanceFact.context }
46
+ let(:provenance_fact_context_with_incorrect_subject) { TestFactories::ProvenanceFact.context(TestFactories::ProvenanceFact.new_subject) }
47
+ let(:provenance_fact_context_with_correct_subject) { TestFactories::ProvenanceFact.context(provenance_resource_subject) }
48
+ let(:fact_1) { TestFactories::Fact.fact_1(provenance_resource_subject) }
49
49
 
50
- describe "adding provenance facts with << " do
51
- it "with correct subject it works" do
50
+ describe 'adding provenance facts with << ' do
51
+ it 'with correct subject it works' do
52
52
  provenance_resource << provenance_fact_context_with_correct_subject
53
53
  provenance_resource.first.subject.should == provenance_resource_subject
54
54
  end
55
55
 
56
- it "with incorrect subject it raises SetOnceError" do
56
+ it 'with incorrect subject it raises SetOnceError' do
57
57
  lambda{ provenance_resource << provenance_fact_context_with_incorrect_subject }.
58
58
  should raise_error(RubyPeterV::SetOnceError),
59
- "Value of subject was #{provenance_fact_context_with_incorrect_subject.subject}, " \
60
- "trying to set it to #{provenance_resource.subject}"
59
+ 'Value of subject was #{provenance_fact_context_with_incorrect_subject.subject}, ' \
60
+ 'trying to set it to #{provenance_resource.subject}'
61
61
  end
62
62
 
63
- it "with nil subject it sets the subject" do
63
+ it 'with nil subject it sets the subject' do
64
64
  provenance_resource << provenance_fact_context
65
65
  provenance_resource.first.subject.should == provenance_resource_subject
66
66
  end
67
67
 
68
- it "with nil (=correct) provenance_subject it is a noop" do
68
+ it 'with nil (=correct) provenance_subject it is a noop' do
69
69
  provenance_resource << provenance_fact_context
70
70
  provenance_resource.first.provenance_subject.should be_nil
71
71
  end
@@ -2,28 +2,28 @@ require 'spec_helper'
2
2
 
3
3
  module Dbd
4
4
  describe RdfBase do
5
- it "module exists" do
5
+ it 'module exists' do
6
6
  described_class # should not raise error
7
7
  end
8
8
 
9
- it "The RDF module is loaded" do
9
+ it 'The RDF module is loaded' do
10
10
  RDF # should not raise error
11
11
  end
12
12
 
13
- describe "play with a rdf_graph" do
13
+ describe 'play with a rdf_graph' do
14
14
 
15
- let(:rdf_graph) { RDF::Graph.new << [:hi, RDF::DC.title, "Hello, world!"] }
15
+ let(:rdf_graph) { RDF::Graph.new << [:hi, RDF::DC.title, 'Hello, world!'] }
16
16
 
17
- it "Create a rdf_graph" do
17
+ it 'Create a rdf_graph' do
18
18
  rdf_graph # should_not raise_error
19
19
  end
20
20
 
21
- it "writing data" do
21
+ it 'writing data' do
22
22
  rdf_graph.dump(:ntriples).chomp.should ==
23
23
  '_:hi <http://purl.org/dc/terms/title> "Hello, world!" .'
24
24
  end
25
25
 
26
- it "Reading N-triples" do
26
+ it 'Reading N-triples' do
27
27
  n_triples_string =
28
28
  '<http://example.com/test#1> ' +
29
29
  '<http://www.w3.org/2000/01/rdf-schema#label> ' +