doodle 0.1.8 → 0.1.9
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.
- data/History.txt +52 -0
- data/Manifest.txt +1 -0
- data/examples/mail-datatypes.rb +1 -0
- data/examples/mail.rb +1 -1
- data/examples/profile-options.rb +1 -1
- data/lib/doodle.rb +332 -103
- data/lib/doodle/app.rb +445 -0
- data/lib/doodle/datatypes.rb +124 -15
- data/lib/doodle/version.rb +1 -1
- data/lib/molic_orderedhash.rb +99 -162
- data/log/debug.log +1 -0
- data/spec/block_init_spec.rb +52 -0
- data/spec/bugs_spec.rb +114 -18
- data/spec/class_var_spec.rb +28 -14
- data/spec/conversion_spec.rb +36 -38
- data/spec/doodle_spec.rb +23 -23
- data/spec/has_spec.rb +19 -1
- data/spec/init_spec.rb +22 -16
- data/spec/member_init_spec.rb +122 -0
- data/spec/readonly_spec.rb +32 -0
- data/spec/singleton_spec.rb +7 -7
- data/spec/spec_helper.rb +1 -1
- data/spec/symbolize_keys_spec.rb +40 -0
- data/spec/to_hash_spec.rb +35 -0
- metadata +39 -22
data/spec/class_var_spec.rb
CHANGED
@@ -48,28 +48,42 @@ describe Doodle, 'class attributes:' do
|
|
48
48
|
}.should_not raise_error
|
49
49
|
end
|
50
50
|
|
51
|
-
it 'should be possible to set a singleton variable without setting a newly added instance var' do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
}.should_not raise_error
|
63
|
-
end
|
51
|
+
it 'should not be possible to set a singleton variable without setting a newly added instance var' do
|
52
|
+
proc {
|
53
|
+
foo = Bar.new
|
54
|
+
class << foo
|
55
|
+
has :svar, :init => 43
|
56
|
+
end
|
57
|
+
class Bar < Doodle
|
58
|
+
has :ivar
|
59
|
+
end
|
60
|
+
foo.svar = 44
|
61
|
+
}.should raise_error(Doodle::ValidationError)
|
64
62
|
end
|
65
63
|
|
64
|
+
it 'should be possible to set a singleton variable along with setting a newly added instance var using defer_validation' do
|
65
|
+
proc {
|
66
|
+
foo = Bar.new
|
67
|
+
class << foo
|
68
|
+
has :svar, :init => 43
|
69
|
+
end
|
70
|
+
class Bar < Doodle
|
71
|
+
has :ivar
|
72
|
+
end
|
73
|
+
foo.doodle.defer_validation do
|
74
|
+
svar 44
|
75
|
+
ivar 42
|
76
|
+
end
|
77
|
+
}.should_not raise_error
|
78
|
+
end
|
79
|
+
|
66
80
|
it 'should validate class var' do
|
67
81
|
proc { Foo.cvar = "Hello" }.should raise_error(Doodle::ValidationError)
|
68
82
|
end
|
69
83
|
|
70
84
|
it 'should be possible to read initialized class var' do
|
71
85
|
#pending 'getting this working' do
|
72
|
-
|
86
|
+
proc { Foo.cvar == 1 }.should_not raise_error
|
73
87
|
#end
|
74
88
|
end
|
75
89
|
end
|
data/spec/conversion_spec.rb
CHANGED
@@ -2,53 +2,51 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
describe Doodle, 'conversions' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
temporary_constant(:Foo) do
|
6
|
+
before(:each) do
|
7
|
+
class Foo < Doodle
|
8
|
+
has :start do
|
9
|
+
default { Date.today }
|
10
|
+
from String do |s|
|
11
|
+
Doodle::Debug.d { [:converting_from, String, s] }
|
12
|
+
Date.parse(s)
|
13
|
+
end
|
14
|
+
from Integer do |jd|
|
15
|
+
Doodle::Debug.d { [:converting_from, Integer, jd] }
|
16
|
+
Date.new(*Date.send(:jd_to_civil, jd))
|
17
|
+
end
|
16
18
|
end
|
17
|
-
from
|
18
|
-
Doodle::Debug.d { [:
|
19
|
-
|
19
|
+
from String do |s|
|
20
|
+
Doodle::Debug.d { [:from, self, self.class] }
|
21
|
+
new(:start => s)
|
20
22
|
end
|
21
23
|
end
|
22
|
-
from String do |s|
|
23
|
-
Doodle::Debug.d { [:from, self, self.class] }
|
24
|
-
new(:start => s)
|
25
|
-
end
|
26
24
|
end
|
27
|
-
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
it 'should have default date == today' do
|
27
|
+
foo = Foo.new
|
28
|
+
foo.start.should == Date.today
|
29
|
+
end
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
it 'should convert String to Date' do
|
32
|
+
foo = Foo.new(:start => '2007-12-31')
|
33
|
+
foo.start.should == Date.new(2007, 12, 31)
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
it 'should convert Integer representing Julian date to Date' do
|
37
|
+
foo = Foo.new(:start => 2454428)
|
38
|
+
foo.start.should == Date.new(2007, 11, 23)
|
39
|
+
end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
it 'should allow from' do
|
42
|
+
foo = Foo.from("2007-12-31")
|
43
|
+
foo.start.should == Date.new(2007, 12, 31)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should return class_conversions' do
|
47
|
+
Foo.doodle.conversions.keys.should == [String]
|
48
|
+
end
|
48
49
|
|
49
|
-
it 'should return class_conversions' do
|
50
|
-
Foo.doodle.conversions.keys.should == [String]
|
51
50
|
end
|
52
51
|
|
53
52
|
end
|
54
|
-
|
data/spec/doodle_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe Doodle, 'instance attributes' do
|
|
30
30
|
it 'should list instance attributes' do
|
31
31
|
@foo.doodle.attributes.keys.should_be [:name]
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it 'should list all instance attributes(false) at class level' do
|
35
35
|
Foo.doodle.attributes(false).keys.should_be [:name]
|
36
36
|
end
|
@@ -70,7 +70,7 @@ describe Doodle, 'class attributes(false)' do
|
|
70
70
|
it "should list all class's own attributes" do
|
71
71
|
Foo.singleton_class.doodle.attributes(false).keys.should_be [:metadata]
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
it "should list all class's own attributes" do
|
75
75
|
Foo.singleton_class.doodle.attributes.keys.should_be [:metadata]
|
76
76
|
end
|
@@ -90,7 +90,7 @@ describe Doodle, 'inherited class attributes(false)' do
|
|
90
90
|
class Bar < Foo
|
91
91
|
has :location, :default => nil
|
92
92
|
class << self
|
93
|
-
has :
|
93
|
+
has :notes
|
94
94
|
end
|
95
95
|
end
|
96
96
|
@foo = Foo.new
|
@@ -135,27 +135,27 @@ describe Doodle, 'inherited class attributes(false)' do
|
|
135
135
|
Foo.metadata.should_be 'Foo metadata'
|
136
136
|
@foo.class.metadata.should_be 'Foo metadata'
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
it "should list class's own attributes" do
|
140
140
|
Foo.singleton_class.doodle.attributes(false).keys.should_be [:metadata]
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
it "should list all class's own attributes" do
|
144
144
|
Foo.singleton_class.doodle.attributes.keys.should_be [:metadata]
|
145
145
|
end
|
146
146
|
|
147
147
|
it "should list class's own attributes(false)" do
|
148
|
-
Bar.singleton_class.doodle.attributes(false).keys.should_be [:
|
148
|
+
Bar.singleton_class.doodle.attributes(false).keys.should_be [:notes]
|
149
149
|
end
|
150
150
|
|
151
151
|
it "should list all singleton class attributes" do
|
152
|
-
Bar.singleton_class.doodle.attributes.keys.should_be [:
|
152
|
+
Bar.singleton_class.doodle.attributes.keys.should_be [:notes]
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should list all inherited meta class attributes" do
|
156
|
-
Bar.doodle.class_attributes.keys.should_be [:metadata, :
|
156
|
+
Bar.doodle.class_attributes.keys.should_be [:metadata, :notes]
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
it "should list all inherited class's attributes" do
|
160
160
|
Bar.doodle.attributes.keys.should_be [:name, :location]
|
161
161
|
end
|
@@ -165,7 +165,7 @@ end
|
|
165
165
|
describe Doodle, 'singleton class attributes' do
|
166
166
|
temporary_constant :Foo do
|
167
167
|
before(:each) do
|
168
|
-
|
168
|
+
|
169
169
|
class Foo
|
170
170
|
include Doodle::Core
|
171
171
|
has :name, :default => nil
|
@@ -181,7 +181,7 @@ describe Doodle, 'singleton class attributes' do
|
|
181
181
|
after :each do
|
182
182
|
remove_ivars :foo
|
183
183
|
end
|
184
|
-
|
184
|
+
|
185
185
|
it 'should allow creation of singleton class attributes' do
|
186
186
|
@foo.special = 42
|
187
187
|
@foo.special.should_be 42
|
@@ -215,7 +215,7 @@ describe Doodle, 'inherited singleton class attributes' do
|
|
215
215
|
class Bar < Foo
|
216
216
|
has :info, :default => nil
|
217
217
|
class << self
|
218
|
-
has :
|
218
|
+
has :notes
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
@@ -229,11 +229,11 @@ describe Doodle, 'inherited singleton class attributes' do
|
|
229
229
|
has :extra
|
230
230
|
end
|
231
231
|
end
|
232
|
-
|
232
|
+
|
233
233
|
after :each do
|
234
234
|
remove_ivars :foo, :bar, :bar2
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
it 'should allow creation of singleton class attributes' do
|
238
238
|
@foo.special = 42
|
239
239
|
@foo.special.should_be 42
|
@@ -259,13 +259,13 @@ describe Doodle, 'inherited singleton class attributes' do
|
|
259
259
|
@foo.singleton_class.doodle.attributes.keys.should_be [:special]
|
260
260
|
@bar.singleton_class.doodle.attributes.keys.should_be [:extra]
|
261
261
|
end
|
262
|
-
|
262
|
+
|
263
263
|
it 'should keep meta attributes separate' do
|
264
264
|
@foo.special = 'foo special'
|
265
265
|
@foo.special.should_be 'foo special'
|
266
266
|
|
267
267
|
# CHECK
|
268
|
-
|
268
|
+
|
269
269
|
# note: you cannot set any other values on @bar until you have set @bar.extra because it's defined as required
|
270
270
|
@bar.extra = 'bar extra'
|
271
271
|
@bar.extra.should_be 'bar extra'
|
@@ -273,8 +273,8 @@ describe Doodle, 'inherited singleton class attributes' do
|
|
273
273
|
Foo.metadata.should_be 'Foo meta'
|
274
274
|
Bar.metadata = 'Bar meta'
|
275
275
|
Bar.metadata.should_be 'Bar meta'
|
276
|
-
Bar.
|
277
|
-
Bar.
|
276
|
+
Bar.notes = 'Bar notes'
|
277
|
+
Bar.notes.should_be 'Bar notes'
|
278
278
|
|
279
279
|
# now make sure they haven't bumped each other off
|
280
280
|
@foo.special.should_be 'foo special'
|
@@ -282,7 +282,7 @@ describe Doodle, 'inherited singleton class attributes' do
|
|
282
282
|
@bar.extra.should_be 'bar extra'
|
283
283
|
Foo.metadata.should_be 'Foo meta'
|
284
284
|
Bar.metadata.should_be 'Bar meta'
|
285
|
-
Bar.
|
285
|
+
Bar.notes.should_be 'Bar notes'
|
286
286
|
end
|
287
287
|
|
288
288
|
it 'should inherit singleton methods from class' do
|
@@ -298,19 +298,19 @@ describe Doodle, 'inherited singleton class attributes' do
|
|
298
298
|
end
|
299
299
|
end
|
300
300
|
end
|
301
|
-
|
301
|
+
|
302
302
|
it 'should behave predictably when setting singleton attributes' do
|
303
303
|
@bar.extra = 'bar extra'
|
304
304
|
@bar.extra.should_be 'bar extra'
|
305
305
|
@bar.singleton_class.metadata = 'bar meta metadata'
|
306
306
|
if RUBY_VERSION < '1.9.0'
|
307
307
|
@bar.singleton_class.metadata.should_be 'bar meta metadata'
|
308
|
-
@bar.singleton_class.
|
309
|
-
@bar.singleton_class.
|
308
|
+
@bar.singleton_class.notes = 'bar notes'
|
309
|
+
@bar.singleton_class.notes.should_be 'bar notes'
|
310
310
|
else
|
311
311
|
pending 'figuring out why this fails in 1.9'
|
312
312
|
end
|
313
|
-
proc { @foo.singleton_class.
|
313
|
+
proc { @foo.singleton_class.notes = 1 }.should raise_error(NoMethodError)
|
314
314
|
end
|
315
315
|
end
|
316
316
|
end
|
data/spec/has_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
3
|
describe Doodle, 'has Class' do
|
4
|
-
temporary_constant :Foo, :Bar do
|
4
|
+
temporary_constant :Foo, :Bar, :AudioClip do
|
5
5
|
it "should convert 'has Bar' into 'has :bar, :kind => Bar'" do
|
6
6
|
class Bar
|
7
7
|
end
|
@@ -41,5 +41,23 @@ describe Doodle, 'has Class' do
|
|
41
41
|
proc { Foo.new(:bar => Bar.new) }.should_not raise_error
|
42
42
|
proc { Foo.new(:bar => "Hello") }.should raise_error(Doodle::ValidationError)
|
43
43
|
end
|
44
|
+
it "should apply validations for 'has Bar' as if 'has :bar, :kind => Bar' was used" do
|
45
|
+
class Bar
|
46
|
+
end
|
47
|
+
class Foo < Doodle
|
48
|
+
has Bar
|
49
|
+
end
|
50
|
+
proc { Foo.new(:bar => Bar.new) }.should_not raise_error
|
51
|
+
proc { Foo.new(:bar => "Hello") }.should raise_error(Doodle::ValidationError)
|
52
|
+
end
|
53
|
+
it "should apply validations for 'has Bar' as if 'has :bar, :kind => Bar' was used" do
|
54
|
+
class Bar
|
55
|
+
end
|
56
|
+
class Foo < Doodle
|
57
|
+
has Bar
|
58
|
+
end
|
59
|
+
proc { Foo.new(:bar => Bar.new) }.should_not raise_error
|
60
|
+
proc { Foo.new(:bar => "Hello") }.should raise_error(Doodle::ValidationError)
|
61
|
+
end
|
44
62
|
end
|
45
63
|
end
|
data/spec/init_spec.rb
CHANGED
@@ -17,37 +17,37 @@ describe Doodle, 'init' do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
it 'should have instance attribute init via class' do
|
20
|
-
Foo.doodle.attributes[:moniker].init.
|
20
|
+
Foo.doodle.attributes[:moniker].init.should_be 'D1'
|
21
21
|
end
|
22
22
|
it 'should have instance attribute init via instance' do
|
23
|
-
@foo.doodle.attributes[:moniker].init.
|
23
|
+
@foo.doodle.attributes[:moniker].init.should_be 'D1'
|
24
24
|
end
|
25
25
|
it 'should have class attribute init via class.singleton_class' do
|
26
|
-
Foo.singleton_class.doodle.attributes(false)[:metadata].init.
|
26
|
+
Foo.singleton_class.doodle.attributes(false)[:metadata].init.should_be 'D2'
|
27
27
|
end
|
28
28
|
it 'should have class attribute init via class.singleton_class' do
|
29
|
-
Foo.singleton_class.doodle.attributes[:metadata].init.
|
29
|
+
Foo.singleton_class.doodle.attributes[:metadata].init.should_be 'D2'
|
30
30
|
end
|
31
31
|
it 'should have singleton attribute init via instance.singleton_class' do
|
32
|
-
@foo.singleton_class.doodle.attributes(false)[:special].init.
|
32
|
+
@foo.singleton_class.doodle.attributes(false)[:special].init.should_be 'D3'
|
33
33
|
end
|
34
34
|
it 'should have singleton attribute init via instance.singleton_class' do
|
35
|
-
@foo.singleton_class.doodle.attributes[:special].init.
|
35
|
+
@foo.singleton_class.doodle.attributes[:special].init.should_be 'D3'
|
36
36
|
end
|
37
37
|
it 'should have an attribute :moniker from init' do
|
38
|
-
@foo.moniker.
|
38
|
+
@foo.moniker.should_be 'D1'
|
39
39
|
end
|
40
40
|
it 'should have an instance_variable for attribute :moniker' do
|
41
|
-
@foo.instance_variables.map{ |x| x.to_sym }.include?(:@moniker).
|
41
|
+
@foo.instance_variables.map{ |x| x.to_sym }.include?(:@moniker).should_be true
|
42
42
|
end
|
43
43
|
it 'should have an initialized class attribute :metadata' do
|
44
44
|
#pending 'deciding how this should work' do
|
45
|
-
Foo.metadata.
|
45
|
+
Foo.metadata.should_be 'D2'
|
46
46
|
#end
|
47
47
|
end
|
48
48
|
it 'should have an initialized singleton attribute :special' do
|
49
49
|
#pending 'deciding how this should work' do
|
50
|
-
@foo.special.
|
50
|
+
@foo.special.should_be 'D3'
|
51
51
|
#end
|
52
52
|
end
|
53
53
|
end
|
@@ -60,7 +60,7 @@ describe Doodle, 'init' do
|
|
60
60
|
has :value, :init => nil
|
61
61
|
end
|
62
62
|
foo = Foo.new
|
63
|
-
foo.value.
|
63
|
+
foo.value.should_be nil
|
64
64
|
end
|
65
65
|
end
|
66
66
|
temporary_constant :Foo do
|
@@ -69,7 +69,7 @@ describe Doodle, 'init' do
|
|
69
69
|
has :value, :init => true
|
70
70
|
end
|
71
71
|
foo = Foo.new
|
72
|
-
foo.value.
|
72
|
+
foo.value.should_be true
|
73
73
|
end
|
74
74
|
end
|
75
75
|
temporary_constant :Foo do
|
@@ -78,7 +78,7 @@ describe Doodle, 'init' do
|
|
78
78
|
has :value, :init => 42
|
79
79
|
end
|
80
80
|
foo = Foo.new
|
81
|
-
foo.value.
|
81
|
+
foo.value.should_be 42
|
82
82
|
end
|
83
83
|
end
|
84
84
|
temporary_constant :Foo do
|
@@ -87,20 +87,26 @@ describe Doodle, 'init' do
|
|
87
87
|
has :value, :init => proc { 42 }
|
88
88
|
end
|
89
89
|
foo = Foo.new
|
90
|
-
foo.value.call.
|
90
|
+
foo.value.call.should_be 42
|
91
91
|
end
|
92
92
|
end
|
93
93
|
temporary_constant :Foo do
|
94
94
|
it 'should evaluate value when block given as :init' do
|
95
95
|
class Foo < Doodle
|
96
|
-
has :value do
|
96
|
+
has :value, :kind => Integer do
|
97
97
|
init do
|
98
98
|
42
|
99
99
|
end
|
100
100
|
end
|
101
|
+
has :name, :kind => String do
|
102
|
+
init do
|
103
|
+
"foo"
|
104
|
+
end
|
105
|
+
end
|
101
106
|
end
|
102
107
|
foo = Foo.new
|
103
|
-
foo.value.
|
108
|
+
foo.value.should_be 42
|
109
|
+
foo.name.should_be "foo"
|
104
110
|
end
|
105
111
|
end
|
106
112
|
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe 'Doodle', 'initialization of scalar attributes from hash' do
|
5
|
+
temporary_constant :Foo, :Bar do
|
6
|
+
before :each do
|
7
|
+
class Bar < Doodle
|
8
|
+
has :name, :kind => String
|
9
|
+
has :count, :kind => Integer
|
10
|
+
end
|
11
|
+
class Foo < Doodle
|
12
|
+
has Bar
|
13
|
+
has :v2, :kind => String, :default => "bar"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should initialize an attribute from a hash' do
|
18
|
+
foo = Foo do
|
19
|
+
bar :name => "hello", :count => 1
|
20
|
+
end
|
21
|
+
foo.bar.name.should_be "hello"
|
22
|
+
foo.bar.count.should_be 1
|
23
|
+
end
|
24
|
+
it 'should fail trying to initialize with incorrect keyword values' do
|
25
|
+
proc {
|
26
|
+
foo = Foo do
|
27
|
+
bar :name => 1, :count => "hello"
|
28
|
+
end
|
29
|
+
}.should raise_error(Doodle::ValidationError)
|
30
|
+
end
|
31
|
+
it 'should work with positional args' do
|
32
|
+
foo = nil
|
33
|
+
proc {
|
34
|
+
foo = Foo do
|
35
|
+
bar "hello", 1
|
36
|
+
end
|
37
|
+
}.should_not raise_error
|
38
|
+
foo.bar.name.should_be "hello"
|
39
|
+
foo.bar.count.should_be 1
|
40
|
+
end
|
41
|
+
it 'should work with block initialization' do
|
42
|
+
foo = nil
|
43
|
+
proc {
|
44
|
+
foo = Foo do
|
45
|
+
bar do
|
46
|
+
name "hello"
|
47
|
+
count 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
}.should_not raise_error
|
51
|
+
foo.bar.name.should_be "hello"
|
52
|
+
foo.bar.count.should_be 1
|
53
|
+
end
|
54
|
+
it 'should work with arg and block initialization' do
|
55
|
+
foo = nil
|
56
|
+
proc {
|
57
|
+
foo = Foo do
|
58
|
+
bar "hello" do
|
59
|
+
count 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
}.should_not raise_error
|
63
|
+
foo.bar.name.should_be "hello"
|
64
|
+
foo.bar.count.should_be 1
|
65
|
+
end
|
66
|
+
it 'should work with keyword and block initialization' do
|
67
|
+
foo = nil
|
68
|
+
proc {
|
69
|
+
foo = Foo do
|
70
|
+
bar :name => "hello" do
|
71
|
+
count 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
}.should_not raise_error
|
75
|
+
foo.bar.name.should_be "hello"
|
76
|
+
foo.bar.count.should_be 1
|
77
|
+
end
|
78
|
+
it 'should raise error with invalid keyword and block initialization' do
|
79
|
+
foo = nil
|
80
|
+
proc {
|
81
|
+
foo = Foo do
|
82
|
+
bar :name => 1 do
|
83
|
+
count "hello"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
}.should raise_error(Doodle::ValidationError)
|
87
|
+
end
|
88
|
+
it 'should raise error with keyword and invalid block initialization' do
|
89
|
+
foo = nil
|
90
|
+
proc {
|
91
|
+
foo = Foo do
|
92
|
+
bar :name => "hello" do
|
93
|
+
count "hello"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
}.should raise_error(Doodle::ValidationError)
|
97
|
+
end
|
98
|
+
it 'should initialize non-Doodle or Proc with simple value' do
|
99
|
+
foo = nil
|
100
|
+
proc {
|
101
|
+
foo = Foo do
|
102
|
+
bar :name => "hello", :count => 1
|
103
|
+
v2 "Hello"
|
104
|
+
end
|
105
|
+
}.should_not raise_error
|
106
|
+
foo.bar.name.should_be "hello"
|
107
|
+
foo.bar.count.should_be 1
|
108
|
+
foo.v2.should_be "Hello"
|
109
|
+
end
|
110
|
+
it 'should fail trying to initialize an inappropriate attribute (not a Doodle or Proc) from a block' do
|
111
|
+
proc {
|
112
|
+
foo = Foo do
|
113
|
+
bar :name => "hello", :count => 1
|
114
|
+
v2 do
|
115
|
+
"Hello"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
}.should raise_error(ArgumentError)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|