doodle 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,44 +17,44 @@ describe Doodle, 'attributes with defaults' do
17
17
  end
18
18
 
19
19
  it 'should have instance attribute default via class' do
20
- Foo.attributes[:name].default.should == 'D1'
20
+ Foo.attributes[:name].default.should_be 'D1'
21
21
  end
22
22
  it 'should have instance attribute default via instance' do
23
- @foo.attributes[:name].default.should == 'D1'
23
+ @foo.attributes[:name].default.should_be 'D1'
24
24
  end
25
25
  it 'should have class attribute default via class.meta' do
26
- Foo.singleton_class.attributes(false)[:metadata].default.should == 'D2'
26
+ Foo.singleton_class.attributes(false)[:metadata].default.should_be 'D2'
27
27
  end
28
28
  it 'should have class attribute default via class.meta' do
29
- Foo.singleton_class.attributes[:metadata].default.should == 'D2'
29
+ Foo.singleton_class.attributes[:metadata].default.should_be 'D2'
30
30
  end
31
31
  it 'should have singleton attribute default via instance.singleton_class.attributes(false)' do
32
- @foo.singleton_class.attributes(false)[:special].default.should == 'D3'
32
+ @foo.singleton_class.attributes(false)[:special].default.should_be 'D3'
33
33
  end
34
34
  it 'should have singleton attribute default via instance.singleton_class.attributes' do
35
- @foo.singleton_class.attributes[:special].default.should == 'D3'
35
+ @foo.singleton_class.attributes[:special].default.should_be 'D3'
36
36
  end
37
37
  it 'should have singleton attribute name by default' do
38
- @foo.name.should == 'D1'
38
+ @foo.name.should_be 'D1'
39
39
  end
40
40
  it 'should have singleton attribute name by default' do
41
- Foo.metadata.should == 'D2'
41
+ Foo.metadata.should_be 'D2'
42
42
  end
43
43
  it 'should have singleton attribute special by default' do
44
- @foo.special.should == 'D3'
44
+ @foo.special.should_be 'D3'
45
45
  end
46
46
 
47
47
  it 'should not have a @name instance variable' do
48
- @foo.instance_variables.include?("@name").should == false
49
- @foo.instance_variables.sort.should == []
48
+ @foo.instance_variables.include?("@name").should_be false
49
+ @foo.instance_variables.sort.should_be []
50
50
  end
51
51
  it 'should not have a @metadata class instance variable' do
52
- Foo.instance_variables.include?("@metadata").should == false
53
- Foo.instance_variables.sort.should == []
52
+ Foo.instance_variables.include?("@metadata").should_be false
53
+ Foo.instance_variables.sort.should_be []
54
54
  end
55
55
  it 'should not have @special singleton instance variable' do
56
- @foo.singleton_class.instance_variables.include?("@special").should == false
57
- @foo.singleton_class.instance_variables.sort.should == []
56
+ @foo.singleton_class.instance_variables.include?("@special").should_be false
57
+ @foo.singleton_class.instance_variables.sort.should_be []
58
58
  end
59
59
  end
60
60
  end
@@ -90,11 +90,11 @@ describe Doodle, 'defaults which have been set' do
90
90
  end
91
91
 
92
92
  it 'should have default value set from hash arg' do
93
- @foo.baz.should == 'Hi!'
93
+ @foo.baz.should_be 'Hi!'
94
94
  end
95
95
 
96
96
  it 'should have default value set from block' do
97
- @foo.start.should == Date.today
97
+ @foo.start.should_be Date.today
98
98
  end
99
99
  end
100
100
  end
@@ -120,8 +120,8 @@ describe Doodle, "overriding inherited defaults" do
120
120
 
121
121
  it 'should allow initialization using defaults' do
122
122
  text = Text.new(:value => 'any')
123
- text.name.should == 'text'
124
- text.value.should == 'any'
123
+ text.name.should_be 'text'
124
+ text.value.should_be 'any'
125
125
  end
126
126
 
127
127
  it 'should raise Doodle::ValidationError if initialized without all required values' do
@@ -130,8 +130,8 @@ describe Doodle, "overriding inherited defaults" do
130
130
 
131
131
  it 'should allow initialization using inherited defaults' do
132
132
  text = Text2.new
133
- text.name.should == 'text'
134
- text.value.should == 'any2'
133
+ text.name.should_be 'text'
134
+ text.value.should_be 'any2'
135
135
  end
136
136
  end
137
137
  end
@@ -37,8 +37,8 @@ describe Doodle, "doodle_context" do
37
37
  end
38
38
 
39
39
  sean = dad.children[0]
40
- sean.dad.name.should == 'Conn'
41
- sean.doodle_parent.name.should == 'Conn'
40
+ sean.dad.name.should_be 'Conn'
41
+ sean.doodle_parent.name.should_be 'Conn'
42
42
  end
43
43
  end
44
44
  end
@@ -15,24 +15,24 @@ describe Doodle, 'instance attributes' do
15
15
 
16
16
  it 'should create attribute' do
17
17
  @foo.name = 'Smee'
18
- @foo.name.should == 'Smee'
18
+ @foo.name.should_be 'Smee'
19
19
  end
20
20
 
21
21
  it 'should create attribute using getter_setter' do
22
22
  @foo.name 'Smee'
23
- @foo.name.should == 'Smee'
23
+ @foo.name.should_be 'Smee'
24
24
  end
25
25
 
26
26
  it 'should list instance attributes(false)' do
27
- @foo.attributes(false).keys.should == []
27
+ @foo.attributes(false).keys.should_be []
28
28
  end
29
29
 
30
30
  it 'should list instance attributes' do
31
- @foo.attributes.keys.should == [:name]
31
+ @foo.attributes.keys.should_be [:name]
32
32
  end
33
33
 
34
34
  it 'should list all instance attributes(false) at class level' do
35
- Foo.attributes(false).keys.should == [:name]
35
+ Foo.attributes(false).keys.should_be [:name]
36
36
  end
37
37
  end
38
38
  end
@@ -54,25 +54,25 @@ describe Doodle, 'class attributes(false)' do
54
54
 
55
55
  it 'should create class attribute' do
56
56
  Foo.metadata = 'Foo metadata'
57
- Foo.metadata.should == 'Foo metadata'
57
+ Foo.metadata.should_be 'Foo metadata'
58
58
  end
59
59
 
60
60
  it 'should access @foo.class attribute via self.class' do
61
61
  @foo.class.metadata = '@foo metadata'
62
- @foo.class.metadata.should == '@foo metadata'
63
- Foo.metadata.should == '@foo metadata'
62
+ @foo.class.metadata.should_be '@foo metadata'
63
+ Foo.metadata.should_be '@foo metadata'
64
64
 
65
65
  Foo.metadata = 'Foo metadata'
66
- Foo.metadata.should == 'Foo metadata'
67
- @foo.class.metadata.should == 'Foo metadata'
66
+ Foo.metadata.should_be 'Foo metadata'
67
+ @foo.class.metadata.should_be 'Foo metadata'
68
68
  end
69
69
 
70
70
  it "should list all class's own attributes" do
71
- Foo.singleton_class.attributes(false).keys.should == [:metadata]
71
+ Foo.singleton_class.attributes(false).keys.should_be [:metadata]
72
72
  end
73
73
 
74
74
  it "should list all class's own attributes" do
75
- Foo.singleton_class.attributes.keys.should == [:metadata]
75
+ Foo.singleton_class.attributes.keys.should_be [:metadata]
76
76
  end
77
77
  end
78
78
  end
@@ -103,61 +103,61 @@ describe Doodle, 'inherited class attributes(false)' do
103
103
  it 'should create inherited class attribute' do
104
104
  Foo.metadata = 'Foo metadata'
105
105
  Bar.metadata = 'Bar metadata'
106
- Foo.metadata.should == 'Foo metadata'
107
- Bar.metadata.should == 'Bar metadata'
108
- Foo.metadata.should == 'Foo metadata'
106
+ Foo.metadata.should_be 'Foo metadata'
107
+ Bar.metadata.should_be 'Bar metadata'
108
+ Foo.metadata.should_be 'Foo metadata'
109
109
  end
110
110
 
111
111
  it 'should access @foo.class attribute via self.class' do
112
112
  @foo.class.metadata = '@foo metadata'
113
- @foo.class.metadata.should == '@foo metadata'
114
- Foo.metadata.should == '@foo metadata'
113
+ @foo.class.metadata.should_be '@foo metadata'
114
+ Foo.metadata.should_be '@foo metadata'
115
115
 
116
116
  Foo.metadata = 'Foo metadata'
117
117
  Bar.metadata = 'Bar metadata'
118
- Foo.metadata.should == 'Foo metadata'
119
- Bar.metadata.should == 'Bar metadata'
120
- Foo.metadata.should == 'Foo metadata'
121
- @foo.class.metadata.should == 'Foo metadata'
122
- @bar.class.metadata.should == 'Bar metadata'
118
+ Foo.metadata.should_be 'Foo metadata'
119
+ Bar.metadata.should_be 'Bar metadata'
120
+ Foo.metadata.should_be 'Foo metadata'
121
+ @foo.class.metadata.should_be 'Foo metadata'
122
+ @bar.class.metadata.should_be 'Bar metadata'
123
123
  end
124
124
 
125
125
  it 'should access inherited @foo.class attribute via self.class' do
126
126
  @foo.class.metadata = '@foo metadata'
127
- @foo.class.metadata.should == '@foo metadata'
128
- Foo.metadata.should == '@foo metadata'
127
+ @foo.class.metadata.should_be '@foo metadata'
128
+ Foo.metadata.should_be '@foo metadata'
129
129
  Foo.metadata = 'Foo metadata'
130
130
 
131
131
  Bar.metadata = 'Bar metadata'
132
- Bar.metadata.should == 'Bar metadata'
133
- @bar.class.metadata.should == 'Bar metadata'
132
+ Bar.metadata.should_be 'Bar metadata'
133
+ @bar.class.metadata.should_be 'Bar metadata'
134
134
 
135
- Foo.metadata.should == 'Foo metadata'
136
- @foo.class.metadata.should == 'Foo metadata'
135
+ Foo.metadata.should_be 'Foo metadata'
136
+ @foo.class.metadata.should_be 'Foo metadata'
137
137
  end
138
138
 
139
139
  it "should list class's own attributes" do
140
- Foo.singleton_class.attributes(false).keys.should == [:metadata]
140
+ Foo.singleton_class.attributes(false).keys.should_be [:metadata]
141
141
  end
142
142
 
143
143
  it "should list all class's own attributes" do
144
- Foo.singleton_class.attributes.keys.should == [:metadata]
144
+ Foo.singleton_class.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.attributes(false).keys.should == [:doc]
148
+ Bar.singleton_class.attributes(false).keys.should_be [:doc]
149
149
  end
150
150
 
151
151
  it "should list all singleton class attributes" do
152
- Bar.singleton_class.attributes.keys.should == [:doc]
152
+ Bar.singleton_class.attributes.keys.should_be [:doc]
153
153
  end
154
154
 
155
155
  it "should list all inherited meta class attributes" do
156
- Bar.class_attributes.keys.should == [:metadata, :doc]
156
+ Bar.class_attributes.keys.should_be [:metadata, :doc]
157
157
  end
158
158
 
159
159
  it "should list all inherited class's attributes" do
160
- Bar.attributes.keys.should == [:name, :location]
160
+ Bar.attributes.keys.should_be [:name, :location]
161
161
  end
162
162
  end
163
163
  end
@@ -184,19 +184,19 @@ describe Doodle, 'singleton class attributes' do
184
184
 
185
185
  it 'should allow creation of singleton class attributes' do
186
186
  @foo.special = 42
187
- @foo.special.should == 42
187
+ @foo.special.should_be 42
188
188
  end
189
189
 
190
190
  it 'should list singleton instance attributes(false)' do
191
- @foo.singleton_class.attributes(false).keys.should == [:special]
191
+ @foo.singleton_class.attributes(false).keys.should_be [:special]
192
192
  end
193
193
 
194
194
  it 'should list singleton instance attributes' do
195
- @foo.singleton_class.attributes.keys.should == [:special]
195
+ @foo.singleton_class.attributes.keys.should_be [:special]
196
196
  end
197
197
 
198
198
  it 'should list instance attributes' do
199
- @foo.attributes.keys.should == [:name, :special]
199
+ @foo.attributes.keys.should_be [:name, :special]
200
200
  end
201
201
 
202
202
  end
@@ -236,65 +236,81 @@ describe Doodle, 'inherited singleton class attributes' do
236
236
 
237
237
  it 'should allow creation of singleton class attributes' do
238
238
  @foo.special = 42
239
- @foo.special.should == 42
239
+ @foo.special.should_be 42
240
240
  @bar.extra = 84
241
- @bar.extra.should == 84
241
+ @bar.extra.should_be 84
242
242
  proc { @foo.extra = 1 }.should raise_error(NoMethodError)
243
243
  proc { @bar2.extra = 1 }.should raise_error(NoMethodError)
244
244
  proc { @bar.special = 1 }.should raise_error(NoMethodError)
245
245
  end
246
246
 
247
247
  it 'should list instance attributes' do
248
- @foo.class.attributes(false).keys.should == [:name]
249
- @bar.class.attributes(false).keys.should == [:info]
250
- @bar2.class.attributes(false).keys.should == [:info]
248
+ @foo.class.attributes(false).keys.should_be [:name]
249
+ @bar.class.attributes(false).keys.should_be [:info]
250
+ @bar2.class.attributes(false).keys.should_be [:info]
251
251
  end
252
252
 
253
253
  it 'should list instance meta attributes' do
254
- @foo.singleton_class.attributes(false).keys.should == [:special]
255
- @bar.singleton_class.attributes(false).keys.should == [:extra]
254
+ @foo.singleton_class.attributes(false).keys.should_be [:special]
255
+ @bar.singleton_class.attributes(false).keys.should_be [:extra]
256
256
  end
257
257
 
258
258
  it 'should list singleton attributes only' do
259
- @foo.singleton_class.attributes.keys.should == [:special]
260
- @bar.singleton_class.attributes.keys.should == [:extra]
259
+ @foo.singleton_class.attributes.keys.should_be [:special]
260
+ @bar.singleton_class.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
- @foo.special.should == 'foo special'
266
- # @foo.singleton_class.methods.map{ |x| x.to_sym}.include?(:metadata).should == false
267
- # @foo.singleton_class.metadata = 'foo meta'
268
- # @foo.singleton_class.metadata.should == 'foo meta'
265
+ @foo.special.should_be 'foo special'
266
+
267
+ # CHECK
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
- @bar.extra.should == 'bar extra'
271
+ @bar.extra.should_be 'bar extra'
272
272
  Foo.metadata = 'Foo meta'
273
- Foo.metadata.should == 'Foo meta'
273
+ Foo.metadata.should_be 'Foo meta'
274
274
  Bar.metadata = 'Bar meta'
275
- Bar.metadata.should == 'Bar meta'
275
+ Bar.metadata.should_be 'Bar meta'
276
276
  Bar.doc = 'Bar doc'
277
- Bar.doc.should == 'Bar doc'
277
+ Bar.doc.should_be 'Bar doc'
278
278
 
279
279
  # now make sure they haven't bumped each other off
280
- @foo.special.should == 'foo special'
281
- # @foo.singleton_class.metadata.should == 'foo meta'
282
- @bar.extra.should == 'bar extra'
283
- Foo.metadata.should == 'Foo meta'
284
- Bar.metadata.should == 'Bar meta'
285
- Bar.doc.should == 'Bar doc'
280
+ @foo.special.should_be 'foo special'
281
+
282
+ @bar.extra.should_be 'bar extra'
283
+ Foo.metadata.should_be 'Foo meta'
284
+ Bar.metadata.should_be 'Bar meta'
285
+ Bar.doc.should_be 'Bar doc'
286
+ end
287
+
288
+ it 'should inherit singleton methods from class' do
289
+ @foo.singleton_class.respond_to?(:metadata).should_be true
290
+ @foo.singleton_class.attributes[:metadata].should_be nil
291
+ @foo.singleton_class.metadata = 'foo meta'
292
+ @foo.singleton_class.instance_eval { @metadata }.should_be 'foo meta'
293
+ if RUBY_VERSION < '1.9.0'
294
+ @foo.singleton_class.metadata.should_be 'foo meta'
295
+ else
296
+ pending 'figuring out why this fails in 1.9' do
297
+ @foo.singleton_class.metadata.should_be 'foo meta'
298
+ end
299
+ end
286
300
  end
287
-
301
+
288
302
  it 'should behave predictably when setting singleton attributes' do
289
303
  @bar.extra = 'bar extra'
290
- @bar.extra.should == 'bar extra'
291
- # pending 'working out how to make this work' do
292
- # @bar.singleton_class.metadata = 'bar meta metadata'
293
- # @bar.singleton_class.metadata.should == 'bar meta metadata'
294
- # @bar.singleton_class.doc = 'bar doc'
295
- # @bar.singleton_class.doc.should == 'bar doc'
296
- # proc { @foo.singleton_class.doc = 1 }.should raise_error(NoMethodError)
297
- # end
304
+ @bar.extra.should_be 'bar extra'
305
+ @bar.singleton_class.metadata = 'bar meta metadata'
306
+ if RUBY_VERSION < '1.9.0'
307
+ @bar.singleton_class.metadata.should_be 'bar meta metadata'
308
+ @bar.singleton_class.doc = 'bar doc'
309
+ @bar.singleton_class.doc.should_be 'bar doc'
310
+ else
311
+ pending 'figuring out why this fails in 1.9'
312
+ end
313
+ proc { @foo.singleton_class.doc = 1 }.should raise_error(NoMethodError)
298
314
  end
299
315
  end
300
316
  end
@@ -14,15 +14,15 @@ describe Doodle::Factory, " as part of Doodle" do
14
14
  it 'should provide factory function' do
15
15
  proc {
16
16
  foo = Foo("abcd")
17
- foo.var1.should == "abcd"
17
+ foo.var1.should_be "abcd"
18
18
  }.should_not raise_error
19
19
  end
20
20
 
21
21
  it 'should inherit factory function' do
22
22
  proc {
23
23
  bar = Bar("abcd", 1234)
24
- bar.var1.should == "abcd"
25
- bar.var2.should == 1234
24
+ bar.var1.should_be "abcd"
25
+ bar.var2.should_be 1234
26
26
  }.should_not raise_error
27
27
  end
28
28
  end
@@ -48,22 +48,22 @@ describe Doodle::Factory, " included as module" do
48
48
  it 'should provide factory function' do
49
49
  proc {
50
50
  foo = Baz("abcd")
51
- foo.var1.should == "abcd"
51
+ foo.var1.should_be "abcd"
52
52
  }.should_not raise_error
53
53
  end
54
54
 
55
55
  it 'should inherit factory function' do
56
56
  proc {
57
57
  qux = Qux("abcd", 1234)
58
- qux.var1.should == "abcd"
59
- qux.var2.should == 1234
58
+ qux.var1.should_be "abcd"
59
+ qux.var2.should_be 1234
60
60
  }.should_not raise_error
61
61
  end
62
62
 
63
63
  it 'should be includeable in non-doodle classes' do
64
64
  proc {
65
65
  qux = MyDate(2008, 01, 01)
66
- qux.to_s.should == "2008-01-01"
66
+ qux.to_s.should_be "2008-01-01"
67
67
  }.should_not raise_error
68
68
  end
69
69
 
@@ -71,7 +71,7 @@ describe Doodle::Factory, " included as module" do
71
71
  # it 'should be inheritable by non-doodle classes' do
72
72
  # proc {
73
73
  # qux = AnotherDate(2008, 01, 01)
74
- # qux.to_s.should == "2008-01-01"
74
+ # qux.to_s.should_be "2008-01-01"
75
75
  # }.should_not raise_error
76
76
  # end
77
77
 
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Doodle, "inheritance" do
4
+ temporary_constants :Foo, :Bar do
5
+ before :each do
6
+ class Foo < Doodle
7
+ class << self
8
+ has :cvar
9
+ end
10
+ has :ivar
11
+ end
12
+ class Bar < Foo
13
+ class << self
14
+ has :cvar2
15
+ end
16
+ has :ivar2
17
+ end
18
+ end
19
+
20
+ it "should collect_inherited for instance" do
21
+ foo = Foo.new(:ivar => "foo")
22
+ foo.send(:collect_inherited, :attributes).map{ |key, value| key}.should_be [:ivar]
23
+ foo.attributes.map{ |key, value| key}.should_be [:ivar]
24
+ end
25
+
26
+ it "should collect inherited for singleton" do
27
+ foo = Foo.new(:ivar => "foo")
28
+ class << foo
29
+ has :svar
30
+ end
31
+ foo.attributes.map{ |key, value| key}.should_be [:ivar, :svar]
32
+ foo.singleton_class.attributes.map{ |key, value| key}.should_be [:svar]
33
+ end
34
+
35
+ it "should collect singleton class attributes for singleton" do
36
+ foo = Foo.new(:ivar => "foo")
37
+ class << foo
38
+ has :svar
39
+ end
40
+ foo.singleton_class.respond_to?(:cvar).should_be true
41
+ foo.attributes.map{ |key, value| key}.should_be [:ivar, :svar]
42
+ # is this what I want? not sure
43
+ # foo.class.singleton_class.should_be foo.singleton_class.superclass
44
+ # foo.singleton_class.singleton_class # => #<Class:#<Class:#<Foo:0xb7bc8dd0>>>
45
+ # and now it's false
46
+ # all different in 1.9
47
+ # foo.class.singleton_class.should_not == foo.singleton_class.superclass # => false
48
+ # foo.singleton_class.respond_to?(:cvar).should_be true
49
+ end
50
+
51
+ it "should collect inherited for subclass singleton" do
52
+ bar = Bar.new(:ivar => "foo", :ivar2 => "bar")
53
+ class << bar
54
+ has :svar2
55
+ end
56
+ bar.attributes.map{ |key, value| key}.should_be [:ivar, :ivar2, :svar2]
57
+ bar.singleton_class.attributes.map{ |key, value| key}.should_be [:svar2]
58
+ end
59
+
60
+ it "should show instance attributes for class" do
61
+ Foo.attributes.map{ |key, value| key}.should_be [:ivar]
62
+ Bar.attributes.map{ |key, value| key}.should_be [:ivar, :ivar2]
63
+ end
64
+
65
+ it "should collect_inherited for class" do
66
+ Foo.class_attributes.map{ |key, value| key}.should_be [:cvar]
67
+ Bar.class_attributes.map{ |key, value| key}.should_be [:cvar, :cvar2]
68
+ end
69
+
70
+ it "should not inherit class attributes via singleton_class" do
71
+ Bar.singleton_class.attributes.map{ |key, value| key}.should_be [:cvar2]
72
+ end
73
+ end
74
+ end