ruber 0.0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,304 @@
1
+ require 'spec/common'
2
+ require 'ruber/gui_states_handler'
3
+
4
+ describe Ruber::GuiStatesHandler do
5
+
6
+ describe '.included' do
7
+
8
+ class TestObject < Qt::Object
9
+ end
10
+
11
+ it 'creates the "ui_state_changed(QString, bool)" signal if included in a class derived from Qt::Object' do
12
+ flexmock(TestObject).should_receive(:signals).with("ui_state_changed(QString, bool)").once
13
+ TestObject.send :include, Ruber::GuiStatesHandler
14
+ end
15
+
16
+ it 'doesn\'t attempt to create the "ui_state_changed(QString, bool)" signal if included in a class not derived from Qt::Object' do
17
+ cls = Class.new
18
+ flexmock(cls).should_receive(:signals).never
19
+ cls.send :include, Ruber::GuiStatesHandler
20
+ end
21
+
22
+ it 'doesn\'t attempt to create the "ui_state_changed(QString, bool)" signal if included in a modules' do
23
+ cls = Module.new
24
+ flexmock(cls).should_receive(:signals).never
25
+ cls.send :include, Ruber::GuiStatesHandler
26
+ end
27
+
28
+ end
29
+
30
+ describe '#initialize_states_handler' do
31
+
32
+ it 'creates an empty hash of states and an empty hash of state handlers' do
33
+ o = Object.new
34
+ o.extend Ruber::GuiStatesHandler
35
+ o.send :initialize_states_handler
36
+ o.instance_variable_get(:@gui_state_handler_states).should == {}
37
+ o.instance_variable_get(:@gui_state_handler_handlers).should == {}
38
+ end
39
+
40
+ end
41
+
42
+ describe '#register_action_handler' do
43
+
44
+ before do
45
+ @handler = Object.new
46
+ @handler.extend Ruber::GuiStatesHandler
47
+ @handler.send :initialize_states_handler
48
+ end
49
+
50
+ it 'creates a new Data object for the action, passing it the action, the block and the extra_id entry of the optional hash as argument' do
51
+ flexmock(Ruber::GuiStatesHandler::Data).should_receive(:new).once.with(KDE::Action, Proc, nil).and_return Object.new
52
+ flexmock(Ruber::GuiStatesHandler::Data).should_receive(:new).once.with(KDE::Action, Proc, :a).and_return Object.new
53
+ @handler.register_action_handler(KDE::Action.new(nil), ['x']){}
54
+ @handler.register_action_handler(KDE::Action.new(nil), ['x'], :extra_id => :a){}
55
+ end
56
+
57
+ it 'adds the Data object to the entries corresponding to the states in the second argument in the state handlers hash' do
58
+ a1 = KDE::Action.new(nil)
59
+ a2 = KDE::Action.new(nil)
60
+ blk1 = Proc.new{true}
61
+ blk2 = Proc.new{false}
62
+ @handler.register_action_handler a1, ['x'], &blk1
63
+ h = @handler.instance_variable_get(:@gui_state_handler_handlers)
64
+ data1 = Ruber::GuiStatesHandler::Data.new(a1, blk1, nil)
65
+ h['x'].should == [data1]
66
+ @handler.register_action_handler a2, ['x', 'y'], :extra_id => :a, &blk2
67
+ data2 = Ruber::GuiStatesHandler::Data.new(a2, blk2, :a)
68
+ h['x'].should == [data1, data2]
69
+ h['y'].should == [data2]
70
+ end
71
+
72
+ it 'treats a single string passed as second argument as an array with only that string' do
73
+ a = KDE::Action.new(nil)
74
+ blk = Proc.new{true}
75
+ @handler.register_action_handler a, 'x', &blk
76
+ h = @handler.instance_variable_get(:@gui_state_handler_handlers)
77
+ h['x'].should == [Ruber::GuiStatesHandler::Data.new(a, blk, nil)]
78
+ end
79
+
80
+ it 'convert any symbol in the second argument to a string' do
81
+ h = @handler.instance_variable_get(:@gui_state_handler_handlers)
82
+ @handler.register_action_handler(KDE::Action.new(nil), [:a, 'b']){}
83
+ h['a'].should_not be_empty
84
+ h[:a].should be_empty
85
+ end
86
+
87
+ it 'raises ArgumentError if no block is given and the second argument is an array with more than one element' do
88
+ lambda{@handler.register_action_handler KDE::Action.new(nil), ['x', 'y']}.should raise_error(ArgumentError, "If more than one state is supplied, a block is needed")
89
+ end
90
+
91
+
92
+ it 'creates a default handler which returns true or false according to the value of the state if no block is given and the second argument is a string or symbol or an array with a single element' do
93
+ h = @handler.instance_variable_get(:@gui_state_handler_handlers)
94
+ @handler.register_action_handler(KDE::Action.new(nil), 'a')
95
+ @handler.register_action_handler(KDE::Action.new(nil), :b)
96
+ h['a'][0].handler.call('a' => true).should be_true
97
+ h['a'][0].handler.call('a' => false).should be_false
98
+ h['b'][0].handler.call('b' => true).should be_true
99
+ h['b'][0].handler.call('b' => false).should be_false
100
+
101
+ end
102
+
103
+ it 'creates a default handler which returns true or false according to the opposite of the value of the state if no block is given and the second argument is a string or symbol starting with !' do
104
+ h = @handler.instance_variable_get(:@gui_state_handler_handlers)
105
+ @handler.register_action_handler(KDE::Action.new(nil), '!a')
106
+ @handler.register_action_handler(KDE::Action.new(nil), :"!b")
107
+ h['a'][0].handler.call('a' => true).should be_false
108
+ h['a'][0].handler.call('a' => false).should be_true
109
+ h['b'][0].handler.call('b' => true).should be_false
110
+ h['b'][0].handler.call('b' => false).should be_true
111
+ end
112
+
113
+ it 'calls the handler passing it the gui states and enables or disables the action according to the returned value if the :check option is given' do
114
+ a1 = KDE::Action.new(nil)
115
+ a2 = KDE::Action.new(nil)
116
+ @handler.change_state 'a', true
117
+ @handler.change_state 'b', false
118
+ flexmock(a1).should_receive(:enabled=).with(true).once
119
+ flexmock(a2).should_receive(:enabled=).with(false).once
120
+ @handler.register_action_handler(a1, 'a', :check => true)
121
+ @handler.register_action_handler(a2, "b", :check => true)
122
+ end
123
+
124
+ it 'doesn\'t call the handlerif the :check option is not given' do
125
+ a1 = KDE::Action.new(nil)
126
+ a2 = KDE::Action.new(nil)
127
+ @handler.change_state 'a', true
128
+ @handler.change_state 'b', false
129
+ flexmock(a1).should_receive(:enabled=).never
130
+ flexmock(a2).should_receive(:enabled=).never
131
+ @handler.register_action_handler(a1, 'a', :check => false)
132
+ @handler.register_action_handler(a2, "b", :check => false)
133
+ end
134
+
135
+ end
136
+
137
+ describe '#remove_action_handler_for' do
138
+
139
+ before do
140
+ @handler = Object.new
141
+ @handler.extend Ruber::GuiStatesHandler
142
+ @handler.send :initialize_states_handler
143
+ end
144
+
145
+ describe ', when the first argument is a KDE::Action' do
146
+
147
+ it 'removes all the handlers corresponding to the action from the handler list' do
148
+ a = KDE::Action.new(nil){self.object_name = 'a'}
149
+ @handler.register_action_handler(KDE::Action.new(nil), %w[x y]){}
150
+ @handler.register_action_handler(a, %w[x z]){}
151
+ @handler.register_action_handler(KDE::Action.new(nil), %w[z w]){}
152
+ @handler.remove_action_handler_for a
153
+ @handler.instance_variable_get(:@gui_state_handler_handlers).each_value.any? do |v|
154
+ v.any?{|d| d.action.equal? a}
155
+ end.should be_false
156
+ end
157
+
158
+ end
159
+
160
+ describe ', when the first argument is a string' do
161
+
162
+ it 'removes all the handlers corresponding to actions having the first argument as object name if the second argument is nil' do
163
+ a1 = KDE::Action.new(nil){self.object_name = 'a'}
164
+ a2= KDE::Action.new(nil){self.object_name = 'a'}
165
+ @handler.register_action_handler(a1, %w[x z]){}
166
+ @handler.register_action_handler(KDE::Action.new(nil), %w[x y]){}
167
+ @handler.register_action_handler(a2, %w[z w], :extra_id => 'x'){}
168
+ @handler.remove_action_handler_for 'a'
169
+ @handler.instance_variable_get(:@gui_state_handler_handlers).each_value.any? do |v|
170
+ v.any?{|d| d.action.object_name == 'a'}
171
+ end.should be_false
172
+ end
173
+
174
+ it 'removes all the handlers corresponding to actions having the first argument as object name and the second as extra_id if the second argument is not nil' do
175
+ a1 = KDE::Action.new(nil){self.object_name = 'a'}
176
+ a2= KDE::Action.new(nil){self.object_name = 'a'}
177
+ @handler.register_action_handler(a1, %w[x z]){}
178
+ @handler.register_action_handler(KDE::Action.new(nil), %w[x y]){}
179
+ @handler.register_action_handler(a2, %w[z w], :extra_id => 'x'){}
180
+ @handler.remove_action_handler_for 'a', 'x'
181
+ @handler.instance_variable_get(:@gui_state_handler_handlers).each_value.any? do |v|
182
+ v.any?{|d| d.action.object_name == 'a' and d.extra_id == 'x'}
183
+ end.should be_false
184
+ @handler.instance_variable_get(:@gui_state_handler_handlers).each_value.any? do |v|
185
+ v.any?{|d| d.action.object_name == 'a' and d.extra_id != 'x'}
186
+ end.should be_true
187
+ end
188
+
189
+ it 'removes all entries corresponding to empty arrays from the handlers hash' do
190
+ a1 = KDE::Action.new(nil){self.object_name = 'a'}
191
+ a2= KDE::Action.new(nil){self.object_name = 'a'}
192
+ @handler.register_action_handler(a1, %w[x z]){}
193
+ @handler.register_action_handler(KDE::Action.new(nil), %w[x y]){}
194
+ @handler.register_action_handler(a2, %w[z w], :extra_id => 'x'){}
195
+ @handler.remove_action_handler_for 'a'
196
+ hash = @handler.instance_variable_get(:@gui_state_handler_handlers)
197
+ hash.should_not have_key('z')
198
+ hash.any?{|k, v| v.empty? }.should_not be_true
199
+ end
200
+
201
+ end
202
+
203
+ describe '#change_state' do
204
+
205
+ class TestObject < Qt::Object
206
+ include Ruber::GuiStatesHandler
207
+ def initialize
208
+ super
209
+ initialize_states_handler
210
+ end
211
+ end
212
+
213
+ before do
214
+ @handler = TestObject.new
215
+ end
216
+
217
+ it 'sets the state corresponding to the first argument to true or false depending on the second argument' do
218
+ @handler.change_state 'x', true
219
+ @handler.instance_variable_get(:@gui_state_handler_states)['x'].should be_true
220
+ @handler.change_state 'x', false
221
+ @handler.instance_variable_get(:@gui_state_handler_states)['x'].should be_false
222
+ @handler.change_state 'x', 3
223
+ @handler.instance_variable_get(:@gui_state_handler_states)['x'].should be_true
224
+ @handler.change_state 'x', nil
225
+ @handler.instance_variable_get(:@gui_state_handler_states)['x'].should be_false
226
+ end
227
+
228
+ it 'converts the first argument to a string' do
229
+ @handler.change_state :x, true
230
+ @handler.instance_variable_get(:@gui_state_handler_states)['x'].should be_true
231
+ @handler.instance_variable_get(:@gui_state_handler_states)[:x].should be_nil
232
+ end
233
+
234
+ it 'calls the handler of each action associated with the state passing it the states hash' do
235
+ @handler.instance_variable_get(:@gui_state_handler_states)['y'] = false
236
+ m1 = flexmock{|m| m.should_receive(:test).once.with({'x' => true, 'y' => false})}
237
+ m2 = flexmock{|m| m.should_receive(:test).once.with({'x' => true, 'y' => false})}
238
+ m3 = flexmock{|m| m.should_receive(:test).never}
239
+ @handler.register_action_handler(KDE::Action.new(nil), %w[x y], :check => false){|states| m1.test states}
240
+ @handler.register_action_handler(KDE::Action.new(nil), %w[x], :check => false){|states| m2.test states}
241
+ @handler.register_action_handler(KDE::Action.new(nil), %w[y], :check => false){|states| m3.test states}
242
+ @handler.change_state 'x', true
243
+ end
244
+
245
+ it 'enables or disables the actions associated with the state according to the value returned by the handler' do
246
+ @handler.instance_variable_get(:@gui_state_handler_states)['y'] = false
247
+ actions = 3.times.map{KDE::Action.new nil}
248
+ m1 = flexmock{|m| m.should_receive(:test).once.with({'x' => true, 'y' => false}).and_return true}
249
+ m2 = flexmock{|m| m.should_receive(:test).once.with({'x' => true, 'y' => false}).and_return false}
250
+ m3 = flexmock{|m| m.should_receive(:test).never}
251
+ flexmock(actions[0]).should_receive(:enabled=).with(true).once
252
+ flexmock(actions[1]).should_receive(:enabled=).with(false).once
253
+ flexmock(actions[2]).should_receive(:enabled=).never
254
+ @handler.register_action_handler(actions[0], %w[x y], :check => false){|states| m1.test states}
255
+ @handler.register_action_handler(actions[1], %w[x], :check => false){|states| m2.test states}
256
+ @handler.register_action_handler(actions[2], %w[y], :check => false){|states| m3.test states}
257
+ @handler.change_state 'x', true
258
+ end
259
+
260
+ it 'emits the "ui_state_changed(QString, bool)" signal passing the name of the state and the value if self is a Qt::Object' do
261
+ m = flexmock{|mk| mk.should_receive(:state_changed).once.with('x', true)}
262
+ @handler.connect(SIGNAL('ui_state_changed(QString, bool)')){|state, val| m.state_changed state, val}
263
+ @handler.change_state 'x', 3
264
+ end
265
+
266
+ it 'should not attempt to emit the "ui_state_changed" signal if self is not a Qt::Object' do
267
+ cls = Class.new do
268
+ include Ruber::GuiStatesHandler
269
+ def initialize
270
+ initialize_states_handler
271
+ end
272
+ end
273
+ @handler = cls.new
274
+ flexmock(@handler).should_receive(:emit).never
275
+ @handler.change_state 'x', 3
276
+ end
277
+
278
+ end
279
+
280
+ describe '#state' do
281
+
282
+ before do
283
+ @handler = Object.new
284
+ @handler.extend Ruber::GuiStatesHandler
285
+ @handler.send :initialize_states_handler
286
+ end
287
+
288
+ it 'returns the value of the state, after converting the name to a string' do
289
+ @handler.instance_variable_get(:@gui_state_handler_states)['a'] = true
290
+ @handler.instance_variable_get(:@gui_state_handler_states)['b'] = false
291
+ @handler.state('a').should be_true
292
+ @handler.state(:b).should be_false
293
+ end
294
+
295
+ it 'returns nil if the state is not known' do
296
+ @handler.state('a').should be_nil
297
+ @handler.state(:b).should be_nil
298
+ end
299
+
300
+ end
301
+
302
+ end
303
+
304
+ end
@@ -0,0 +1,214 @@
1
+ require 'spec/common'
2
+
3
+ require 'tmpdir'
4
+
5
+ require 'ruber/kde_config_option_backend'
6
+
7
+ #We need to generate a different file for each test, since otherwise the config object generated for one spec will also be used for the others (since they're KDE::SharedConfig objects)
8
+ def generate_random_file base = "ruber_kde_config_option_backend"
9
+ File.join Dir.tmpdir, "#{base}-#{5.times.map{rand 10}.join}"
10
+ end
11
+
12
+
13
+ describe 'Ruber::KDEConfigSettingsBackend when created' do
14
+
15
+ it 'should use the global kde config object if the constructor is called with no arguments' do
16
+ cfg = KDE::Config.new File.join( Dir.tmpdir, 'ruber_kde_config_option_backend'), KDE::Config::SimpleConfig
17
+ flexmock(KDE::Global).should_receive(:config).once.and_return cfg
18
+ back = Ruber::KDEConfigSettingsBackend.new
19
+ back.instance_variable_get(:@config).should equal(cfg)
20
+ end
21
+
22
+ it 'should use a new full KDE::SharedConfig object corresponding to the path given as argument if called with one argument' do
23
+ filename = generate_random_file
24
+ back = Ruber::KDEConfigSettingsBackend.new filename
25
+ back.instance_variable_get(:@config).name.should == filename
26
+ end
27
+
28
+ it 'should use a new KDE::SharedConfig object corresponding to the path and the mode given as arguments if called with two arguments' do
29
+ filename = generate_random_file
30
+ cfg = KDE::SharedConfig.open_config filename, KDE::Config::SimpleConfig
31
+ flexmock(KDE::SharedConfig).should_receive(:open_config).once.with(filename, KDE::Config::SimpleConfig).and_return cfg
32
+ back = Ruber::KDEConfigSettingsBackend.new filename, KDE::Config::SimpleConfig
33
+ back.instance_variable_get(:@config).name.should == filename
34
+ end
35
+
36
+ it 'should read the "Yaml options" entry of the "Ruber Internal" group and store the result in the @yaml_options instance variable, after having converted it' do
37
+ filename = generate_random_file
38
+ File.open(filename, 'w') do |f|
39
+ data = <<-EOS
40
+ [Ruber Internal]
41
+ Yaml options=g1/o1,g1/o2,g2/o3
42
+ EOS
43
+ f.write data
44
+ end
45
+ back = Ruber::KDEConfigSettingsBackend.new filename
46
+ FileUtils.rm_f filename
47
+ back.instance_variable_get(:@yaml_options).should == [[:g1, :o1], [:g1, :o2], [:g2, :o3]]
48
+ end
49
+
50
+ end
51
+
52
+ describe 'Ruber::KDEConfigSettingsBackend#[]' do
53
+
54
+ before(:all) do
55
+ @filename = generate_random_file
56
+ data = <<-EOS
57
+ [Ruber Internal]
58
+ Yaml options=group_two/option_two,group_two/option_three
59
+
60
+ [Group One]
61
+ Option 1=test string
62
+ Option 2=1224
63
+
64
+ [Group Two]
65
+ Option One=ab,cd,ef
66
+ Option Two={a: b, c: :d}
67
+ Option Three=:xyz
68
+ EOS
69
+ File.open( @filename, 'w'){|f| f.write data}
70
+ end
71
+
72
+ after :all do
73
+ FileUtils.rm_f @filename
74
+ end
75
+
76
+ it 'should return the value of option corresponding to the automatically determined human-friendly versions of the group and name of the argument' do
77
+ back = Ruber::KDEConfigSettingsBackend.new @filename
78
+ opt = OS.new({:name => :option_1, :group => :group_one, :default => ''})
79
+ back[opt].should == 'test string'
80
+ opt = OS.new({:name => :option_2, :group => :group_one, :default => 12})
81
+ back[opt].should == 1224
82
+ opt = OS.new({:name => :option_one, :group => :group_two, :default => []})
83
+ back[opt].should == %w[ab cd ef]
84
+ end
85
+
86
+ it 'should process the string using YAML if it is included in the Yaml options list' do
87
+ back = Ruber::KDEConfigSettingsBackend.new @filename
88
+ opt = OS.new({:name => :option_two, :group => :group_two, :default => {}})
89
+ back[opt].should == {'a' => 'b', 'c' => :d}
90
+ opt = OS.new({:name => :option_three, :group => :group_two, :default => :abc})
91
+ back[opt].should == :xyz
92
+ end
93
+
94
+ it 'should process the string using YAML if the option\'s default value isn\'t manageable using KDE::Config' do
95
+ back = Ruber::KDEConfigSettingsBackend.new @filename
96
+ opt = OS.new({:name => :option_2, :group => :group_one, :default => nil})
97
+ flexmock(YAML).should_receive(:load).with('1224').once.and_return 1224
98
+ back[opt].should == 1224
99
+ end
100
+
101
+ it 'should return a deep duplicate of the default value for the option if the option isn\'t in the file' do
102
+ back = Ruber::KDEConfigSettingsBackend.new @filename
103
+ opt = OS.new({:name => :option_6, :group => :group_one, :default => {:a => 2}})
104
+ back[opt].should == {:a => 2}
105
+ back[opt].should_not equal(opt.default)
106
+ opt = OS.new({:name => :option_2, :group => :group_three, :default => 'hello'})
107
+ back[opt].should == 'hello'
108
+ back[opt].should_not equal(opt.default)
109
+ opt = OS.new({:name => :option_6, :group => :group_one, :default => {:a => %w[a b]}})
110
+ back[opt].should == {:a => %w[a b]}
111
+ back[opt].should_not equal(opt.default)
112
+ back[opt][:a].should_not equal(opt.default[:a])
113
+ opt = OS.new({:name => :option_7, :group => :group_three, :default => 3})
114
+ back[opt].should == 3
115
+ end
116
+
117
+ end
118
+
119
+ describe 'Ruber::KDEConfigSettingsBackend#[]' do
120
+
121
+ # before(:all) do
122
+ # end
123
+
124
+ before do
125
+ @filename = generate_random_file
126
+ data = <<-EOS
127
+ [Ruber Internal]
128
+ Yaml options=group_two/option_two,group_two/option_three
129
+
130
+ [Group One]
131
+ Option 1=test string
132
+ Option 2=1224
133
+
134
+ [Group Two]
135
+ Option One=ab,cd,ef
136
+ Option Two={a: b, c: :d}
137
+ Option Three=:xyz
138
+ EOS
139
+ File.open( @filename, 'w'){|f| f.write data}
140
+ @back = Ruber::KDEConfigSettingsBackend.new @filename
141
+ end
142
+
143
+ it 'should write the options which the KDE configuration system can handle' do
144
+ opts = {
145
+ OS.new({:name => :option_1, :group => :group_one, :default => ''}) => 'hello',
146
+ OS.new({:name => :option_one, :group => :group_two, :default => []}) => %w[x y],
147
+ OS.new({:name => :o1, :group => :G3, :default => 0}) => 5
148
+ }
149
+ @back.write opts
150
+ cfg = KDE::Config.new @filename, KDE::Config::SimpleConfig
151
+ cfg.group('Group One').read_entry('Option 1', '').should == 'hello'
152
+ cfg.group('Group Two').read_entry('Option One', []).should == %w[x y]
153
+ cfg.group('G3').read_entry('O1', 1).should == 5
154
+ end
155
+
156
+ it 'should write the options which the KDE configuration system can\'t handle converting them to YAML and store them in the "Yaml options option"' do
157
+ opts = {
158
+ OS.new({:name => :option_3, :group => :group_one, :default => (1..2)}) => (3..5),
159
+ OS.new({:name => :option_two, :group => :group_two, :default => {}}) => {1 => :x},
160
+ }
161
+ @back.write opts
162
+ cfg = KDE::Config.new @filename, KDE::Config::SimpleConfig
163
+ YAML.load(cfg.group('Group One').read_entry('Option 3', '')).should == (3..5)
164
+ YAML.load(cfg.group('Group Two').read_entry('Option Two', '')).should == {1 => :x}
165
+ cfg.group('Ruber Internal').read_entry('Yaml options', []).should =~ %w[group_two/option_two group_two/option_three group_one/option_3]
166
+ end
167
+
168
+ it 'should write the options which whose value is of a different class from the default value (except for true and false) converting them to YAML and store them in the "Yaml options option"' do
169
+ opts = {
170
+ OS.new({:name => :option_3, :group => :group_one, :default => 'abc'}) => %w[a b],
171
+ OS.new({:name => :option_two, :group => :group_two, :default => []}) => 3,
172
+ OS.new({:name => :option_four, :group => :group_three, :default => true}) => false,
173
+ OS.new({:name => :option_five, :group => :group_three, :default => false}) => true,
174
+ }
175
+ @back.write opts
176
+ cfg = KDE::Config.new @filename, KDE::Config::SimpleConfig
177
+ YAML.load(cfg.group('Group One').read_entry('Option 3', 'abc')).should == %w[a b]
178
+ YAML.load(cfg.group('Group Two').read_entry('Option Two', '')).should == 3
179
+ cfg.group('Group Three').read_entry('Option Four', true).should == false
180
+ cfg.group('Group Three').read_entry('Option Five', false).should == true
181
+ cfg.group('Ruber Internal').read_entry('Yaml options', []).should =~ %w[group_two/option_two group_two/option_three group_one/option_3]
182
+ end
183
+
184
+ it 'should keep the options which haven\'t been explicitly written' do
185
+ opts = {
186
+ OS.new({:name => :option_1, :group => :group_one, :default => ''}) => 'hello',
187
+ OS.new({:name => :o1, :group => :G3, :default => 0}) => 5,
188
+ OS.new({:name => :o2, :group => :G3, :default => /ab/}) => /abc/
189
+ }
190
+ @back.write opts
191
+ cfg = KDE::Config.new @filename, KDE::Config::SimpleConfig
192
+ cfg.group('Group One').read_entry('Option 2', 0).should == 1224
193
+ cfg.group('Group Two').read_entry('Option One', []).should == %w[ab cd ef]
194
+ YAML.load(cfg.group('Group Two').read_entry('Option Two', '')).should == {'a' => 'b', 'c' => :d}
195
+ YAML.load(cfg.group('Group Two').read_entry('Option Three', '')).should == :xyz
196
+ cfg.group('Ruber Internal').read_entry('Yaml options', []).should =~ %w[group_two/option_two group_two/option_three G3/o2]
197
+ end
198
+
199
+ it 'should not write options whose value is equal to their default value' do
200
+ opts = {
201
+ OS.new({:name => :option_2, :group => :group_one, :default => 5}) => 5,
202
+ OS.new({:name => :option_3, :group => :group_three, :default => 'ab'}) => 'ab',
203
+ }
204
+ @back.write opts
205
+ cfg = KDE::Config.new @filename, KDE::Config::SimpleConfig
206
+ cfg.group('Group One').has_key('Option 2').should be_false
207
+ cfg.group('Group Three').has_key('Option 3').should be_false
208
+ end
209
+
210
+ after do
211
+ FileUtils.rm_f @filename
212
+ end
213
+
214
+ end