agio 0.5.0
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/.gemtest +0 -0
- data/.rspec +2 -0
- data/History.rdoc +3 -0
- data/License.rdoc +23 -0
- data/Manifest.txt +23 -0
- data/README.rdoc +97 -0
- data/Rakefile +35 -0
- data/agio.gemspec +53 -0
- data/bin/agio +17 -0
- data/lib/agio.rb +171 -0
- data/lib/agio/block.rb +132 -0
- data/lib/agio/bourse.rb +340 -0
- data/lib/agio/broker.rb +415 -0
- data/lib/agio/data.rb +90 -0
- data/lib/agio/flags.rb +317 -0
- data/lib/agio/html_element_description.rb +126 -0
- data/spec/block_spec.rb +168 -0
- data/spec/bourse_spec.rb +10 -0
- data/spec/broker_spec.rb +539 -0
- data/spec/data_spec.rb +341 -0
- data/spec/flags_spec.rb +473 -0
- data/spec/html_element_description_spec.rb +52 -0
- data/spec/pmh_spec.rb +31 -0
- data/spec/spec_helper.rb +308 -0
- metadata +216 -0
data/spec/data_spec.rb
ADDED
@@ -0,0 +1,341 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Agio::Data do
|
6
|
+
subject { Agio::Data.new("test") }
|
7
|
+
|
8
|
+
it "should compare leftwise against a String (data == string)" do
|
9
|
+
subject.should == "test"
|
10
|
+
subject.should_not == "test1"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should compare rightwise against a String (string == data)" do
|
14
|
+
"test".should == subject
|
15
|
+
"test1".should_not == subject
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should compare against another Agio::Data object" do
|
19
|
+
Agio::Data.new("test").should == subject
|
20
|
+
subject.should == Agio::Data.new("test")
|
21
|
+
|
22
|
+
Agio::Data.new("test1").should_not == subject
|
23
|
+
subject.should_not == Agio::Data.new("test1")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not compare against an Agio::CData" do
|
27
|
+
Agio::CData.new("test").should_not == subject
|
28
|
+
subject.should_not == Agio::CData.new("test")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not compare against an Agio::Comment" do
|
32
|
+
Agio::Comment.new("test").should_not == subject
|
33
|
+
subject.should_not == Agio::Comment.new("test")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not compare against an Agio::XMLDecl" do
|
37
|
+
Agio::XMLDecl.new.should_not == subject
|
38
|
+
subject.should_not == Agio::XMLDecl.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe Agio::CData do
|
43
|
+
subject { Agio::CData.new("test") }
|
44
|
+
|
45
|
+
it "should compare leftwise against a String (data == string)" do
|
46
|
+
subject.should == "test"
|
47
|
+
subject.should_not == "test1"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should compare rightwise against a String (string == data)" do
|
51
|
+
"test".should == subject
|
52
|
+
"test1".should_not == subject
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should compare against another Agio::Data object" do
|
56
|
+
Agio::CData.new("test").should == subject
|
57
|
+
subject.should == Agio::CData.new("test")
|
58
|
+
|
59
|
+
Agio::CData.new("test1").should_not == subject
|
60
|
+
subject.should_not == Agio::CData.new("test1")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not compare against an Agio::Data" do
|
64
|
+
Agio::Data.new("test").should_not == subject
|
65
|
+
subject.should_not == Agio::Data.new("test")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not compare against an Agio::Comment" do
|
69
|
+
Agio::Comment.new("test").should_not == subject
|
70
|
+
subject.should_not == Agio::Comment.new("test")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should not compare against an Agio::XMLDecl" do
|
74
|
+
Agio::XMLDecl.new.should_not == subject
|
75
|
+
subject.should_not == Agio::XMLDecl.new
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe Agio::Comment do
|
80
|
+
subject { Agio::Comment.new("test") }
|
81
|
+
|
82
|
+
it "should compare leftwise against a String (data == string)" do
|
83
|
+
subject.should == "test"
|
84
|
+
subject.should_not == "test1"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should compare rightwise against a String (string == data)" do
|
88
|
+
"test".should == subject
|
89
|
+
"test1".should_not == subject
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should compare against another Agio::Data object" do
|
93
|
+
Agio::Comment.new("test").should == subject
|
94
|
+
subject.should == Agio::Comment.new("test")
|
95
|
+
|
96
|
+
Agio::Comment.new("test1").should_not == subject
|
97
|
+
subject.should_not == Agio::Comment.new("test1")
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not compare against an Agio::Data" do
|
101
|
+
Agio::Data.new("test").should_not == subject
|
102
|
+
subject.should_not == Agio::Data.new("test")
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not compare against an Agio::CData" do
|
106
|
+
Agio::CData.new("test").should_not == subject
|
107
|
+
subject.should_not == Agio::CData.new("test")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should not compare against an Agio::XMLDecl" do
|
111
|
+
Agio::XMLDecl.new.should_not == subject
|
112
|
+
subject.should_not == Agio::XMLDecl.new
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe Agio::XMLDecl do
|
117
|
+
context "constructed with only version" do
|
118
|
+
let(:decl_string) { %Q(<?xml version="1.0" ?>) }
|
119
|
+
let(:decl_array) { [ "1.0", nil, nil ] }
|
120
|
+
|
121
|
+
subject { Agio::XMLDecl.new(:version => "1.0") }
|
122
|
+
|
123
|
+
its(:version) { should == "1.0" }
|
124
|
+
its(:encoding) { should be_nil }
|
125
|
+
its(:standalone) { should be_nil }
|
126
|
+
its(:to_s) { should == decl_string }
|
127
|
+
its(:to_str) { should == decl_string }
|
128
|
+
its(:to_a) { should == decl_array }
|
129
|
+
its(:inspect) { should == %Q(#<Agio::XMLDecl '#{decl_string}'>) }
|
130
|
+
|
131
|
+
it "should equality-compare with a String transitively" do
|
132
|
+
decl_string.should == subject
|
133
|
+
decl_string.upcase.should_not == subject
|
134
|
+
|
135
|
+
subject.should == decl_string
|
136
|
+
subject.should_not == decl_string.upcase
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should compare with an Array" do
|
140
|
+
subject.should == decl_array
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should compare with another Agio::XMLDecl" do
|
144
|
+
subject.should == Agio::XMLDecl.new(:version => "1.0")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "constructed with only encoding" do
|
149
|
+
let(:decl_string) { %Q(<?xml encoding="UTF-8" ?>) }
|
150
|
+
let(:decl_array) { [ nil, "UTF-8", nil ] }
|
151
|
+
|
152
|
+
subject { Agio::XMLDecl.new(:encoding => "UTF-8") }
|
153
|
+
|
154
|
+
its(:version) { should be_nil }
|
155
|
+
its(:encoding) { should == "UTF-8" }
|
156
|
+
its(:standalone) { should be_nil }
|
157
|
+
its(:to_s) { should == decl_string }
|
158
|
+
its(:to_str) { should == decl_string }
|
159
|
+
its(:to_a) { should == decl_array }
|
160
|
+
its(:inspect) { should == %Q(#<Agio::XMLDecl '#{decl_string}'>) }
|
161
|
+
|
162
|
+
it "should equality-compare with a String transitively" do
|
163
|
+
decl_string.should == subject
|
164
|
+
decl_string.upcase.should_not == subject
|
165
|
+
|
166
|
+
subject.should == decl_string
|
167
|
+
subject.should_not == decl_string.upcase
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should compare with an Array" do
|
171
|
+
subject.should == decl_array
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should compare with another Agio::XMLDecl" do
|
175
|
+
subject.should == Agio::XMLDecl.new(:encoding => "UTF-8")
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context "constructed with only standalone" do
|
180
|
+
let(:decl_string) { %Q(<?xml standalone="true" ?>) }
|
181
|
+
let(:decl_array) { [ nil, nil, true ] }
|
182
|
+
|
183
|
+
subject { Agio::XMLDecl.new(:standalone => true) }
|
184
|
+
|
185
|
+
its(:version) { should be_nil }
|
186
|
+
its(:encoding) { should be_nil }
|
187
|
+
its(:standalone) { should == true }
|
188
|
+
its(:to_s) { should == decl_string }
|
189
|
+
its(:to_str) { should == decl_string }
|
190
|
+
its(:to_a) { should == decl_array }
|
191
|
+
its(:inspect) { should == %Q(#<Agio::XMLDecl '#{decl_string}'>) }
|
192
|
+
|
193
|
+
it "should equality-compare with a String transitively" do
|
194
|
+
decl_string.should == subject
|
195
|
+
decl_string.upcase.should_not == subject
|
196
|
+
|
197
|
+
subject.should == decl_string
|
198
|
+
subject.should_not == decl_string.upcase
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should compare with an Array" do
|
202
|
+
subject.should == decl_array
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should compare with another Agio::XMLDecl" do
|
206
|
+
subject.should == Agio::XMLDecl.new(:standalone => true)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context "constructed with version and encoding" do
|
211
|
+
let(:decl_string) { %Q(<?xml version="1.0" encoding="UTF-8" ?>) }
|
212
|
+
let(:decl_array) { [ "1.0", "UTF-8", nil ] }
|
213
|
+
|
214
|
+
subject { Agio::XMLDecl.new(:version => "1.0", :encoding => "UTF-8") }
|
215
|
+
|
216
|
+
its(:version) { should == "1.0" }
|
217
|
+
its(:encoding) { should == "UTF-8" }
|
218
|
+
its(:standalone) { should be_nil }
|
219
|
+
its(:to_s) { should == decl_string }
|
220
|
+
its(:to_str) { should == decl_string }
|
221
|
+
its(:to_a) { should == decl_array }
|
222
|
+
its(:inspect) { should == %Q(#<Agio::XMLDecl '#{decl_string}'>) }
|
223
|
+
|
224
|
+
it "should equality-compare with a String transitively" do
|
225
|
+
decl_string.should == subject
|
226
|
+
decl_string.upcase.should_not == subject
|
227
|
+
|
228
|
+
subject.should == decl_string
|
229
|
+
subject.should_not == decl_string.upcase
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should compare with an Array" do
|
233
|
+
subject.should == decl_array
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should compare with another Agio::XMLDecl" do
|
237
|
+
subject.should ==
|
238
|
+
Agio::XMLDecl.new(:version => "1.0", :encoding => "UTF-8")
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context "constructed with version and standalone" do
|
243
|
+
let(:decl_string) { %Q(<?xml version="1.0" standalone="false" ?>) }
|
244
|
+
let(:decl_array) { [ "1.0", nil, false ] }
|
245
|
+
|
246
|
+
subject { Agio::XMLDecl.new(:version => "1.0", :standalone => false) }
|
247
|
+
|
248
|
+
its(:version) { should == "1.0" }
|
249
|
+
its(:encoding) { should be_nil }
|
250
|
+
its(:standalone) { should == false }
|
251
|
+
its(:to_s) { should == decl_string }
|
252
|
+
its(:to_str) { should == decl_string }
|
253
|
+
its(:to_a) { should == decl_array }
|
254
|
+
its(:inspect) { should == %Q(#<Agio::XMLDecl '#{decl_string}'>) }
|
255
|
+
|
256
|
+
it "should equality-compare with a String transitively" do
|
257
|
+
decl_string.should == subject
|
258
|
+
decl_string.upcase.should_not == subject
|
259
|
+
|
260
|
+
subject.should == decl_string
|
261
|
+
subject.should_not == decl_string.upcase
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should compare with an Array" do
|
265
|
+
subject.should == decl_array
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should compare with another Agio::XMLDecl" do
|
269
|
+
subject.should ==
|
270
|
+
Agio::XMLDecl.new(:version => "1.0", :standalone => false)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context "constructed with encoding and standalone" do
|
275
|
+
let(:decl_string) { %Q(<?xml encoding="UTF-8" standalone="false" ?>) }
|
276
|
+
let(:decl_array) { [ nil, "UTF-8", false ] }
|
277
|
+
|
278
|
+
subject { Agio::XMLDecl.new(:encoding => "UTF-8", :standalone => false) }
|
279
|
+
|
280
|
+
its(:version) { should be_nil }
|
281
|
+
its(:encoding) { should == "UTF-8" }
|
282
|
+
its(:standalone) { should == false }
|
283
|
+
its(:to_s) { should == decl_string }
|
284
|
+
its(:to_str) { should == decl_string }
|
285
|
+
its(:to_a) { should == decl_array }
|
286
|
+
its(:inspect) { should == %Q(#<Agio::XMLDecl '#{decl_string}'>) }
|
287
|
+
|
288
|
+
it "should equality-compare with a String transitively" do
|
289
|
+
decl_string.should == subject
|
290
|
+
decl_string.upcase.should_not == subject
|
291
|
+
|
292
|
+
subject.should == decl_string
|
293
|
+
subject.should_not == decl_string.upcase
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should compare with an Array" do
|
297
|
+
subject.should == decl_array
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should compare with another Agio::XMLDecl" do
|
301
|
+
subject.should ==
|
302
|
+
Agio::XMLDecl.new(:encoding => "UTF-8", :standalone => false)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context "constructed with all values" do
|
307
|
+
let(:decl_string) { %Q(<?xml version="1.0" encoding="UTF-8" standalone="false" ?>) }
|
308
|
+
let(:decl_array) { [ "1.0", "UTF-8", false ] }
|
309
|
+
|
310
|
+
subject { Agio::XMLDecl.new(:version => "1.0", :encoding => "UTF-8",
|
311
|
+
:standalone => false) }
|
312
|
+
|
313
|
+
its(:version) { should == "1.0" }
|
314
|
+
its(:encoding) { should == "UTF-8" }
|
315
|
+
its(:standalone) { should == false }
|
316
|
+
its(:to_s) { should == decl_string }
|
317
|
+
its(:to_str) { should == decl_string }
|
318
|
+
its(:to_a) { should == decl_array }
|
319
|
+
its(:inspect) { should == %Q(#<Agio::XMLDecl '#{decl_string}'>) }
|
320
|
+
|
321
|
+
it "should equality-compare with a String transitively" do
|
322
|
+
decl_string.should == subject
|
323
|
+
decl_string.upcase.should_not == subject
|
324
|
+
|
325
|
+
subject.should == decl_string
|
326
|
+
subject.should_not == decl_string.upcase
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should compare with an Array" do
|
330
|
+
subject.should == decl_array
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should compare with another Agio::XMLDecl" do
|
334
|
+
subject.should ==
|
335
|
+
Agio::XMLDecl.new(:version => "1.0", :encoding => "UTF-8",
|
336
|
+
:standalone => false)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
# vim: ft=ruby
|
data/spec/flags_spec.rb
ADDED
@@ -0,0 +1,473 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Agio::Flags do
|
6
|
+
subject {
|
7
|
+
klass = Class.new
|
8
|
+
klass.class_eval { extend Agio::Flags }
|
9
|
+
klass
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:meta) {
|
13
|
+
class << subject
|
14
|
+
self
|
15
|
+
end
|
16
|
+
}
|
17
|
+
|
18
|
+
describe "basic 'extend'" do
|
19
|
+
it "should inherit from Agio::Flags" do
|
20
|
+
subject.ancestors.should include(Agio::Flags)
|
21
|
+
subject.private_instance_methods.should include("reset_flags")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be extended by Agio::Flags::ClassMethods" do
|
25
|
+
meta.ancestors.should include(Agio::Flags::ClassMethods)
|
26
|
+
|
27
|
+
methods = subject.public_methods
|
28
|
+
|
29
|
+
methods.should include("flag_builder")
|
30
|
+
methods.should include("string_flag")
|
31
|
+
methods.should include("boolean_flag")
|
32
|
+
methods.should include("integer_flag")
|
33
|
+
methods.should include("hash_flag")
|
34
|
+
methods.should include("flag_inits")
|
35
|
+
methods.should include("public_flag_inits")
|
36
|
+
methods.should include("flags")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "duplicate prevention" do
|
41
|
+
before(:each) do
|
42
|
+
subject.class_eval do
|
43
|
+
string_flag :my_string, :default => 'xyz', :private => true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should raise a SyntaxError if defined again" do
|
48
|
+
expect do
|
49
|
+
subject.class_eval do
|
50
|
+
string_flag :my_string, :default => 'xyz', :private => false
|
51
|
+
end
|
52
|
+
end.to raise_error(SyntaxError, /already defined/)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "string_flag :my_string, :default => 'xyz', :public => false" do
|
57
|
+
$xyz = 'xyz'
|
58
|
+
|
59
|
+
before(:each) do
|
60
|
+
subject.class_eval do
|
61
|
+
string_flag :my_string, :default => $xyz, :public => false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have new string_flag methods" do
|
66
|
+
pim = subject.private_instance_methods
|
67
|
+
pim.should include("init_my_string")
|
68
|
+
pim.should include("my_string")
|
69
|
+
pim.should include("set_my_string")
|
70
|
+
pim.should include("my_string?")
|
71
|
+
|
72
|
+
subject.flag_inits.should include(:init_my_string)
|
73
|
+
|
74
|
+
subject.flags[:my_string].should == {
|
75
|
+
:ivar => "@flag_my_string",
|
76
|
+
:init => :init_my_string,
|
77
|
+
:getter => :my_string,
|
78
|
+
:setter => :set_my_string,
|
79
|
+
:tester => :my_string?,
|
80
|
+
:public => false,
|
81
|
+
:type => :string,
|
82
|
+
:default => subject.flags[:my_string][:default],
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
context "object instance" do
|
87
|
+
let(:obj) { subject.new }
|
88
|
+
|
89
|
+
def call(method, *args)
|
90
|
+
obj.__send__(method, *args)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should create and set the instance variable when #reset_flags is called" do
|
94
|
+
obj.instance_variables.should_not include("@flag_my_string")
|
95
|
+
call(:reset_flags)
|
96
|
+
obj.instance_variables.should include("@flag_my_string")
|
97
|
+
obj.instance_variable_get("@flag_my_string").should == $xyz
|
98
|
+
obj.instance_variable_get("@flag_my_string").should_not equal($xyz)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "#set_my_string should set the value as a string" do
|
102
|
+
call(:set_my_string, 'foo')
|
103
|
+
call(:my_string).should == 'foo'
|
104
|
+
|
105
|
+
call(:set_my_string, 3)
|
106
|
+
call(:my_string).should == "3"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "#set_my_string should clear the value if provided nil" do
|
110
|
+
call(:set_my_string, 'foo')
|
111
|
+
call(:my_string).should == 'foo'
|
112
|
+
|
113
|
+
call(:set_my_string, nil)
|
114
|
+
call(:my_string).should be_nil
|
115
|
+
end
|
116
|
+
|
117
|
+
it "#my_string? should return false if the value is nil" do
|
118
|
+
call(:set_my_string, nil)
|
119
|
+
call(:my_string?).should == false
|
120
|
+
end
|
121
|
+
|
122
|
+
it "#my_string? should return false if the value is empty" do
|
123
|
+
call(:set_my_string, "")
|
124
|
+
call(:my_string?).should == false
|
125
|
+
end
|
126
|
+
|
127
|
+
it "#my_string? should return true if the value is not nil or empty" do
|
128
|
+
call(:set_my_string, "foo")
|
129
|
+
call(:my_string?).should == true
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "boolean_flag :my_boolean, :public => true" do
|
135
|
+
before(:each) do
|
136
|
+
subject.class_eval do
|
137
|
+
boolean_flag :my_bool, :public => true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should have new boolean_flag methods" do
|
142
|
+
subject.private_instance_methods.should include("init_my_bool")
|
143
|
+
|
144
|
+
pim = subject.public_instance_methods
|
145
|
+
pim.should include("my_bool")
|
146
|
+
pim.should include("my_bool=")
|
147
|
+
pim.should include("my_bool?")
|
148
|
+
|
149
|
+
subject.public_flag_inits.should include(:init_my_bool)
|
150
|
+
|
151
|
+
subject.flags[:my_bool].should == {
|
152
|
+
:ivar => "@flag_my_bool",
|
153
|
+
:init => :init_my_bool,
|
154
|
+
:getter => :my_bool,
|
155
|
+
:setter => :my_bool=,
|
156
|
+
:tester => :my_bool?,
|
157
|
+
:public => true,
|
158
|
+
:type => :boolean,
|
159
|
+
:default => false,
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
context "object instance" do
|
164
|
+
let(:obj) { subject.new }
|
165
|
+
|
166
|
+
def call(method, *args)
|
167
|
+
obj.__send__(method, *args)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should do nothing when #reset_flags is called" do
|
171
|
+
obj.instance_variables.should_not include("@flag_my_bool")
|
172
|
+
call(:reset_flags)
|
173
|
+
obj.instance_variables.should_not include("@flag_my_bool")
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should create and set the instance variable when #reset_flags(true) is called" do
|
177
|
+
obj.instance_variables.should_not include("@flag_my_bool")
|
178
|
+
call(:reset_flags, true)
|
179
|
+
obj.instance_variables.should include("@flag_my_bool")
|
180
|
+
obj.instance_variable_get("@flag_my_bool").should == false
|
181
|
+
end
|
182
|
+
|
183
|
+
it "#my_bool= should set the value as a Boolean value" do
|
184
|
+
obj.my_bool = 'foo'
|
185
|
+
obj.my_bool.should == true
|
186
|
+
|
187
|
+
obj.my_bool = 3
|
188
|
+
obj.my_bool.should == true
|
189
|
+
|
190
|
+
obj.my_bool = nil
|
191
|
+
obj.my_bool.should == false
|
192
|
+
|
193
|
+
obj.my_bool = false
|
194
|
+
obj.my_bool.should == false
|
195
|
+
end
|
196
|
+
|
197
|
+
it "#my_bool? and #my_bool should return the same value" do
|
198
|
+
obj.my_bool = 'foo'
|
199
|
+
obj.my_bool.should == obj.my_bool?
|
200
|
+
|
201
|
+
obj.my_bool = false
|
202
|
+
obj.my_bool.should == obj.my_bool?
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "integer_flag :my_integer, :default => 42, :public => false" do
|
208
|
+
before(:each) do
|
209
|
+
subject.class_eval do
|
210
|
+
integer_flag :my_integer, :default => 42, :public => false
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should have new integer_flag methods" do
|
215
|
+
pim = subject.private_instance_methods
|
216
|
+
pim.should include("init_my_integer")
|
217
|
+
pim.should include("my_integer")
|
218
|
+
pim.should include("set_my_integer")
|
219
|
+
pim.should include("my_integer?")
|
220
|
+
pim.should include("incr_my_integer")
|
221
|
+
pim.should include("decr_my_integer")
|
222
|
+
|
223
|
+
subject.flag_inits.should include(:init_my_integer)
|
224
|
+
|
225
|
+
subject.flags[:my_integer].should == {
|
226
|
+
:ivar => "@flag_my_integer",
|
227
|
+
:init => :init_my_integer,
|
228
|
+
:getter => :my_integer,
|
229
|
+
:setter => :set_my_integer,
|
230
|
+
:tester => :my_integer?,
|
231
|
+
:public => false,
|
232
|
+
:type => :integer,
|
233
|
+
:default => 42,
|
234
|
+
}
|
235
|
+
end
|
236
|
+
|
237
|
+
context "object instance" do
|
238
|
+
let(:obj) { subject.new }
|
239
|
+
|
240
|
+
def call(method, *args)
|
241
|
+
obj.__send__(method, *args)
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should create and set the instance variable when #reset_flags is called" do
|
245
|
+
obj.instance_variables.should_not include("@flag_my_integer")
|
246
|
+
call(:reset_flags)
|
247
|
+
obj.instance_variables.should include("@flag_my_integer")
|
248
|
+
obj.instance_variable_get("@flag_my_integer").should == 42
|
249
|
+
end
|
250
|
+
|
251
|
+
it "#set_my_integer should set the value as a integer" do
|
252
|
+
call(:set_my_integer, 'foo')
|
253
|
+
call(:my_integer).should == 0
|
254
|
+
|
255
|
+
call(:set_my_integer, 3)
|
256
|
+
call(:my_integer).should == 3
|
257
|
+
|
258
|
+
call(:set_my_integer, 3.5)
|
259
|
+
call(:my_integer).should == 3
|
260
|
+
|
261
|
+
call(:set_my_integer, nil)
|
262
|
+
call(:my_integer).should == 0
|
263
|
+
end
|
264
|
+
|
265
|
+
it "#my_integer? should return nil if the value is zero" do
|
266
|
+
call(:set_my_integer, nil)
|
267
|
+
call(:my_integer?).should == nil
|
268
|
+
end
|
269
|
+
|
270
|
+
it "#my_integer? should return the value if the value is non-zero" do
|
271
|
+
call(:reset_flags)
|
272
|
+
call(:my_integer?).should == call(:my_integer)
|
273
|
+
end
|
274
|
+
|
275
|
+
it "#incr_my_integer should increment the integer by the provided value" do
|
276
|
+
call(:reset_flags)
|
277
|
+
call(:my_integer).should == 42
|
278
|
+
|
279
|
+
call(:incr_my_integer, 3)
|
280
|
+
call(:my_integer).should == 45
|
281
|
+
end
|
282
|
+
|
283
|
+
it "#decr_my_integer should decrement the integer by the provided value" do
|
284
|
+
call(:reset_flags)
|
285
|
+
call(:my_integer).should == 42
|
286
|
+
|
287
|
+
call(:decr_my_integer, 3)
|
288
|
+
call(:my_integer).should == 39
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
describe "array_flag :my_array" do
|
294
|
+
before(:each) do
|
295
|
+
subject.class_eval do
|
296
|
+
array_flag :my_array
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should have new array_flag methods" do
|
301
|
+
pim = subject.private_instance_methods
|
302
|
+
pim.should include("init_my_array")
|
303
|
+
pim.should include("my_array")
|
304
|
+
pim.should include("set_my_array")
|
305
|
+
pim.should include("my_array?")
|
306
|
+
|
307
|
+
subject.flag_inits.should include(:init_my_array)
|
308
|
+
|
309
|
+
subject.flags[:my_array].should == {
|
310
|
+
:ivar => "@flag_my_array",
|
311
|
+
:init => :init_my_array,
|
312
|
+
:getter => :my_array,
|
313
|
+
:setter => :set_my_array,
|
314
|
+
:tester => :my_array?,
|
315
|
+
:public => nil,
|
316
|
+
:type => :array,
|
317
|
+
:default => subject.flags[:my_array][:default],
|
318
|
+
}
|
319
|
+
end
|
320
|
+
|
321
|
+
context "object instance" do
|
322
|
+
let(:obj) { subject.new }
|
323
|
+
|
324
|
+
def call(method, *args)
|
325
|
+
obj.__send__(method, *args)
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should create and set the instance variable when #reset_flags is called" do
|
329
|
+
obj.instance_variables.should_not include("@flag_my_array")
|
330
|
+
call(:reset_flags)
|
331
|
+
obj.instance_variables.should include("@flag_my_array")
|
332
|
+
obj.instance_variable_get("@flag_my_array").should == []
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should not make the same default array over two #reset_flags calls" do
|
336
|
+
call(:reset_flags)
|
337
|
+
x = obj.instance_variable_get("@flag_my_array")
|
338
|
+
|
339
|
+
call(:reset_flags)
|
340
|
+
obj.instance_variable_get("@flag_my_array").should == x
|
341
|
+
obj.instance_variable_get("@flag_my_array").should_not equal(x)
|
342
|
+
end
|
343
|
+
|
344
|
+
it "#set_my_array should set the value as a array" do
|
345
|
+
call(:set_my_array, nil)
|
346
|
+
call(:my_array).should be_nil
|
347
|
+
|
348
|
+
call(:set_my_array, 3)
|
349
|
+
call(:my_array).should == [ 3 ]
|
350
|
+
|
351
|
+
call(:set_my_array, 3.5)
|
352
|
+
call(:my_array).should == [ 3.5 ]
|
353
|
+
|
354
|
+
call(:set_my_array, %W(a b c))
|
355
|
+
call(:my_array).should == %W(a b c)
|
356
|
+
end
|
357
|
+
|
358
|
+
it "#set_my_array should clear the value if provided nil" do
|
359
|
+
call(:set_my_array, 'foo')
|
360
|
+
call(:my_array).should == [ 'foo' ]
|
361
|
+
|
362
|
+
call(:set_my_array, nil)
|
363
|
+
call(:my_array).should be_nil
|
364
|
+
end
|
365
|
+
|
366
|
+
it "#my_array? should return false if the value is empty or nil" do
|
367
|
+
call(:set_my_array, nil)
|
368
|
+
call(:my_array?).should == false
|
369
|
+
|
370
|
+
call(:set_my_array, [])
|
371
|
+
call(:my_array?).should == false
|
372
|
+
end
|
373
|
+
|
374
|
+
it "#my_array? should return true if the value is not empty" do
|
375
|
+
call(:set_my_array, %W(a b c))
|
376
|
+
call(:my_array?).should == true
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
describe "hash_flag :my_hash" do
|
382
|
+
before(:each) do
|
383
|
+
subject.class_eval do
|
384
|
+
hash_flag :my_hash
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
it "should have new hash_flag methods" do
|
389
|
+
pim = subject.private_instance_methods
|
390
|
+
pim.should include("init_my_hash")
|
391
|
+
pim.should include("my_hash")
|
392
|
+
pim.should include("set_my_hash")
|
393
|
+
pim.should include("my_hash?")
|
394
|
+
|
395
|
+
subject.flag_inits.should include(:init_my_hash)
|
396
|
+
|
397
|
+
subject.flags[:my_hash].should == {
|
398
|
+
:ivar => "@flag_my_hash",
|
399
|
+
:init => :init_my_hash,
|
400
|
+
:getter => :my_hash,
|
401
|
+
:setter => :set_my_hash,
|
402
|
+
:tester => :my_hash?,
|
403
|
+
:public => nil,
|
404
|
+
:type => :hash,
|
405
|
+
:default => subject.flags[:my_hash][:default],
|
406
|
+
}
|
407
|
+
end
|
408
|
+
|
409
|
+
context "object instance" do
|
410
|
+
let(:obj) { subject.new }
|
411
|
+
let(:hash) do
|
412
|
+
{ :a => 1, :b => 2 }
|
413
|
+
end
|
414
|
+
|
415
|
+
def call(method, *args)
|
416
|
+
obj.__send__(method, *args)
|
417
|
+
end
|
418
|
+
|
419
|
+
it "should create and set the instance variable when #reset_flags is called" do
|
420
|
+
obj.instance_variables.should_not include("@flag_my_hash")
|
421
|
+
call(:reset_flags)
|
422
|
+
obj.instance_variables.should include("@flag_my_hash")
|
423
|
+
obj.instance_variable_get("@flag_my_hash").should == {}
|
424
|
+
end
|
425
|
+
|
426
|
+
it "should not make the same default hash over two #reset_flags calls" do
|
427
|
+
call(:reset_flags)
|
428
|
+
x = obj.instance_variable_get("@flag_my_hash")
|
429
|
+
|
430
|
+
call(:reset_flags)
|
431
|
+
obj.instance_variable_get("@flag_my_hash").should == x
|
432
|
+
obj.instance_variable_get("@flag_my_hash").should_not equal(x)
|
433
|
+
end
|
434
|
+
|
435
|
+
it "#set_my_hash should set the value as a hash" do
|
436
|
+
call(:set_my_hash, nil)
|
437
|
+
call(:my_hash).should be_nil
|
438
|
+
|
439
|
+
call(:set_my_hash, { :a => 1, :b => 2 })
|
440
|
+
call(:my_hash).should == { :a => 1, :b => 2 }
|
441
|
+
end
|
442
|
+
|
443
|
+
it "#set_my_hash will raise an ArgumentError if not provided nil or a Hash" do
|
444
|
+
expect {
|
445
|
+
call(:set_my_hash, 3)
|
446
|
+
}.to raise_error(ArgumentError)
|
447
|
+
end
|
448
|
+
|
449
|
+
it "#set_my_hash should clear the value if provided nil" do
|
450
|
+
call(:set_my_hash, hash)
|
451
|
+
call(:my_hash).should == hash
|
452
|
+
|
453
|
+
call(:set_my_hash, nil)
|
454
|
+
call(:my_hash).should be_nil
|
455
|
+
end
|
456
|
+
|
457
|
+
it "#my_hash? should return false if the value is empty or nil" do
|
458
|
+
call(:set_my_hash, nil)
|
459
|
+
call(:my_hash?).should == false
|
460
|
+
|
461
|
+
call(:set_my_hash, {})
|
462
|
+
call(:my_hash?).should == false
|
463
|
+
end
|
464
|
+
|
465
|
+
it "#my_hash? should return true if the value is not empty" do
|
466
|
+
call(:set_my_hash, hash)
|
467
|
+
call(:my_hash?).should == true
|
468
|
+
end
|
469
|
+
end
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
# vim: ft=ruby
|