ruber 0.0.8 → 0.0.9

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 (81) hide show
  1. data/CHANGES +21 -0
  2. data/data/share/apps/ruber/ruberui.rc +3 -1
  3. data/lib/ruber/application/application.rb +22 -23
  4. data/lib/ruber/application/plugin.yaml +7 -2
  5. data/lib/ruber/{projects → application}/project_files_list.rb +0 -0
  6. data/lib/ruber/{projects → application}/project_files_widget.rb +0 -0
  7. data/lib/ruber/application/ui/project_files_rule_chooser_widget.rb +74 -0
  8. data/lib/ruber/{projects → application}/ui/project_files_rule_chooser_widget.ui +0 -0
  9. data/lib/ruber/application/ui/project_files_widget.rb +117 -0
  10. data/lib/ruber/{projects → application}/ui/project_files_widget.ui +0 -0
  11. data/lib/ruber/component_manager.rb +14 -9
  12. data/lib/ruber/editor/document.rb +35 -5
  13. data/lib/ruber/kde_sugar.rb +16 -0
  14. data/lib/ruber/main_window/choose_plugins_dlg.rb +7 -4
  15. data/lib/ruber/main_window/main_window.rb +131 -193
  16. data/lib/ruber/main_window/main_window_actions.rb +157 -58
  17. data/lib/ruber/main_window/main_window_internal.rb +145 -54
  18. data/lib/ruber/main_window/open_file_in_project_dlg.rb +4 -4
  19. data/lib/ruber/main_window/plugin.yaml +3 -6
  20. data/lib/ruber/main_window/ui/workspace_settings_widget.rb +2 -2
  21. data/lib/ruber/main_window/workspace.rb +62 -32
  22. data/lib/ruber/output_widget.rb +20 -16
  23. data/lib/ruber/pane.rb +11 -5
  24. data/lib/ruber/project.rb +27 -12
  25. data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +2 -2
  26. data/lib/ruber/projects/ui/project_files_widget.rb +2 -2
  27. data/lib/ruber/utils.rb +37 -4
  28. data/lib/ruber/version.rb +1 -1
  29. data/lib/ruber/world/document_factory.rb +121 -0
  30. data/lib/ruber/world/document_list.rb +396 -0
  31. data/lib/ruber/world/environment.rb +470 -0
  32. data/lib/ruber/{main_window → world}/hint_solver.rb +1 -1
  33. data/lib/ruber/world/plugin.yaml +11 -0
  34. data/lib/ruber/world/project_factory.rb +131 -0
  35. data/lib/ruber/world/project_list.rb +265 -0
  36. data/lib/ruber/world/ui/workspace_settings_widget.rb +51 -0
  37. data/lib/ruber/{main_window → world}/ui/workspace_settings_widget.ui +0 -0
  38. data/lib/ruber/world/world.rb +307 -0
  39. data/plugins/auto_end/auto_end.rb +135 -9
  40. data/plugins/autosave/autosave.rb +4 -4
  41. data/plugins/find_in_files/find_in_files.rb +5 -5
  42. data/plugins/find_in_files/find_in_files_widgets.rb +1 -1
  43. data/plugins/project_browser/project_browser.rb +4 -4
  44. data/plugins/rake/rake.rb +4 -4
  45. data/plugins/rake/rake_extension.rb +1 -1
  46. data/plugins/rspec/rspec.rb +4 -4
  47. data/plugins/rspec/ruber_rspec_formatter.rb +2 -2
  48. data/plugins/ruby_development/ruby_development.rb +3 -3
  49. data/plugins/ruby_runner/ruby_runner.rb +2 -2
  50. data/plugins/state/plugin.yaml +6 -8
  51. data/plugins/state/state.rb +201 -391
  52. data/plugins/state/ui/config_widget.rb +5 -5
  53. data/plugins/state/ui/config_widget.ui +3 -3
  54. data/plugins/syntax_checker/syntax_checker.rb +4 -0
  55. data/spec/annotation_model_spec.rb +1 -1
  56. data/spec/auto_end_spec.rb +98 -47
  57. data/spec/component_manager_spec.rb +80 -21
  58. data/spec/document_factory_spec.rb +115 -0
  59. data/spec/document_list_spec.rb +560 -450
  60. data/spec/document_spec.rb +143 -55
  61. data/spec/editor_view_spec.rb +2 -2
  62. data/spec/environment_spec.rb +1900 -0
  63. data/spec/hint_solver_spec.rb +5 -5
  64. data/spec/kde_sugar_spec.rb +16 -0
  65. data/spec/output_widget_spec.rb +177 -51
  66. data/spec/pane_spec.rb +29 -5
  67. data/spec/plugin_spec.rb +1 -1
  68. data/spec/project_factory_spec.rb +104 -0
  69. data/spec/project_list_spec.rb +352 -447
  70. data/spec/project_spec.rb +34 -33
  71. data/spec/qt_sugar_spec.rb +2 -2
  72. data/spec/state_spec.rb +508 -811
  73. data/spec/utils_spec.rb +149 -98
  74. data/spec/workspace_spec.rb +120 -9
  75. data/spec/world_spec.rb +1219 -0
  76. metadata +23 -14
  77. data/lib/ruber/documents/document_list.rb +0 -412
  78. data/lib/ruber/documents/plugin.yaml +0 -4
  79. data/lib/ruber/main_window/view_manager.rb +0 -431
  80. data/lib/ruber/projects/plugin.yaml +0 -11
  81. data/lib/ruber/projects/project_list.rb +0 -314
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'config_widget.ui'
3
3
  **
4
- ** Created: mer gen 12 12:12:11 2011
5
- ** by: Qt User Interface Compiler version 4.7.1
4
+ ** Created: gio apr 21 20:42:42 2011
5
+ ** by: Qt User Interface Compiler version 4.7.2
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
8
  =end
@@ -72,9 +72,9 @@ class Ui_StateConfigWidget
72
72
  @_state__restore_cursor_position.text = Qt::Application.translate("StateConfigWidget", "Restore cursor position when opening documents", nil, Qt::Application::UnicodeUTF8)
73
73
  @_state__restore_project_files.text = Qt::Application.translate("StateConfigWidget", "Restore open files when opening a project", nil, Qt::Application::UnicodeUTF8)
74
74
  @label_2.text = Qt::Application.translate("StateConfigWidget", "On startup", nil, Qt::Application::UnicodeUTF8)
75
- @_state__startup_behaviour.insertItems(0, [Qt::Application.translate("StateConfigWidget", "Restore open project and files", nil, Qt::Application::UnicodeUTF8),
76
- Qt::Application.translate("StateConfigWidget", "Restore open files only", nil, Qt::Application::UnicodeUTF8),
77
- Qt::Application.translate("StateConfigWidget", "Restore open project only", nil, Qt::Application::UnicodeUTF8),
75
+ @_state__startup_behaviour.insertItems(0, [Qt::Application.translate("StateConfigWidget", "Restore everything", nil, Qt::Application::UnicodeUTF8),
76
+ Qt::Application.translate("StateConfigWidget", "Restore projects", nil, Qt::Application::UnicodeUTF8),
77
+ Qt::Application.translate("StateConfigWidget", "Restore documents not associated with projects", nil, Qt::Application::UnicodeUTF8),
78
78
  Qt::Application.translate("StateConfigWidget", "Keep empty workspace", nil, Qt::Application::UnicodeUTF8)])
79
79
  @_state__startup_behaviour.setProperty("access", Qt::Variant.new(Qt::Application.translate("StateConfigWidget", "$startup_behaviour", nil, Qt::Application::UnicodeUTF8)))
80
80
  end # retranslateUi
@@ -50,17 +50,17 @@
50
50
  </property>
51
51
  <item>
52
52
  <property name="text">
53
- <string>Restore open project and files</string>
53
+ <string>Restore everything</string>
54
54
  </property>
55
55
  </item>
56
56
  <item>
57
57
  <property name="text">
58
- <string>Restore open files only</string>
58
+ <string>Restore projects</string>
59
59
  </property>
60
60
  </item>
61
61
  <item>
62
62
  <property name="text">
63
- <string>Restore open project only</string>
63
+ <string>Restore documents not associated with projects</string>
64
64
  </property>
65
65
  </item>
66
66
  <item>
@@ -379,6 +379,10 @@ the one that a syntax checker's @check@ method). It is passed to the syntax chec
379
379
  nil
380
380
  end
381
381
 
382
+ def check_syntax async = false
383
+
384
+ end
385
+
382
386
  =begin rdoc
383
387
  Starts a syntax check for the document
384
388
 
@@ -8,7 +8,7 @@ describe Ruber::AnnotationModel do
8
8
  @components = flexmock{|m| m.should_ignore_missing}
9
9
  @w = Qt::Widget.new
10
10
  flexmock(Ruber).should_receive(:[]).with(:components).and_return(@components).by_default
11
- @doc = Ruber::Document.new @app
11
+ @doc = Ruber::Document.new nil, @app
12
12
  @model = Ruber::AnnotationModel.new @doc
13
13
  end
14
14
 
@@ -71,7 +71,7 @@ describe Ruber::AutoEnd::Extension do
71
71
  before do
72
72
  Ruber[:components].load_plugin 'plugins/auto_end/'
73
73
  @file = Tempfile.new ['auto_end_test', '.rb']
74
- @doc = Ruber[:documents].document @file.path
74
+ @doc = Ruber[:world].document @file.path
75
75
  @ext = @doc.extension(:auto_end)
76
76
  end
77
77
 
@@ -148,7 +148,7 @@ describe Ruber::AutoEnd::Extension do
148
148
 
149
149
  end
150
150
 
151
- context "and the last line contains an if " do
151
+ context "and the last line contains an if" do
152
152
 
153
153
  it_should_insert_end "if the if is at the beginning of the line", "if kkk\n", "class X\n%\nend", "class X\nif kkk\n\nend\nend", [2, 0]
154
154
 
@@ -161,6 +161,48 @@ describe Ruber::AutoEnd::Extension do
161
161
 
162
162
  end
163
163
 
164
+ context "and the last line contains a for followed by an identifier, and in and some other characters" do
165
+
166
+ it_should_insert_end "if the for is at the beginning of the line", "for kkk in abc\n", "class X\n%\nend", "class X\nfor kkk in abc\n\nend\nend", [2, 0]
167
+
168
+ it_should_insert_end "if the for is preceded only by whitespaces", " for kkk in abc\n", "class X\n%\nend", "class X\n for kkk in abc\n\nend\nend", [2, 0]
169
+
170
+ it_should_insert_end 'if the for is preceded by an =', "x =for kkk in abc\n",
171
+ "class X\n%\nend", "class X\nx =for kkk in abc\n\nend\nend"
172
+
173
+ it_should_insert_end 'if the for is preceded by an = followed by spaces', "x = for kkk in abc\n", "class X\n%\nend", "class X\nx = for kkk in abc\n\nend\nend"
174
+
175
+ end
176
+
177
+ context "and the last line contains an unless" do
178
+
179
+ it_should_insert_end "if the unless is at the beginning of the line", "unless kkk\n", "class X\n%\nend", "class X\nunless kkk\n\nend\nend", [2, 0]
180
+
181
+ it_should_insert_end "if the unless is preceded only by whitespaces", " unless kkk\n", "class X\n%\nend", "class X\n unless kkk\n\nend\nend", [2, 0]
182
+
183
+ it_should_insert_end 'if the unless is preceded by an =', "x =unless kkk\n",
184
+ "class X\n%\nend", "class X\nx =unless kkk\n\nend\nend"
185
+
186
+ it_should_insert_end 'if the unless is preceded by an = followed by spaces', "x = unless kkk\n", "class X\n%\nend", "class X\nx = unless kkk\n\nend\nend"
187
+
188
+ end
189
+
190
+ context "and the last line contains a while" do
191
+
192
+ it_should_insert_end "if the while is at the beginning of the line", "while kkk\n", "class X\n%\nend", "class X\nwhile kkk\n\nend\nend", [2, 0]
193
+
194
+ it_should_insert_end "if the while is preceded only by whitespaces", " while kkk\n", "class X\n%\nend", "class X\n while kkk\n\nend\nend", [2, 0]
195
+
196
+ end
197
+
198
+ context "and the last line contains a until" do
199
+
200
+ it_should_insert_end "if the until is at the beginning of the line", "until kkk\n", "class X\n%\nend", "class X\nuntil kkk\n\nend\nend", [2, 0]
201
+
202
+ it_should_insert_end "if the until is preceded only by whitespaces", " until kkk\n", "class X\n%\nend", "class X\n until kkk\n\nend\nend", [2, 0]
203
+
204
+ end
205
+
164
206
  context "and the line contains a do" do
165
207
 
166
208
  it_should_insert_end "if the do is at the end of the line", "x.each do\n", "def y x\n%\nend", "def y x\nx.each do\n\nend\nend", [2, 0]
@@ -198,54 +240,63 @@ describe Ruber::AutoEnd::Extension do
198
240
 
199
241
  it_should_insert_end 'if the begin is preceded by an = followed by spaces', "x = begin kkk\n", "class X\n%\nend", "class X\nx = begin kkk\n\nend\nend"
200
242
 
243
+ it 'does nothing if the line starts with =begin ' do
244
+ @doc.block_signals true
245
+ @doc.text = "def x\n\nend"
246
+ @doc.block_signals false
247
+ @doc.insert_text KTextEditor::Cursor.new(1,0), "=begin \n"
248
+ @doc.text.should == "def x\n=begin \n\nend"
249
+ end
250
+
251
+
201
252
  end
202
253
 
203
254
  context "and the last line starts with =begin" do
204
-
205
- context "and the active view is associated with the document" do
206
-
207
- before do
208
- @view = @doc.create_view
209
- flexmock(@doc).should_receive(:active_view).and_return @view
210
- @doc.block_signals true
211
- @doc.text= "abc\n"
212
- @doc.block_signals false
213
- @insert_pos = KTextEditor::Cursor.new(1,0)
214
- #avoid messing up the text with indentation
215
- flexmock(@view).should_receive(:execute_action).with('tools_align').by_default
216
- end
217
-
218
- it "inserts an an empty line followed by a =end" do
219
- @doc.insert_text @insert_pos, "=begin xyz\n"
220
- @doc.text.should == "abc\n=begin xyz\n\n=end"
221
- end
222
-
223
- it 'indents the text' do
224
- flexmock(@view).should_receive(:execute_action).with('tools_align').once
225
- @doc.insert_text @insert_pos, "=begin xyz\n"
226
- end
227
-
228
- it 'moves the cursor to the line before the end' do
229
- @doc.insert_text @insert_pos, "=begin xyz\n"
230
- @view.cursor_position.should == KTextEditor::Cursor.new(2,0)
231
- end
232
-
233
- end
234
-
235
- context 'and the active view is not associated with the document' do
236
-
237
- it 'does nothing' do
238
- flexmock(@doc).should_receive(:active_view).and_return nil
239
- @doc.block_signals true
240
- old_text = "abc\n"
241
- @doc.text = old_text
242
- @doc.block_signals false
243
- @doc.insert_text KTextEditor::Cursor.new(1,0), "=begin xyz\n"
244
- @doc.text.should == "abc\n=begin xyz\n"
245
- end
246
-
247
- end
248
-
255
+ pending
256
+ # context "and the active view is associated with the document" do
257
+ #
258
+ # before do
259
+ # @view = @doc.create_view
260
+ # flexmock(@doc).should_receive(:active_view).and_return @view
261
+ # @doc.block_signals true
262
+ # @doc.text= "abc\n"
263
+ # @doc.block_signals false
264
+ # @insert_pos = KTextEditor::Cursor.new(1,0)
265
+ # #avoid messing up the text with indentation
266
+ # flexmock(@view).should_receive(:execute_action).with('tools_align').by_default
267
+ # end
268
+ #
269
+ # it "inserts an an empty line followed by a =end" do
270
+ # @doc.insert_text @insert_pos, "=begin xyz\n"
271
+ # @doc.text.should == "abc\n=begin xyz\n\n=end"
272
+ # end
273
+ #
274
+ # it 'indents the text' do
275
+ # flexmock(@view).should_receive(:execute_action).with('tools_align').once
276
+ # @doc.insert_text @insert_pos, "=begin xyz\n"
277
+ # end
278
+ #
279
+ # it 'moves the cursor to the line before the end' do
280
+ # @doc.insert_text @insert_pos, "=begin xyz\n"
281
+ # @view.cursor_position.should == KTextEditor::Cursor.new(2,0)
282
+ # end
283
+ #
284
+ # end
285
+ #
286
+ # context 'and the active view is not associated with the document' do
287
+ #
288
+ # it 'does nothing' do
289
+ # flexmock(@doc).should_receive(:active_view).and_return nil
290
+ # @doc.block_signals true
291
+ # old_text = "abc\n"
292
+ # @doc.text = old_text
293
+ # @doc.block_signals false
294
+ # @doc.insert_text KTextEditor::Cursor.new(1,0), "=begin xyz\n"
295
+ # @doc.text.should == "abc\n=begin xyz\n"
296
+ # end
297
+ #
298
+ # end
299
+ #
249
300
  end
250
301
 
251
302
  end
@@ -56,22 +56,45 @@ end
56
56
 
57
57
  describe 'Ruber::ComponentManager#each_component' do
58
58
 
59
- it 'should call the block passing each component in turn, in reverse loading order' do
60
- man = Ruber::ComponentManager.new
61
- components = 5.times.map{|i| flexmock(i.to_s, :component_name => i.to_s, :plugin_description => OpenStruct.new({:features => []}))}
62
- m = flexmock do |mk|
63
- components.reverse_each{|c| mk.should_receive(:test).once.with(c).globally.ordered}
59
+ context 'if the argument is :normal or missing' do
60
+
61
+ it 'calls the block passing each component in turn, in loading order' do
62
+ man = Ruber::ComponentManager.new
63
+ components = 5.times.map{|i| flexmock(i.to_s, :component_name => i.to_s, :plugin_description => OpenStruct.new({:features => []}))}
64
+ m = flexmock do |mk|
65
+ components.each{|c| mk.should_receive(:test).once.with(c).globally.ordered}
66
+ end
67
+ man.instance_variable_get(:@components).clear
68
+ components.each{|c| man.add c}
69
+ man.each_component(:normal){|i| m.test i}
70
+ m = flexmock do |mk|
71
+ components.each{|c| mk.should_receive(:test).once.with(c).globally.ordered}
72
+ end
73
+ man.each_component{|i| m.test i}
64
74
  end
65
- man.instance_variable_get(:@components).clear
66
- components.each{|c| man.add c}
67
- man.each_component{|i| m.test i}
75
+
76
+ end
77
+
78
+ context 'if the argument is :reverse' do
79
+
80
+ it 'should call the block passing each component in turn, in loading order' do
81
+ man = Ruber::ComponentManager.new
82
+ components = 5.times.map{|i| flexmock(i.to_s, :component_name => i.to_s, :plugin_description => OpenStruct.new({:features => []}))}
83
+ m = flexmock do |mk|
84
+ components.reverse_each{|c| mk.should_receive(:test).once.with(c).globally.ordered}
85
+ end
86
+ man.instance_variable_get(:@components).clear
87
+ components.each{|c| man.add c}
88
+ man.each_component(:reverse){|i| m.test i}
89
+ end
90
+
68
91
  end
69
92
 
70
93
  end
71
94
 
72
95
  describe 'Ruber::ComponentManager#components' do
73
96
 
74
- it 'should call the block passing each component in turn, in reverse loading order' do
97
+ it 'calls the block passing each component in turn, in reverse loading order' do
75
98
  man = Ruber::ComponentManager.new
76
99
  components = 5.times.map{|i| flexmock(i.to_s, :component_name => i.to_s, :plugin_description => OpenStruct.new({:features => []}))}
77
100
  man.instance_variable_get(:@components).clear
@@ -83,22 +106,54 @@ end
83
106
 
84
107
  describe 'Ruber::ComponentManager#each_plugin' do
85
108
 
86
- it 'should call the block passing each plugin in turn, in reverse loading order' do
87
- man = Ruber::ComponentManager.new
88
- components = 5.times.map{|i| flexmock("component #{i}", :component_name => :"#{i}",:plugin_description => OpenStruct.new({:features => []}))}
89
- m = flexmock("test")
90
- plugins = [1, 3, 4]
91
- components.each_with_index do |c, i|
92
- is_plugin = plugins.include?(i)
93
- c.should_receive(:is_a?).with(Ruber::Plugin).and_return( is_plugin)
94
- if is_plugin then m.should_receive(:test).with(c).once.globally.ordered
95
- else m.should_receive(:test).with(c).never
109
+ context 'when the argument is :normal or missing' do
110
+
111
+ it 'calls the block passing each plugin in turn, in loading order' do
112
+ man = Ruber::ComponentManager.new
113
+ components = 5.times.map{|i| flexmock("component #{i}", :component_name => :"#{i}",:plugin_description => OpenStruct.new({:features => []}))}
114
+ m = flexmock("test")
115
+ plugins = [1, 3, 4]
116
+ components.each_with_index do |c, i|
117
+ is_plugin = plugins.include?(i)
118
+ c.should_receive(:is_a?).with(Ruber::Plugin).and_return( is_plugin)
119
+ if is_plugin then m.should_receive(:test).with(c).once.globally.ordered
120
+ else m.should_receive(:test).with(c).never
121
+ end
122
+ end
123
+ components.each{|c| man.add c}
124
+ man.each_plugin(:normal){|i| m.test i}
125
+ components.each_with_index do |c, i|
126
+ is_plugin = plugins.include?(i)
127
+ c.should_receive(:is_a?).with(Ruber::Plugin).and_return( is_plugin)
128
+ if is_plugin then m.should_receive(:test).with(c).once.globally.ordered
129
+ else m.should_receive(:test).with(c).never
130
+ end
96
131
  end
132
+ man.each_plugin(:normal){|i| m.test i}
97
133
  end
98
- components.reverse_each{|c| man.add c}
99
- man.each_plugin{|i| m.test i}
134
+
100
135
  end
101
136
 
137
+ context 'when the argument is :reverse' do
138
+
139
+ it 'should call the block passing each plugin in turn, in reverse loading order' do
140
+ man = Ruber::ComponentManager.new
141
+ components = 5.times.map{|i| flexmock("component #{i}", :component_name => :"#{i}",:plugin_description => OpenStruct.new({:features => []}))}
142
+ m = flexmock("test")
143
+ plugins = [1, 3, 4]
144
+ components.each_with_index do |c, i|
145
+ is_plugin = plugins.include?(i)
146
+ c.should_receive(:is_a?).with(Ruber::Plugin).and_return( is_plugin)
147
+ if is_plugin then m.should_receive(:test).with(c).once.globally.ordered
148
+ else m.should_receive(:test).with(c).never
149
+ end
150
+ end
151
+ components.reverse_each{|c| man.add c}
152
+ man.each_plugin(:reverse){|i| m.test i}
153
+ end
154
+
155
+ end
156
+
102
157
  end
103
158
 
104
159
  describe 'Ruber::ComponentManager#plugins' do
@@ -1038,6 +1093,10 @@ describe 'Ruber::ComponentManager#unload_plugin' do
1038
1093
  @manager.instance_variable_get(:@components).keys.map(&:to_s).should =~ [:p0, :p2, :c0, :c1, :components].map(&:to_s)
1039
1094
  end
1040
1095
 
1096
+ it 'raises ArgumentError if there\'s no plugin with that name' do
1097
+ lambda{@manager.unload_plugin(:xyz)}.should raise_error(ArgumentError, "No plugin with name xyz")
1098
+ end
1099
+
1041
1100
  it 'should raise ArgumentError if the name corresponds to a component instead of a plugin' do
1042
1101
  lambda{@manager.unload_plugin(:c1)}.should raise_error(ArgumentError, "A component can't be unloaded")
1043
1102
  end
@@ -0,0 +1,115 @@
1
+ require './spec/framework'
2
+ require './spec/common'
3
+ require 'ruber/world/document_factory'
4
+
5
+ describe Ruber::World::DocumentFactory do
6
+
7
+ it 'derives from Qt::Object' do
8
+ Ruber::World::DocumentFactory.ancestors.should include(Qt::Object)
9
+ end
10
+
11
+ before do
12
+ @factory = Ruber::World::DocumentFactory.new
13
+ end
14
+
15
+ describe '#document' do
16
+
17
+ it 'returns a document having the object passed as second argument as parent' do
18
+ obj = Qt::Object.new
19
+ doc = @factory.document nil, obj
20
+ doc.should be_a(Ruber::Document)
21
+ doc.parent.should == obj
22
+ end
23
+
24
+ context 'when called with a file or URL as first argument' do
25
+
26
+ it 'returns a new document for the given file, if no other document for it exists' do
27
+ doc = @factory.document __FILE__
28
+ doc.path.should == __FILE__
29
+ end
30
+
31
+ it 'returns an existing document for the same file, if it already exists' do
32
+ old = @factory.document __FILE__
33
+ new = @factory.document __FILE__
34
+ new.should == old
35
+ end
36
+
37
+ it 'returns the existing file even if of the two calls to document one was passed a string and the other an URL' do
38
+ old = @factory.document KDE::Url.new(__FILE__)
39
+ new = @factory.document __FILE__
40
+ new.should == old
41
+ end
42
+
43
+ it 'does not attempt to return a document which has been closed' do
44
+ old = @factory.document __FILE__
45
+ old.close
46
+ new = @factory.document __FILE__
47
+ new.should_not == old
48
+ end
49
+
50
+ it 'returns an existing document even if it was created without a file and saved with the new name later' do
51
+ old = @factory.document nil
52
+ url = KDE::Url.new __FILE__
53
+ flexmock(old).should_receive(:url).and_return url
54
+ old.instance_eval{emit document_url_changed(self)}
55
+ new = @factory.document __FILE__
56
+ new.should == old
57
+ end
58
+
59
+ it 'returns an existing document even if it was created for another file then
60
+ saved with the new name later' do
61
+ old = @factory.document File.join File.dirname(__FILE__), 'common.rb'
62
+ url = KDE::Url.new __FILE__
63
+ flexmock(old).should_receive(:url).and_return url
64
+ old.instance_eval{emit document_url_changed(self)}
65
+ new = @factory.document __FILE__
66
+ new.should == old
67
+ end
68
+
69
+ it 'doesn\'t return a document which was created for the same file but was saved with another name later' do
70
+ old = @factory.document __FILE__
71
+ url = KDE::Url.new File.join(File.dirname(__FILE__), 'common.rb')
72
+ flexmock(old).should_receive(:url).and_return url
73
+ old.instance_eval{emit document_url_changed(self)}
74
+ new = @factory.document __FILE__
75
+ new.should_not == old
76
+ end
77
+
78
+ it 'returns nil if the file is a local file and it doesn\'t exist' do
79
+ @factory.document('/xyz').should be_nil
80
+ @factory.document(KDE::Url.new('/xyz')).should be_nil
81
+ end
82
+
83
+ end
84
+
85
+ context 'when called with nil as first argument' do
86
+
87
+ it 'always returns a new document' do
88
+ old = @factory.document nil
89
+ new = @factory.document nil
90
+ new.should_not == old
91
+ end
92
+
93
+ end
94
+
95
+ context 'when creating a new document' do
96
+
97
+ it 'emits the document_created signal passing the document as argument' do
98
+ docs = [Ruber::Document.new(__FILE__), Ruber::Document.new]
99
+ flexmock(Ruber::Document).should_receive(:new).with(__FILE__,nil).once.and_return docs[0]
100
+ flexmock(Ruber::Document).should_receive(:new).with(nil,nil).once.and_return docs[1]
101
+ mk = flexmock do |m|
102
+ m.should_receive(:document_created).with(docs[0]).once
103
+ m.should_receive(:document_created).with(docs[1]).once
104
+ end
105
+ @factory.connect(SIGNAL('document_created(QObject*)')){|o| mk.document_created o}
106
+ doc = @factory.document __FILE__
107
+ @factory.document nil
108
+ @factory.document __FILE__
109
+ end
110
+
111
+ end
112
+
113
+ end
114
+
115
+ end