ruber 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/COPYING +339 -0
  2. data/INSTALL +137 -0
  3. data/LICENSE +8 -0
  4. data/bin/ruber +65 -0
  5. data/data/share/apps/ruber/core_components.yaml +31 -0
  6. data/data/share/apps/ruber/ruberui.rc +109 -0
  7. data/data/share/icons/ruber.png +0 -0
  8. data/data/share/pixmaps/ruby.png +0 -0
  9. data/icons/ruber-16.png +0 -0
  10. data/icons/ruber-32.png +0 -0
  11. data/icons/ruber-48.png +0 -0
  12. data/icons/ruber-8.png +0 -0
  13. data/lib/ruber/application/application.rb +288 -0
  14. data/lib/ruber/application/plugin.yaml +11 -0
  15. data/lib/ruber/component_manager.rb +899 -0
  16. data/lib/ruber/config/config.rb +82 -0
  17. data/lib/ruber/config/plugin.yaml +3 -0
  18. data/lib/ruber/document_project.rb +209 -0
  19. data/lib/ruber/documents/document_list.rb +416 -0
  20. data/lib/ruber/documents/plugin.yaml +4 -0
  21. data/lib/ruber/editor/document.rb +506 -0
  22. data/lib/ruber/editor/editor_view.rb +167 -0
  23. data/lib/ruber/editor/ktexteditor_wrapper.rb +202 -0
  24. data/lib/ruber/exception_widgets.rb +245 -0
  25. data/lib/ruber/external_program_plugin.rb +397 -0
  26. data/lib/ruber/filtered_output_widget.rb +342 -0
  27. data/lib/ruber/gui_states_handler.rb +231 -0
  28. data/lib/ruber/kde_config_option_backend.rb +167 -0
  29. data/lib/ruber/kde_sugar.rb +249 -0
  30. data/lib/ruber/main_window/choose_plugins_dlg.rb +353 -0
  31. data/lib/ruber/main_window/main_window.rb +524 -0
  32. data/lib/ruber/main_window/main_window_actions.rb +537 -0
  33. data/lib/ruber/main_window/main_window_internal.rb +239 -0
  34. data/lib/ruber/main_window/open_file_in_project_dlg.rb +212 -0
  35. data/lib/ruber/main_window/output_color_widget.rb +35 -0
  36. data/lib/ruber/main_window/plugin.yaml +58 -0
  37. data/lib/ruber/main_window/save_modified_files_dlg.rb +89 -0
  38. data/lib/ruber/main_window/status_bar.rb +156 -0
  39. data/lib/ruber/main_window/ui/choose_plugins_widget.rb +90 -0
  40. data/lib/ruber/main_window/ui/choose_plugins_widget.ui +77 -0
  41. data/lib/ruber/main_window/ui/main_window_settings_widget.rb +108 -0
  42. data/lib/ruber/main_window/ui/main_window_settings_widget.ui +89 -0
  43. data/lib/ruber/main_window/ui/new_project_widget.rb +119 -0
  44. data/lib/ruber/main_window/ui/new_project_widget.ui +178 -0
  45. data/lib/ruber/main_window/ui/open_file_in_project_dlg.rb +109 -0
  46. data/lib/ruber/main_window/ui/open_file_in_project_dlg.ui +168 -0
  47. data/lib/ruber/main_window/ui/output_color_widget.rb +241 -0
  48. data/lib/ruber/main_window/ui/output_color_widget.ui +204 -0
  49. data/lib/ruber/main_window/workspace.rb +442 -0
  50. data/lib/ruber/output_widget.rb +1093 -0
  51. data/lib/ruber/plugin.rb +264 -0
  52. data/lib/ruber/plugin_like.rb +589 -0
  53. data/lib/ruber/plugin_specification.rb +106 -0
  54. data/lib/ruber/plugin_specification_reader.rb +451 -0
  55. data/lib/ruber/project.rb +493 -0
  56. data/lib/ruber/project_backend.rb +105 -0
  57. data/lib/ruber/projects/plugin.yaml +11 -0
  58. data/lib/ruber/projects/project_files_list.rb +314 -0
  59. data/lib/ruber/projects/project_files_widget.rb +301 -0
  60. data/lib/ruber/projects/project_list.rb +314 -0
  61. data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +74 -0
  62. data/lib/ruber/projects/ui/project_files_rule_chooser_widget.ui +61 -0
  63. data/lib/ruber/projects/ui/project_files_widget.rb +117 -0
  64. data/lib/ruber/projects/ui/project_files_widget.ui +123 -0
  65. data/lib/ruber/qt_sugar.rb +673 -0
  66. data/lib/ruber/settings_container.rb +515 -0
  67. data/lib/ruber/settings_dialog.rb +244 -0
  68. data/lib/ruber/settings_dialog_manager.rb +503 -0
  69. data/lib/ruber/utils.rb +414 -0
  70. data/lib/ruber/yaml_option_backend.rb +159 -0
  71. data/outsider_files +15 -0
  72. data/plugins/autosave/autosave.rb +404 -0
  73. data/plugins/autosave/plugin.yaml +16 -0
  74. data/plugins/autosave/ui/autosave_config_widget.rb +83 -0
  75. data/plugins/autosave/ui/autosave_config_widget.ui +68 -0
  76. data/plugins/command/command.png +0 -0
  77. data/plugins/command/command.rb +74 -0
  78. data/plugins/command/plugin.yaml +11 -0
  79. data/plugins/find_in_files/find_in_files.rb +337 -0
  80. data/plugins/find_in_files/find_in_files_dlg.rb +411 -0
  81. data/plugins/find_in_files/find_in_files_ui.rc +11 -0
  82. data/plugins/find_in_files/find_in_files_widgets.rb +485 -0
  83. data/plugins/find_in_files/plugin.yaml +23 -0
  84. data/plugins/find_in_files/ui/config_widget.rb +58 -0
  85. data/plugins/find_in_files/ui/config_widget.ui +41 -0
  86. data/plugins/find_in_files/ui/find_in_files_widget.rb +260 -0
  87. data/plugins/find_in_files/ui/find_in_files_widget.ui +324 -0
  88. data/plugins/project_browser/plugin.yaml +10 -0
  89. data/plugins/project_browser/project_browser.rb +245 -0
  90. data/plugins/rake/plugin.yaml +39 -0
  91. data/plugins/rake/rake.png +0 -0
  92. data/plugins/rake/rake.rb +567 -0
  93. data/plugins/rake/rake_extension.rb +153 -0
  94. data/plugins/rake/rake_widgets.rb +615 -0
  95. data/plugins/rake/rakeui.rc +27 -0
  96. data/plugins/rake/ui/add_quick_task_widget.rb +71 -0
  97. data/plugins/rake/ui/add_quick_task_widget.ui +59 -0
  98. data/plugins/rake/ui/choose_task_widget.rb +77 -0
  99. data/plugins/rake/ui/choose_task_widget.ui +72 -0
  100. data/plugins/rake/ui/config_widget.rb +127 -0
  101. data/plugins/rake/ui/config_widget.ui +123 -0
  102. data/plugins/rake/ui/project_widget.rb +217 -0
  103. data/plugins/rake/ui/project_widget.ui +246 -0
  104. data/plugins/rspec/plugin.yaml +30 -0
  105. data/plugins/rspec/rspec.png +0 -0
  106. data/plugins/rspec/rspec.rb +945 -0
  107. data/plugins/rspec/rspec.svg +90 -0
  108. data/plugins/rspec/rspecui.rc +20 -0
  109. data/plugins/rspec/ruber_rspec_formatter.rb +312 -0
  110. data/plugins/rspec/ui/rspec_project_widget.rb +170 -0
  111. data/plugins/rspec/ui/rspec_project_widget.ui +193 -0
  112. data/plugins/ruby_development/plugin.yaml +27 -0
  113. data/plugins/ruby_development/ruby_development.png +0 -0
  114. data/plugins/ruby_development/ruby_development.rb +453 -0
  115. data/plugins/ruby_development/ruby_developmentui.rc +19 -0
  116. data/plugins/ruby_development/ui/project_widget.rb +112 -0
  117. data/plugins/ruby_development/ui/project_widget.ui +108 -0
  118. data/plugins/ruby_runner/config_widget.rb +116 -0
  119. data/plugins/ruby_runner/plugin.yaml +26 -0
  120. data/plugins/ruby_runner/project_widget.rb +62 -0
  121. data/plugins/ruby_runner/ruby.png +0 -0
  122. data/plugins/ruby_runner/ruby_interpretersui.rc +26 -0
  123. data/plugins/ruby_runner/ruby_runner.rb +411 -0
  124. data/plugins/ruby_runner/ui/config_widget.rb +92 -0
  125. data/plugins/ruby_runner/ui/config_widget.ui +91 -0
  126. data/plugins/ruby_runner/ui/project_widget.rb +60 -0
  127. data/plugins/ruby_runner/ui/project_widget.ui +48 -0
  128. data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.rb +59 -0
  129. data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.ui +44 -0
  130. data/plugins/state/plugin.yaml +28 -0
  131. data/plugins/state/state.rb +520 -0
  132. data/plugins/state/ui/config_widget.rb +92 -0
  133. data/plugins/state/ui/config_widget.ui +89 -0
  134. data/plugins/syntax_checker/plugin.yaml +18 -0
  135. data/plugins/syntax_checker/syntax_checker.rb +662 -0
  136. data/ruber.desktop +10 -0
  137. data/spec/annotation_model_spec.rb +174 -0
  138. data/spec/common.rb +119 -0
  139. data/spec/component_manager_spec.rb +1259 -0
  140. data/spec/document_list_spec.rb +626 -0
  141. data/spec/document_project_spec.rb +373 -0
  142. data/spec/document_spec.rb +779 -0
  143. data/spec/editor_view_spec.rb +167 -0
  144. data/spec/external_program_plugin_spec.rb +676 -0
  145. data/spec/filtered_output_widget_spec.rb +642 -0
  146. data/spec/gui_states_handler_spec.rb +304 -0
  147. data/spec/kde_config_option_backend_spec.rb +214 -0
  148. data/spec/kde_sugar_spec.rb +101 -0
  149. data/spec/ktexteditor_wrapper_spec.rb +305 -0
  150. data/spec/output_widget_spec.rb +1703 -0
  151. data/spec/plugin_spec.rb +1393 -0
  152. data/spec/plugin_specification_reader_spec.rb +1765 -0
  153. data/spec/plugin_specification_spec.rb +401 -0
  154. data/spec/project_backend_spec.rb +172 -0
  155. data/spec/project_files_list_spec.rb +401 -0
  156. data/spec/project_list_spec.rb +511 -0
  157. data/spec/project_spec.rb +990 -0
  158. data/spec/qt_sugar_spec.rb +328 -0
  159. data/spec/settings_container_spec.rb +617 -0
  160. data/spec/settings_dialog_manager_spec.rb +773 -0
  161. data/spec/settings_dialog_spec.rb +419 -0
  162. data/spec/state_spec.rb +991 -0
  163. data/spec/utils_spec.rb +406 -0
  164. data/spec/workspace_spec.rb +869 -0
  165. data/spec/yaml_option_backend_spec.rb +246 -0
  166. metadata +284 -0
@@ -0,0 +1,1765 @@
1
+ require 'spec/common'
2
+ require 'facets/random'
3
+
4
+ require 'ruber/plugin_specification_reader'
5
+ require 'ruber/plugin_specification'
6
+ require 'ruber/plugin'
7
+
8
+ module PluginSpecificationReaderSpec
9
+ class C
10
+ end
11
+
12
+ end
13
+
14
+ module Ruber
15
+
16
+ describe PluginSpecificationReader do
17
+
18
+ def random_string len
19
+ a = ('a'..'z').to_a
20
+ len.times.map{a.at_rand}.join
21
+ end
22
+
23
+ describe '#process_pdf' do
24
+ names = %w[
25
+ name version about features deps runtime_deps ui_file tool_widgets config_widgets config_options project_options project_widgets extensions actions
26
+ ]
27
+ names.insert names.index('ui_file'), ['required', 'required', ['a', 'b']]
28
+ names.insert names.index('ui_file'), %w[class class_obj]
29
+
30
+ before do
31
+ @info = OpenStruct.new
32
+ @reader = Ruber::PluginSpecificationReader.new @info
33
+ @info.directory = ''
34
+ flexmock(@reader).should_receive(:require).by_default
35
+ names.each do |n|
36
+ entry, _, value = n.is_a?(Array) ? n : [n, n]
37
+ flexmock(@reader).should_receive("read_#{entry}").by_default.and_return(value || '')
38
+ end
39
+ end
40
+
41
+ names.each do |n|
42
+ entry, attr, value = n.is_a?(Array) ? n : [n, n]
43
+ it "should return an object whose #{attr} method returns the value returned by calling the read_#{entry} method" do
44
+ name = random_string 5
45
+ value ||= random_string 10
46
+ arg = {:name => name}
47
+ flexmock(@reader).should_receive("read_#{entry}").once.with({:name => name}).and_return value
48
+ @reader.process_pdf(arg).send(attr).should == value
49
+ end
50
+ end
51
+
52
+ it 'should accept a hash and return the related PluginSpecification' do
53
+ @reader.process_pdf({}).should eql(@info)
54
+ end
55
+
56
+ it 'should require all files obtained by joining the PluginSpecification\'s directory with the files returned by the read_required method, before calling the read_required method' do
57
+ @info.directory = '/xyz'
58
+ flexmock(@reader).should_receive(:read_required).and_return %w[a b]
59
+ flexmock(@reader).should_receive(:require).globally.ordered.once.with '/xyz/a'
60
+ flexmock(@reader).should_receive(:require).globally.ordered.once.with '/xyz/b'
61
+ flexmock(@reader).should_receive(:read_ui_file).globally.ordered.once.and_return 'testui.rc'
62
+ @reader.process_pdf({})
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ describe 'Ruber::PluginSpecificationReader#process_pdf_intro' do
72
+
73
+ before do
74
+ @info = OpenStruct.new
75
+ @reader = Ruber::PluginSpecificationReader.new @info
76
+ flexmock(@reader).should_receive(:read_name).by_default.and_return(:x)
77
+ flexmock(@reader).should_receive(:read_about).by_default.and_return(OpenStruct.new)
78
+ flexmock(@reader).should_receive(:read_version).by_default.and_return('0.0.1')
79
+ flexmock(@reader).should_receive(:read_required).by_default.and_return(['test_file'])
80
+ flexmock(@reader).should_receive(:read_features).by_default.and_return([:p1])
81
+ flexmock(@reader).should_receive(:read_deps).by_default.and_return([])
82
+ flexmock(@reader).should_receive(:read_runtime_deps).by_default.and_return([])
83
+ end
84
+
85
+ it 'should store the value returned by calling the read_name method with both arguments in the result under the :name key' do
86
+ hash = {}
87
+ flexmock(@reader).should_receive(:read_name).once.with(hash, false).and_return(:x)
88
+ res = @reader.process_pdf_intro({})
89
+ res.name.should == :x
90
+
91
+ flexmock(@reader).should_receive(:read_name).once.with(hash, true).and_return(:x)
92
+ res = @reader.process_pdf_intro({}, true)
93
+ res.name.should == :x
94
+ end
95
+
96
+ it 'should store the value returned by the read_about method under the about key' do
97
+ hash = {:name => :x, :human_name => 'Y'}
98
+ exp = OpenStruct.new({:human_name => 'Y'})
99
+ flexmock(@reader).should_receive(:read_about).once.with(hash).and_return(exp)
100
+ res = @reader.process_pdf_intro(hash)
101
+ res.about.should == exp
102
+ end
103
+
104
+ it 'should store the value returned by the read_version method under the version key' do
105
+ hash = {:name => :x, :version => '1.2.3'}
106
+ flexmock(@reader).should_receive(:read_version).once.with(hash).and_return('1.2.3')
107
+ res = @reader.process_pdf_intro(hash)
108
+ res.version.should == '1.2.3'
109
+ end
110
+
111
+ it 'should store the value returned by the read_required method in the result under the :required key' do
112
+ hash = {}
113
+ flexmock(@reader).should_receive(:read_required).once.with(hash).and_return(%w[f1 f2])
114
+ res = @reader.process_pdf_intro hash
115
+ @info.required.should == %w[f1 f2]
116
+ res.required.should == %w[f1 f2]
117
+ end
118
+
119
+ it 'should store the value returned by the read_features method in the result under the :features key' do
120
+ hash = {}
121
+ flexmock(@reader).should_receive(:read_features).once.with(hash).and_return(%w[f1 f2])
122
+ res = @reader.process_pdf_intro hash
123
+ @info.features.should == %w[f1 f2]
124
+ res.features.should == %w[f1 f2]
125
+ end
126
+
127
+ it 'should store the value returned by the read_deps method in the result under the :deps key' do
128
+ hash = {}
129
+ flexmock(@reader).should_receive(:read_deps).once.with(hash).and_return([:p1, :p2])
130
+ res = @reader.process_pdf_intro hash
131
+ @info.deps.should == [:p1, :p2]
132
+ res.deps.should == [:p1, :p2]
133
+ end
134
+
135
+ it 'should store the value returned by the read_runtime_deps method in the result under the :runtime_deps key' do
136
+ hash = {}
137
+ flexmock(@reader).should_receive(:read_runtime_deps).once.with(hash).and_return([:p1, :p2])
138
+ res = @reader.process_pdf_intro hash
139
+ @info.runtime_deps.should == [:p1, :p2]
140
+ res.runtime_deps.should == [:p1, :p2]
141
+ end
142
+
143
+ it 'should not call the read_class method' do
144
+ flexmock(@reader).should_receive(:read_class).never
145
+ @reader.process_pdf_intro({})
146
+ end
147
+
148
+ it 'should not call the read_ui_file method' do
149
+ flexmock(@reader).should_receive(:read_ui_file).never
150
+ @reader.process_pdf_intro({})
151
+ end
152
+
153
+ it 'should not call the read_tool_widgets method' do
154
+ flexmock(@reader).should_receive(:read_tool_widgets).never
155
+ @reader.process_pdf_intro({})
156
+ end
157
+
158
+ it 'should not call the read_config_widgets method' do
159
+ flexmock(@reader).should_receive(:read_config_widgets).never
160
+ @reader.process_pdf_intro({})
161
+ end
162
+
163
+ it 'should not call the read_config_options method' do
164
+ flexmock(@reader).should_receive(:read_config_options).never
165
+ @reader.process_pdf_intro({})
166
+ end
167
+
168
+ it 'should not call the read_project_options method' do
169
+ flexmock(@reader).should_receive(:read_project_options).never
170
+ @reader.process_pdf_intro({})
171
+ end
172
+
173
+ it 'should not call the read_project_widgets method' do
174
+ flexmock(@reader).should_receive(:read_project_widgets).never
175
+ @reader.process_pdf_intro({})
176
+ end
177
+
178
+ it 'should not call the read_extensions method' do
179
+ flexmock(@reader).should_receive(:read_extensions).never
180
+ @reader.process_pdf_intro({:name => :x})
181
+ end
182
+
183
+ it 'should not call the read_actions method' do
184
+ flexmock(@reader).should_receive(:read_actions).never
185
+ @reader.process_pdf_intro({})
186
+ end
187
+
188
+
189
+ end
190
+
191
+ describe 'KRuber::PluginSpecificationReader#read_name' do
192
+
193
+ before do
194
+ @info = OpenStruct.new
195
+ @reader = Ruber::PluginSpecificationReader.new @info
196
+ end
197
+
198
+ it 'should convert the :name or "name" entry of the input hash to a symbol and insert it in the returned hash under the :name key' do
199
+ @reader.send(:read_name, {:name => :x}).should == :x
200
+ @reader.send(:read_name, {'name' => :x}).should == :x
201
+ @reader.send(:read_name, {:name => 'x'}).should == :x
202
+ @reader.send(:read_name, {'name' => 'x'}).should == :x
203
+ end
204
+
205
+ it 'should use the :name entry if both the :name and "name" entry exist in the input hash' do
206
+ @reader.send(:read_name, {:name => :x, 'name' => :y}).should == :x
207
+ end
208
+
209
+ it 'should raise Ruber::PluginSpecification::PSFError if a name entry doesn\'t exist in the input hash and the second argument is false' do
210
+ lambda{@reader.send(:read_name, {})}.should raise_error(Ruber::PluginSpecification::PSFError, "The required 'name' entry is missing from the PDF")
211
+ end
212
+
213
+ it 'should return nil if the :name/"name" entry doesn\'t exist in the input hash and the second argument is true' do
214
+ @reader.send(:read_name, {}, true).should be_nil
215
+ end
216
+
217
+ end
218
+
219
+ describe 'KRuber::PluginSpecificationReader#read_description' do
220
+
221
+ before do
222
+ @info = OpenStruct.new
223
+ @reader = Ruber::PluginSpecificationReader.new @info
224
+ end
225
+
226
+ it 'should convert the :description or "description" entry of the input hash to a string and insert it in the returned hash under the :description key' do
227
+ @reader.send(:read_description, {:description => :x}).should == 'x'
228
+ @reader.send(:read_description, {'description' => :x}).should == 'x'
229
+ @reader.send(:read_description, {:description => 'x'}).should == 'x'
230
+ @reader.send(:read_description, {'description' => 'x'}).should == 'x'
231
+ end
232
+
233
+ it 'should use the :description entry if both the :description and "description" entry exist in the input hash' do
234
+ @reader.send(:read_description, {:description => 'x', 'description' => 'y'}).should == 'x'
235
+ end
236
+
237
+ it 'should return an empty string if neither the :description nor the "description" entries exist in the input hash' do
238
+ @reader.send(:read_description, {}).should == ''
239
+ end
240
+
241
+ end
242
+
243
+ describe 'Ruber::PluginSpecificationReader#read_class' do
244
+
245
+ before do
246
+ @info = OpenStruct.new
247
+ @reader = Ruber::PluginSpecificationReader.new @info
248
+ end
249
+
250
+ it 'should return the class corresponding to the :class/"class" entry' do
251
+ @reader.send(:read_class, {:class => 'String'}).should == String
252
+ @reader.send(:read_class, {'class' => :"Ruber::PluginSpecification"}).should == Ruber::PluginSpecification
253
+ end
254
+
255
+ it 'should use the :class entry if both the :class and "class" entry exist in the input hash' do
256
+ @reader.send(:read_class, {:class => String, 'class' => Array}).should == String
257
+ end
258
+
259
+ it 'should return Ruber::Plugin if the :class/"class" entry doesn\'t exist' do
260
+ @reader.send(:read_class, {}, true).should == Ruber::Plugin
261
+ end
262
+
263
+ end
264
+
265
+ describe 'KRuber::PluginSpecificationReader#read_required' do
266
+
267
+ before do
268
+ @info = OpenStruct.new
269
+ @reader = Ruber::PluginSpecificationReader.new @info
270
+ end
271
+
272
+ it 'should return an array containing the value of the :required or "required" entries of the input hash, converted to a string, if any of those entries is a string or a symbol' do
273
+ [{:require => 'test'}, {:require => :test}, {'require' => 'test'}, {'require' => :test}].each do |h|
274
+ @reader.send(:read_required, h).should == ['test']
275
+ end
276
+ end
277
+
278
+ it 'should return an array containing the contents of the array in the :requried or "require" entry of the input hash converted to strings if any of those entries is an array' do
279
+ [{:require => ['test1', :test2]}, {'require' => ['test1', :test2]}].each do |h|
280
+ @reader.send(:read_required, h).should == %w[test1 test2]
281
+ end
282
+ end
283
+
284
+ it 'should use the :require entry if both the :require and "require" entry exist in the input hash' do
285
+ @reader.send(:read_required, {:require => 'f1', 'require' => 'f2'}).should == ['f1']
286
+ end
287
+
288
+ it 'should return an empty array if neither the :require nor the "require" entries exist in the input hash' do
289
+ @reader.send(:read_required, {}).should == []
290
+ end
291
+
292
+ end
293
+
294
+ describe 'KRuber::PluginSpecificationReader#read_features' do
295
+
296
+ before do
297
+ @info = OpenStruct.new
298
+ @reader = Ruber::PluginSpecificationReader.new @info
299
+ end
300
+
301
+ it 'should return an array containing the value of the :features or "features" entries of the input hash, plus the plugin name, converted to a symbol, if any of those entries is a string or a symbol' do
302
+ [{:name => 'x', :features => 'test'}, {:name => 'x', :features => :test}, {:name => 'x', 'features' => 'test'}, {:name => 'x', 'features' => :test}].each do |h|
303
+ @reader.send(:read_features, h).should == [:x, :test]
304
+ end
305
+ end
306
+
307
+ it 'should return an array containing the contents of the array in the :requried or "features" entry of the input hash converted to symbols, plus the plugin name, if any of those entries is an array' do
308
+ [{:name => 'x', :features => ['test1', :test2]}, {:name => 'x', 'features' => ['test1', :test2]}].each do |h|
309
+ @reader.send(:read_features, h).should == [:x, :test1, :test2]
310
+ end
311
+ end
312
+
313
+ it 'should use the :features entry if both the :features and "features" entry exist in the input hash' do
314
+ @reader.send(:read_features, {:name => 'x', :features => 'test1', 'features' => 'test2'}).should == [:x, :test1]
315
+ end
316
+
317
+ it 'should return an array containing only the plugin name (as symbol) if neither the :features nor the "features" entries exist in the input hash' do
318
+ @reader.send(:read_features, {:name => :test}).should == [:test]
319
+ @reader.send(:read_features, {:name => 'test'}).should == [:test]
320
+ end
321
+
322
+ it 'should not attempt to add the plugin name if it isn\'t given' do
323
+ @reader.send(:read_features, {}).should == []
324
+ @reader.send(:read_features, {:features => :test}).should == [:test]
325
+ end
326
+
327
+ end
328
+
329
+ describe 'KRuber::PluginSpecificationReader#read_deps' do
330
+
331
+ before do
332
+ @info = OpenStruct.new
333
+ @reader = Ruber::PluginSpecificationReader.new @info
334
+ end
335
+
336
+ it 'should return an array containing the value of the :deps or "deps" entries of the input hash, converted to a symbol, if any of those entries is a string or a symbol' do
337
+ [{:deps => 'test'}, {:deps => :test}, {'deps' => 'test'}, {'deps' => :test}].each do |h|
338
+ @reader.send(:read_deps, h).should == [:test]
339
+ end
340
+ end
341
+
342
+ it 'should return an array containing the contents of the array in the :requried or "deps" entry of the input hash converted to symbols if any of those entries is an array' do
343
+ [{:deps => ['test1', :test2]}, {'deps' => ['test1', :test2]}].each do |h|
344
+ @reader.send(:read_deps, h).should == [:test1, :test2]
345
+ end
346
+ end
347
+
348
+ it 'should use the :deps entry if both the :deps and "deps" entry exist in the input hash' do
349
+ @reader.send(:read_deps, {:deps => 'test1', 'deps' => 'test2'}).should == [:test1]
350
+ end
351
+
352
+ it 'should return an empty array if neither the :deps nor the "deps" entries exist in the input hash' do
353
+ @reader.send(:read_deps, {}).should == []
354
+ end
355
+
356
+ end
357
+
358
+ describe 'KRuber::PluginSpecificationReader#read_runtime_deps' do
359
+
360
+ before do
361
+ @info = OpenStruct.new
362
+ @reader = Ruber::PluginSpecificationReader.new @info
363
+ end
364
+
365
+ it 'should return an array containing the value of the :runtime_deps or "runtime_deps" entries of the input hash, converted to a symbol, if any of those entries is a string or a symbol' do
366
+ [{:runtime_deps => 'test'}, {:runtime_deps => :test}, {'runtime_deps' => 'test'}, {'runtime_deps' => :test}].each do |h|
367
+ @reader.send(:read_runtime_deps, h).should == [:test]
368
+ end
369
+ end
370
+
371
+ it 'should return an array containing the contents of the array in the :requried or "runtime_deps" entry of the input hash converted to symbols if any of those entries is an array' do
372
+ [{:runtime_deps => ['test1', :test2]}, {'runtime_deps' => ['test1', :test2]}].each do |h|
373
+ @reader.send(:read_runtime_deps, h).should == [:test1, :test2]
374
+ end
375
+ end
376
+
377
+ it 'should use the :runtime_deps entry if both the :runtime_deps and "runtime_deps" entry exist in the input hash' do
378
+ @reader.send(:read_runtime_deps, {:runtime_deps => 'test1', 'runtime_deps' => 'test2'}).should == [:test1]
379
+ end
380
+
381
+ it 'should return an empty array if neither the :runtime_deps nor the "runtime_deps" entries exist in the input hash' do
382
+ @reader.send(:read_runtime_deps, {}).should == []
383
+ end
384
+
385
+ end
386
+
387
+ describe 'KRuber::PluginSpecificationReader#read_ui_file' do
388
+
389
+ before do
390
+ @info = OpenStruct.new
391
+ @reader = Ruber::PluginSpecificationReader.new @info
392
+ end
393
+
394
+ it 'should convert the :ui_file or "ui_file" entry of the input hash to a string and insert it in the returned hash under the :ui_file key' do
395
+ @reader.send(:read_ui_file, {:ui_file => :x}).should == 'x'
396
+ @reader.send(:read_ui_file, {'ui_file' => :x}).should == 'x'
397
+ @reader.send(:read_ui_file, {:ui_file => 'x'}).should == 'x'
398
+ @reader.send(:read_ui_file, {'ui_file' => 'x'}).should == 'x'
399
+ end
400
+
401
+ it 'should use the :ui_file entry if both the :ui_file and "ui_file" entry exist in the input hash' do
402
+ @reader.send(:read_ui_file, {:ui_file => 'x', 'ui_file' => 'y'}).should == 'x'
403
+ end
404
+
405
+ it 'should return an empty string if neither the :ui_file nor the "ui_file" entries exist in the input hash' do
406
+ @reader.send(:read_ui_file, {}).should == ''
407
+ end
408
+
409
+ end
410
+
411
+ describe 'KRuber::PluginSpecificationReader#read_widget' do
412
+
413
+ before do
414
+ @info = OpenStruct.new({:directory => '/dir', :about => OpenStruct.new(:icon => '')})
415
+ @reader = Ruber::PluginSpecificationReader.new @info
416
+ end
417
+
418
+ it 'should return an OpenStruct with the contents of the :caption or "caption" entry of the input hash under the :caption key' do
419
+ res = @reader.send(:read_widget, {:caption =>"caption", :class => 'Array'})
420
+ res.caption.should == "caption"
421
+ res.caption.should == "caption"
422
+ res = @reader.send(:read_widget, {'caption' =>"caption", :class => 'Hash'})
423
+ res.caption.should == "caption"
424
+ res.caption.should == "caption"
425
+ end
426
+
427
+ it 'should return an OpenStruct with the contents of the :pixmap or "pixmap" entry of the input hash, prepended with the plugin directory, under the :pixmap key if the entry is an existing file' do
428
+ flexmock(KDE::Application).should_receive(:instance).and_return true
429
+ flexmock(File).should_receive(:exist?).with("/dir/pixmap").and_return true
430
+ res = @reader.send(:read_widget, {:pixmap =>"pixmap", :class => 'Array'})
431
+ res.pixmap.should == '/dir/pixmap'
432
+ res = @reader.send(:read_widget, {'pixmap' =>"pixmap", :class => 'Array'})
433
+ res.pixmap.should == '/dir/pixmap'
434
+ end
435
+
436
+ it 'should return an OpenStruct with the string obtained passing the contents of the :pixmap/"pixmap" entry of the input hash to KDE::IconLoader.pixmap_path as :pixmap entry if the entry is not an existing file' do
437
+ flexmock(KDE::Application).should_receive(:instance).and_return true
438
+ flexmock(KDE::IconLoader).should_receive(:pixmap_path).with( 'pixmap').twice.and_return '/usr/pixmap'
439
+ res = @reader.send(:read_widget, {:pixmap =>"pixmap", :class => 'Array'})
440
+ res.pixmap.should == '/usr/pixmap'
441
+ res = @reader.send(:read_widget, {'pixmap' =>"pixmap", :class => 'Array'})
442
+ res.pixmap.should == '/usr/pixmap'
443
+ end
444
+
445
+ it 'should return an OpenStruct with the contents of the :pixmap or "pixmap" entry of the input hash, prepended with the plugin directory, under the :pixmap key if the application doesn\'t exist, even if the file doesn\'t exist' do
446
+ flexmock(KDE::Application).should_receive(:instance).and_return(nil)
447
+ flexmock(File).should_receive(:exist?).with("/dir/pixmap").and_return false
448
+ flexmock(KDE::IconLoader).should_receive(:pixmap_path).with( 'pixmap').never
449
+ res = @reader.send(:read_widget, {:pixmap =>"pixmap", :class => 'Array'})
450
+ res.pixmap.should == '/dir/pixmap'
451
+ res = @reader.send(:read_widget, {'pixmap' =>"pixmap", :class => 'Array'})
452
+ res.pixmap.should == '/dir/pixmap'
453
+ end
454
+
455
+ it 'should return an OpenStruct with an empty string as pixmap entry if the :pixmap/"pixmap" entry of the input hash is not an existing file and KDE::IconLoader can\'t find an icon with that name' do
456
+ flexmock(KDE::IconLoader).should_receive(:pixmap_path).twice.and_return ''
457
+ flexmock(KDE::Application).should_receive(:instance).and_return(true)
458
+ res = @reader.send(:read_widget, {:pixmap =>"pixmap", :class => 'Array'})
459
+ res.pixmap.should == ''
460
+ res = @reader.send(:read_widget, {'pixmap' =>"pixmap", :class => 'Array'})
461
+ res.pixmap.should == ''
462
+ end
463
+
464
+ it 'should return an OpenStruct with the contents of the :class or "class" entry of the input hash under the :class_obj key' do
465
+ res = @reader.send(:read_widget, {:class => 'Array'})
466
+ res.class_obj.should == Array
467
+ res.class_obj.should == Array
468
+ res = @reader.send(:read_widget, {'class' => 'Array'})
469
+ res.class_obj.should == Array
470
+ res.class_obj.should == Array
471
+ end
472
+
473
+ it 'should return an OpenStruct with the contents of the :code or "code" entry of the input hash under the :code key' do
474
+ res = @reader.send(:read_widget, {:code =>"C.new"})
475
+ res.code.should == "C.new"
476
+ res.code.should == "C.new"
477
+ res = @reader.send(:read_widget, {'code' =>"C.new"})
478
+ res.code.should == "C.new"
479
+ res.code.should == "C.new"
480
+ end
481
+
482
+ it 'should raise Ruber::PluginSpecification::PSFError if both the :code/"code" and the :class/"class" entries are specified in the input hash' do
483
+ lambda{@reader.send(:read_widget, {:code => "Cls.new", :class => 'Array'})}.should raise_error(Ruber::PluginSpecification::PSFError, "A widget description can't contain both the :class and the :code entries")
484
+ lambda{@reader.send(:read_widget, {'code' => "Cls.new", :class => 'Array'})}.should raise_error(Ruber::PluginSpecification::PSFError, "A widget description can't contain both the :class and the :code entries")
485
+ lambda{@reader.send(:read_widget, {:code => "Cls.new", 'class' => 'Array'})}.should raise_error(Ruber::PluginSpecification::PSFError, "A widget description can't contain both the :class and the :code entries")
486
+ lambda{@reader.send(:read_widget, {'code' => "Cls.new", 'class' => 'Array'})}.should raise_error(Ruber::PluginSpecification::PSFError, "A widget description can't contain both the :class and the :code entries")
487
+ end
488
+
489
+ it 'should raise Ruber::PluginSpecification::PSFError if neither the :class/"class" nor the :code/"code" entries exist in the input hash' do
490
+ lambda{@reader.send(:read_widget, {})}.should raise_error(Ruber::PluginSpecification::PSFError, "Either the :class or the :code entry must be present in the widget description")
491
+ end
492
+
493
+ it 'should raise Ruber::PluginSpecification::PSFError if the second argument includes :caption and the :caption/"caption" entry doesn\'t exist in the input hash' do
494
+ lambda{@reader.send(:read_widget, {:class => 'Array'}, [:caption])}.should raise_error(Ruber::PluginSpecification::PSFError, "The :caption entry must be present in the widget description")
495
+ end
496
+
497
+ it 'should use "" as caption if the :caption/"caption" is not included in the input hash' do
498
+ @reader.send(:read_widget, {:class => 'Array'}).caption.should == ''
499
+ end
500
+
501
+ it 'should use the plugin icon if the pixmap entry doesn\'t exist' do
502
+ @info.about.icon = '/usr/test.png'
503
+ @reader.send(:read_widget, {:class => 'Array'}).pixmap.should == '/usr/test.png'
504
+ end
505
+
506
+ it 'should raise Ruber::PluginSpecification::PSFError if the second argument includes :pixmap, the pixmap entry doesn\'t exist in the input hash and the plugin icon is empty' do
507
+ @info.about.icon = ''
508
+ lambda{@reader.send(:read_widget, {:class => 'Array'}, [:pixmap])}.should raise_error(Ruber::PluginSpecification::PSFError, "The :pixmap entry must be present in the widget description")
509
+ end
510
+
511
+ end
512
+
513
+ describe 'KRuber::PluginSpecificationReader#read_tool_widgets' do
514
+
515
+ before do
516
+ @info = OpenStruct.new({:directory => '/dir'})
517
+ @reader = Ruber::PluginSpecificationReader.new @info
518
+ end
519
+
520
+ it 'should pass the :tool_widgets/"tool_widgets" entry to the read_widget method and return an array containing the returned value if the :tool_widgets/"tool_widgets" entry is an hash' do
521
+ widget_hashes = [
522
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :position => :bottom},
523
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', 'position' => :bottom},
524
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', 'position' => :bottom},
525
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :position => 'bottom'}
526
+ ]
527
+ widget_hashes.each do |h|
528
+ exp = {:class => Array, :pixmap => 'pix', :caption => 'caption'}
529
+ ost = OpenStruct.new( exp)
530
+ flexmock(@reader).should_receive(:read_widget).once.with(h, Array).and_return( ost )
531
+ res = @reader.send(:read_tool_widgets, {:tool_widgets => h})
532
+ res.should be_instance_of(Array)
533
+ res.size.should == 1
534
+ res[0].should eql(ost)
535
+ end
536
+ end
537
+
538
+ it 'should pass each item in the :tool_widgets or "tool_widgets" entry to the read_widget method and return an array of the returned values if the :tool_widgets/"tool_widgets" entry is an array' do
539
+ widget_hashes = [
540
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :position => :bottom},
541
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', 'position' => :bottom},
542
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', 'position' => :bottom},
543
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :position => 'bottom'}
544
+ ]
545
+ widget_hashes.each do |h|
546
+ exp = {:class => Array, :pixmap => 'pix', :caption => 'caption'}
547
+ ost = OpenStruct.new( exp)
548
+ flexmock(@reader).should_receive(:read_widget).twice.with(h, Array).and_return( ost )
549
+ res = @reader.send(:read_tool_widgets, {:tool_widgets => [h, h]})
550
+ res.should be_instance_of(Array)
551
+ res.size.should == 2
552
+ res[0].should eql(ost)
553
+ res[1].should eql(ost)
554
+ end
555
+ end
556
+
557
+ it 'should add the value of the :position/"position" entry of the original hash, converted to a symbol, to the values returned by the read_widget method, under the :position key' do
558
+ widget_hashes = [
559
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :position => :top},
560
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', 'position' => :left},
561
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', 'position' => :right},
562
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :position => 'bottom'}
563
+ ]
564
+ widget_hashes.each do |h|
565
+ exp = {:class => 'Array', :pixmap => 'pix', :caption => 'caption'}
566
+ flexmock(@reader).should_receive(:read_widget).twice.with(h, Array).and_return( OpenStruct.new(exp) )
567
+ @reader.send(:read_tool_widgets, {:tool_widgets => [h, h]}).each do |w|
568
+ w.position.should == (h[:position]||h["position"]).to_sym
569
+ end
570
+ end
571
+ end
572
+
573
+ it 'should add the value of the :name/"name" entry of the original hash, converted to a string, to the values returned by the read_widget method, under the :name key' do
574
+ widget_hashes = [
575
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :name => :w},
576
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', 'name' => :w},
577
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', 'name' => :w},
578
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :name=> 'w'}
579
+ ]
580
+ widget_hashes.each do |h|
581
+ exp = {:class => 'Array', :pixmap => 'pix', :caption => 'caption'}
582
+ flexmock(@reader).should_receive(:read_widget).twice.with(h, Array).and_return( OpenStruct.new(exp) )
583
+ @reader.send(:read_tool_widgets, {:tool_widgets => [h, h]}).each do |w|
584
+ w.name.should == (h[:name]||h["name"]).to_s
585
+ end
586
+ end
587
+ end
588
+
589
+ it 'should add the value of the :variable_name/"variable_name" entry of the original hash, converted to a string, to the values returned by the read_widget method, under the :var_name key' do
590
+ widget_hashes = [
591
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :var_name => :w},
592
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', 'var_name' => :w},
593
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', 'var_name' => :w},
594
+ {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :var_name=> 'w'}
595
+ ]
596
+ widget_hashes.each do |h|
597
+ exp = {:class => 'Array', :pixmap => 'pix', :caption => 'caption'}
598
+ flexmock(@reader).should_receive(:read_widget).twice.with(h, Array).and_return( OpenStruct.new(exp) )
599
+ @reader.send(:read_tool_widgets, {:tool_widgets => [h, h]}).each do |w|
600
+ w.var_name.should == (h[:var_name]||h["var_name"]).to_s
601
+ end
602
+ end
603
+ end
604
+
605
+ it 'should use the :tool_widgets entry if both the :tool_widgets and "tool_widgets" entry exist in the input hash' do
606
+ widget_hash1 = {:class => 'Array', :pixmap => 'pix', :caption => 'caption', :position => :bottom}
607
+ widget_hash2 = {:class => 'Test1'}
608
+ exp = {:class_obj => Array, :pixmap => 'pix', :caption => 'caption'}
609
+ flexmock(@reader).should_receive(:read_widget).once.with(widget_hash1, Array).and_return OpenStruct.new(exp)
610
+ res = @reader.send(:read_tool_widgets, {:tool_widgets => widget_hash1, "tool_widgets" => widget_hash2})[0].class_obj.should == Array
611
+ end
612
+
613
+ it 'should return an empty array if neither the :tool_widgets nor the "tool_widgets" entry exist in the input hash' do
614
+ @reader.send(:read_tool_widgets, {}).should == []
615
+ end
616
+
617
+ it 'should pass the array [:pixmap, :caption] as second argument of the read_widget method' do
618
+ flexmock(@reader).should_receive(:read_widget).twice.with(Hash, [:pixmap, :caption]).and_return( OpenStruct.new )
619
+ @reader.send(:read_tool_widgets, {:tool_widgets => [{:position => :left}]})
620
+ @reader.send(:read_tool_widgets, {:tool_widgets => {:position => :right}})
621
+ end
622
+
623
+ it 'should use :bottom as default value if neither the :position nor the "position" entry exist for a hash' do
624
+ flexmock(@reader).should_receive(:read_widget).and_return( OpenStruct.new)
625
+ @reader.send(:read_tool_widgets, {:tool_widgets => [{}]})[0].position.should == :bottom
626
+ @reader.send(:read_tool_widgets, {:tool_widgets => {}})[0].position.should == :bottom
627
+ end
628
+
629
+ it 'uses the caption as default value for the :name/"name" entry' do
630
+ flexmock(@reader).should_receive(:read_widget).and_return OpenStruct.new(:caption => 'Abc def')
631
+ @reader.send(:read_tool_widgets, {:tool_widgets => [{}]})[0].name.should == "Abc def"
632
+ @reader.send(:read_tool_widgets, {:tool_widgets => {}})[0].name.should == "Abc def"
633
+ end
634
+
635
+ it 'should use "widget" as default value for the :var_name/"var_name" entry if the entry doesn\'t exist' do
636
+ flexmock(@reader).should_receive(:read_widget).and_return( OpenStruct.new)
637
+ @reader.send(:read_tool_widgets, {:tool_widgets => [{}]})[0].var_name.should == "widget"
638
+ @reader.send(:read_tool_widgets, {:tool_widgets => {}})[0].var_name.should == "widget"
639
+ end
640
+
641
+ it 'should use nil as default value for the :var_name/"var_name" entry if the entry is nil' do
642
+ flexmock(@reader).should_receive(:read_widget).and_return( OpenStruct.new)
643
+ @reader.send(:read_tool_widgets, {:tool_widgets => [{:var_name => nil}]})[0].var_name.should be_nil
644
+ @reader.send(:read_tool_widgets, {:tool_widgets => {:var_name => nil}})[0].var_name.should be_nil
645
+ end
646
+
647
+ end
648
+
649
+ describe 'KRuber::PluginSpecificationReader#read_config_widgets' do
650
+
651
+ before do
652
+ @info = OpenStruct.new({:directory => '/dir', :about => OS.new(:icon => '') })
653
+ @reader = Ruber::PluginSpecificationReader.new @info
654
+ end
655
+
656
+ it 'should call the read_widget method passing as first argument the :config_widgets/"config_widgets" entry and return its return value put in an array, when the :config_widgets/"config_widgets" entry is not an array' do
657
+ hashes = [
658
+ {:config_widgets => {}},
659
+ {'config_widgets' => {}}
660
+ ]
661
+ exp = [{:class => 'Array'}, {:class => 'Array'}]
662
+ flexmock(@reader).should_receive(:read_widget).once.with(hashes[0][:config_widgets], Array).and_return(OpenStruct.new(exp[0]))
663
+ flexmock(@reader).should_receive(:read_widget).once.with(hashes[1]['config_widgets'], Array).and_return(OpenStruct.new(exp[1]))
664
+ @reader.send(:read_config_widgets,hashes[0]).should == [OpenStruct.new(exp[0])]
665
+ @reader.send(:read_config_widgets,hashes[1]).should == [OpenStruct.new(exp[1])]
666
+ end
667
+
668
+ it 'should call the read_widget method for each element of the :config_widgets/"config_widgets" entry and return an array with all the return values, when the :config_widgets/"config_widgets" is an array' do
669
+ hashes = [
670
+ {:config_widgets => [{:class => 'Array'}, {:class => 'Ruber::PluginSpecification'}]},
671
+ {'config_widgets' => [{:class => 'Ruber::PluginSpecification'}, {:class => 'Array'}]}
672
+ ]
673
+ exp = [{:class => 'Array'}, {:class => 'Ruber::PluginSpecification'}, {:class => 'Ruber::PluginSpecification'}, {:class => 'Array'}]
674
+ 2.times{|i| flexmock(@reader).should_receive(:read_widget).once.with(hashes[0][:config_widgets][i], Array).and_return(OpenStruct.new(exp[i]))}
675
+ 2.times{|i| flexmock(@reader).should_receive(:read_widget).once.with(hashes[1]['config_widgets'][i], Array).and_return(OpenStruct.new(exp[2 + i]))}
676
+ @reader.send(:read_config_widgets,hashes[0]).should == [OpenStruct.new(exp[0]), OpenStruct.new(exp[1])]
677
+ @reader.send(:read_config_widgets,hashes[1]).should == [OpenStruct.new(exp[2]), OpenStruct.new(exp[3])]
678
+ end
679
+
680
+ it 'should use the :config_widgets, if both the :config_widgets and the "config_widgets" entries exist in the input hash' do
681
+ hash = {:config_widgets => {:class => 'Array'}, "config_widgets" => {:class => 'B'}}
682
+ flexmock(@reader).should_receive(:read_widget).once.with(hash[:config_widgets], Array)
683
+ flexmock(@reader).should_receive(:read_widget).never.with(hash['config_widgets'], Array)
684
+ @reader.send(:read_config_widgets, hash)
685
+ end
686
+
687
+ it 'should raise Ruber::PluginSpecification::PSFError if the caption is not specified for one widget' do
688
+ lambda{@reader.send(:read_config_widgets, {:config_widgets => {:class => 'Array'}})}.should raise_error(Ruber::PluginSpecification::PSFError, "The :caption entry must be present in the widget description")
689
+ lambda{@reader.send(:read_config_widgets, {:config_widgets => [{:class => 'Array'}, {:class => 'Array', :caption => 'c'}]})}.should raise_error(Ruber::PluginSpecification::PSFError, "The :caption entry must be present in the widget description")
690
+ end
691
+
692
+ it 'should return an empty array if the :config_widgets/"config_widgets" entry doesn\'t exist in the input hash' do
693
+ @reader.send(:read_config_widgets, {}).should == []
694
+ end
695
+
696
+ end
697
+
698
+ describe 'KRuber::PluginSpecificationReader#read_config_options' do
699
+
700
+ before do
701
+ @info = OpenStruct.new
702
+ @reader = Ruber::PluginSpecificationReader.new @info
703
+ @data = {
704
+ :config_options => {
705
+ :G1 => {
706
+ :o1 => {:default => 3},
707
+ 'o2' => {:default => 'abc'}
708
+ },
709
+ 'G2' => {
710
+ :o1 => {:default => :xyz},
711
+ :o3 => {:default => %w[a b c]}
712
+ }
713
+ }
714
+ }
715
+
716
+ end
717
+
718
+ it 'should return a Hash' do
719
+ @reader.send(:read_config_options, {:config_options => {}}).should be_instance_of( Hash )
720
+ end
721
+
722
+ it 'should call the read_config_option method for each entry in each group in the :config_options/"config_options" entry' do
723
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o1, {:default => 3})
724
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o2, {:default => 'abc'})
725
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o1, {:default => :xyz})
726
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o3, {:default => %w[a b c]})
727
+ @reader.send(:read_config_options, @data)
728
+ data = {
729
+ 'config_options' => {
730
+ :G1 => {
731
+ :o1 => {:default => 3},
732
+ 'o2' => {:default => 'abc'}
733
+ },
734
+ 'G2' => {
735
+ :o1 => {:default => :xyz},
736
+ :o3 => {:default => %w[a b c]}
737
+ }
738
+ }
739
+ }
740
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o1, {:default => 3})
741
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o2, {:default => 'abc'})
742
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o1, {:default => :xyz})
743
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o3, {:default => %w[a b c]})
744
+ @reader.send(:read_config_options, data)
745
+ end
746
+
747
+ it 'should store the value returned by each call to read_config_option under the [group, name] key in the returned hash, with group and name converted to a symbol' do
748
+ h = @data[:config_options]
749
+ exp = {
750
+ [:G1, :o1] => h[:G1][:o1],
751
+ [:G1, :o2] => h[:G1][:o2],
752
+ [:G2, :o1] => h['G2'][:o1],
753
+ [:G2, :o3] => h['G2'][:o3]
754
+ }
755
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o1, {:default => 3}).and_return exp[[:G1, :o1]]
756
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o2, {:default => 'abc'}).and_return exp[[:G1, :o2]]
757
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o1, {:default => :xyz}).and_return exp[[:G2, :o1]]
758
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o3, {:default => %w[a b c]}).and_return exp[[:G2, :o3]]
759
+ @reader.send(:read_config_options, @data).should == exp
760
+ end
761
+
762
+ it 'should use the :config_options entry if both the :config_options and the "config_options" entries exist in the input hash' do
763
+ data = {:config_options => {:G1 => {:o1 => {:default => 3}}}, 'config_options' => {:G2 => {:o2 => {:default => 5}}}}
764
+ flexmock(@reader).should_receive(:read_option).with(:G1, :o1, {:default => 3}).once
765
+ flexmock(@reader).should_receive(:read_option).with(:G2, :o2, {:default => 5}).never
766
+ @reader.send(:read_config_options, data)
767
+ end
768
+
769
+ it 'should return an empty hash if the :config_options/"config_options" entry doesn\'t exist in the input hash' do
770
+ @reader.send(:read_config_options, {}).should == {}
771
+ end
772
+
773
+ end
774
+
775
+ describe 'KRuber::PluginSpecificationReader#read_project_options' do
776
+
777
+ before do
778
+ @info = OpenStruct.new
779
+ @reader = Ruber::PluginSpecificationReader.new @info
780
+ @data = {
781
+ :project_options => {
782
+ :G1 => {
783
+ :o1 => {:default => 3},
784
+ 'o2' => {:default => 'abc'}
785
+ },
786
+ 'G2' => {
787
+ :o1 => {:default => :xyz},
788
+ :o3 => {:default => %w[a b c]}
789
+ }
790
+ }
791
+ }
792
+
793
+ end
794
+
795
+ it 'should return a Hash' do
796
+ @reader.send(:read_project_options, {:project_options => {}}).should be_instance_of( Hash )
797
+ end
798
+
799
+ it 'should call the read_option method for each entry in each group in the :project_options/"project_options" entry' do
800
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o1, {:default => 3}).and_return(OS.new)
801
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o2, {:default => 'abc'}).and_return(OS.new)
802
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o1, {:default => :xyz}).and_return(OS.new)
803
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o3, {:default => %w[a b c]}).and_return(OS.new)
804
+ @reader.send(:read_project_options, @data)
805
+ data = {
806
+ 'project_options' => {
807
+ :G1 => {
808
+ :o1 => {:default => 3},
809
+ 'o2' => {:default => 'abc'}
810
+ },
811
+ 'G2' => {
812
+ :o1 => {:default => :xyz},
813
+ :o3 => {:default => %w[a b c]}
814
+ }
815
+ }
816
+ }
817
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o1, {:default => 3}).and_return(OS.new)
818
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o2, {:default => 'abc'}).and_return(OS.new)
819
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o1, {:default => :xyz}).and_return(OS.new)
820
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o3, {:default => %w[a b c]}).and_return(OS.new)
821
+ @reader.send(:read_project_options, data)
822
+ end
823
+
824
+ it 'should store the value returned by each call to read_config_option under the [group, name] key in the returned hash, with group and name converted to a symbol' do
825
+ h = @data[:project_options]
826
+ exp = {
827
+ [:G1, :o1] => h[:G1][:o1],
828
+ [:G1, :o2] => h[:G1]['o2'],
829
+ [:G2, :o1] => h['G2'][:o1],
830
+ [:G2, :o3] => h['G2'][:o3]
831
+ }
832
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o1, {:default => 3}).and_return OS.new(exp[[:G1, :o1]])
833
+ flexmock(@reader).should_receive(:read_option).once.with(:G1, :o2, {:default => 'abc'}).and_return OS.new(exp[[:G1, :o2]])
834
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o1, {:default => :xyz}).and_return OS.new(exp[[:G2, :o1]])
835
+ flexmock(@reader).should_receive(:read_option).once.with(:G2, :o3, {:default => %w[a b c]}).and_return OS.new(exp[[:G2, :o3]])
836
+ res = @reader.send(:read_project_options, @data)
837
+ res.size.should == exp.size
838
+ res.each_pair do |k, v|
839
+ e = exp[k]
840
+ v.default.should == e[:default]
841
+ end
842
+ end
843
+
844
+ it 'merges the object returned by read_option with the hash returned by read_rules' do
845
+ data = {:project_options => {:g1 => {:o1 => {:default => 1, :file_extension => '*.rb', :scope => :global}}}}
846
+ exp = OS.new(:default => 1, :group => :g1, :name => :o1)
847
+ flexmock(@reader).should_receive(:read_option).once.with(:g1, :o1, {:default => 1, :file_extension => '*.rb', :scope => :global}).and_return exp
848
+ flexmock(@reader).should_receive(:read_rules).once.with({:default => 1, :file_extension => '*.rb', :scope => :global}).and_return({:file_extension => ['*.rb'], :scope => [:global], :mimetype => []})
849
+ res = @reader.send(:read_project_options, data)
850
+ res[[:g1, :o1]].scope.should == [:global]
851
+ res[[:g1, :o1]].file_extension.should == ['*.rb']
852
+ res[[:g1, :o1]].mimetype.should == []
853
+ end
854
+
855
+ it 'should add the "type" attribute to the object returned by read_option and set it to the type entry of the hash, converted into a symbol' do
856
+ h = @data[:project_options]
857
+ h[:G1][:o1][:type] = :global
858
+ h[:G1]["o2"][:type] = "user"
859
+ h["G2"][:o1]["type"] = :session
860
+ h["G2"][:o3]["type"] = "global"
861
+ res = @reader.send(:read_project_options, @data)
862
+ res[[:G1, :o1]].type.should == :global
863
+ res[[:G1, :o2]].type.should == :user
864
+ res[[:G2, :o1]].type.should == :session
865
+ res[[:G2, :o3]].type.should == :global
866
+ end
867
+
868
+ it 'should use :global as default value for the type attribute' do
869
+ res = @reader.send(:read_project_options, @data)
870
+ res[[:G1, :o1]].type.should == :global
871
+ end
872
+
873
+
874
+ it 'should use the :project_options entry if both the :project_options and the "project_options" entries exist in the input hash' do
875
+ data = {:project_options => {:G1 => {:o1 => {:default => 3}}}, 'project_options' => {:G2 => {:o2 => {:default => 5}}}}
876
+ flexmock(@reader).should_receive(:read_option).with(:G1, :o1, {:default => 3}).once.and_return(OS.new)
877
+ flexmock(@reader).should_receive(:read_option).with(:G2, :o2, {:default => 5}).never
878
+ @reader.send(:read_project_options, data)
879
+ end
880
+
881
+ it 'should return an empty hash if the :project_options/"project_options" entry doesn\'t exist in the input hash' do
882
+ @reader.send(:read_project_options, {}).should == {}
883
+ end
884
+
885
+ end
886
+
887
+ describe 'Ruber::PluginSpecificationReader#read_option' do
888
+
889
+ before do
890
+ @info = OpenStruct.new
891
+ @reader = Ruber::PluginSpecificationReader.new @info
892
+ end
893
+
894
+ it 'should return a Ruber::PluginSpecificationReader::Option object' do
895
+ @reader.send(:read_option, :G1, :o1, {}).should be_a(Ruber::PluginSpecificationReader::Option)
896
+ end
897
+
898
+ it 'should use the first argument as the "group" attribute of the returned value, after converting it to a symbol' do
899
+ @reader.send(:read_option, :G1, :o1, {}).group.should == :G1
900
+ @reader.send(:read_option, 'G1', :o1, {}).group.should == :G1
901
+ end
902
+
903
+ it 'should use the first argument as the "name" attribute of the returned value, after converting it to a symbol' do
904
+ @reader.send(:read_option, :G1, :o1, {}).name.should == :o1
905
+ @reader.send(:read_option, :G1, 'o1', {}).name.should == :o1
906
+ end
907
+
908
+ it 'should use the :relative_path/"relative_path" entry of the second argument as "relative_path" attribute of the returned object, if it exists in the second argument' do
909
+ @reader.send(:read_option, :G1, :o1, {:relative_path => true}).relative_path.should be_true
910
+ @reader.send(:read_option, :G1, :o1, {:relative_path => false}).relative_path.should_not be_true
911
+ @reader.send(:read_option, :G1, :o1, {'relative_path' => true}).relative_path.should be_true
912
+ @reader.send(:read_option, :G1, :o1, {'relative_path' => false}).relative_path.should_not be_true
913
+ end
914
+
915
+ it 'should use false as "relative_path" attribute for the returned object if the :relative_path/"relative_path" entry doesn\'t exist in the returned object' do
916
+ @reader.send(:read_option, :G1, :o1, {}).relative_path.should be_false
917
+ end
918
+
919
+ it 'should use the :default/"default" entry of the second argument as "default" attribute of the returned object if the entry exists' do
920
+ @reader.send(:read_option, :G1, :o1, {:default => 3}).instance_variable_get(:@table)[:default].should == 3
921
+ @reader.send(:read_option, :G1, :o1, {'default' => 3}).instance_variable_get(:@table)[:default].should == 3
922
+ @reader.send(:read_option, :G1, :o1, {:default => false}).instance_variable_get(:@table)[:default].should == false
923
+ @reader.send(:read_option, :G1, :o1, {'default' => false}).instance_variable_get(:@table)[:default].should == false
924
+ @reader.send(:read_option, :G1, :o1, {:default => true}).instance_variable_get(:@table)[:default].should == true
925
+ @reader.send(:read_option, :G1, :o1, {'default' => true}).instance_variable_get(:@table)[:default].should == true
926
+ @reader.send(:read_option, :G1, :o1, {:default => 'x'}).instance_variable_get(:@table)[:default].should == 'x'
927
+ @reader.send(:read_option, :G1, :o1, {'default' => 'x'}).instance_variable_get(:@table)[:default].should == 'x'
928
+ end
929
+
930
+ it 'should use an emtpy string as "default" attribute of the returned object if the :default/"default" entry doesn\'t exist in the second argument' do
931
+ @reader.send(:read_option, :G1, :o1, {}).instance_variable_get(:@table)[:default].should == ''
932
+ end
933
+
934
+ it 'should set the eval_default entry of the returned object to the value of the "eval_default" entry' do
935
+ @reader.send(:read_option, :G1, :o1, {:eval_default => false}).eval_default.should be_false
936
+ end
937
+
938
+ it 'should use true as default value for the eval_default entry' do
939
+ @reader.send(:read_option, :G1, :o1, {}).eval_default.should be_true
940
+ end
941
+
942
+ it 'uses the order entry of the second argument as order attribute of the returned object' do
943
+ @reader.send(:read_option, :G1, :o1, {:order => 3}).order.should == 3
944
+ @reader.send(:read_option, :G1, :o1, {'order' => 4}).order.should == 4
945
+ end
946
+
947
+ it 'uses nil as the default value for the order entry' do
948
+ @reader.send(:read_option, :G1, :o1, {}).order.should be_nil
949
+ end
950
+
951
+ end
952
+
953
+ describe 'Ruber::PluginSpecificationReader#read_project_widgets' do
954
+
955
+ before do
956
+ @info = OpenStruct.new({:directory => '/dir', :about => OS.new(:icon => '')})
957
+ @reader = Ruber::PluginSpecificationReader.new @info
958
+ end
959
+
960
+ it 'should call the read_widget method passing as first argument the :project_widgets/"project_widgets" entry and return its return value put in an array, when the :project_widgets/"project_widgets" entry is not an array' do
961
+ hashes = [
962
+ {:project_widgets => {}},
963
+ {'project_widgets' => {}}
964
+ ]
965
+ exp = [{:class => 'Array', :scope => [:global], :file_extension => [], :mimetype => []}, {:class => 'C2', :scope => [:global], :file_extension => [], :mimetype => []}]
966
+ flexmock(@reader).should_receive(:read_widget).once.with(hashes[0][:project_widgets], Array).and_return(OpenStruct.new(exp[0]))
967
+ flexmock(@reader).should_receive(:read_widget).once.with(hashes[1]['project_widgets'], Array).and_return(OpenStruct.new(exp[1]))
968
+ @reader.send(:read_project_widgets,hashes[0]).should == [OpenStruct.new(exp[0])]
969
+ @reader.send(:read_project_widgets,hashes[1]).should == [OpenStruct.new(exp[1])]
970
+ end
971
+
972
+ it 'should call the read_widget method for each element of the :project_widgets/"project_widgets" entry and return an array with all the return values, when the :project_widgets/"project_widgets" is an array' do
973
+ hashes = [
974
+ {:project_widgets => [{:class => 'Array'}, {:class => 'Ruber::PluginSpecification'}]},
975
+ {'project_widgets' => [{:class => 'Ruber::PluginSpecificationReader'}, {:class => 'Array'}]}
976
+ ]
977
+ exp = [
978
+ {:class_obj => Array, :scope => [:global], :file_extension => [], :mimetype => []},
979
+ {:class_obj => Ruber::PluginSpecification, :scope => [:global], :file_extension => [], :mimetype => []},
980
+ {:class_obj => Ruber::PluginSpecificationReader, :scope => [:global], :file_extension => [], :mimetype => []},
981
+ {:class_obj => Array, :scope => [:global], :file_extension => [], :mimetype => []}
982
+ ]
983
+ 2.times{|i| flexmock(@reader).should_receive(:read_widget).once.with(hashes[0][:project_widgets][i], Array).and_return(OpenStruct.new(exp[i]))}
984
+ 2.times{|i| flexmock(@reader).should_receive(:read_widget).once.with(hashes[1]['project_widgets'][i], Array).and_return(OpenStruct.new(exp[2 + i]))}
985
+ @reader.send(:read_project_widgets,hashes[0]).should == [OpenStruct.new(exp[0]), OpenStruct.new(exp[1])]
986
+ @reader.send(:read_project_widgets,hashes[1]).should == [OpenStruct.new(exp[2]), OpenStruct.new(exp[3])]
987
+ end
988
+
989
+ it 'calls the read_rules method for each widget and merges the returned hash with the widget\'s data' do
990
+ data = {
991
+ :project_widgets => [
992
+ {:class => Qt::CheckBox, :scope => :global, :caption => 'x'},
993
+ {:class => Qt::LineEdit, :scope => :document, :mimetype => 'application/x-ruby', :caption => 'y'}
994
+ ]
995
+ }
996
+ flexmock(@reader).should_receive(:read_rules).once.with(data[:project_widgets][0]).and_return({:scope => [:global], :file_extension => [], :mimetype => []})
997
+ flexmock(@reader).should_receive(:read_rules).once.with(data[:project_widgets][1]).and_return({:scope => [:document], :file_extension => [], :mimetype => ['application/x-ruby']})
998
+ res = @reader.send(:read_project_widgets, data)
999
+ res[0].scope.should == [:global]
1000
+ res[0].file_extension.should == []
1001
+ res[0].mimetype.should == []
1002
+ res[1].scope.should == [:document]
1003
+ res[1].file_extension.should == []
1004
+ res[1].mimetype.should == ['application/x-ruby']
1005
+ end
1006
+
1007
+ it 'should use the :project_widgets, if both the :project_widgets and the "project_widgets" entries exist in the input hash' do
1008
+ hash = {:project_widgets => {:class => 'A'}, "project_widgets" => {:class => 'B'}}
1009
+ flexmock(@reader).should_receive(:read_widget).once.with(hash[:project_widgets], Array).and_return(OpenStruct.new)
1010
+ flexmock(@reader).should_receive(:read_widget).never.with(hash['project_widgets'], Array)
1011
+ @reader.send(:read_project_widgets, hash)
1012
+ end
1013
+
1014
+ it 'should raise Ruber::PluginSpecification::PSFError if the caption is not specified for one widget' do
1015
+ lambda{@reader.send(:read_project_widgets, {:project_widgets => {:class => 'Array'}})}.should raise_error(Ruber::PluginSpecification::PSFError, "The :caption entry must be present in the widget description")
1016
+ lambda{@reader.send(:read_project_widgets, {:project_widgets => [{:class => 'Array'}, {:class => 'Array', :caption => 'c'}]})}.should raise_error(Ruber::PluginSpecification::PSFError, "The :caption entry must be present in the widget description")
1017
+ end
1018
+
1019
+ it 'should return an empty array if the :project_widgets/"project_widgets" entry doesn\'t exist in the input hash' do
1020
+ @reader.send(:read_project_widgets, {}).should == []
1021
+ end
1022
+
1023
+ end
1024
+
1025
+ describe 'Ruber::PluginSpecificationReader#read_extensions' do
1026
+
1027
+ before do
1028
+ @info = OpenStruct.new
1029
+ @reader = Ruber::PluginSpecificationReader.new @info
1030
+ end
1031
+
1032
+ it 'should return a Hash' do
1033
+ @reader.send(:read_extensions, {}).should be_instance_of(Hash)
1034
+ end
1035
+
1036
+ it 'should call the read_extension method for each entry in the :extensions/"project_extensions" entry in the input hash and store the returned value under the same key, converted to a symbol, in the returned hash' do
1037
+ hash = {:extensions => {:e1 => {:class => 'Array'}, 'e2' => {:class => 'Ruber::PluginSpecification'}}}
1038
+ flexmock(@reader).should_receive(:read_extension).once.with(:e1, {:class => 'Array'}).and_return OpenStruct.new({:class_obj => Array})
1039
+ flexmock(@reader).should_receive(:read_extension).once.with(:e2, {:class => 'Ruber::PluginSpecification'}).and_return OpenStruct.new({:class_obj => Ruber::PluginSpecification})
1040
+ res = @reader.send(:read_extensions, hash)
1041
+ res.size.should == 2
1042
+ res[:e1].should have_entries(:class_obj => Array)
1043
+ res[:e2].should have_entries(:class_obj => Ruber::PluginSpecification)
1044
+ hash = {'extensions' => {:e1 => {:class => 'Array'}, 'e2' => {:class => 'Ruber::PluginSpecification'}}}
1045
+ flexmock(@reader).should_receive(:read_extension).once.with(:e1, {:class => 'Array'}).and_return OpenStruct.new({:class_obj => Array})
1046
+ flexmock(@reader).should_receive(:read_extension).once.with(:e2, {:class => 'Ruber::PluginSpecification'}).and_return OpenStruct.new({:class_obj => Ruber::PluginSpecification})
1047
+ res = @reader.send(:read_extensions, hash)
1048
+ res.size.should == 2
1049
+ res[:e1].should have_entries(:class_obj => Array)
1050
+ res[:e2].should have_entries(:class_obj => Ruber::PluginSpecification)
1051
+ end
1052
+
1053
+ it 'should return an empty hash if the :extensions/"project_extensions" entry doesn\'t exist in the input hash' do
1054
+ @reader.send(:read_extensions, {}).should == {}
1055
+ end
1056
+
1057
+ end
1058
+
1059
+ describe 'Ruber::PluginSpecificationReader#read_extension' do
1060
+
1061
+ before do
1062
+ @info = OpenStruct.new
1063
+ @reader = Ruber::PluginSpecificationReader.new @info
1064
+ end
1065
+
1066
+ describe ', when the second argument is a hash' do
1067
+
1068
+ it 'should return an OpenStruct' do
1069
+ @reader.send(:read_extension, :e, {:class => 'Array'}).should be_instance_of(OpenStruct)
1070
+ end
1071
+
1072
+ it 'should use the first argument as "name" attribute for the returned object' do
1073
+ @reader.send(:read_extension, :e, {:class => 'Array'}).name.should == :e
1074
+ end
1075
+
1076
+ it 'should use the :class/"class" entry of the second argument as "class_name" attribute for the returned object' do
1077
+ @reader.send(:read_extension, :e, {:class => 'Array'}).class_obj.should == Array
1078
+ end
1079
+
1080
+ it 'calls read_rules and stores the value it returns in the returned object' do
1081
+ res = @reader.send(:read_extension, :e, {:class => 'Array', :scope => :global, :file_extension => '*.rb'})
1082
+ res.scope.should == [:global]
1083
+ res.mimetype.should == []
1084
+ res.file_extension.should == ['*.rb']
1085
+ end
1086
+
1087
+ it 'should raise Ruber::PluginSpecification::PSFError if the :class/"class" entry doesn\'t exist in the second argument' do
1088
+ lambda{@reader.send(:read_extension, :e, {})}.should raise_error(Ruber::PluginSpecification::PSFError, "The required 'class' entry is missing from the PDF")
1089
+ end
1090
+
1091
+ end
1092
+
1093
+ describe ', when the second argument is a array' do
1094
+
1095
+ it 'returns an array' do
1096
+ @reader.send(:read_extension, :e, [{:class => 'Array'}, {:class => 'String'}]).should be_a(Array)
1097
+ end
1098
+
1099
+ it 'calls the read_extension method once for each element of the array, passing it the first argument and the element itself and puts the result in the returned array' do
1100
+ res = @reader.send(:read_extension, :e, [{:class => 'Array', :scope => :global}, {:class => 'String', :file_extension => '*.xyz'}])
1101
+ res[0].should have_entries(:class_obj => Array, :scope => [:global], :name => :e)
1102
+ res[1].should have_entries(:class_obj => String, :file_extension => ['*.xyz'], :name => :e)
1103
+ end
1104
+
1105
+ end
1106
+
1107
+ end
1108
+
1109
+ describe Ruber::PluginSpecificationReader do
1110
+
1111
+ describe '#read_action' do
1112
+
1113
+ before do
1114
+ @info = OpenStruct.new
1115
+ @reader = Ruber::PluginSpecificationReader.new @info
1116
+ end
1117
+
1118
+ it 'should return an OpenStruct' do
1119
+ @reader.send(:read_action, 'xyz', {}).should be_an(OpenStruct)
1120
+ end
1121
+
1122
+ it 'should store the first argument in the name attribute of the returned object' do
1123
+ @reader.send(:read_action, 'xyz', {}).name.should == 'xyz'
1124
+ end
1125
+
1126
+ it 'should store the content of the text entry in the text attribute of the returned object' do
1127
+ @reader.send(:read_action, 'xyz', {:text => 'Abc'}).text.should == 'Abc'
1128
+ end
1129
+
1130
+ it 'should use an empty string as default value for the text entry' do
1131
+ @reader.send(:read_action, 'xyz', {}).text.should == ''
1132
+ end
1133
+
1134
+ it 'should create a KDE::Shortcut from the shortcut entry and store it in the shortuct attribute of the returned object' do
1135
+ short = @reader.send(:read_action, 'xyz', {:shortcut => 'Ctrl+S'}).shortcut
1136
+ short.should be_a(KDE::Shortcut)
1137
+ short.to_string.should == 'Ctrl+S'
1138
+ end
1139
+
1140
+ it 'should use nil as default value for the shortcut entry' do
1141
+ @reader.send(:read_action, 'xyz', {}).shortcut.should be_nil
1142
+ end
1143
+
1144
+ it 'should store the content of the help entry in the help attribute of the returned object' do
1145
+ @reader.send(:read_action, 'xyz', {:help => 'Abc'}).help.should == 'Abc'
1146
+ end
1147
+
1148
+ it 'should use an empty string as default value for the help entry' do
1149
+ @reader.send(:read_action, 'xyz', {}).help.should == ''
1150
+ end
1151
+
1152
+ it 'should store the pixmap entry, prepended with the plugin directory, under the icon entry of the returned object if the file exists' do
1153
+ @reader.instance_variable_get(:@plugin_info).directory = '/dir'
1154
+ flexmock(KDE::Application).should_receive(:instance).and_return true
1155
+ flexmock(File).should_receive(:exist?).with("/dir/pixmap").and_return true
1156
+ @reader.send(:read_action, 'xyz', {:icon =>"pixmap"}).icon.should == '/dir/pixmap'
1157
+ end
1158
+
1159
+ it 'should store the path returned by KDE::IconLoader.pixmap_path when called with the icon entry, under the icon entry of the returned object if the file doesn\'t exist in the plugin directory' do
1160
+ @reader.instance_variable_get(:@plugin_info).directory = '/dir'
1161
+ flexmock(KDE::IconLoader).should_receive(:pixmap_path).with( 'pixmap').once.and_return '/usr/pixmap'
1162
+ flexmock(File).should_receive(:exist?).with("/dir/pixmap").and_return false
1163
+ @reader.send(:read_action, 'xyz', {:icon =>"pixmap"}).icon.should == '/usr/pixmap'
1164
+ end
1165
+
1166
+ it 'should store the pixmap entry, prepended with the plugin directory, under the icon entry of the returned object if the file doesn\'t exist but the application object hasn\'t been created yet' do
1167
+ @reader.instance_variable_get(:@plugin_info).directory = '/dir'
1168
+ flexmock(KDE::Application).should_receive(:instance).and_return nil
1169
+ flexmock(File).should_receive(:exist?).with("/dir/pixmap").and_return false
1170
+ flexmock(KDE::IconLoader).should_receive(:pixmap_path).never
1171
+ @reader.send(:read_action, 'xyz', {:icon =>"pixmap"}).icon.should == '/dir/pixmap'
1172
+ end
1173
+
1174
+ it 'should use an empty string as default value for the icon entry' do
1175
+ res = @reader.send(:read_action, 'xyz', {}).icon.should == ''
1176
+ end
1177
+
1178
+ it 'should store the constant corresponding to the class entry in the action_class attribute of the returned object' do
1179
+ @reader.send(:read_action, 'xyz', {:class => 'KDE::ToggleAction'}).action_class.should == KDE::ToggleAction
1180
+ end
1181
+
1182
+ it 'should use KDE::Action as default value of the class entry' do
1183
+ @reader.send(:read_action, 'xyz', {}).action_class.should == KDE::Action
1184
+ end
1185
+
1186
+ it 'should store the content of the standard_action entry, converted to a symbol, in the standard_action attribute of the returned object' do
1187
+ @reader.send(:read_action, 'xyz', {:standard_action => 'open_new'}).standard_action.should == :open_new
1188
+ end
1189
+
1190
+ it 'should use nil as default value of the standard_action entry' do
1191
+ @reader.send(:read_action, 'xyz', {}).standard_action.should be_nil
1192
+ end
1193
+
1194
+ it 'should set the standard_action attribute of the returned object to nil if a class entry exists in the hash' do
1195
+ @reader.send(:read_action, 'xyz', {:standard_action => 'open_new', :class => KDE::ToggleAction}).standard_action.should be_nil
1196
+ end
1197
+
1198
+ it 'should set the action_class attribute of the returned object to nil if the standard_action entry exists in the hash and the class entry doesn\'t' do
1199
+ @reader.send(:read_action, 'xyz', {:standard_action => 'open_new'}).action_class.should be_nil
1200
+ end
1201
+
1202
+ it 'should store the content of the receiver entry in the receiver attribute of the returned object' do
1203
+ @reader.send(:read_action, 'xyz', {:receiver => '@var'}).receiver.should == '@var'
1204
+ end
1205
+
1206
+ it 'should use "self" as default value of the receiver entry' do
1207
+ @reader.send(:read_action, 'xyz', {}).receiver.should == 'self'
1208
+ end
1209
+
1210
+ it 'should store the content of the signal entry in the signal attribute of the returned object' do
1211
+ @reader.send(:read_action, 'xyz', {:signal => 'toggled(bool)'}).signal.should == 'toggled(bool)'
1212
+ end
1213
+
1214
+ it 'should use "triggered(bool)" as default value of the signal entry' do
1215
+ @reader.send(:read_action, 'xyz', {}).signal.should == 'triggered(bool)'
1216
+ end
1217
+
1218
+ it 'should store the content of the slot entry in the slot attribute of the returned object' do
1219
+ @reader.send(:read_action, 'xyz', {:slot => 'test()'}).slot.should == 'test()'
1220
+ end
1221
+
1222
+ it 'should use nil as default value of the slot entry' do
1223
+ @reader.send(:read_action, 'xyz', {}).slot.should be_nil
1224
+ end
1225
+
1226
+ it 'should store the content of the states entry in the states attrbiute of the returned object' do
1227
+ @reader.send(:read_action, 'xyz', {:states => %w[s1 s2]}).states.should == %w[s1 s2]
1228
+ end
1229
+
1230
+ it 'should use an empty array as default value of the states entry' do
1231
+ @reader.send(:read_action, 'xyz', {}).states.should == []
1232
+ end
1233
+
1234
+ it 'should store the content of the state entry in the state attribute of the returned object' do
1235
+ @reader.send(:read_action, 'xyz', {:state => 's'}).state.should == 's'
1236
+ end
1237
+
1238
+ it 'should use nil as default value of the state entry' do
1239
+ @reader.send(:read_action, 'xyz', {}).state.should be_nil
1240
+ end
1241
+
1242
+ it 'should set the state attribute of the returned object to nil if the states entry also exists' do
1243
+ @reader.send(:read_action, 'xyz', {:states => %w[s1 s2], :state => 's'}).state.should be_nil
1244
+ end
1245
+
1246
+ it 'should use the symbol version of the keys over the string version if both exist' do
1247
+ hash = {
1248
+ :text => 'A', 'text' => 'B',
1249
+ :shortcut => 'Ctrl+A', 'shortcut' => 'Ctrl+B',
1250
+ :help => 'H', 'help' => 'h',
1251
+ :class => 'KDE::ToggleAction', 'class' => 'KDE::RecentFilesAction',
1252
+ :receiver => '@var1', 'receiver' => '@var2',
1253
+ :signal => 'S1()', 'signal' => 'S2()',
1254
+ :slot => 's1()', 'slot' => 's2()',
1255
+ :states => %w[a b], 'states' => %w[c d]
1256
+ }
1257
+ res = @reader.send :read_action, 'xyz', hash
1258
+ res.text.should == 'A'
1259
+ res.shortcut.to_string.should == 'Ctrl+A'
1260
+ res.help.should == 'H'
1261
+ res.action_class.should == KDE::ToggleAction
1262
+ res.receiver.should == '@var1'
1263
+ res.signal.should == 'S1()'
1264
+ res.slot.should == 's1()'
1265
+ res.states.should == %w[a b]
1266
+ end
1267
+
1268
+ it 'should use the string versions of the keys if the symbol version doesn\'t exist' do
1269
+ hash = {
1270
+ "text" => 'A',
1271
+ "shortcut" => 'Ctrl+A',
1272
+ "help" => 'H',
1273
+ "class" => 'KDE::ToggleAction',
1274
+ "receiver" => '@var1',
1275
+ "signal" => 'S1()',
1276
+ "slot" => 's1()',
1277
+ "states" => %w[a b],
1278
+ }
1279
+ res = @reader.send :read_action, 'xyz', hash
1280
+ res.text.should == 'A'
1281
+ res.shortcut.to_string.should == 'Ctrl+A'
1282
+ res.help.should == 'H'
1283
+ res.action_class.should == KDE::ToggleAction
1284
+ res.receiver.should == '@var1'
1285
+ res.signal.should == 'S1()'
1286
+ res.slot.should == 's1()'
1287
+ res.states.should == %w[a b]
1288
+ end
1289
+
1290
+ end
1291
+
1292
+ describe '#read_actions' do
1293
+
1294
+ before do
1295
+ @info = OpenStruct.new
1296
+ @reader = Ruber::PluginSpecificationReader.new @info
1297
+ @hash = {
1298
+ :actions => {
1299
+ 'a1' => {:text => 'X'},
1300
+ :a2 => {:text => 'Y'},
1301
+ 'a3' => {:text => 'Z'}
1302
+ }
1303
+ }
1304
+ end
1305
+
1306
+ it 'should return a hash' do
1307
+ @reader.send( :read_actions, @hash).should be_a(Hash)
1308
+ end
1309
+
1310
+ it 'should call the read_action method for each entry in the actions entry, passing it each key (converted to a string) and the corresponding value' do
1311
+ flexmock(@reader).should_receive(:read_action).with('a1', @hash[:actions]['a1']).once
1312
+ flexmock(@reader).should_receive(:read_action).with('a2', @hash[:actions][:a2]).once
1313
+ flexmock(@reader).should_receive(:read_action).with('a3', @hash[:actions]['a3']).once
1314
+ @reader.send :read_actions, @hash
1315
+ end
1316
+
1317
+ it 'should store the value returned by each call to read_action in the returned hash under its name' do
1318
+ res = @reader.send :read_actions, @hash
1319
+ res['a1'].text.should == 'X'
1320
+ res['a2'].text.should == 'Y'
1321
+ res['a3'].text.should == 'Z'
1322
+ end
1323
+
1324
+ end
1325
+
1326
+ describe '#read_human_name' do
1327
+
1328
+ before do
1329
+ @info = OpenStruct.new
1330
+ @reader = Ruber::PluginSpecificationReader.new @info
1331
+ end
1332
+
1333
+ it 'should return the content of the :human_name entry of the argument, if it exists' do
1334
+ @reader.send(:read_human_name, {:human_name => 'Test'}).should == 'Test'
1335
+ @reader.send(:read_human_name, {'human_name' => 'Test'}).should == 'Test'
1336
+ end
1337
+
1338
+ it 'should use the value in the :human_name entry if both it and the "human_name" entry exist' do
1339
+ @reader.send(:read_human_name, {:human_name => 'Test', 'human_name' => 'X'}).should == 'Test'
1340
+ end
1341
+
1342
+ it 'should obtain the human_name entry from the name entry if the former is missing' do
1343
+ @info.name = :xy_z
1344
+ @reader.send(:read_human_name, {}).should == 'Xy z'
1345
+ end
1346
+
1347
+ end
1348
+
1349
+ describe '#read_authors' do
1350
+
1351
+ before do
1352
+ @info = OpenStruct.new
1353
+ @reader = Ruber::PluginSpecificationReader.new @info
1354
+ end
1355
+
1356
+ it 'should return the contents of the authors entry of the argument, if it exists' do
1357
+ @reader.send(:read_authors, {:authors => [['Stefano Crocco', 'stefano.crocco@alice.it']]}).should == [['Stefano Crocco', 'stefano.crocco@alice.it']]
1358
+ @reader.send(:read_authors, {'authors' => [['Stefano Crocco', 'stefano.crocco@alice.it']]}).should == [['Stefano Crocco', 'stefano.crocco@alice.it']]
1359
+ end
1360
+
1361
+ it 'inserts an empty string as second element to all the inner arrays which only have one element' do
1362
+ @reader.send(:read_authors, {:authors => [['Stefano Crocco']]}).should == [['Stefano Crocco', '']]
1363
+ end
1364
+
1365
+ it 'should use the :authors entry if both it and the "authors" entry exist' do
1366
+ @reader.send(:read_authors, {:authors => [['Stefano Crocco', 'stefano.crocco@alice.it']], 'authors' => []}).should == [['Stefano Crocco', 'stefano.crocco@alice.it']]
1367
+ end
1368
+
1369
+ it 'should use an empty array as default value' do
1370
+ @reader.send(:read_authors, {}).should == []
1371
+ end
1372
+
1373
+ it 'should raise PluginSpecification::PSFError if the value contained in the entry isn\'t an array' do
1374
+ lambda{@reader.send(:read_authors, {:authors => 'Name'})}.should raise_error(Ruber::PluginSpecification::PSFError, 'The "authors" entry in the PDF should be an array')
1375
+ end
1376
+
1377
+ it 'should enclose the value contained in the authors entry in an array if it\'s not a nested array' do
1378
+ @reader.send(:read_authors, {:authors => ['Stefano Crocco', 'stefano.crocco@alice.it']}).should == [['Stefano Crocco', 'stefano.crocco@alice.it']]
1379
+ end
1380
+
1381
+ it 'encloses the value contained in the authors entry in an array if the authors entry is an array with a single entry and that\'s not an array' do
1382
+ @reader.send(:read_authors, {:authors => ['Stefano Crocco']}).should == [['Stefano Crocco', '']]
1383
+ end
1384
+
1385
+ it 'should not enclose an empty array in another array' do
1386
+ @reader.send(:read_authors, {:authors => []}).should == []
1387
+ end
1388
+
1389
+ end
1390
+
1391
+ describe '#read_license' do
1392
+
1393
+ before do
1394
+ @info = OpenStruct.new
1395
+ @reader = Ruber::PluginSpecificationReader.new @info
1396
+ end
1397
+
1398
+ it 'should return the contents of the license entry in the argument if it exists' do
1399
+ @reader.send(:read_license, {:license => :gpl}).should == :gpl
1400
+ @reader.send(:read_license, {'license' => :gpl}).should == :gpl
1401
+ end
1402
+
1403
+ it 'should convert the contents of the license entry to a symbol' do
1404
+ @reader.send(:read_license, {:license => 'gpl'}).should == :gpl
1405
+ end
1406
+
1407
+ it 'should use the :license entry if both it and the "license" entry exist' do
1408
+ @reader.send(:read_license, {:license => :gpl3, 'license' => :gpl}).should == :gpl3
1409
+ end
1410
+
1411
+ it 'should use :unknown as default value' do
1412
+ @reader.send(:read_license, {}).should == :unknown
1413
+ end
1414
+
1415
+ it 'should raise PluginSpecification::PSFError if the license is a symbol but it\'s not recognized' do
1416
+ allowed = [:unknown, :gpl, :gpl2, :lgpl, :lgpl2, :bsd, :artistic, :qpl, :qpl1, :gpl3, :lgpl3]
1417
+ allowed.each do |l|
1418
+ lambda{@reader.send(:read_license, {:license => l})}.should_not raise_error
1419
+ end
1420
+ lambda{@reader.send(:read_license, {:license => :xyz})}.should raise_error(Ruber::PluginSpecification::PSFError, "Invalid licese type :xyz")
1421
+ end
1422
+
1423
+ it 'should use the content of the entry, even if it doesn\'t correspond to a license name if it is a string' do
1424
+ @reader.send(:read_license, {:license => 'xyz'}).should == 'xyz'
1425
+ end
1426
+
1427
+ end
1428
+
1429
+ describe "#read_version" do
1430
+
1431
+ before do
1432
+ @info = OpenStruct.new
1433
+ @reader = Ruber::PluginSpecificationReader.new @info
1434
+ end
1435
+
1436
+ it 'should return the contents of the version entry in the argument if it exists' do
1437
+ @reader.send(:read_version, {:version => '1.2.3'}).should == '1.2.3'
1438
+ @reader.send(:read_version, {'version' => '1.2.3'}).should == '1.2.3'
1439
+ end
1440
+
1441
+ it 'should use the :version entry if both it and the "version" entry exist' do
1442
+ @reader.send(:read_version, {:version => '1.2.3', 'version' => '4.5.6'}).should == '1.2.3'
1443
+ end
1444
+
1445
+ it 'should use "0.0.0" as default value' do
1446
+ @reader.send(:read_version, {}).should == '0.0.0'
1447
+ end
1448
+
1449
+ end
1450
+
1451
+ describe '#read_about' do
1452
+
1453
+ before do
1454
+ @info = OpenStruct.new
1455
+ @reader = Ruber::PluginSpecificationReader.new @info
1456
+ end
1457
+
1458
+ it 'should return an OpenStruct' do
1459
+ @reader.send(:read_about, {:about => {}}).should be_a(OpenStruct)
1460
+ end
1461
+
1462
+ it 'should store the human name of the plugin in the returned value' do
1463
+ flexmock(@reader).should_receive(:read_human_name).once.with({:human_name => 'Xyz'}).and_return('Xyz')
1464
+ @reader.send(:read_about, {:about => {:human_name => 'Xyz'}}).human_name.should == 'Xyz'
1465
+ end
1466
+
1467
+ it 'should store the authors of the plugin in the returned value' do
1468
+ flexmock(@reader).should_receive(:read_authors).once.with({:authors => '[[Author, xyz@abc.or]]'}).and_return([%w[Author xyz@abc.or]])
1469
+ @reader.send(:read_about, ({:about => {:authors => '[[Author, xyz@abc.or]]'}})).authors.should == [%w[Author xyz@abc.or]]
1470
+ end
1471
+
1472
+ it 'should store the description of the plugin in the returned value' do
1473
+ flexmock(@reader).should_receive(:read_description).once.with({:description => 'Short description'}).and_return('Short description')
1474
+ @reader.send(:read_about, :about => {:description => 'Short description'}).description.should == 'Short description'
1475
+ end
1476
+
1477
+ it 'should store the license of the plugin in the returned value' do
1478
+ flexmock(@reader).should_receive(:read_license).once.with({:license => :gpl}).and_return(:gpl)
1479
+ @reader.send(:read_about, :about => {:license => :gpl}).license.should == :gpl
1480
+ end
1481
+
1482
+ it 'should store the address for reporting bugs in the returned object' do
1483
+ flexmock(@reader).should_receive(:read_bug_address).once.with({:bug_address => 'xyz@abc.com'}).and_return('xyz@abc.com')
1484
+ @reader.send(:read_about, :about => {:bug_address => 'xyz@abc.com'}).bug_address.should == 'xyz@abc.com'
1485
+ end
1486
+
1487
+ it 'should store the copyright information in the returned object' do
1488
+ flexmock(@reader).should_receive(:read_copyright).once.with({:copyright => 'Author'}).and_return('Author')
1489
+ @reader.send(:read_about, :about => {:copyright => 'Author'}).copyright.should == 'Author'
1490
+ end
1491
+
1492
+ it 'should store the homepage information in the returned object' do
1493
+ flexmock(@reader).should_receive(:read_homepage).once.with({:homepage => 'http://www.abc.xyz.org'}).and_return('http://www.abc.xyz.org')
1494
+ @reader.send(:read_about, :about => {:homepage => 'http://www.abc.xyz.org'}).homepage.should == 'http://www.abc.xyz.org'
1495
+ end
1496
+
1497
+ it 'should store the icon associated with the plugin in the returned object' do
1498
+ flexmock(@reader).should_receive(:read_icon).once.with({:icon => 'ruby.png'}).and_return('ruby.png')
1499
+ @reader.send(:read_about, :about => {:icon => 'ruby.png'}).icon.should == 'ruby.png'
1500
+ end
1501
+
1502
+ end
1503
+
1504
+ describe '#read_bug_address' do
1505
+
1506
+ before do
1507
+ @info = OpenStruct.new
1508
+ @reader = Ruber::PluginSpecificationReader.new @info
1509
+ end
1510
+
1511
+ it 'should return the bug_address entry of the PDF' do
1512
+ @reader.send(:read_bug_address, {:bug_address => 'xyz@abc.org'}).should == 'xyz@abc.org'
1513
+ @reader.send('read_bug_address', {:bug_address => 'xyz@abc.org'}).should == 'xyz@abc.org'
1514
+ end
1515
+
1516
+ it 'should use an empty string as default value' do
1517
+ @reader.send(:read_bug_address, {}).should == ''
1518
+ end
1519
+
1520
+ it 'should use the symbol entry if both entries exist' do
1521
+ @reader.send(:read_bug_address, {:bug_address => 'xyz@abc.org', 'bug_address' => 'abc@xyz.com'}).should == 'xyz@abc.org'
1522
+ end
1523
+
1524
+ end
1525
+
1526
+ describe '#read_copyright' do
1527
+
1528
+ before do
1529
+ @info = OpenStruct.new
1530
+ @reader = Ruber::PluginSpecificationReader.new @info
1531
+ end
1532
+
1533
+ it 'should return the copyright entry of the PDF' do
1534
+ @reader.send(:read_copyright, {:copyright => 'copyright text'}).should == 'copyright text'
1535
+ @reader.send('read_copyright', {:copyright => 'copyright text'}).should == 'copyright text'
1536
+ end
1537
+
1538
+ it 'should use an empty string as default value' do
1539
+ @reader.send(:read_copyright, {}).should == ''
1540
+ end
1541
+
1542
+ it 'should use the symbol entry if both entries exist' do
1543
+ @reader.send(:read_copyright, {:copyright => 'copyright text', 'copyright' => 'other copyright text'}).should == 'copyright text'
1544
+ end
1545
+
1546
+ end
1547
+
1548
+ describe '#read_homepage' do
1549
+
1550
+ before do
1551
+ @info = OpenStruct.new
1552
+ @reader = Ruber::PluginSpecificationReader.new @info
1553
+ end
1554
+
1555
+ it 'should return the homepage entry of the PDF' do
1556
+ @reader.send(:read_homepage, {:homepage => 'http://www.abc.org'}).should == 'http://www.abc.org'
1557
+ @reader.send(:read_homepage, {'homepage' => 'http://www.abc.org'}).should == 'http://www.abc.org'
1558
+ end
1559
+
1560
+ it 'should prepend http:// to the home page if it isn\'t empty but doesn\'t start with http://' do
1561
+ @reader.send(:read_homepage, {:homepage => 'www.abc.org'}).should == 'http://www.abc.org'
1562
+ @reader.send(:read_homepage, {:homepage => ''}).should == ''
1563
+ end
1564
+
1565
+ it 'should use an empty string as default value' do
1566
+ @reader.send(:read_homepage, {}).should == ''
1567
+ end
1568
+
1569
+ it 'should use the symbol entry if both entries exist' do
1570
+ @reader.send(:read_homepage, {:homepage => 'http://www.abc.org', 'homepage' => 'http://www.xyz.org'}).should == 'http://www.abc.org'
1571
+ end
1572
+
1573
+ end
1574
+
1575
+ describe '#read_icon' do
1576
+
1577
+ before do
1578
+ @info = OpenStruct.new
1579
+ @reader = Ruber::PluginSpecificationReader.new @info
1580
+ @info.directory = '/dir'
1581
+ end
1582
+
1583
+ it 'should return the icon file prepended with the plugin directory, if the icon file exists in the plugin directory' do
1584
+ flexmock(KDE::Application).should_receive(:instance).and_return true
1585
+ flexmock(File).should_receive(:exist?).with("/dir/pixmap").and_return true
1586
+ @reader.send(:read_icon, {:icon => "pixmap"}).should == '/dir/pixmap'
1587
+ @reader.send(:read_icon, {'icon' => "pixmap"}).should == '/dir/pixmap'
1588
+ end
1589
+
1590
+ it 'should return the absolute path of the icon file obtained using KDE::IconLoader if the icon file isn\'t in the plugin directory and the application object exists' do
1591
+ flexmock(KDE::Application).should_receive(:instance).and_return true
1592
+ flexmock(KDE::IconLoader).should_receive(:pixmap_path).with( 'pixmap').twice.and_return '/usr/pixmap'
1593
+ @reader.send(:read_icon, {:icon =>"pixmap"}).should == '/usr/pixmap'
1594
+ @reader.send(:read_icon, {'icon' =>"pixmap"}).should == '/usr/pixmap'
1595
+ end
1596
+
1597
+ it 'should return the icon file prepended with the plugin directory, if the icon file exists in the plugin directory if the icon file isn\'t in the plugin directory but the application object doesn\'t exist' do
1598
+ flexmock(KDE::Application).should_receive(:instance).and_return(nil)
1599
+ flexmock(File).should_receive(:exist?).with("/dir/pixmap").and_return false
1600
+ flexmock(KDE::IconLoader).should_receive(:pixmap_path).with( 'pixmap').never
1601
+ @reader.send(:read_icon, {:icon =>"pixmap"}).should == '/dir/pixmap'
1602
+ @reader.send(:read_icon, {'icon' =>"pixmap"}).should == '/dir/pixmap'
1603
+ end
1604
+
1605
+ it 'should use an empty string as default value' do
1606
+ @reader.send(:read_icon, {}).should == ''
1607
+ end
1608
+
1609
+ it 'should use the symbol entry if both entries exist' do
1610
+ flexmock(KDE::Application).should_receive(:instance).and_return true
1611
+ flexmock(File).should_receive(:exist?).with("/dir/pixmap").and_return true
1612
+ @reader.send(:read_icon, {:icon => 'pixmap', 'icon' => 'Pixmap'}).should == '/dir/pixmap'
1613
+ end
1614
+
1615
+ end
1616
+
1617
+ describe '#read_rules' do
1618
+
1619
+ before do
1620
+ @info = OpenStruct.new
1621
+ @reader = Ruber::PluginSpecificationReader.new @info
1622
+ end
1623
+
1624
+ it 'returns a hash' do
1625
+ @reader.send(:read_rules, {}).should be_a(Hash)
1626
+ end
1627
+
1628
+ describe ', when reading the scope' do
1629
+
1630
+ it 'puts the contents of the scope entry of the argument in the :scope entry of the returned hash' do
1631
+ @reader.send(:read_rules, {:scope => [:global]})[:scope].should == [:global]
1632
+ @reader.send(:read_rules, {'scope' => [:document]})[:scope].should == [:document]
1633
+ end
1634
+
1635
+ it 'converts the values :all and all to [:global, :document]' do
1636
+ @reader.send(:read_rules, {:scope => 'all'})[:scope].should == [:global, :document]
1637
+ @reader.send(:read_rules, {'scope' => :all})[:scope].should == [:global, :document]
1638
+ end
1639
+
1640
+ it 'encloses the scope entry of the argument in a array, unless it\'s already an array' do
1641
+ @reader.send(:read_rules, {:scope => :global})[:scope].should == [:global]
1642
+ end
1643
+
1644
+ it 'converts each entry of the scope array to a symbol' do
1645
+ @reader.send(:read_rules, {:scope => %w[global document]})[:scope].should == [:global, :document]
1646
+ end
1647
+
1648
+ it 'uses [:global] as default value for the scope entry' do
1649
+ @reader.send(:read_rules, {})[:scope].should == [:global]
1650
+ end
1651
+
1652
+ end
1653
+
1654
+ describe ', when reading the mimetype' do
1655
+
1656
+ it 'stores the contents of the mimetype entry of the argument in the returned value' do
1657
+ @reader.send(:read_rules, :mimetype => ['application/x-ruby'])[:mimetype].should == ['application/x-ruby']
1658
+ @reader.send(:read_rules, 'mimetype' => ['application/x-ruby'])[:mimetype].should == ['application/x-ruby']
1659
+ end
1660
+
1661
+ it 'encloses the mimetype entry in a array unless it\'s already a array' do
1662
+ @reader.send(:read_rules, :mimetype => 'application/x-ruby')[:mimetype].should == ['application/x-ruby']
1663
+ end
1664
+
1665
+ it 'uses an empty array as default value' do
1666
+ @reader.send(:read_rules, {})[:mimetype].should == []
1667
+ end
1668
+
1669
+ end
1670
+
1671
+ describe ', when reading the file extension' do
1672
+
1673
+ it 'stores the contents of the file_extension entry of the argument in the returned value' do
1674
+ @reader.send(:read_rules, :file_extension => %w[*.rb *.yaml])[:file_extension].should == %w[*.rb *.yaml]
1675
+ @reader.send(:read_rules, 'file_extension' => %w[*.rb *.yaml])[:file_extension].should == %w[*.rb *.yaml]
1676
+ end
1677
+
1678
+ it 'converts the file_extension entry in a array, unless it\'s already one' do
1679
+ @reader.send(:read_rules, :file_extension => '*.rb')[:file_extension].should == ['*.rb']
1680
+ end
1681
+
1682
+ it 'uses an empty array as default value' do
1683
+ @reader.send(:read_rules, {})[:file_extension].should == []
1684
+ end
1685
+
1686
+ end
1687
+
1688
+ end
1689
+
1690
+ end
1691
+
1692
+ describe Ruber::PluginSpecificationReader::Option do
1693
+
1694
+ describe '#default' do
1695
+
1696
+ it 'should work as the base class method if the value isn\'t a string' do
1697
+ o = Ruber::PluginSpecificationReader::Option.new :default => 1
1698
+ o.default.should == 1
1699
+ o.default = true
1700
+ o.default.should be_true
1701
+ o.default = %w[a b c]
1702
+ o.default.should == %w[a b c]
1703
+ end
1704
+
1705
+ it 'should return the value as it is if it is a string and the "eval_default" entry is false' do
1706
+ o = Ruber::PluginSpecificationReader::Option.new :default => "puts", :eval_default => false
1707
+ o.default.should == 'puts'
1708
+ end
1709
+
1710
+ it 'should call "eval" on the value, using TOPLEVEL_BINDING as second argument, if the value is a string and no argument is given' do
1711
+ o = Ruber::PluginSpecificationReader::Option.new :default => "1+3", :eval_default => true
1712
+ flexmock(o).should_receive(:eval).with("1+3", TOPLEVEL_BINDING).and_return(4)
1713
+ o.default.should == 4
1714
+ end
1715
+
1716
+ it 'should call "eval" on the value, using the argument as second argument to eval, if the value is a string and an argument is given' do
1717
+ o = Ruber::PluginSpecificationReader::Option.new :default => "1+3", :eval_default => true
1718
+ b = binding
1719
+ flexmock(o).should_receive(:eval).with("1+3", b).and_return(4)
1720
+ o.default(b).should == 4
1721
+ end
1722
+
1723
+ it 'should return the value as it is if eval raises NoMethodError, NameError, ArgumentError or SyntaxError' do
1724
+ o = Ruber::PluginSpecificationReader::Option.new :default => "class"
1725
+ o.default.should == 'class'
1726
+ o.default = 'XYZ'
1727
+ o.default.should == 'XYZ'
1728
+ o.default = 'x'
1729
+ o.default.should == 'x'
1730
+ o.default = 'require'
1731
+ o.default.should == 'require'
1732
+ end
1733
+
1734
+ end
1735
+
1736
+ describe 'to_os' do
1737
+
1738
+ it 'should return an OpenStruct' do
1739
+ o = Ruber::PluginSpecificationReader::Option.new :default => 1, :x => 'a'
1740
+ o.to_os.should be_instance_of(OpenStruct)
1741
+ end
1742
+
1743
+ it 'should put the value returned by the #default method in the :default attribute of the OpenStruct' do
1744
+ o = Ruber::PluginSpecificationReader::Option.new :default => "1", :x => 'a'
1745
+ flexmock(o).should_receive(:default).once.and_return 1
1746
+ o.to_os.default.should == 1
1747
+ end
1748
+
1749
+ it 'should pass the argument to #default, using TOPLEVEL_BINDING if it isn\'t given' do
1750
+ o = Ruber::PluginSpecificationReader::Option.new :default => "1", :x => 'a'
1751
+ flexmock(o).should_receive(:default).once.with(TOPLEVEL_BINDING).and_return 1
1752
+ o.to_os
1753
+ b = binding
1754
+ flexmock(o).should_receive(:default).once.with(b).and_return 1
1755
+ o.to_os(b)
1756
+ end
1757
+
1758
+ it 'should store all the entries except default in the returned object as they are' do
1759
+ o = Ruber::PluginSpecificationReader::Option.new :default => "1", :x => 'puts'
1760
+ o.to_os.x.should == 'puts'
1761
+ end
1762
+
1763
+ end
1764
+
1765
+ end