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/spec_helper'
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
4
2
  require 'date'
5
3
 
6
4
  describe Doodle, 'defaults which have not been set' do
@@ -1,158 +1,137 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '../.'))
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
- before(:each) do
10
- raise_if_defined :Foo
11
- class Foo
12
- include Doodle::Helper
13
- has :name, :default => 'D1'
14
- class << self
15
- has :metadata, :default => 'D2'
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
- it 'should have instance attribute default via class' do
28
- Foo.attributes[:name].default.should == 'D1'
29
- end
30
- it 'should have instance attribute default via instance' do
31
- @foo.attributes[:name].default.should == 'D1'
32
- end
33
- it 'should have class attribute default via class.meta' do
34
- Foo.meta.attributes(false)[:metadata].default.should == 'D2'
35
- end
36
- it 'should have class attribute default via class.meta' do
37
- Foo.meta.attributes[:metadata].default.should == 'D2'
38
- end
39
- it 'should have singleton attribute default via instance.meta.attributes(false)' do
40
- @foo.meta.attributes(false)[:special].default.should == 'D3'
41
- end
42
- it 'should have singleton attribute default via instance.meta.attributes' do
43
- @foo.meta.attributes[:special].default.should == 'D3'
44
- end
45
- it 'should have singleton attribute name by default' do
46
- @foo.name.should == 'D1'
47
- end
48
- it 'should have singleton attribute name by default' do
49
- Foo.metadata.should == 'D2'
50
- end
51
- it 'should have singleton attribute special by default' do
52
- @foo.special.should == 'D3'
53
- end
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
- it 'should not have a @name instance variable' do
56
- @foo.instance_variables.include?("@name").should == false
57
- @foo.instance_variables.sort.should == []
58
- end
59
- it 'should not have a @metadata class instance variable' do
60
- Foo.instance_variables.include?("@metadata").should == false
61
- Foo.instance_variables.sort.should == []
62
- end
63
- it 'should not have @special singleton instance variable' do
64
- @foo.meta.instance_variables.include?("@special").should == false
65
- @foo.meta.instance_variables.sort.should == []
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
- before :each do
71
- raise_if_defined :Foo
72
- class Foo < Doodle::Base
73
- has :baz
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
- it 'should raise error if required attributes not passed to new' do
81
- proc { foo = Foo.new }.should raise_error(ArgumentError)
82
- end
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
- it 'should not raise error if required attributes passed to new' do
85
- proc { foo = Foo.new(:baz => 'Hi' ) }.should_not raise_error
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
- before :each do
92
- raise_if_defined :Foo
93
- class Foo < Doodle::Base
94
- has :baz, :default => 'Hi!'
95
- has :start do
96
- default { Date.today }
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
- it 'should have default value set from hash arg' do
106
- @foo.baz.should == 'Hi!'
107
- end
92
+ it 'should have default value set from hash arg' do
93
+ @foo.baz.should == 'Hi!'
94
+ end
108
95
 
109
- it 'should have default value set from block' do
110
- @foo.start.should == Date.today
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
- before :each do
116
- raise_if_defined :Text, :Text2, :KeyValue
117
- class KeyValue < Doodle::Base
118
- has :name
119
- has :value
120
- def to_s
121
- %[--#{name}="#{value}"]
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
- it 'should not raise error if initialized with required values' do
138
- proc { Text.new(:value => 'any') }.should_not raise_error
139
- end
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
- it 'should allow initialization using defaults' do
142
- text = Text.new(:value => 'any')
143
- text.name.should == 'text'
144
- text.value.should == 'any'
145
- end
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
- it 'should raise NoDefaultError if initialized without all required values' do
148
- proc { KeyValue.new(:value => 'Enter name:') }.should raise_error(Doodle::NoDefaultError)
149
- end
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
- it 'should allow initialization using inherited defaults' do
152
- text = Text2.new
153
- text.name.should == 'text'
154
- text.value.should == 'any2'
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
@@ -1,297 +1,310 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '../.'))
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
- after :each do
9
- undefine_const(:Foo)
10
- end
11
- before(:each) do
12
- raise_if_defined :Foo
13
- class Foo
14
- include Doodle::Helper
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
- it 'should have meta as synonym for singleton_class' do
20
- Foo.singleton_class.should == Foo.meta
21
- @foo.singleton_class.should == @foo.meta
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
- after :each do
27
- undefine_const(:Foo)
28
- end
29
- before(:each) do
30
- raise_if_defined :Foo
31
- class Foo
32
- include Doodle::Helper
33
- has :name, :default => nil
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
- it 'should create attribute' do
39
- @foo.name = 'Smee'
40
- @foo.name.should == 'Smee'
41
- end
35
+ it 'should create attribute' do
36
+ @foo.name = 'Smee'
37
+ @foo.name.should == 'Smee'
38
+ end
42
39
 
43
- it 'should create attribute using getter_setter' do
44
- @foo.name 'Smee'
45
- @foo.name.should == 'Smee'
46
- end
40
+ it 'should create attribute using getter_setter' do
41
+ @foo.name 'Smee'
42
+ @foo.name.should == 'Smee'
43
+ end
47
44
 
48
- it 'should list instance attributes(false)' do
49
- @foo.attributes(false).keys.should == []
50
- end
45
+ it 'should list instance attributes(false)' do
46
+ @foo.attributes(false).keys.should == []
47
+ end
51
48
 
52
- it 'should list instance attributes' do
53
- @foo.attributes.keys.should == [:name]
54
- end
49
+ it 'should list instance attributes' do
50
+ @foo.attributes.keys.should == [:name]
51
+ end
55
52
 
56
- it 'should list all instance attributes(false) at class level' do
57
- Foo.attributes(false).keys.should == [:name]
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
- after :each do
64
- undefine_const(:Foo)
65
- end
66
- before(:each) do
67
- raise_if_defined :Foo
68
- class Foo
69
- include Doodle::Helper
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
- it 'should create class attribute' do
78
- Foo.metadata = 'Foo metadata'
79
- Foo.metadata.should == 'Foo metadata'
80
- end
74
+ it 'should create class attribute' do
75
+ Foo.metadata = 'Foo metadata'
76
+ Foo.metadata.should == 'Foo metadata'
77
+ end
81
78
 
82
- it 'should access class attribute via self.class' do
83
- @foo.class.metadata = '@foo metadata'
84
- @foo.class.metadata.should == '@foo metadata'
85
- Foo.metadata.should == '@foo metadata'
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
- Foo.metadata = 'Foo metadata'
88
- Foo.metadata.should == 'Foo metadata'
89
- @foo.class.metadata.should == 'Foo metadata'
90
- end
84
+ Foo.metadata = 'Foo metadata'
85
+ Foo.metadata.should == 'Foo metadata'
86
+ @foo.class.metadata.should == 'Foo metadata'
87
+ end
91
88
 
92
- it "should list all class's own attributes" do
93
- Foo.meta.attributes(false).keys.should == [:metadata]
94
- end
89
+ it "should list all class's own attributes" do
90
+ Foo.meta.attributes(false).keys.should == [:metadata]
91
+ end
95
92
 
96
- it "should list all class's own attributes" do
97
- Foo.meta.attributes.keys.should == [:metadata]
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
- after :each do
104
- undefine_const(:Foo)
105
- undefine_const(:Bar)
106
- end
107
- before(:each) do
108
- raise_if_defined :Foo, :Bar
109
-
110
- class Foo
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
- end
117
- class Bar < Foo
118
- has :location, :default => nil
119
- class << self
120
- has :doc
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
- it 'should create inherited class attribute' do
128
- Foo.metadata = 'Foo metadata'
129
- Bar.metadata = 'Bar metadata'
130
- Foo.metadata.should == 'Foo metadata'
131
- Bar.metadata.should == 'Bar metadata'
132
- Foo.metadata.should == 'Foo metadata'
133
- end
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
- it 'should access class attribute via self.class' do
136
- @foo.class.metadata = '@foo metadata'
137
- @foo.class.metadata.should == '@foo metadata'
138
- Foo.metadata.should == '@foo metadata'
139
-
140
- Foo.metadata = 'Foo metadata'
141
- Bar.metadata = 'Bar metadata'
142
- Foo.metadata.should == 'Foo metadata'
143
- Bar.metadata.should == 'Bar metadata'
144
- Foo.metadata.should == 'Foo metadata'
145
- @foo.class.metadata.should == 'Foo metadata'
146
- @bar.class.metadata.should == 'Bar metadata'
147
- end
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
- it 'should access inherited class attribute via self.class' do
150
- @foo.class.metadata = '@foo metadata'
151
- @foo.class.metadata.should == '@foo metadata'
152
- Foo.metadata.should == '@foo metadata'
153
- Foo.metadata = 'Foo metadata'
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
- Bar.metadata = 'Bar metadata'
156
- Bar.metadata.should == 'Bar metadata'
157
- @bar.class.metadata.should == 'Bar metadata'
150
+ Bar.metadata = 'Bar metadata'
151
+ Bar.metadata.should == 'Bar metadata'
152
+ @bar.class.metadata.should == 'Bar metadata'
158
153
 
159
- Foo.metadata.should == 'Foo metadata'
160
- @foo.class.metadata.should == 'Foo metadata'
161
- end
154
+ Foo.metadata.should == 'Foo metadata'
155
+ @foo.class.metadata.should == 'Foo metadata'
156
+ end
162
157
 
163
- it "should list class's own attributes" do
164
- Foo.meta.attributes(false).keys.should == [:metadata]
165
- end
158
+ it "should list class's own attributes" do
159
+ Foo.meta.attributes(false).keys.should == [:metadata]
160
+ end
166
161
 
167
- it "should list all class's own attributes" do
168
- Foo.meta.attributes.keys.should == [:metadata]
169
- end
162
+ it "should list all class's own attributes" do
163
+ Foo.meta.attributes.keys.should == [:metadata]
164
+ end
170
165
 
171
- it "should list class's own attributes(false)" do
172
- Bar.meta.attributes(false).keys.should == [:doc]
173
- end
166
+ it "should list class's own attributes(false)" do
167
+ Bar.meta.attributes(false).keys.should == [:doc]
168
+ end
174
169
 
175
- it "should list all inherited meta class attributes" do
176
- Bar.meta.attributes.keys.should == [:metadata, :doc]
177
- end
170
+ it "should list all inherited meta class attributes" do
171
+ Bar.meta.attributes.keys.should == [:metadata, :doc]
172
+ end
178
173
 
179
- it "should list all inherited class's attributes" do
180
- Bar.attributes.keys.should == [:name, :location]
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
- after :each do
186
- undefine_const(:Foo)
187
- end
188
- before(:each) do
189
- raise_if_defined :Foo
181
+ temporary_constant :Foo do
182
+ before(:each) do
190
183
 
191
- class Foo
192
- include Doodle::Helper
193
- has :name, :default => nil
194
- class << self
195
- has :metadata
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
- @foo = Foo.new
199
- class << @foo
200
- has :special, :default => nil
196
+ after :each do
197
+ remove_ivars :foo
201
198
  end
202
- end
203
199
 
204
- it 'should allow creation of singleton class attributes' do
205
- @foo.special = 42
206
- @foo.special.should == 42
207
- end
200
+ it 'should allow creation of singleton class attributes' do
201
+ @foo.special = 42
202
+ @foo.special.should == 42
203
+ end
208
204
 
209
- it 'should list instance attributes' do
210
- @foo.meta.attributes(false).keys.should == [:special]
211
- end
205
+ it 'should list instance attributes' do
206
+ @foo.meta.attributes(false).keys.should == [:special]
207
+ end
212
208
 
213
- it 'should list instance attributes' do
214
- @foo.meta.attributes.keys.should == [:metadata, :special]
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
- after :each do
221
- undefine_const(:Foo)
222
- undefine_const(:Bar)
223
- end
224
- before(:each) do
225
- raise_if_defined :Foo, :Bar
226
-
227
- class Foo
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
- end
234
- class Bar < Foo
235
- has :info, :default => nil
236
- class << self
237
- has :doc
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
- @foo = Foo.new
242
- class << @foo
243
- has :special, :default => nil # must give default because already initialized
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
- @bar = Bar.new
246
- @bar2 = Bar.new
247
- class << @bar
248
- has :extra
242
+
243
+ after :each do
244
+ remove_ivars :foo, :bar, :bar2
249
245
  end
250
- end
251
246
 
252
- it 'should allow creation of singleton class attributes' do
253
- @foo.special = 42
254
- @foo.special.should == 42
255
- @bar.extra = 84
256
- @bar.extra.should == 84
257
- proc { @foo.extra = 1 }.should raise_error(NoMethodError)
258
- proc { @bar2.extra = 1 }.should raise_error(NoMethodError)
259
- proc { @bar.special = 1 }.should raise_error(NoMethodError)
260
- end
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
- it 'should list instance attributes' do
263
- @foo.class.attributes(false).keys.should == [:name]
264
- @bar.class.attributes(false).keys.should == [:info]
265
- @bar2.class.attributes(false).keys.should == [:info]
266
- end
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
- it 'should list instance meta attributes' do
269
- @foo.meta.attributes(false).keys.should == [:special]
270
- @bar.meta.attributes(false).keys.should == [:extra]
271
- end
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
- it 'should list instance attributes' do
274
- @foo.meta.attributes.keys.should == [:metadata, :special]
275
- @bar.meta.attributes.keys.should == [:metadata, :doc, :extra]
276
- end
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
- it 'should keep meta attributes separate' do
279
- @foo.special = 'foo special'
280
- @foo.meta.metadata = 'foo meta'
281
- # @bar.meta.metadata = 'bar meta'
282
- # @bar.meta.doc = 'bar doc'
283
- # Foo.metadata = 'Foo meta'
284
- # Bar.metadata = 'Bar meta'
285
- # Bar.doc = 'Bar doc'
286
-
287
- # @foo.meta.metadata.should == 'foo meta'
288
- # @bar.meta.metadata.should == 'bar meta'
289
- # @bar.meta.doc.should == 'bar doc'
290
- # Foo.metadata.should == 'Foo meta'
291
- # Bar.metadata.should == 'Bar meta'
292
- # Bar.doc.should == 'Bar doc'
293
-
294
- # proc { @foo.meta.doc = 1 }.should raise_error(NoMethodError)
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