adhearsion-loquacious 1.9.2

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.
@@ -0,0 +1,369 @@
1
+
2
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
3
+
4
+ describe Loquacious::Configuration::Help do
5
+
6
+ before :all do
7
+ @sio = StringIO.new
8
+ end
9
+
10
+ before :each do
11
+ @config = Loquacious.configuration_for 'specs'
12
+ @help = Loquacious::Configuration::Help.new 'specs', :io => @sio
13
+ @sio.clear
14
+ end
15
+
16
+ it "returns a help object by name" do
17
+ help = Loquacious::Configuration::Help.new 'specs'
18
+ config = help.instance_variable_get(:@config)
19
+ config.equal?(@config).should be_true
20
+ end
21
+
22
+ it "returns a help object for a configuration" do
23
+ help = Loquacious::Configuration::Help.new @config
24
+ config = help.instance_variable_get(:@config)
25
+ config.equal?(@config).should be_true
26
+ end
27
+
28
+ it "raises an error for invalid attribute names" do
29
+ lambda {@help.show(42)}.should raise_error(
30
+ Loquacious::Configuration::Help::Error,
31
+ "cannot convert 42 into an attribute identifier"
32
+ )
33
+ end
34
+
35
+ it "prints out all attribues" do
36
+ str = <<-OUTPUT
37
+ | foo method
38
+ | - first
39
+ |
40
+ | bar method
41
+ | - second
42
+ |
43
+ | the third group
44
+ | - third
45
+ |
46
+ | life the universe and everything
47
+ | - third.answer
48
+ |
49
+ | perhaps you do not understand
50
+ | - third.question
51
+ |
52
+ OUTPUT
53
+
54
+ @help.show_all
55
+ @sio.to_s.should be == str.gutter!
56
+ end
57
+
58
+ it "prints out a specific attribute" do
59
+ str = <<-OUTPUT
60
+ | bar method
61
+ | - second
62
+ |
63
+ OUTPUT
64
+ @help.show_attribute :second
65
+ @sio.to_s.should be == str.gutter!
66
+ end
67
+
68
+ it "properly parses nested attributes" do
69
+ str = <<-OUTPUT
70
+ | the third group
71
+ | - third
72
+ |
73
+ | life the universe and everything
74
+ | - third.answer
75
+ |
76
+ | perhaps you do not understand
77
+ | - third.question
78
+ |
79
+ OUTPUT
80
+ @help.show_attribute 'third'
81
+ @sio.to_s.should be == str.gutter!
82
+
83
+ @sio.clear
84
+ str = <<-OUTPUT
85
+ | perhaps you do not understand
86
+ | - third.question
87
+ |
88
+ OUTPUT
89
+ @help.show_attribute %w[third question]
90
+ @sio.to_s.should be == str.gutter!
91
+
92
+ @sio.clear
93
+ str = <<-OUTPUT
94
+ | life the universe and everything
95
+ | - third.answer
96
+ |
97
+ OUTPUT
98
+ @help.show_attribute 'third.answer'
99
+ @sio.to_s.should be == str.gutter!
100
+ end
101
+
102
+ it "hides nesting attributes" do
103
+ help = Loquacious::Configuration::Help.new @config, :nesting_nodes => false, :io => @sio
104
+
105
+ str = <<-OUTPUT
106
+ | foo method
107
+ | - first
108
+ |
109
+ | bar method
110
+ | - second
111
+ |
112
+ | life the universe and everything
113
+ | - third.answer
114
+ |
115
+ | perhaps you do not understand
116
+ | - third.question
117
+ |
118
+ OUTPUT
119
+
120
+ help.show_all
121
+ @sio.to_s.should be == str.gutter!
122
+
123
+ @sio.clear
124
+ str = <<-OUTPUT
125
+ | life the universe and everything
126
+ | - third.answer
127
+ |
128
+ | perhaps you do not understand
129
+ | - third.question
130
+ |
131
+ OUTPUT
132
+ help.show_attribute 'third'
133
+ @sio.to_s.should be == str.gutter!
134
+
135
+ @sio.clear
136
+ end
137
+
138
+ it "preserves indentation for descriptions" do
139
+ Loquacious.configuration_for('specs') do
140
+ desc <<-DESC
141
+ This is a multiline description that has an example.
142
+ |
143
+ | foo = %w[one two three]
144
+ |
145
+ See, the example is right above this line.
146
+ Hope it was instructive.
147
+ DESC
148
+ fourth 'the fourth value'
149
+ end
150
+
151
+ str = <<-OUTPUT
152
+ | This is a multiline description that has an example.
153
+ |
154
+ | foo = %w[one two three]
155
+ |
156
+ | See, the example is right above this line.
157
+ | Hope it was instructive.
158
+ | - fourth
159
+ |
160
+ OUTPUT
161
+ @help.show_attribute 'fourth'
162
+ @sio.to_s.should be == str.gutter!
163
+ end
164
+
165
+ it "pretty prints values" do
166
+ str = <<-OUTPUT
167
+ | foo method
168
+ | - first => "foo"
169
+ |
170
+ | bar method
171
+ | - second => "bar"
172
+ |
173
+ | the third group
174
+ | - third
175
+ |
176
+ | life the universe and everything
177
+ | - third.answer => 42
178
+ |
179
+ | perhaps you do not understand
180
+ | - third.question => :symbol
181
+ |
182
+ OUTPUT
183
+ @help.show :values => true
184
+ @sio.to_s.should be == str.gutter!
185
+ end
186
+
187
+ it "closely packs attributes when descriptions are omitted" do
188
+ str = <<-OUTPUT
189
+ | - first => "foo"
190
+ | - second => "bar"
191
+ | - third
192
+ | - third.answer => 42
193
+ | - third.question => :symbol
194
+ OUTPUT
195
+ @help.show_all :values => true, :descriptions => false
196
+ @sio.to_s.should be == str.gutter!
197
+ end
198
+
199
+ it "automatically picks up changes to the configuration" do
200
+ Loquacious.configuration_for('specs') do
201
+ fifth 'foo', :desc => 'the fifth configuration setting'
202
+ end
203
+
204
+ str = <<-OUTPUT
205
+ | the fifth configuration setting
206
+ | - fifth
207
+ |
208
+ OUTPUT
209
+ @help.show_attribute 'fifth'
210
+ @sio.to_s.should be == str.gutter!
211
+ end
212
+
213
+ it "uses a custom name leader" do
214
+ help = Loquacious.help_for 'specs', :io => @sio, :name_leader => ' ## '
215
+ str = <<-OUTPUT
216
+ | foo method
217
+ | ## first
218
+ |
219
+ | bar method
220
+ | ## second
221
+ |
222
+ | the third group
223
+ | ## third
224
+ |
225
+ | life the universe and everything
226
+ | ## third.answer
227
+ |
228
+ | perhaps you do not understand
229
+ | ## third.question
230
+ |
231
+ OUTPUT
232
+ help.show_all
233
+ @sio.to_s.should be == str.gutter!
234
+
235
+ @sio.clear
236
+ str = <<-OUTPUT
237
+ | ## first => "foo"
238
+ | ## second => "bar"
239
+ | ## third
240
+ | ## third.answer => 42
241
+ | ## third.question => :symbol
242
+ OUTPUT
243
+ help.show_all :values => true, :descriptions => false
244
+ @sio.to_s.should be == str.gutter!
245
+ end
246
+
247
+ it "uses a custom name length" do
248
+ help = Loquacious.help_for 'specs', :io => @sio, :name_length => 10
249
+ str = <<-OUTPUT
250
+ | foo method
251
+ | - first
252
+ |
253
+ | bar method
254
+ | - second
255
+ |
256
+ | the third group
257
+ | - third
258
+ |
259
+ | life the universe and everything
260
+ | - thir...wer
261
+ |
262
+ | perhaps you do not understand
263
+ | - thir...ion
264
+ |
265
+ OUTPUT
266
+ help.show_all
267
+ @sio.to_s.should be == str.gutter!
268
+
269
+ @sio.clear
270
+ str = <<-OUTPUT
271
+ | - first => "foo"
272
+ | - second => "bar"
273
+ | - third
274
+ | - thir...wer => 42
275
+ | - thir...ion => :symbol
276
+ OUTPUT
277
+ help.show_all :values => true, :descriptions => false
278
+ @sio.to_s.should be == str.gutter!
279
+ end
280
+
281
+ it "uses a custom name/value separator" do
282
+ help = Loquacious.help_for 'specs', :io => @sio, :name_value_sep => ' :: '
283
+ str = <<-OUTPUT
284
+ | foo method
285
+ | - first :: "foo"
286
+ |
287
+ | bar method
288
+ | - second :: "bar"
289
+ |
290
+ | the third group
291
+ | - third
292
+ |
293
+ | life the universe and everything
294
+ | - third.answer :: 42
295
+ |
296
+ | perhaps you do not understand
297
+ | - third.question :: :symbol
298
+ |
299
+ OUTPUT
300
+ help.show_all :values => true
301
+ @sio.to_s.should be == str.gutter!
302
+
303
+ @sio.clear
304
+ str = <<-OUTPUT
305
+ | - first :: "foo"
306
+ | - second :: "bar"
307
+ | - third
308
+ | - third.answer :: 42
309
+ | - third.question :: :symbol
310
+ OUTPUT
311
+ help.show_all :values => true, :descriptions => false
312
+ @sio.to_s.should be == str.gutter!
313
+ end
314
+
315
+ it "uses a custom description leader" do
316
+ Loquacious.configuration_for('specs') do
317
+ desc <<-DESC
318
+ This is a multiline description that has an example.
319
+ |
320
+ | foo = %w[one two three]
321
+ |
322
+ See, the example is right above this line.
323
+ Hope it was instructive.
324
+ DESC
325
+ fourth 'the fourth value'
326
+ end
327
+
328
+ help = Loquacious.help_for 'specs', :io => @sio, :desc_leader => '~'
329
+ str = <<-OUTPUT
330
+ |~foo method
331
+ | - first => "foo"
332
+ |
333
+ |~This is a multiline description that has an example.
334
+ |~
335
+ |~ foo = %w[one two three]
336
+ |~
337
+ |~See, the example is right above this line.
338
+ |~Hope it was instructive.
339
+ | - fourth => "the fourth value"
340
+ |
341
+ |~bar method
342
+ | - second => "bar"
343
+ |
344
+ |~the third group
345
+ | - third
346
+ |
347
+ |~life the universe and everything
348
+ | - third.answer => 42
349
+ |
350
+ |~perhaps you do not understand
351
+ | - third.question => :symbol
352
+ |
353
+ OUTPUT
354
+ help.show_all :values => true
355
+ @sio.to_s.should be == str.gutter!
356
+
357
+ end
358
+ it "prints out a specific attribute" do
359
+ Loquacious.env_config = true
360
+ str = <<-OUTPUT
361
+ | bar method [LOQ_SPECS_SECOND]
362
+ | - second
363
+ |
364
+ OUTPUT
365
+ @help.show_attribute :second
366
+ @sio.to_s.should be == str.gutter!
367
+ Loquacious.env_config = false
368
+ end
369
+ end
@@ -0,0 +1,70 @@
1
+
2
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
3
+
4
+ describe Loquacious::Configuration::Iterator do
5
+
6
+ before(:each) do
7
+ @config = Loquacious.configuration_for 'specs'
8
+ @iterator = Loquacious::Configuration::Iterator.new(@config)
9
+ end
10
+
11
+ it 'should find a particular attribute' do
12
+ node = @iterator.find 'first'
13
+ node.name.should be == 'first'
14
+ node.key.should be == :first
15
+ node.desc.should be == 'foo method'
16
+ node.obj.should be == 'foo'
17
+ node.config?.should be == false
18
+
19
+ node = @iterator.find :third
20
+ node.name.should be == 'third'
21
+ node.key.should be == :third
22
+ node.desc.should be == 'the third group'
23
+ node.config?.should be == true
24
+
25
+ node = @iterator.find('third.answer')
26
+ node.name.should be == 'third.answer'
27
+ node.key.should be == :answer
28
+ node.desc.should be == 'life the universe and everything'
29
+ node.obj.should be == 42
30
+ node.config?.should be == false
31
+ end
32
+
33
+ it 'should return nil for unknown attributes' do
34
+ @iterator.find('last').should be_nil
35
+ @iterator.find('last.first.none').should be_nil
36
+ @iterator.find('third.none').should be_nil
37
+ @iterator.find(:foo).should be_nil
38
+ end
39
+
40
+ it 'should iterate over all attributes' do
41
+ ary = Array.new
42
+ @iterator.each {|n| ary << n.name}
43
+
44
+ ary.should be == %w{first second third third.answer third.question}
45
+ end
46
+
47
+ it 'should iterate over nested attributes if given' do
48
+ ary = Array.new
49
+ @iterator.each('third') {|n| ary << n.name}
50
+ ary.should be == %w{third third.answer third.question}
51
+
52
+ ary.clear
53
+ @iterator.each('first') {|n| ary << n.name}
54
+ ary.should be == %w{first}
55
+
56
+ ary.clear
57
+ @iterator.each('not_here') {|n| ary << n.name}
58
+ ary.should be_empty
59
+ end
60
+
61
+ it 'should ignore undefined nodes' do
62
+ @config.does_not_exist.foo # this creates a Loquacious::Undefined node
63
+ @config.does_not_exist.kind_of?(::Loquacious::Undefined).should be_true
64
+
65
+ ary = Array.new
66
+ @iterator.each {|n| ary << n.name}
67
+ ary.should be == %w{first second third third.answer third.question}
68
+ end
69
+ end
70
+ # EOF
@@ -0,0 +1,76 @@
1
+
2
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
3
+
4
+ describe Loquacious do
5
+ before(:all) do
6
+ @root_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
7
+ end
8
+
9
+ it "should report a version number" do
10
+ Loquacious.version.should match(%r/\d+\.\d+\.\d+/)
11
+ end
12
+
13
+ it "finds things releative to 'lib'" do
14
+ Loquacious.libpath(%w[loquacious config.rb]).should be == File.join(@root_dir, %w[lib loquacious config.rb])
15
+ end
16
+
17
+ it "finds things releative to 'root'" do
18
+ Loquacious.path('Rakefile').should be == File.join(@root_dir, 'Rakefile')
19
+ end
20
+
21
+ describe "when copying configuration objects" do
22
+ it "creates a deep copy" do
23
+ obj = Loquacious::Configuration.new {
24
+ first 'foo'
25
+ second {
26
+ bar 'baz'
27
+ }
28
+ }
29
+
30
+ copy = Loquacious.copy obj
31
+ copy.first = 'foobar'
32
+ copy.second.bar = 'buz'
33
+
34
+ obj.first.eql?('foo').should be_true
35
+ obj.second.bar.eql?('baz').should be_true
36
+ copy.first.eql?('foobar').should be_true
37
+ copy.second.bar.eql?('buz').should be_true
38
+ end
39
+
40
+ it "looks up a configuration object by name" do
41
+ Loquacious.config_for('by name') {
42
+ first 'foo'
43
+ second {
44
+ bar 'baz'
45
+ }
46
+ }
47
+
48
+ copy = Loquacious.copy('by name')
49
+ copy.first.eql?('foo').should be_true
50
+ copy.second.bar.eql?('baz').should be_true
51
+ end
52
+
53
+ it "returns nil when a configuration object cannot be found" do
54
+ Loquacious.copy('does not exist').eql?(nil).should be_true
55
+ end
56
+
57
+ it "overrides options with a block" do
58
+ Loquacious.config_for('another by name') {
59
+ first 'foo'
60
+ second {
61
+ bar 'baz'
62
+ }
63
+ }
64
+
65
+ copy = Loquacious.copy('another by name') {
66
+ second { bar 'foobar' }
67
+ third "hey I'm new"
68
+ }
69
+
70
+ copy.first.eql?('foo').should be_true
71
+ copy.second.bar.eql?('foobar').should be_true
72
+ copy.third.eql?("hey I'm new").should be_true
73
+ end
74
+ end
75
+ end
76
+