doodle 0.0.4 → 0.0.5
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/ChangeLog +36 -7
- data/lib/doodle.rb +71 -42
- data/spec/arg_order_spec.rb +81 -98
- data/spec/attributes_spec.rb +70 -82
- data/spec/bugs_spec.rb +21 -0
- data/spec/class_spec.rb +63 -70
- data/spec/collector_spec.rb +97 -0
- data/spec/conversion_spec.rb +1 -3
- data/spec/defaults_spec.rb +104 -125
- data/spec/doodle_spec.rb +240 -227
- data/spec/flatten_first_level_spec.rb +4 -3
- data/spec/init_spec.rb +45 -49
- data/spec/required_spec.rb +9 -17
- data/spec/serialization_spec.rb +32 -0
- data/spec/superclass_spec.rb +17 -20
- data/spec/validation_spec.rb +79 -88
- metadata +5 -6
- data/examples/example-01.rdoc +0 -16
- data/examples/example-02.rdoc +0 -62
- data/examples/foo.rb +0 -10
- data/lib/spec_helper.rb +0 -19
data/spec/conversion_spec.rb
CHANGED
data/spec/defaults_spec.rb
CHANGED
@@ -1,158 +1,137 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lib/spec_helper'
|
4
|
-
require 'date'
|
5
|
-
raise_if_defined :Foo, :Text, :Text2, :KeyValue
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
2
|
|
7
3
|
describe Doodle, 'attributes with defaults' do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
temporary_constant :Foo do
|
5
|
+
before(:each) do
|
6
|
+
class Foo
|
7
|
+
include Doodle::Helper
|
8
|
+
has :name, :default => 'D1'
|
9
|
+
class << self
|
10
|
+
has :metadata, :default => 'D2'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
@foo = Foo.new
|
14
|
+
class << @foo
|
15
|
+
has :special, :default => 'D3'
|
16
16
|
end
|
17
17
|
end
|
18
|
-
@foo = Foo.new
|
19
|
-
class << @foo
|
20
|
-
has :special, :default => 'D3'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
after :each do
|
24
|
-
undefine_const :Foo
|
25
|
-
end
|
26
18
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
19
|
+
it 'should have instance attribute default via class' do
|
20
|
+
Foo.attributes[:name].default.should == 'D1'
|
21
|
+
end
|
22
|
+
it 'should have instance attribute default via instance' do
|
23
|
+
@foo.attributes[:name].default.should == 'D1'
|
24
|
+
end
|
25
|
+
it 'should have class attribute default via class.meta' do
|
26
|
+
Foo.meta.attributes(false)[:metadata].default.should == 'D2'
|
27
|
+
end
|
28
|
+
it 'should have class attribute default via class.meta' do
|
29
|
+
Foo.meta.attributes[:metadata].default.should == 'D2'
|
30
|
+
end
|
31
|
+
it 'should have singleton attribute default via instance.meta.attributes(false)' do
|
32
|
+
@foo.meta.attributes(false)[:special].default.should == 'D3'
|
33
|
+
end
|
34
|
+
it 'should have singleton attribute default via instance.meta.attributes' do
|
35
|
+
@foo.meta.attributes[:special].default.should == 'D3'
|
36
|
+
end
|
37
|
+
it 'should have singleton attribute name by default' do
|
38
|
+
@foo.name.should == 'D1'
|
39
|
+
end
|
40
|
+
it 'should have singleton attribute name by default' do
|
41
|
+
Foo.metadata.should == 'D2'
|
42
|
+
end
|
43
|
+
it 'should have singleton attribute special by default' do
|
44
|
+
@foo.special.should == 'D3'
|
45
|
+
end
|
54
46
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
47
|
+
it 'should not have a @name instance variable' do
|
48
|
+
@foo.instance_variables.include?("@name").should == false
|
49
|
+
@foo.instance_variables.sort.should == []
|
50
|
+
end
|
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 == []
|
54
|
+
end
|
55
|
+
it 'should not have @special singleton instance variable' do
|
56
|
+
@foo.meta.instance_variables.include?("@special").should == false
|
57
|
+
@foo.meta.instance_variables.sort.should == []
|
58
|
+
end
|
66
59
|
end
|
67
60
|
end
|
68
61
|
|
69
62
|
describe Doodle, 'defaults which have not been set' do
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
63
|
+
temporary_constant :Foo do
|
64
|
+
before :each do
|
65
|
+
class Foo < Doodle::Base
|
66
|
+
has :baz
|
67
|
+
end
|
74
68
|
end
|
75
|
-
end
|
76
|
-
after :each do
|
77
|
-
undefine_const :Foo
|
78
|
-
end
|
79
69
|
|
80
|
-
|
81
|
-
|
82
|
-
|
70
|
+
it 'should raise error if required attributes not passed to new' do
|
71
|
+
proc { foo = Foo.new }.should raise_error(ArgumentError)
|
72
|
+
end
|
83
73
|
|
84
|
-
|
85
|
-
|
74
|
+
it 'should not raise error if required attributes passed to new' do
|
75
|
+
proc { foo = Foo.new(:baz => 'Hi' ) }.should_not raise_error
|
76
|
+
end
|
86
77
|
end
|
87
|
-
|
88
78
|
end
|
89
79
|
|
90
80
|
describe Doodle, 'defaults which have been set' do
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
81
|
+
temporary_constant :Foo do
|
82
|
+
before :each do
|
83
|
+
class Foo < Doodle::Base
|
84
|
+
has :baz, :default => 'Hi!'
|
85
|
+
has :start do
|
86
|
+
default { Date.today }
|
87
|
+
end
|
97
88
|
end
|
89
|
+
@foo = Foo.new
|
98
90
|
end
|
99
|
-
@foo = Foo.new
|
100
|
-
end
|
101
|
-
after :each do
|
102
|
-
undefine_const :Foo
|
103
|
-
end
|
104
91
|
|
105
|
-
|
106
|
-
|
107
|
-
|
92
|
+
it 'should have default value set from hash arg' do
|
93
|
+
@foo.baz.should == 'Hi!'
|
94
|
+
end
|
108
95
|
|
109
|
-
|
110
|
-
|
96
|
+
it 'should have default value set from block' do
|
97
|
+
@foo.start.should == Date.today
|
98
|
+
end
|
111
99
|
end
|
112
100
|
end
|
113
101
|
|
114
102
|
describe Doodle, "overriding inherited defaults" do
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
103
|
+
temporary_constant :Text, :Text2, :KeyValue do
|
104
|
+
before :each do
|
105
|
+
class KeyValue < Doodle::Base
|
106
|
+
has :name
|
107
|
+
has :value
|
108
|
+
end
|
109
|
+
class Text < KeyValue
|
110
|
+
has :name, :default => "text"
|
111
|
+
end
|
112
|
+
class Text2 < Text
|
113
|
+
has :value, :default => "any2"
|
122
114
|
end
|
123
115
|
end
|
124
|
-
class Text < KeyValue
|
125
|
-
has :name, :default => "text"
|
126
|
-
end
|
127
|
-
class Text2 < Text
|
128
|
-
has :value, :default => "any2"
|
129
|
-
end
|
130
|
-
end
|
131
|
-
after :each do
|
132
|
-
undefine_const :Text2
|
133
|
-
undefine_const :Text
|
134
|
-
undefine_const :KeyValue
|
135
|
-
end
|
136
116
|
|
137
|
-
|
138
|
-
|
139
|
-
|
117
|
+
it 'should not raise error if initialized with required values' do
|
118
|
+
proc { Text.new(:value => 'any') }.should_not raise_error
|
119
|
+
end
|
140
120
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
121
|
+
it 'should allow initialization using defaults' do
|
122
|
+
text = Text.new(:value => 'any')
|
123
|
+
text.name.should == 'text'
|
124
|
+
text.value.should == 'any'
|
125
|
+
end
|
146
126
|
|
147
|
-
|
148
|
-
|
149
|
-
|
127
|
+
it 'should raise ArgumentError if initialized without all required values' do
|
128
|
+
proc { KeyValue.new(:value => 'Enter name:') }.should raise_error(ArgumentError)
|
129
|
+
end
|
150
130
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
131
|
+
it 'should allow initialization using inherited defaults' do
|
132
|
+
text = Text2.new
|
133
|
+
text.name.should == 'text'
|
134
|
+
text.value.should == 'any2'
|
135
|
+
end
|
155
136
|
end
|
156
137
|
end
|
157
|
-
|
158
|
-
raise_if_defined :Foo, :Text, :Text2, :KeyValue
|
data/spec/doodle_spec.rb
CHANGED
@@ -1,297 +1,310 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# require 'relpath'
|
4
|
-
# loaddir_parent(__FILE__)
|
5
|
-
require 'lib/spec_helper'
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
2
|
|
7
3
|
describe Doodle, 'basics' do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
temporary_constant :Foo do
|
5
|
+
before(:each) do
|
6
|
+
class Foo
|
7
|
+
include Doodle::Helper
|
8
|
+
end
|
9
|
+
@foo = Foo.new
|
10
|
+
end
|
11
|
+
after :each do
|
12
|
+
remove_ivars :foo
|
15
13
|
end
|
16
|
-
@foo = Foo.new
|
17
|
-
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
it 'should have meta as synonym for singleton_class' do
|
16
|
+
Foo.singleton_class.should == Foo.meta
|
17
|
+
@foo.singleton_class.should == @foo.meta
|
18
|
+
end
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
25
22
|
describe Doodle, 'instance attributes' do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
temporary_constant :Foo do
|
24
|
+
before(:each) do
|
25
|
+
class Foo
|
26
|
+
include Doodle::Helper
|
27
|
+
has :name, :default => nil
|
28
|
+
end
|
29
|
+
@foo = Foo.new
|
30
|
+
end
|
31
|
+
after :each do
|
32
|
+
remove_ivars :foo
|
34
33
|
end
|
35
|
-
@foo = Foo.new
|
36
|
-
end
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
it 'should create attribute' do
|
36
|
+
@foo.name = 'Smee'
|
37
|
+
@foo.name.should == 'Smee'
|
38
|
+
end
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
it 'should create attribute using getter_setter' do
|
41
|
+
@foo.name 'Smee'
|
42
|
+
@foo.name.should == 'Smee'
|
43
|
+
end
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
it 'should list instance attributes(false)' do
|
46
|
+
@foo.attributes(false).keys.should == []
|
47
|
+
end
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
it 'should list instance attributes' do
|
50
|
+
@foo.attributes.keys.should == [:name]
|
51
|
+
end
|
55
52
|
|
56
|
-
|
57
|
-
|
53
|
+
it 'should list all instance attributes(false) at class level' do
|
54
|
+
Foo.attributes(false).keys.should == [:name]
|
55
|
+
end
|
58
56
|
end
|
59
|
-
|
60
57
|
end
|
61
58
|
|
62
59
|
describe Doodle, 'class attributes(false)' do
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
class << self
|
71
|
-
has :metadata
|
60
|
+
temporary_constant :Foo do
|
61
|
+
before(:each) do
|
62
|
+
class Foo
|
63
|
+
include Doodle::Helper
|
64
|
+
class << self
|
65
|
+
has :metadata
|
66
|
+
end
|
72
67
|
end
|
68
|
+
@foo = Foo.new
|
69
|
+
end
|
70
|
+
after :each do
|
71
|
+
remove_ivars :foo
|
73
72
|
end
|
74
|
-
@foo = Foo.new
|
75
|
-
end
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
it 'should create class attribute' do
|
75
|
+
Foo.metadata = 'Foo metadata'
|
76
|
+
Foo.metadata.should == 'Foo metadata'
|
77
|
+
end
|
81
78
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
79
|
+
it 'should access class attribute via self.class' do
|
80
|
+
@foo.class.metadata = '@foo metadata'
|
81
|
+
@foo.class.metadata.should == '@foo metadata'
|
82
|
+
Foo.metadata.should == '@foo metadata'
|
86
83
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
Foo.metadata = 'Foo metadata'
|
85
|
+
Foo.metadata.should == 'Foo metadata'
|
86
|
+
@foo.class.metadata.should == 'Foo metadata'
|
87
|
+
end
|
91
88
|
|
92
|
-
|
93
|
-
|
94
|
-
|
89
|
+
it "should list all class's own attributes" do
|
90
|
+
Foo.meta.attributes(false).keys.should == [:metadata]
|
91
|
+
end
|
95
92
|
|
96
|
-
|
97
|
-
|
93
|
+
it "should list all class's own attributes" do
|
94
|
+
Foo.meta.attributes.keys.should == [:metadata]
|
95
|
+
end
|
98
96
|
end
|
99
|
-
|
100
97
|
end
|
101
98
|
|
102
99
|
describe Doodle, 'inherited class attributes(false)' do
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
include Doodle::Helper
|
112
|
-
has :name, :default => nil
|
113
|
-
class << self
|
114
|
-
has :metadata
|
100
|
+
temporary_constant :Foo, :Bar do
|
101
|
+
before(:each) do
|
102
|
+
class Foo
|
103
|
+
include Doodle::Helper
|
104
|
+
has :name, :default => nil
|
105
|
+
class << self
|
106
|
+
has :metadata
|
107
|
+
end
|
115
108
|
end
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
109
|
+
class Bar < Foo
|
110
|
+
has :location, :default => nil
|
111
|
+
class << self
|
112
|
+
has :doc
|
113
|
+
end
|
121
114
|
end
|
115
|
+
@foo = Foo.new
|
116
|
+
@bar = Bar.new
|
117
|
+
end
|
118
|
+
after :each do
|
119
|
+
remove_ivars :foo, :bar
|
122
120
|
end
|
123
|
-
@foo = Foo.new
|
124
|
-
@bar = Bar.new
|
125
|
-
end
|
126
121
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
122
|
+
it 'should create inherited class attribute' do
|
123
|
+
Foo.metadata = 'Foo metadata'
|
124
|
+
Bar.metadata = 'Bar metadata'
|
125
|
+
Foo.metadata.should == 'Foo metadata'
|
126
|
+
Bar.metadata.should == 'Bar metadata'
|
127
|
+
Foo.metadata.should == 'Foo metadata'
|
128
|
+
end
|
134
129
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
130
|
+
it 'should access class attribute via self.class' do
|
131
|
+
@foo.class.metadata = '@foo metadata'
|
132
|
+
@foo.class.metadata.should == '@foo metadata'
|
133
|
+
Foo.metadata.should == '@foo metadata'
|
134
|
+
|
135
|
+
Foo.metadata = 'Foo metadata'
|
136
|
+
Bar.metadata = 'Bar metadata'
|
137
|
+
Foo.metadata.should == 'Foo metadata'
|
138
|
+
Bar.metadata.should == 'Bar metadata'
|
139
|
+
Foo.metadata.should == 'Foo metadata'
|
140
|
+
@foo.class.metadata.should == 'Foo metadata'
|
141
|
+
@bar.class.metadata.should == 'Bar metadata'
|
142
|
+
end
|
148
143
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
144
|
+
it 'should access inherited class attribute via self.class' do
|
145
|
+
@foo.class.metadata = '@foo metadata'
|
146
|
+
@foo.class.metadata.should == '@foo metadata'
|
147
|
+
Foo.metadata.should == '@foo metadata'
|
148
|
+
Foo.metadata = 'Foo metadata'
|
154
149
|
|
155
|
-
|
156
|
-
|
157
|
-
|
150
|
+
Bar.metadata = 'Bar metadata'
|
151
|
+
Bar.metadata.should == 'Bar metadata'
|
152
|
+
@bar.class.metadata.should == 'Bar metadata'
|
158
153
|
|
159
|
-
|
160
|
-
|
161
|
-
|
154
|
+
Foo.metadata.should == 'Foo metadata'
|
155
|
+
@foo.class.metadata.should == 'Foo metadata'
|
156
|
+
end
|
162
157
|
|
163
|
-
|
164
|
-
|
165
|
-
|
158
|
+
it "should list class's own attributes" do
|
159
|
+
Foo.meta.attributes(false).keys.should == [:metadata]
|
160
|
+
end
|
166
161
|
|
167
|
-
|
168
|
-
|
169
|
-
|
162
|
+
it "should list all class's own attributes" do
|
163
|
+
Foo.meta.attributes.keys.should == [:metadata]
|
164
|
+
end
|
170
165
|
|
171
|
-
|
172
|
-
|
173
|
-
|
166
|
+
it "should list class's own attributes(false)" do
|
167
|
+
Bar.meta.attributes(false).keys.should == [:doc]
|
168
|
+
end
|
174
169
|
|
175
|
-
|
176
|
-
|
177
|
-
|
170
|
+
it "should list all inherited meta class attributes" do
|
171
|
+
Bar.meta.attributes.keys.should == [:metadata, :doc]
|
172
|
+
end
|
178
173
|
|
179
|
-
|
180
|
-
|
174
|
+
it "should list all inherited class's attributes" do
|
175
|
+
Bar.attributes.keys.should == [:name, :location]
|
176
|
+
end
|
181
177
|
end
|
182
178
|
end
|
183
179
|
|
184
180
|
describe Doodle, 'singleton class attributes' do
|
185
|
-
|
186
|
-
|
187
|
-
end
|
188
|
-
before(:each) do
|
189
|
-
raise_if_defined :Foo
|
181
|
+
temporary_constant :Foo do
|
182
|
+
before(:each) do
|
190
183
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
184
|
+
class Foo
|
185
|
+
include Doodle::Helper
|
186
|
+
has :name, :default => nil
|
187
|
+
class << self
|
188
|
+
has :metadata
|
189
|
+
end
|
190
|
+
end
|
191
|
+
@foo = Foo.new
|
192
|
+
class << @foo
|
193
|
+
has :special, :default => nil
|
196
194
|
end
|
197
195
|
end
|
198
|
-
|
199
|
-
|
200
|
-
has :special, :default => nil
|
196
|
+
after :each do
|
197
|
+
remove_ivars :foo
|
201
198
|
end
|
202
|
-
end
|
203
199
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
200
|
+
it 'should allow creation of singleton class attributes' do
|
201
|
+
@foo.special = 42
|
202
|
+
@foo.special.should == 42
|
203
|
+
end
|
208
204
|
|
209
|
-
|
210
|
-
|
211
|
-
|
205
|
+
it 'should list instance attributes' do
|
206
|
+
@foo.meta.attributes(false).keys.should == [:special]
|
207
|
+
end
|
212
208
|
|
213
|
-
|
214
|
-
|
209
|
+
it 'should list instance attributes' do
|
210
|
+
@foo.meta.attributes.keys.should == [:metadata, :special]
|
211
|
+
end
|
215
212
|
end
|
216
|
-
|
217
213
|
end
|
218
214
|
|
219
215
|
describe Doodle, 'inherited singleton class attributes' do
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
include Doodle::Helper
|
229
|
-
has :name, :default => nil
|
230
|
-
class << self
|
231
|
-
has :metadata
|
216
|
+
temporary_constant :Foo, :Bar do
|
217
|
+
before(:each) do
|
218
|
+
class Foo
|
219
|
+
include Doodle::Helper
|
220
|
+
has :name, :default => nil
|
221
|
+
class << self
|
222
|
+
has :metadata
|
223
|
+
end
|
232
224
|
end
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
225
|
+
class Bar < Foo
|
226
|
+
has :info, :default => nil
|
227
|
+
class << self
|
228
|
+
has :doc
|
229
|
+
end
|
238
230
|
end
|
239
|
-
end
|
240
231
|
|
241
|
-
|
242
|
-
|
243
|
-
|
232
|
+
@foo = Foo.new
|
233
|
+
class << @foo
|
234
|
+
has :special, :default => nil # must give default because already initialized
|
235
|
+
end
|
236
|
+
@bar = Bar.new
|
237
|
+
@bar2 = Bar.new
|
238
|
+
class << @bar
|
239
|
+
has :extra
|
240
|
+
end
|
244
241
|
end
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
has :extra
|
242
|
+
|
243
|
+
after :each do
|
244
|
+
remove_ivars :foo, :bar, :bar2
|
249
245
|
end
|
250
|
-
end
|
251
246
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
247
|
+
it 'should allow creation of singleton class attributes' do
|
248
|
+
@foo.special = 42
|
249
|
+
@foo.special.should == 42
|
250
|
+
@bar.extra = 84
|
251
|
+
@bar.extra.should == 84
|
252
|
+
proc { @foo.extra = 1 }.should raise_error(NoMethodError)
|
253
|
+
proc { @bar2.extra = 1 }.should raise_error(NoMethodError)
|
254
|
+
proc { @bar.special = 1 }.should raise_error(NoMethodError)
|
255
|
+
end
|
261
256
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
257
|
+
it 'should list instance attributes' do
|
258
|
+
@foo.class.attributes(false).keys.should == [:name]
|
259
|
+
@bar.class.attributes(false).keys.should == [:info]
|
260
|
+
@bar2.class.attributes(false).keys.should == [:info]
|
261
|
+
end
|
267
262
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
263
|
+
it 'should list instance meta attributes' do
|
264
|
+
@foo.meta.attributes(false).keys.should == [:special]
|
265
|
+
@bar.meta.attributes(false).keys.should == [:extra]
|
266
|
+
end
|
272
267
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
268
|
+
it 'should list instance attributes' do
|
269
|
+
@foo.meta.attributes.keys.should == [:metadata, :special]
|
270
|
+
@bar.meta.attributes.keys.should == [:metadata, :doc, :extra]
|
271
|
+
end
|
277
272
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
#
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
273
|
+
it 'should keep meta attributes separate' do
|
274
|
+
@foo.special = 'foo special'
|
275
|
+
@foo.special.should == 'foo special'
|
276
|
+
@foo.meta.metadata = 'foo meta'
|
277
|
+
@foo.meta.metadata.should == 'foo meta'
|
278
|
+
# note: you cannot set any other values on @bar until you have set @bar.extra because it's defined as required
|
279
|
+
@bar.extra = 'bar extra'
|
280
|
+
@bar.extra.should == 'bar extra'
|
281
|
+
Foo.metadata = 'Foo meta'
|
282
|
+
Foo.metadata.should == 'Foo meta'
|
283
|
+
Bar.metadata = 'Bar meta'
|
284
|
+
Bar.metadata.should == 'Bar meta'
|
285
|
+
Bar.doc = 'Bar doc'
|
286
|
+
Bar.doc.should == 'Bar doc'
|
287
|
+
|
288
|
+
# now make sure they haven't bumped each other off
|
289
|
+
@foo.special.should == 'foo special'
|
290
|
+
@foo.meta.metadata.should == 'foo meta'
|
291
|
+
@bar.extra.should == 'bar extra'
|
292
|
+
Foo.metadata.should == 'Foo meta'
|
293
|
+
Bar.metadata.should == 'Bar meta'
|
294
|
+
Bar.doc.should == 'Bar doc'
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'should behave predictably when setting singleton attributes' do
|
298
|
+
@bar.extra = 'bar extra'
|
299
|
+
@bar.extra.should == 'bar extra'
|
300
|
+
# pending 'working out how to make this work' do
|
301
|
+
# @bar.meta.metadata = 'bar meta metadata'
|
302
|
+
# @bar.meta.metadata.should == 'bar meta metadata'
|
303
|
+
# @bar.meta.doc = 'bar doc'
|
304
|
+
# @bar.meta.doc.should == 'bar doc'
|
305
|
+
# proc { @foo.meta.doc = 1 }.should raise_error(NoMethodError)
|
306
|
+
# end
|
307
|
+
end
|
295
308
|
end
|
296
309
|
end
|
297
310
|
|