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,990 @@
1
+ require 'spec/common'
2
+
3
+ require 'set'
4
+ require 'stringio'
5
+ require 'flexmock/argument_types'
6
+ require 'pathname'
7
+ require 'ostruct'
8
+ require 'forwardable'
9
+ require 'dictionary'
10
+
11
+ require 'ruber/project'
12
+ require 'ruber/plugin'
13
+ require 'ruber/plugin_specification'
14
+
15
+ class TestComponentManager < Qt::Object
16
+
17
+ extend Forwardable
18
+
19
+ def_delegators :@data, :[], :<<
20
+ def_delegator :@data, :each, :each_component
21
+
22
+ signals 'component_loaded(QObject*)', 'unloading_component(QObject*)'
23
+
24
+ def initialize
25
+ super
26
+ @data = []
27
+ end
28
+
29
+ def emit_signal sig, obj
30
+ emit method(sig).call(obj)
31
+ end
32
+
33
+ end
34
+
35
+ class Application < Qt::Object
36
+ signals 'plugins_changed()'
37
+ end
38
+
39
+ unless defined? OS
40
+ OS = OpenStruct
41
+ end
42
+
43
+ describe 'an_abstract_project_spec_method', :shared => true do
44
+
45
+ include FlexMock::ArgumentTypes
46
+
47
+ before do
48
+ @comp = TestComponentManager.new
49
+ @fake_app = Application.new
50
+ @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
51
+ @mw = Qt::Widget.new
52
+ flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
53
+ flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
54
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
55
+ end
56
+
57
+ after do
58
+ FileUtils.rm_f 'test.ruprj'
59
+ end
60
+
61
+ end
62
+
63
+ describe 'Ruber::AbstractProject, when created' do
64
+
65
+ it_should_behave_like 'an_abstract_project_spec_method'
66
+
67
+ def backend file
68
+ Ruber::YamlSettingsBackend.new file
69
+ end
70
+
71
+ before do
72
+ contents = <<-EOS
73
+ :general:
74
+ :project_name: Test
75
+ EOS
76
+ @dir = make_dir_tree ['f1.ruprj'], '/tmp', {'f1.ruprj'=>contents}
77
+ @file = File.join @dir, 'f1.ruprj'
78
+ end
79
+
80
+ after do
81
+ FileUtils.rm_rf @dir
82
+ end
83
+
84
+ it 'should accept a parent, a file name and optionally the project name' do
85
+ lambda{Ruber::AbstractProject.new nil, backend(@file)}.should_not raise_error
86
+ FileUtils.rm_rf @dir
87
+ lambda{Ruber::AbstractProject.new nil, backend(@file), 'project name'}.should_not raise_error
88
+ end
89
+
90
+ it 'should use the first argument as parent' do
91
+ parent = Qt::Object.new
92
+ prj = Ruber::AbstractProject.new parent, backend(@file)
93
+ prj.parent.should equal(parent)
94
+ end
95
+
96
+ it 'sets the dialog_class instance variable to Ruber::ProjectDialog' do
97
+ parent = Qt::Object.new
98
+ prj = Ruber::AbstractProject.new parent, backend(@file)
99
+ prj.instance_variable_get(:@dialog_class).should == Ruber::ProjectDialog
100
+ end
101
+
102
+ it 'should store the path of the project file as is if it\'s absolute' do
103
+ path = @file
104
+ prj = Ruber::AbstractProject.new nil, backend(path)
105
+ prj.project_file.should == path
106
+ path = File.join Dir.pwd, 'test.ruprj'
107
+ prj = Ruber::AbstractProject.new nil, backend( path), 'Test'
108
+ prj.project_file.should == path
109
+ end
110
+
111
+ it 'should raise ArgumentError if the file doesn\'t exist and the project name is not given' do
112
+ lambda{Ruber::AbstractProject.new(nil, backend,'test.ruprj')}.should raise_error(ArgumentError)
113
+ end
114
+
115
+ it 'should raise ArgumentError if the file exists and the project name is given' do
116
+ lambda{Ruber::AbstractProject.new nil, backend, @file, 'project name'}.should raise_error(ArgumentError)
117
+ end
118
+
119
+ it 'should store the project name if the file doesn\'t exist' do
120
+ path = File.join Dir.pwd, 'test.ruprj'
121
+ prj = Ruber::AbstractProject.new nil, Ruber::YamlSettingsBackend.new( path), 'Test Project'
122
+ prj.project_name.should == 'Test Project'
123
+ end
124
+
125
+ it 'should read the project name from the file, if it exists' do
126
+ prj = Ruber::AbstractProject.new nil, backend( @file)
127
+ prj.project_name.should == 'Test'
128
+ end
129
+
130
+ it 'should call the "register_with_project" method of the plugins, passing itself as argument' do
131
+ pdf1 = OpenStruct.new({:project_extensions => {}, :project_options => {}, :name => :plug1, :project_widgets => []})
132
+ pdf2 = OpenStruct.new({:project_extensions => {}, :project_options => {}, :name => :plug2, :project_widgets => []})
133
+ plugin1 = flexmock('plugin1', :plugin_description => pdf1)
134
+ plugin2 = flexmock('plugin2', :plugin_description => pdf2)
135
+ @comp << plugin1 << plugin2
136
+ plugin1.should_receive(:register_with_project).once.with(Ruber::AbstractProject)
137
+ plugin2.should_receive(:register_with_project).once.with(Ruber::AbstractProject)
138
+ path = File.join Dir.pwd, 'test.ruprj'
139
+ prj = Ruber::AbstractProject.new nil, Ruber::YamlSettingsBackend.new( path), 'Test'
140
+ end
141
+
142
+ it 'should connect the signal \'component_loaded\' of the component manager to a block which calls the register_with_project method of the plugin' do
143
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
144
+ o = Qt::Object.new
145
+ flexmock(o).should_receive(:register_with_project).once.with(prj)
146
+ @comp.emit_signal :component_loaded, o
147
+ end
148
+
149
+ it 'should connect the signal \'unloading_component\' of the component manager to a block which calls the remove_from_project method of the plugin' do
150
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
151
+ o = Qt::Object.new
152
+ flexmock(o).should_receive(:remove_from_project).once.with(prj)
153
+ @comp.emit_signal :unloading_component, o
154
+ end
155
+
156
+ end
157
+
158
+ describe 'Ruber::AbstractProject#match_rule?' do
159
+
160
+ it_should_behave_like 'an_abstract_project_spec_method'
161
+
162
+ def backend file
163
+ Ruber::YamlSettingsBackend.new file
164
+ end
165
+
166
+ it 'returns true if the object\'s scope includes the project\'s scope and false otherwise' do
167
+ prj = Ruber::AbstractProject.new(nil, backend(File.join(Dir.pwd, 'project.ruprj')), 'Test')
168
+ flexmock(prj).should_receive(:scope).and_return(:global)
169
+ prj.match_rule?(OS.new(:scope => [:global])).should be_true
170
+ prj.match_rule?(OS.new(:scope => [:document])).should be_false
171
+ prj.match_rule?(OS.new(:scope => [:global, :document])).should be_true
172
+ end
173
+
174
+ end
175
+
176
+ describe 'Ruber::AbstractProject#scope' do
177
+
178
+ it_should_behave_like 'an_abstract_project_spec_method'
179
+
180
+ def backend file
181
+ Ruber::YamlSettingsBackend.new file
182
+ end
183
+
184
+ it 'raises NoMethodError' do
185
+ prj = Ruber::AbstractProject.new(nil, backend(File.join(Dir.pwd, 'project.ruprj')), 'Test')
186
+ lambda{prj.scope}.should raise_error(NoMethodError)
187
+ end
188
+
189
+ end
190
+
191
+ describe 'Ruber::AbstractProject#add_extension' do
192
+
193
+ it_should_behave_like 'an_abstract_project_spec_method'
194
+
195
+ def backend file
196
+ Ruber::YamlSettingsBackend.new file
197
+ end
198
+
199
+ it 'should add the given extension to the list of extensions' do
200
+ ext = Qt::Object.new
201
+ prj = Ruber::AbstractProject.new(nil, backend(File.join(Dir.pwd, 'project.ruprj')), 'Test')
202
+ prj.add_extension :test_ext, ext
203
+ prj.project_extension(:test_ext).should equal(ext)
204
+ end
205
+
206
+ it 'should raise ArgumentError if an extension with that name already exists' do
207
+ ext1 = Qt::Object.new
208
+ ext2 = Qt::Object.new
209
+ prj = Ruber::AbstractProject.new(nil, backend(File.join(Dir.pwd, 'project.ruprj')), 'Test')
210
+ prj.add_extension :test_ext, ext1
211
+ lambda{prj.add_extension(:test_ext, ext2)}.should raise_error(ArgumentError, 'An extension called \'test_ext\' already exists')
212
+ end
213
+
214
+ end
215
+
216
+ describe 'Ruber::AbstractProject#remove_extension' do
217
+
218
+ it_should_behave_like 'an_abstract_project_spec_method'
219
+
220
+ def backend file
221
+ Ruber::YamlSettingsBackend.new file
222
+ end
223
+
224
+ it 'should remove the extension with the given name from the list' do
225
+ ext1 = Qt::Object.new
226
+ ext2 = Qt::Object.new
227
+ prj = Ruber::AbstractProject.new(nil, backend(File.join(Dir.pwd, 'project.ruprj')), 'Test')
228
+ prj.add_extension :ext1, ext1
229
+ prj.add_extension :ext2, ext2
230
+ prj.remove_extension :ext2
231
+ prj.instance_variable_get(:@project_extensions).should_not include(:ext2)
232
+ prj.ext1.should equal(ext1)
233
+ end
234
+
235
+ it 'should call the "remove_from_project" method of the extension, if it provides it' do
236
+ ext1 = Qt::Object.new
237
+ def ext1.remove_from_project
238
+ end
239
+ ext2 = Qt::Object.new
240
+ flexmock(ext1).should_receive(:remove_from_project).once
241
+ prj = Ruber::AbstractProject.new(nil, backend(File.join(Dir.pwd, 'project.ruprj')), 'Test')
242
+ prj.add_extension :e1, ext1
243
+ prj.add_extension :e2, ext2
244
+ prj.remove_extension :e1
245
+ lambda{prj.remove_extension :e2}.should_not raise_error
246
+ end
247
+
248
+ it 'should do nothing if a project extension with that name doesn\'t exist' do
249
+ ext1 = Qt::Object.new
250
+ ext2 = Qt::Object.new
251
+ prj = Ruber::AbstractProject.new(nil, backend(File.join(Dir.pwd, 'project.ruprj')), 'Test')
252
+ prj.add_extension :ext1, ext1
253
+ prj.add_extension :ext2, ext2
254
+ old = prj.instance_variable_get(:@project_extensions).dup
255
+ prj.remove_extension :ext3
256
+ prj.instance_variable_get(:@project_extensions).should == old
257
+ end
258
+
259
+ end
260
+
261
+ describe 'Ruber::AbstractProject#[]=' do
262
+
263
+ it_should_behave_like 'an_abstract_project_spec_method'
264
+
265
+ def backend file
266
+ Ruber::YamlSettingsBackend.new file
267
+ end
268
+
269
+ before do
270
+ contents = <<-EOS
271
+ :general:
272
+ :project_name: Test
273
+ :g1:
274
+ :o1: 3
275
+ :g2:
276
+ :o2: xyz
277
+ :o3: [a, b]
278
+ EOS
279
+ @dir = make_dir_tree ['test.ruprj'], '/tmp', {'test.ruprj' => contents}
280
+ @file = File.join @dir, 'test.ruprj'
281
+ @options = [
282
+ OS.new({:name => :o1, :group => :g1, :default => 0}),
283
+ OS.new({:name => :o2, :group => :g2, :default => 'abc'}),
284
+ OS.new({:name => :o3, :group => :g2, :default => []}),
285
+ ]
286
+ @prj = Ruber::AbstractProject.new nil, backend(@file)
287
+ @options.each{|o| @prj.add_option o}
288
+ end
289
+
290
+ after do
291
+ FileUtils.rm_rf @dir
292
+ end
293
+
294
+ it 'should change the value of the option whose name is passed as first argument' do
295
+ @prj[:g1, :o1]= 6
296
+ @prj[:g2, :o2] = 'ABC'
297
+ @prj[:g2, :o3] = :x
298
+ @prj[:g1, :o1].should == 6
299
+ @prj[:g2, :o2].should == 'ABC'
300
+ @prj[:g2, :o3].should == :x
301
+ end
302
+
303
+ it 'should emit the "option_changed(QString, QString)" signal if the option is modified, passing the group and the name of the option (converted to strings) as argument' do
304
+ test = flexmock('test') do |mk|
305
+ mk.should_receive(:option_changed).once.with('g1', 'o1')
306
+ mk.should_receive(:option_changed).once.with('g2', 'o2')
307
+ mk.should_receive(:option_changed).once.with('g2', 'o3')
308
+ end
309
+ @prj.connect(SIGNAL('option_changed(QString, QString)')){|g, n| test.option_changed g, n}
310
+ @prj[:g1, :o1]= 6
311
+ @prj[:g2, :o2] = 'ABC'
312
+ @prj[:g2, :o3] = :x
313
+ end
314
+
315
+ it 'should not emit the option_changed signal if the new value of the option is the same as the old (according to eql?)' do
316
+ test = flexmock('test') do |mk|
317
+ mk.should_receive(:option_changed).with('g1', 'o1').never
318
+ mk.should_receive(:option_changed).with('g2', 'o2').never
319
+ mk.should_receive(:option_changed).with('g2', 'o3').never
320
+ end
321
+ @prj[:g1, :o1]= 5
322
+ @prj[:g2, :o2] = 'xyz'
323
+ @prj[:g2, :o3] = :a
324
+ @prj.connect(SIGNAL('option_changed(QString, QString)')){|g, n| test.option_changed g, n}
325
+ @prj[:g1, :o1]= 5
326
+ @prj[:g2, :o2] = 'xyz'
327
+ @prj[:g2, :o3] = :a
328
+
329
+ end
330
+
331
+ end
332
+
333
+ describe 'Ruber::AbstractProject#project_directory' do
334
+
335
+ it_should_behave_like 'an_abstract_project_spec_method'
336
+
337
+ def backend file
338
+ Ruber::YamlSettingsBackend.new file
339
+ end
340
+
341
+ it 'should return the absolute path of the project directory' do
342
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
343
+ prj.project_directory.should == Dir.pwd
344
+ end
345
+
346
+ end
347
+
348
+ describe 'Ruber::AbstractProject#method_missing' do
349
+
350
+ it_should_behave_like 'an_abstract_project_spec_method'
351
+
352
+ def backend file
353
+ Ruber::YamlSettingsBackend.new file
354
+ end
355
+
356
+ it 'should return the project extension object with the same name as the method, if it exists' do
357
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
358
+ p1 = flexmock('p1')
359
+ prj.instance_variable_get(:@project_extensions)[:p1] = p1
360
+ prj.p1.should == p1
361
+ end
362
+
363
+ it 'should raise ArgumentError if any arguments are passed to the method' do
364
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
365
+ p1 = flexmock('p1')
366
+ prj.instance_variable_get(:@project_extensions)[:p1] = p1
367
+ lambda{prj.p1 'x'}.should raise_error(ArgumentError, "wrong number of arguments (1 for 0)")
368
+ end
369
+
370
+ it 'should raise ArgumentError if there\'s no project extension with the name of the method' do
371
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
372
+ p1 = flexmock('p1')
373
+ prj.instance_variable_get(:@project_extensions)[:p1] = p1
374
+ lambda{prj.p2}.should raise_error(ArgumentError, "No project extension with name p2")
375
+ end
376
+
377
+ end
378
+
379
+ describe 'Ruber::AbstractProject#project_extension' do
380
+
381
+ it_should_behave_like 'an_abstract_project_spec_method'
382
+
383
+ def backend file
384
+ Ruber::YamlSettingsBackend.new file
385
+ end
386
+
387
+ it 'should return the project extension with the given name, if it exists' do
388
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
389
+ p1 = flexmock('p1')
390
+ prj.instance_variable_get(:@project_extensions)[:p1] = p1
391
+ prj.project_extension(:p1).should == p1
392
+ end
393
+
394
+ it 'should return nil if no project extension with that name exists' do
395
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test.prj'
396
+ prj.project_extension(:p1).should be_nil
397
+ end
398
+
399
+ end
400
+
401
+ describe Ruber::AbstractProject do
402
+
403
+ def backend file
404
+ Ruber::YamlSettingsBackend.new file
405
+ end
406
+
407
+ it_should_behave_like 'an_abstract_project_spec_method'
408
+
409
+ describe '#each_extension' do
410
+
411
+ before do
412
+ @prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
413
+ @exts = {:a => 1, :b => 2, :c => 3}
414
+ @prj.instance_variable_set(:@project_extensions, @exts)
415
+ end
416
+
417
+ describe ', when called with a block' do
418
+
419
+ it 'calls the block for each extension, passing it the name of the extension and the object itself as arguments' do
420
+ res = {}
421
+ @prj.each_extension{|i, j| res[i] = j}
422
+ res.should == @exts
423
+ end
424
+
425
+ end
426
+
427
+ describe ', when called without a block' do
428
+
429
+ it 'returns an enumerator which, whose each method calls the block for each extension, passing it the name of the extension and the object itself as arguments' do
430
+ res = {}
431
+ enum = @prj.each_extension
432
+ enum.should be_a(Enumerator)
433
+ enum.each{|i, j| res[i] = j}
434
+ res.should == @exts
435
+ end
436
+
437
+ end
438
+
439
+ end
440
+
441
+ describe '#extensions' do
442
+
443
+ before do
444
+ @prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
445
+ @exts = {:a => "1", :b => "2", :c => "3"}
446
+ @prj.instance_variable_set(:@project_extensions, @exts)
447
+ end
448
+
449
+ it 'returns a hash containing the extensions with their names' do
450
+ @prj.extensions.should == @exts
451
+ end
452
+
453
+ it 'returns a hash which can be modified without modifying the internal list of extensions' do
454
+ @prj.extensions.should_not be_the_same_as(@exts)
455
+ end
456
+
457
+ end
458
+
459
+ describe '#has_extension?' do
460
+
461
+ before do
462
+ @prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
463
+ @exts = {:a => "1", :b => "2", :c => "3"}
464
+ @prj.instance_variable_set(:@project_extensions, @exts)
465
+ end
466
+
467
+ it 'returns true if the project contains an extension with the given name' do
468
+ @prj.has_extension?(:a).should == true
469
+ end
470
+
471
+ it 'returns false if the project doesn\'t contain an extension with the given name' do
472
+ @prj.has_extension?(:x).should == false
473
+ end
474
+
475
+ end
476
+
477
+ end
478
+
479
+ describe 'Ruber::AbstractProject#close' do
480
+
481
+ it_should_behave_like 'an_abstract_project_spec_method'
482
+
483
+ include FlexMock::ArgumentTypes
484
+
485
+ def backend file
486
+ Ruber::YamlSettingsBackend.new file
487
+ end
488
+
489
+ describe ', when the argument is true' do
490
+
491
+ it 'calls the "save" method' do
492
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
493
+ flexmock(prj).should_receive(:save).once
494
+ prj.close true
495
+ end
496
+
497
+ it 'returns false if save returns false' do
498
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
499
+ flexmock(prj).should_receive(:save).once.and_return false
500
+ prj.close(true).should be_false
501
+ end
502
+
503
+ it 'returns true if save returns true' do
504
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
505
+ flexmock(prj).should_receive(:save).once.and_return true
506
+ prj.close(true).should be_true
507
+ end
508
+
509
+ end
510
+
511
+ describe ', when the argument is false' do
512
+
513
+ it 'doesn\'t call the "save" method' do
514
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
515
+ flexmock(prj).should_receive(:save).never
516
+ prj.close false
517
+ end
518
+
519
+ it 'always returns true' do
520
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
521
+ prj.close(false).should be_true
522
+ end
523
+
524
+ end
525
+
526
+ it 'should emit the "closing(QObject*)" signal, passing itself as argument' do
527
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
528
+ m = flexmock{|mk| mk.should_receive(:project_closing).with(prj.object_id).once}
529
+ prj.connect(SIGNAL('closing(QObject*)')){|pr| m.project_closing pr.object_id}
530
+ prj.close
531
+ end
532
+
533
+ it 'should remove all extensions' do
534
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
535
+ prj.add_extension :e1, Qt::Object.new{|o| o.extend Ruber::Extension}
536
+ prj.add_extension :e2, Qt::Object.new{|o| o.extend Ruber::Extension}
537
+ flexmock(prj).should_receive(:remove_extension).with(:e1).once
538
+ flexmock(prj).should_receive(:remove_extension).with(:e2).once
539
+ prj.close
540
+ end
541
+
542
+ it 'removes the connection with the block which register a component with the project' do
543
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
544
+ flexmock(@comp).should_receive(:named_disconnect).once.with("register_component_with_project #{prj.object_id}")
545
+ flexmock(@comp).should_receive(:named_disconnect).with(any)
546
+ prj.close
547
+ end
548
+
549
+ it 'removes the connection with the block which removes a component from the project' do
550
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
551
+ flexmock(@comp).should_receive(:named_disconnect).once.with("remove_component_from_project #{prj.object_id}")
552
+ flexmock(@comp).should_receive(:named_disconnect).with(any)
553
+ prj.close
554
+ end
555
+
556
+ it 'doesn\'t dispose of the project' do
557
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
558
+ prj.close
559
+ prj.should_not be_disposed
560
+ end
561
+
562
+ end
563
+
564
+ describe 'Ruber::AbstractProject#save' do
565
+
566
+ it_should_behave_like 'an_abstract_project_spec_method'
567
+
568
+ def backend file
569
+ Ruber::YamlSettingsBackend.new file
570
+ end
571
+
572
+ it 'emits the "saving()" signal' do
573
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
574
+ m = flexmock{|mk| mk.should_receive(:save).once}
575
+ prj.connect(SIGNAL(:saving)){m.save}
576
+ flexmock(prj).should_receive(:write) #to avoid actually creating a file
577
+ prj.save
578
+ end
579
+
580
+ it 'calls the save_settings method of each extension' do
581
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
582
+ flexmock(prj).should_receive(:write) #to avoid actually creating a file
583
+ 5.times do |i|
584
+ prj.instance_variable_get(:@project_extensions)[i.to_s] = flexmock{|m| m.should_receive(:save_settings).once}
585
+ end
586
+ prj.save
587
+ end
588
+
589
+ it 'calls the write method after saving the extensions' do
590
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
591
+ m = flexmock{|mk| mk.should_receive(:save).once.ordered}
592
+ prj.instance_variable_get(:@project_extensions)[:x] = flexmock{|mk| mk.should_receive(:save_settings).once.ordered}
593
+ prj.connect(SIGNAL(:saving)){m.save}
594
+ flexmock(prj).should_receive(:write).once.ordered
595
+ prj.save
596
+ end
597
+
598
+ it 'returns true if the project was saved correctly and false if an error occurs in the write method' do
599
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
600
+ flexmock(prj).should_receive(:write).once
601
+ prj.save.should be_true
602
+ flexmock(prj).should_receive(:write).once.and_raise(Exception)
603
+ prj.save.should be_false
604
+ end
605
+
606
+ it 'propagates any exception raised from methods connected to the "saving()" signal' do
607
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
608
+ m = flexmock{|mk| mk.should_receive(:save).once.and_raise(Exception, "A slot raised an error")}
609
+ prj.connect(SIGNAL(:saving)){m.save}
610
+ flexmock(prj).should_receive(:write) #to avoid actually creating a file
611
+ lambda{prj.save}.should raise_error(Exception, "A slot raised an error")
612
+ end
613
+
614
+ end
615
+
616
+ describe Ruber::AbstractProject, "#write" do
617
+
618
+ it_should_behave_like 'an_abstract_project_spec_method'
619
+
620
+ def backend file
621
+ Ruber::YamlSettingsBackend.new file
622
+ end
623
+
624
+ it 'should emit the "settings_changed()" signal' do
625
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
626
+ mk = flexmock{|m| m.should_receive(:settings_changed).once}
627
+ prj.connect(SIGNAL(:settings_changed)){mk.settings_changed}
628
+ prj.write
629
+ end
630
+
631
+ end
632
+
633
+ describe Ruber::AbstractProject do
634
+
635
+ it_should_behave_like 'an_abstract_project_spec_method'
636
+
637
+ def backend file
638
+ Ruber::YamlSettingsBackend.new file
639
+ end
640
+
641
+ before do
642
+ @prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
643
+ end
644
+
645
+ describe "#query_close" do
646
+
647
+ before do
648
+ @exts = Dictionary.new
649
+ 5.times{|i| @exts[i.to_s] = flexmock}
650
+ @prj.instance_variable_set :@project_extensions, @exts
651
+ end
652
+
653
+ it 'calls the query_close method of all the extensions and returns true if they all return true' do
654
+ @exts.each{|n, e| e.should_receive(:query_close).once.and_return true}
655
+ @prj.query_close.should be_true
656
+ end
657
+
658
+ it 'stops iterating through the extensions and returns false if one of the extensions\' query_close method returns false' do
659
+ @exts['0'].should_receive(:query_close).once.and_return true
660
+ @exts['1'].should_receive(:query_close).once.and_return true
661
+ @exts['2'].should_receive(:query_close).once.and_return false
662
+ @exts['3'].should_receive(:query_close).never
663
+ @exts['4'].should_receive(:query_close).never
664
+ @prj.query_close.should be_false
665
+ end
666
+
667
+ end
668
+
669
+ describe '#files' do
670
+
671
+ it 'retruns an empty array' do
672
+ prj = Ruber::AbstractProject.new nil, backend(File.join(Dir.pwd, 'test.ruprj')), 'Test'
673
+ prj.files.should == []
674
+ end
675
+
676
+ end
677
+
678
+ end
679
+
680
+ describe Ruber::Project do
681
+
682
+ it 'should inherit from Ruber::AbstractProject' do
683
+ Ruber::Project.ancestors.should include(Ruber::AbstractProject)
684
+ end
685
+
686
+ it 'should include the Ruber::Activable module' do
687
+ Ruber::Project.ancestors.should include(Ruber::Activable)
688
+ end
689
+
690
+ end
691
+
692
+ describe Ruber::Project do
693
+
694
+ describe 'when created' do
695
+
696
+ before do
697
+ @comp = TestComponentManager.new
698
+ @projects = Qt::Object.new
699
+ @fake_app = Application.new
700
+ @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
701
+ @mw = Qt::Widget.new
702
+ flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
703
+ flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
704
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
705
+ flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
706
+ @file = File.join Dir.pwd, 'test.ruprj'
707
+ @dir = nil
708
+ end
709
+
710
+ after do
711
+ FileUtils.rm_rf @dir if @dir
712
+ end
713
+
714
+ it 'uses the projects component as parent' do
715
+ prj = Ruber::Project.new @file, 'Test'
716
+ prj.parent.should equal(@projects)
717
+ end
718
+
719
+ it 'uses Ruber::ProjectBackend as backend' do
720
+ prj = Ruber::Project.new @file, 'Test'
721
+ prj.instance_variable_get(:@backend).should be_a(Ruber::ProjectBackend)
722
+ end
723
+
724
+ it 'raises Ruber::AbstractProject::InvalidProjectFile if the file exists and is not a valid project file' do
725
+ @dir = make_dir_tree ['f1.ruprj'], '/tmp', {'f1.ruprj'=> "project_name: {"}
726
+ lambda{Ruber::Project.new File.join(@dir, 'f1.ruprj')}.should raise_error(Ruber::AbstractProject::InvalidProjectFile)
727
+ end
728
+
729
+ it 'considers a relative file relative to the current directory' do
730
+ prj = Ruber::Project.new 'test.ruprj', 'Test'
731
+ prj.project_file.should == @file
732
+ end
733
+
734
+ it 'is not active' do
735
+ Ruber::Project.new(@file, 'Test').should_not be_active
736
+ end
737
+
738
+ end
739
+
740
+ describe ', when closing' do
741
+
742
+ before do
743
+ @comp = TestComponentManager.new
744
+ @fake_app = Application.new
745
+ @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
746
+ @mw = Qt::Widget.new
747
+ @projects = Qt::Object.new
748
+ flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
749
+ flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
750
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
751
+ flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
752
+ @file = File.join Dir.pwd, 'test.ruprj'
753
+ end
754
+
755
+ it 'should deactivate itself' do
756
+ prj = Ruber::Project.new @file, 'Test'
757
+ flexmock(prj).should_receive(:deactivate).once
758
+ flexmock(prj.instance_variable_get(:@backend)).should_receive(:write)
759
+ prj.close
760
+ end
761
+
762
+ it 'should call super' do
763
+ prj = Ruber::Project.new @file, 'Test'
764
+ flexmock(prj).should_receive(:save).once
765
+ prj.close true
766
+ end
767
+
768
+ it 'disposes of itself' do
769
+ prj = Ruber::Project.new @file, 'Test'
770
+ prj.close false
771
+ prj.should be_disposed
772
+ end
773
+
774
+
775
+ describe ', if super returns true' do
776
+
777
+ it 'returns true' do
778
+ prj = Ruber::Project.new @file, 'Test'
779
+ prj.close(false).should == true
780
+ end
781
+
782
+ end
783
+
784
+ describe ', if super returns false' do
785
+
786
+ it 'returns false' do
787
+ prj = Ruber::Project.new @file, 'Test'
788
+ flexmock(prj).should_receive(:write).once.and_raise(Exception)
789
+ prj.close(true).should == false
790
+ end
791
+
792
+ end
793
+
794
+ end
795
+
796
+ describe '#activate' do
797
+
798
+ before do
799
+ @comp = TestComponentManager.new
800
+ @fake_app = Application.new
801
+ @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
802
+ @mw = Qt::Widget.new
803
+ @projects = Qt::Object.new
804
+ flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
805
+ flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
806
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
807
+ flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
808
+ @file = File.join Dir.pwd, 'test.ruprj'
809
+ end
810
+
811
+ it 'sets the "active" state to true' do
812
+ prj = Ruber::Project.new @file, 'Test'
813
+ prj.activate
814
+ prj.should be_active
815
+ end
816
+
817
+ it 'emits the "activated()" signal if previously the project wasn\'t active' do
818
+ prj = Ruber::Project.new @file, 'Test'
819
+ m = flexmock('test'){|mk| mk.should_receive(:project_activated).once}
820
+ prj.connect(SIGNAL('activated()')){m.project_activated}
821
+ prj.activate
822
+ end
823
+
824
+ it 'doesn\'t emit the "activated()" signal if the project was already active' do
825
+ prj = Ruber::Project.new @file, 'Test'
826
+ prj.activate
827
+ m = flexmock('test'){|mk| mk.should_receive(:project_activated).never}
828
+ prj.connect(SIGNAL('activated()')){m.project_activated}
829
+ prj.activate
830
+ end
831
+
832
+ end
833
+
834
+ describe '#deactivate' do
835
+
836
+ before do
837
+ @comp = TestComponentManager.new
838
+ @fake_app = Application.new
839
+ @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
840
+ @mw = Qt::Widget.new
841
+ @projects = Qt::Object.new
842
+ flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
843
+ flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
844
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
845
+ flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
846
+ @file = File.join Dir.pwd, 'test.ruprj'
847
+ end
848
+
849
+ it 'sets the "active" state to false' do
850
+ prj = Ruber::Project.new @file, 'Test'
851
+ prj.activate
852
+ prj.deactivate
853
+ prj.should_not be_active
854
+ end
855
+
856
+ it 'emits the "deactivated()" signal if the project was active' do
857
+ prj = Ruber::Project.new @file, 'Test'
858
+ prj.activate
859
+ m = flexmock('test'){|mk| mk.should_receive(:project_deactivated).once}
860
+ prj.connect(SIGNAL('deactivated()')){m.project_deactivated}
861
+ prj.deactivate
862
+ end
863
+
864
+ it 'doesn\'t emit the "deactivated()" signal if the project was already inactive' do
865
+ prj = Ruber::Project.new @file, 'Test'
866
+ m = flexmock('test'){|mk| mk.should_receive(:project_deactivated).never}
867
+ prj.connect(SIGNAL('deactivated()')){m.project_deactivated}
868
+ prj.deactivate
869
+ end
870
+
871
+ end
872
+
873
+ describe '#scope' do
874
+ before do
875
+ @comp = TestComponentManager.new
876
+ @fake_app = Application.new
877
+ @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
878
+ @mw = Qt::Widget.new
879
+ @projects = Qt::Object.new
880
+ flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
881
+ flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
882
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
883
+ flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
884
+ @file = File.join Dir.pwd, 'test.ruprj'
885
+ end
886
+
887
+ it 'returns :global' do
888
+ Ruber::Project.new(@file, 'Test').scope.should == :global
889
+ end
890
+ end
891
+
892
+ describe '#add_option' do
893
+
894
+ before do
895
+ @comp = TestComponentManager.new
896
+ @fake_app = Application.new
897
+ @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
898
+ @mw = Qt::Widget.new
899
+ @projects = Qt::Object.new
900
+ flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
901
+ flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
902
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
903
+ flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
904
+ @file = File.join Dir.pwd, 'test.ruprj'
905
+ @prj = Ruber::Project.new(@file, 'Test')
906
+ end
907
+
908
+ it 'sets the type of the option to :global if it is nil' do
909
+ opt = OS.new(:name => :o, :group => :g, :default => 3)
910
+ back = @prj.instance_variable_get :@backend
911
+ flexmock(back).should_receive(:[]).once.with(OS.new(:name => :o, :group => :g, :default => 3, :type => :global))
912
+ lambda{@prj.add_option opt}.should_not raise_error
913
+ end
914
+
915
+ it 'calls super' do
916
+ opt = OS.new(:name => :o, :group => :g, :default => 3, :type => :user)
917
+ @prj.add_option opt
918
+ vars = @prj.instance_variable_get(:@known_options)
919
+ vars[[:g, :o]].should == opt
920
+ @prj[:g, :o].should == 3
921
+ end
922
+
923
+ end
924
+
925
+ describe '#files' do
926
+
927
+ before do
928
+ @comp = TestComponentManager.new
929
+ @fake_app = Application.new
930
+ @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
931
+ @mw = Qt::Widget.new
932
+ @projects = Qt::Object.new
933
+ flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
934
+ flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
935
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
936
+ flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
937
+ @file = File.join Dir.pwd, 'test.ruprj'
938
+ @prj = Ruber::Project.new(@file, 'Test')
939
+ end
940
+
941
+ it 'returns an array containing the files belonging to the project' do
942
+ files = %w[/a /b /c]
943
+ project_files = flexmock{|m| m.should_receive(:project_files).once.and_return files}
944
+ @prj.instance_variable_get(:@project_extensions)[:project_files] = project_files
945
+ @prj.files.should == %w[/a /b /c]
946
+ end
947
+
948
+ end
949
+
950
+ end
951
+
952
+ describe Ruber::ProjectDialog do
953
+
954
+ describe 'widget_from_class' do
955
+
956
+ it 'passes the project to the widget\'s class new method' do
957
+ mw = Qt::Widget.new
958
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return mw
959
+ prj = flexmock('project')
960
+ box = Qt::CheckBox.new
961
+ flexmock(Qt::CheckBox).should_receive(:new).once.with(prj).and_return box
962
+ dlg = Ruber::ProjectDialog.new prj, [], [OpenStruct.new(:class_obj => Qt::CheckBox, :caption => 'General')]
963
+ end
964
+
965
+ end
966
+
967
+ end
968
+
969
+ describe Ruber::ProjectConfigWidget do
970
+
971
+ it 'derives from Qt::Widget' do
972
+ Ruber::ProjectConfigWidget.ancestors.should include(Qt::Widget)
973
+ end
974
+
975
+ describe ', when created' do
976
+
977
+ it 'passes nil to the superclass constructor' do
978
+ w = Ruber::ProjectConfigWidget.new 'x'
979
+ w.parent.should be_nil
980
+ end
981
+
982
+ it 'accepts one argument and stores it in the "project" attribute' do
983
+ prj = flexmock('project')
984
+ w = Ruber::ProjectConfigWidget.new prj
985
+ w.project.should == prj
986
+ end
987
+
988
+ end
989
+
990
+ end