doodle 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,4 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '../.'))
2
-
3
- require 'lib/doodle'
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
4
2
 
5
3
  describe 'flatten_first_level' do
6
4
 
@@ -26,6 +24,9 @@ describe 'flatten_first_level' do
26
24
  [1, [2, 3]],
27
25
  ]
28
26
  end
27
+ after :each do
28
+ remove_ivars :data, :results
29
+ end
29
30
 
30
31
  it 'should flatten first level' do
31
32
  @data.zip(@results).each do |input, result|
@@ -1,57 +1,53 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '../.'))
2
- require 'lib/spec_helper'
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
2
 
4
3
  describe Doodle, 'init' do
4
+ temporary_constant :Foo do
5
5
 
6
- before(:each) do
7
- raise_if_defined :Foo
8
- class Foo
9
- include Doodle::Helper
10
- has :name, :init => 'D1'
11
- class << self
12
- has :metadata, :init => 'D2'
6
+ before(:each) do
7
+ class Foo
8
+ include Doodle::Helper
9
+ has :name, :init => 'D1'
10
+ class << self
11
+ has :metadata, :init => 'D2'
12
+ end
13
+ end
14
+ @foo = Foo.new
15
+ class << @foo
16
+ has :special, :init => 'D3'
13
17
  end
14
18
  end
15
- @foo = Foo.new
16
- class << @foo
17
- has :special, :init => 'D3'
18
- end
19
- end
20
- after :each do
21
- undefine_const :Foo
22
- end
23
19
 
24
- it 'should have instance attribute init via class' do
25
- Foo.attributes[:name].init.should == 'D1'
26
- end
27
- it 'should have instance attribute init via instance' do
28
- @foo.attributes[:name].init.should == 'D1'
29
- end
30
- it 'should have class attribute init via class.singleton_class' do
31
- Foo.singleton_class.attributes(false)[:metadata].init.should == 'D2'
32
- end
33
- it 'should have class attribute init via class.singleton_class' do
34
- Foo.singleton_class.attributes[:metadata].init.should == 'D2'
35
- end
36
- it 'should have singleton attribute init via instance.singleton_class' do
37
- @foo.singleton_class.attributes(false)[:special].init.should == 'D3'
38
- end
39
- it 'should have singleton attribute init via instance.singleton_class' do
40
- @foo.singleton_class.attributes[:special].init.should == 'D3'
41
- end
42
- it 'should have an attribute :name from init' do
43
- @foo.name.should == 'D1'
44
- end
45
- it 'should have an instance_variable for attribute :name' do
46
- @foo.instance_variables.include?('@name').should == true
47
- end
48
- it 'should have an initialized class attribute :metadata' do
49
- pending 'deciding how this should work'
50
- Foo.metadata.should == 'D2'
51
- end
52
- it 'should have an initialized singleton attribute :special' do
53
- pending 'deciding how this should work'
54
- @foo.special.should == 'D3'
20
+ it 'should have instance attribute init via class' do
21
+ Foo.attributes[:name].init.should == 'D1'
22
+ end
23
+ it 'should have instance attribute init via instance' do
24
+ @foo.attributes[:name].init.should == 'D1'
25
+ end
26
+ it 'should have class attribute init via class.singleton_class' do
27
+ Foo.singleton_class.attributes(false)[:metadata].init.should == 'D2'
28
+ end
29
+ it 'should have class attribute init via class.singleton_class' do
30
+ Foo.singleton_class.attributes[:metadata].init.should == 'D2'
31
+ end
32
+ it 'should have singleton attribute init via instance.singleton_class' do
33
+ @foo.singleton_class.attributes(false)[:special].init.should == 'D3'
34
+ end
35
+ it 'should have singleton attribute init via instance.singleton_class' do
36
+ @foo.singleton_class.attributes[:special].init.should == 'D3'
37
+ end
38
+ it 'should have an attribute :name from init' do
39
+ @foo.name.should == 'D1'
40
+ end
41
+ it 'should have an instance_variable for attribute :name' do
42
+ @foo.instance_variables.include?('@name').should == true
43
+ end
44
+ it 'should have an initialized class attribute :metadata' do
45
+ pending 'deciding how this should work'
46
+ #Foo.metadata.should == 'D2'
47
+ end
48
+ it 'should have an initialized singleton attribute :special' do
49
+ pending 'deciding how this should work'
50
+ #@foo.special.should == 'D3'
51
+ end
55
52
  end
56
53
  end
57
- raise_if_defined :Foo
@@ -1,25 +1,17 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '../.'))
2
-
3
- require 'lib/spec_helper'
4
- require 'date'
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
5
2
 
6
3
  describe Doodle, 'defaults which have not been set' do
7
- after :each do
8
- undefine_const(:Foo)
9
- end
10
- before :each do
11
- raise_if_defined :Foo
12
-
13
- class Foo < Doodle::Base
14
- has :baz
15
- has :start do
16
- default { Date.today }
4
+ temporary_constant :Foo do
5
+ before :each do
6
+ class Foo < Doodle::Base
7
+ has :baz
8
+ has :start, :default => 1
17
9
  end
18
10
  end
19
- end
20
11
 
21
- it 'should have raise error if required value not set' do
22
- proc { Foo.new }.should raise_error(ArgumentError)
12
+ it 'should have raise error if required value not set' do
13
+ proc { Foo.new }.should raise_error(ArgumentError)
14
+ end
23
15
  end
24
16
  end
25
17
 
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require 'yaml'
3
+
4
+ describe Doodle, "Serialization" do
5
+ temporary_constant :Foo do
6
+ before :each do
7
+ class Foo < Doodle::Base
8
+ has :var, :kind => Integer
9
+ end
10
+ @foo = Foo 42
11
+ end
12
+ after :each do
13
+ remove_ivars :foo
14
+ end
15
+
16
+ it "should be serializable to yaml" do
17
+ @foo.to_yaml.should == "--- !ruby/object:Foo \nvar: 42\n"
18
+ end
19
+
20
+ it "should be loadable from yaml" do
21
+ src = @foo.to_yaml
22
+ new_foo = YAML::load(src)
23
+ new_foo.var.should == 42
24
+ end
25
+
26
+ it "should make it possible to validate already set instance variables" do
27
+ new_foo = YAML::load("--- !ruby/object:Foo \nvar: Hello World!\n")
28
+ proc { new_foo.validate!(true) }.should raise_error(Doodle::ValidationError)
29
+ end
30
+
31
+ end
32
+ end
@@ -1,27 +1,24 @@
1
- require 'lib/spec_helper'
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe 'Doodle', 'singleton superclass == self' do
4
- after :each do
5
- undefine_const(:Foo)
6
- end
7
- before :each do
8
- raise_if_defined :Foo
9
-
10
- class Foo < Doodle::Base
3
+ describe 'Doodle', 'parents' do
4
+ temporary_constant :Foo do
5
+ before :each do
6
+ class Foo < Doodle::Base
7
+ end
8
+ @foo = Foo.new
9
+ @sc = class << @foo; self; end
10
+ @scc = class << @sc; self; end
11
+ @sclass_doodle_root = class << Doodle::Base; self; end
12
+ @sclass_foo = class << @foo; class << self; self; end; end
11
13
  end
12
- @foo = Foo.new
13
- @sc = class << @foo; self; end
14
- @scc = class << @sc; self; end
15
- @sclass_doodle_root = class << Doodle::Base; self; end
16
- @sclass_foo = class << @foo; class << self; self; end; end
17
- end
18
14
 
19
- it 'should have singleton class superclass == self' do
20
- @sc.parents.should == [@sclass_foo, @sclass_doodle_root]
21
- end
15
+ it 'should have singleton class parents == class, doodle root' do
16
+ @sc.parents.should == [@sclass_foo, @sclass_doodle_root]
17
+ end
22
18
 
23
- it 'should have singleton class superclass == self' do
24
- @scc.parents.should == []
19
+ it "should have singleton class's singleton class parents == []" do
20
+ @scc.parents.should == []
21
+ end
25
22
  end
26
23
  end
27
24
 
@@ -1,108 +1,99 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '../.'))
2
-
3
- require 'lib/spec_helper'
4
- require 'date'
5
-
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
2
 
7
3
  describe :DateRange, 'validation & conversions' do
8
- after :each do
9
- undefine_const :DateRange
10
- undefine_const :Base
11
- undefine_const :ClassMethods
12
- end
13
- before :each do
14
- raise_if_defined :Base, :ClassMethods, :DateRange
15
-
16
- module ClassMethods
17
- def date(*a, &b)
18
- # if a.size > 0
19
- name = a.shift
20
- # else
21
- # name = :date
22
- # end
23
- td = has(name, :kind => Date, *a) do
24
- # it is a bit clumsy to define these conversions &
25
- # conditions for every attribute/typedef - could define a
26
- # subclass of Typedef which does this by default (so we
27
- # instances can override or defer to class level conversions
28
- # and conditions)
29
- from String do |s|
30
- Date.parse(s)
31
- end
32
- from Array do |y,m,d|
33
- #p [:from, Array, y, m, d]
34
- Date.new(y, m, d)
35
- end
36
- from Integer do |jd|
37
- Doodle::Debug.d { [:converting_from, Integer, jd] }
38
- Date.new(*Date.jd_to_civil(jd))
4
+ temporary_constants :Base, :DateRange, :ClassMethods do
5
+
6
+ before :each do
7
+ module ClassMethods
8
+ def date(*a, &b)
9
+ # if a.size > 0
10
+ name = a.shift
11
+ # else
12
+ # name = :date
13
+ # end
14
+ td = has(name, :kind => Date, *a) do
15
+ # it is a bit clumsy to define these conversions &
16
+ # conditions for every attribute/typedef - could define a
17
+ # subclass of Typedef which does this by default (so we
18
+ # instances can override or defer to class level conversions
19
+ # and conditions)
20
+ from String do |s|
21
+ Date.parse(s)
22
+ end
23
+ from Array do |y,m,d|
24
+ #p [:from, Array, y, m, d]
25
+ Date.new(y, m, d)
26
+ end
27
+ from Integer do |jd|
28
+ Doodle::Debug.d { [:converting_from, Integer, jd] }
29
+ Date.new(*Date.jd_to_civil(jd))
30
+ end
39
31
  end
32
+ Doodle::Debug.d { [:date, td] }
33
+ td.instance_eval(&b) if block_given? # user's block should override default
40
34
  end
41
- Doodle::Debug.d { [:date, td] }
42
- td.instance_eval(&b) if block_given? # user's block should override default
43
35
  end
44
- end
45
36
 
46
- class Base < Doodle::Base
47
- extend ClassMethods
48
- end
37
+ class Base < Doodle::Base
38
+ extend ClassMethods
39
+ end
49
40
 
50
- class DateRange < Base
51
- date :start_date do
52
- Doodle::Debug.d { [:start_date, self, self.class] }
53
- default { Date.today }
54
- must "be >= 2007-01-01" do |d|
55
- d >= Date.new(2007, 01, 01)
41
+ class DateRange < Base
42
+ date :start_date do
43
+ Doodle::Debug.d { [:start_date, self, self.class] }
44
+ default { Date.today }
45
+ must "be >= 2007-01-01" do |d|
46
+ d >= Date.new(2007, 01, 01)
47
+ end
48
+ end
49
+ date :end_date do
50
+ default { start_date }
51
+ end
52
+ must "have end_date >= start_date" do
53
+ end_date >= start_date
56
54
  end
57
- end
58
- date :end_date do
59
- default { start_date }
60
- end
61
- must "have end_date >= start_date" do
62
- end_date >= start_date
63
55
  end
64
56
  end
65
- end
66
57
 
67
- it 'should not raise an exception if end_date >= start_date' do
68
- proc { DateRange.new('2007-01-01', '2007-01-02') }.should_not raise_error
69
- end
58
+ it 'should not raise an exception if end_date >= start_date' do
59
+ proc { DateRange.new('2007-01-01', '2007-01-02') }.should_not raise_error
60
+ end
70
61
 
71
- it 'should raise an exception if end_date < start_date' do
72
- proc { DateRange.new('2007-01-02', '2007-01-01') }.should raise_error
73
- end
62
+ it 'should raise an exception if end_date < start_date' do
63
+ proc { DateRange.new('2007-01-02', '2007-01-01') }.should raise_error
64
+ end
74
65
 
75
- it 'should raise an exception if end_date < start_date' do
76
- proc { DateRange.new('2007-01-01', '2007-01-01') }.should_not raise_error
77
- end
66
+ it 'should raise an exception if end_date < start_date' do
67
+ proc { DateRange.new('2007-01-01', '2007-01-01') }.should_not raise_error
68
+ end
78
69
 
79
- it 'should have start_date kind == Date' do
80
- d = DateRange.new
81
- d.attributes[:start_date].kind == Date
82
- end
70
+ it 'should have start_date kind == Date' do
71
+ d = DateRange.new
72
+ d.attributes[:start_date].kind == Date
73
+ end
83
74
 
84
- it 'should have two validations' do
85
- d = DateRange.new
86
- d.attributes[:start_date].validations.size.should == 2
87
- d.attributes[:start_date].validations(false).size.should == 2
88
- end
75
+ it 'should have two validations' do
76
+ d = DateRange.new
77
+ d.attributes[:start_date].validations.size.should == 2
78
+ d.attributes[:start_date].validations(false).size.should == 2
79
+ end
89
80
 
90
- it 'should have two conversions' do
91
- d = DateRange.new
92
- d.attributes[:start_date].conversions.size.should == 3
93
- d.attributes[:start_date].conversions(false).size.should == 3
94
- end
81
+ it 'should have two conversions' do
82
+ d = DateRange.new
83
+ d.attributes[:start_date].conversions.size.should == 3
84
+ d.attributes[:start_date].conversions(false).size.should == 3
85
+ end
95
86
 
96
- it 'should convert from Array' do
97
- d = DateRange.new [2007,01,01], [2007,01,02]
98
- d.start_date.should == Date.new(2007,01,01)
99
- d.end_date.should == Date.new(2007,01,02)
100
- end
87
+ it 'should convert from Array' do
88
+ d = DateRange.new [2007,01,01], [2007,01,02]
89
+ d.start_date.should == Date.new(2007,01,01)
90
+ d.end_date.should == Date.new(2007,01,02)
91
+ end
101
92
 
102
- it 'should convert Integer representing Julian date to Date' do
103
- d = DateRange.new 2454428, 2454429
104
- d.start_date.should == Date.new(2007,11,23)
105
- d.end_date.should == Date.new(2007,11,24)
93
+ it 'should convert Integer representing Julian date to Date' do
94
+ d = DateRange.new 2454428, 2454429
95
+ d.start_date.should == Date.new(2007,11,23)
96
+ d.end_date.should == Date.new(2007,11,24)
97
+ end
106
98
  end
107
-
108
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doodle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean O'Halpin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-15 00:00:00 +00:00
12
+ date: 2008-03-16 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,16 +26,12 @@ extra_rdoc_files:
26
26
  files:
27
27
  - lib/doodle.rb
28
28
  - lib/molic_orderedhash.rb
29
- - lib/spec_helper.rb
30
29
  - examples/event-location.rb
31
30
  - examples/event.rb
32
31
  - examples/event1.rb
33
32
  - examples/event2.rb
34
33
  - examples/example-01.rb
35
- - examples/example-01.rdoc
36
34
  - examples/example-02.rb
37
- - examples/example-02.rdoc
38
- - examples/foo.rb
39
35
  - README
40
36
  - COPYING
41
37
  - ChangeLog
@@ -68,12 +64,15 @@ summary: Declarative attribute definitions, validations and conversions
68
64
  test_files:
69
65
  - spec/arg_order_spec.rb
70
66
  - spec/attributes_spec.rb
67
+ - spec/bugs_spec.rb
71
68
  - spec/class_spec.rb
69
+ - spec/collector_spec.rb
72
70
  - spec/conversion_spec.rb
73
71
  - spec/defaults_spec.rb
74
72
  - spec/doodle_spec.rb
75
73
  - spec/flatten_first_level_spec.rb
76
74
  - spec/init_spec.rb
77
75
  - spec/required_spec.rb
76
+ - spec/serialization_spec.rb
78
77
  - spec/superclass_spec.rb
79
78
  - spec/validation_spec.rb