ruber 0.0.5 → 0.0.7

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 (83) hide show
  1. data/CHANGES +25 -0
  2. data/bin/ruber +0 -0
  3. data/data/share/apps/ruber/ruberui.rc +15 -1
  4. data/data/share/icons/{ruber.png → ruber-old.pgn} +0 -0
  5. data/lib/ruber/application/application.rb +216 -73
  6. data/lib/ruber/application/plugin.yaml +2 -2
  7. data/lib/ruber/document_project.rb +25 -5
  8. data/lib/ruber/documents/document_list.rb +11 -15
  9. data/lib/ruber/editor/document.rb +106 -50
  10. data/lib/ruber/editor/editor_view.rb +4 -2
  11. data/lib/ruber/external_program_plugin.rb +8 -0
  12. data/lib/ruber/kde_config_option_backend.rb +12 -4
  13. data/lib/ruber/kde_sugar.rb +35 -1
  14. data/lib/ruber/main_window/choose_plugins_dlg.rb +10 -10
  15. data/lib/ruber/main_window/hint_solver.rb +263 -0
  16. data/lib/ruber/main_window/main_window.rb +462 -206
  17. data/lib/ruber/main_window/main_window_actions.rb +228 -62
  18. data/lib/ruber/main_window/main_window_internal.rb +169 -115
  19. data/lib/ruber/main_window/plugin.yaml +13 -3
  20. data/lib/ruber/main_window/save_modified_files_dlg.rb +1 -1
  21. data/lib/ruber/main_window/ui/choose_plugins_widget.rb +1 -1
  22. data/lib/ruber/main_window/ui/main_window_settings_widget.rb +1 -1
  23. data/lib/ruber/main_window/ui/new_project_widget.rb +1 -1
  24. data/lib/ruber/main_window/ui/open_file_in_project_dlg.rb +1 -1
  25. data/lib/ruber/main_window/ui/output_color_widget.rb +1 -1
  26. data/lib/ruber/main_window/ui/workspace_settings_widget.rb +51 -0
  27. data/lib/ruber/main_window/ui/workspace_settings_widget.ui +28 -0
  28. data/lib/ruber/main_window/view_manager.rb +418 -0
  29. data/lib/ruber/main_window/workspace.png +0 -0
  30. data/lib/ruber/output_widget.rb +43 -37
  31. data/lib/ruber/pane.rb +621 -0
  32. data/lib/ruber/plugin_specification_reader.rb +8 -1
  33. data/lib/ruber/projects/project_files_list.rb +6 -0
  34. data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +1 -1
  35. data/lib/ruber/projects/ui/project_files_widget.rb +1 -1
  36. data/lib/ruber/qt_sugar.rb +94 -4
  37. data/lib/ruber/utils.rb +16 -7
  38. data/lib/ruber/version.rb +2 -2
  39. data/plugins/autosave/autosave.rb +62 -1
  40. data/plugins/autosave/plugin.yaml +1 -0
  41. data/plugins/autosave/ui/autosave_config_widget.rb +37 -14
  42. data/plugins/autosave/ui/autosave_config_widget.ui +62 -12
  43. data/plugins/find_in_files/find_in_files_widgets.rb +1 -3
  44. data/plugins/find_in_files/ui/config_widget.rb +1 -1
  45. data/plugins/find_in_files/ui/find_in_files_widget.rb +1 -1
  46. data/plugins/rake/plugin.yaml +1 -1
  47. data/plugins/rake/ui/add_quick_task_widget.rb +1 -1
  48. data/plugins/rake/ui/choose_task_widget.rb +1 -1
  49. data/plugins/rake/ui/config_widget.rb +1 -1
  50. data/plugins/rake/ui/project_widget.rb +1 -1
  51. data/plugins/rspec/rspec.rb +14 -22
  52. data/plugins/rspec/ruber_rspec_formatter.rb +4 -1
  53. data/plugins/rspec/ui/rspec_project_widget.rb +1 -1
  54. data/plugins/ruby_development/plugin.yaml +7 -2
  55. data/plugins/ruby_development/ruby_development.rb +134 -13
  56. data/plugins/ruby_development/ui/config_widget.rb +66 -0
  57. data/plugins/ruby_development/ui/config_widget.ui +58 -0
  58. data/plugins/ruby_development/ui/project_widget.rb +1 -1
  59. data/plugins/ruby_runner/plugin.yaml +2 -2
  60. data/plugins/ruby_runner/ruby_runner.rb +15 -3
  61. data/plugins/ruby_runner/ui/config_widget.rb +1 -1
  62. data/plugins/ruby_runner/ui/project_widget.rb +1 -1
  63. data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.rb +1 -1
  64. data/plugins/state/plugin.yaml +6 -2
  65. data/plugins/state/state.rb +305 -81
  66. data/plugins/state/ui/config_widget.rb +1 -1
  67. data/spec/common.rb +11 -3
  68. data/spec/document_list_spec.rb +8 -8
  69. data/spec/document_project_spec.rb +98 -25
  70. data/spec/document_spec.rb +178 -152
  71. data/spec/editor_view_spec.rb +26 -5
  72. data/spec/framework.rb +5 -0
  73. data/spec/hint_solver_spec.rb +450 -0
  74. data/spec/kde_sugar_spec.rb +73 -6
  75. data/spec/output_widget_spec.rb +172 -156
  76. data/spec/pane_spec.rb +1165 -0
  77. data/spec/plugin_specification_reader_spec.rb +37 -1
  78. data/spec/project_files_list_spec.rb +30 -20
  79. data/spec/qt_sugar_spec.rb +269 -0
  80. data/spec/state_spec.rb +566 -353
  81. data/spec/utils_spec.rb +1 -1
  82. data/spec/view_manager_spec.rb +71 -0
  83. metadata +16 -4
@@ -1,36 +1,46 @@
1
- require 'spec/common'
1
+ require './spec/framework'
2
+ require './spec/common'
2
3
 
3
4
  require 'tempfile'
4
5
  require 'fileutils'
5
6
 
6
7
  require 'ruber/plugin_specification'
7
8
  require 'ruber/editor/document'
9
+ require 'ruber/pane'
8
10
 
9
11
  require 'plugins/state/state'
10
12
 
11
13
  describe Ruber::State::Plugin do
12
14
 
13
15
  before do
14
- #Needed because the Qt::Object connect method doesn't like @components not being a
15
- #Qt::Object
16
- class Ruber::State::Plugin
17
- def connect *args
18
- end
19
- end
20
- @components = flexmock('components'){|m| m.should_ignore_missing}
21
- @config = flexmock('config'){|m| m.should_ignore_missing}
22
- flexmock(Ruber).should_receive(:[]).with(:components).and_return(@components).by_default
23
- flexmock(Ruber).should_receive(:[]).with(:app).and_return(KDE::Application.instance).by_default
24
- flexmock(Ruber).should_receive(:[]).with(:config).and_return(@config).by_default
25
- pdf = Ruber::PluginSpecification.full :name => :state
26
- @plug = Ruber::State::Plugin.new pdf
16
+ # #Needed because the Qt::Object connect method doesn't like @components not being a
17
+ # #Qt::Object
18
+ # class Ruber::State::Plugin
19
+ # def connect *args
20
+ # end
21
+ # end
22
+ # @components = flexmock('components'){|m| m.should_ignore_missing}
23
+ # @config = flexmock('config'){|m| m.should_ignore_missing}
24
+ # flexmock(Ruber).should_receive(:[]).with(:components).and_return(@components).by_default
25
+ # flexmock(Ruber).should_receive(:[]).with(:app).and_return(KDE::Application.instance).by_default
26
+ # flexmock(Ruber).should_receive(:[]).with(:config).and_return(@config).by_default
27
+ Ruber[:documents].close_all(false)
28
+ Ruber[:components].load_plugin 'plugins/state/'
29
+ @plug = Ruber[:components][:state]
30
+ # data = YAML.load('plugins/state/plugin.yaml')
31
+ # psf = Ruber::PluginSpecification.full data
32
+ # @plug = Ruber::State::Plugin.new psf
27
33
  end
28
34
 
29
35
  after do
30
- class Ruber::State::Plugin
31
- remove_method :connect rescue nil
32
- end
36
+ Ruber[:components].unload_plugin(:state)
33
37
  end
38
+ #
39
+ # after do
40
+ # class Ruber::State::Plugin
41
+ # remove_method :connect rescue nil
42
+ # end
43
+ # end
34
44
 
35
45
  it 'inherits Ruber::Plugin' do
36
46
  Ruber::State::Plugin.ancestors.should include(Ruber::Plugin)
@@ -52,58 +62,45 @@ describe Ruber::State::Plugin do
52
62
 
53
63
  describe '#delayed_initialize' do
54
64
 
55
- before do
56
- @documents = flexmock('documents')
57
- @projects = flexmock('projects')
58
- flexmock(KDE::Application.instance).should_receive(:starting?).and_return(true).by_default
59
- flexmock(Ruber).should_receive(:[]).with(:docs).and_return(@documents).by_default
60
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
61
- end
65
+ # before do
66
+ # @documents = flexmock('documents')
67
+ # @projects = flexmock('projects')
68
+ # flexmock(KDE::Application.instance).should_receive(:starting?).and_return(true).by_default
69
+ # end
62
70
 
63
71
  it 'calls the restore_last_state method if there\'s no open project and the only open document is pristine' do
64
- doc = flexmock('doc', :pristine? => true)
65
- @documents.should_receive(:to_a).once.and_return [doc]
66
- @documents.should_receive(:[]).with(0).once.and_return doc
67
- @projects.should_receive(:to_a).once.and_return []
72
+ Ruber[:documents].new_document
68
73
  flexmock(@plug).should_receive(:restore_last_state).once
69
74
  @plug.send :delayed_initialize
70
75
  end
71
76
 
72
77
  it 'doesn\'t call the restore_last_state method if there are open projects' do
73
78
  prj = flexmock('project')
74
- @projects.should_receive(:to_a).once.and_return [prj]
79
+ flexmock(Ruber[:projects]).should_receive(:to_a).once.and_return [prj]
75
80
  flexmock(@plug).should_receive(:restore_last_state).never
76
81
  @plug.send :delayed_initialize
77
82
  end
78
83
 
79
84
  it 'doesn\'t call the restore_last_state method if there is more than one open document' do
80
- @documents.should_receive(:to_a).once.and_return 2.times.map{flexmock}
81
- @projects.should_receive(:to_a).once.and_return []
85
+ 2.times{Ruber[:documents].new_document}
82
86
  flexmock(@plug).should_receive(:restore_last_state).never
83
87
  @plug.send :delayed_initialize
84
88
  end
85
89
 
86
90
  it 'doesn\'t call the restore_last_state method if there aren\'t open documents' do
87
- @documents.should_receive(:to_a).once.and_return []
88
- @projects.should_receive(:to_a).once.and_return []
89
91
  flexmock(@plug).should_receive(:restore_last_state).never
90
92
  @plug.send :delayed_initialize
91
93
  end
92
94
 
93
95
  it 'doesn\'t call the restore_last_state method if the only open document isn\'t pristine' do
94
- doc = flexmock('doc', :pristine? => false)
95
- @documents.should_receive(:to_a).once.and_return [doc]
96
- @documents.should_receive(:[]).with(0).once.and_return doc
97
- @projects.should_receive(:to_a).once.and_return []
96
+ doc = Ruber[:documents].new_document
97
+ doc.text = 'xyz'
98
98
  flexmock(@plug).should_receive(:restore_last_state).never
99
99
  @plug.send :delayed_initialize
100
100
  end
101
101
 
102
102
  it 'does nothing if the application is already running' do
103
- doc = flexmock('doc', :pristine? => true)
104
- @documents.should_receive(:to_a).and_return [doc]
105
- @documents.should_receive(:[]).with(0).and_return doc
106
- @projects.should_receive(:to_a).and_return []
103
+ doc = Ruber[:documents].new_document
107
104
  flexmock(KDE::Application.instance).should_receive(:starting?).and_return false
108
105
  flexmock(@plug).should_receive(:restore_last_state).never
109
106
  @plug.send :delayed_initialize
@@ -113,39 +110,24 @@ describe Ruber::State::Plugin do
113
110
 
114
111
  describe '#gather_settings' do
115
112
 
116
- before do
117
- @projects = flexmock('projects') do |m|
118
- m.should_receive(:projects).and_return([]).by_default
119
- m.should_receive(:current).and_return(nil).by_default
120
- end
121
- @documents = flexmock('documents') do |m|
122
- m.should_receive(:documents).and_return([]).by_default
123
- m.should_receive(:current).and_return(nil).by_default
124
- end
125
- @mw = flexmock('main window'){|m| m.should_ignore_missing}
126
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
127
- flexmock(Ruber).should_receive(:[]).with(:docs).and_return(@documents).by_default
128
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
129
- end
130
-
131
113
  it 'stores a list with the project file of each open project under the :open_projects key' do
132
114
  prjs = 5.times.map{|i| flexmock(i.to_s){|m| m.should_receive(:project_file).and_return i.to_s}}
133
- @projects.should_receive(:projects).once.and_return(prjs)
134
- @projects.should_receive(:current).once.and_return(nil)
115
+ flexmock(Ruber[:projects]).should_receive(:projects).once.and_return(prjs)
116
+ flexmock(Ruber[:projects]).should_receive(:current).once.and_return(nil)
135
117
  @plug.send(:gather_settings).should have_entries(:open_projects => (0...5).map(&:to_s))
136
118
  end
137
119
 
138
120
  it 'puts the file corresponding to the open project at the beginning of the :open_projects entry' do
139
121
  prjs = 5.times.map{|i| flexmock(i.to_s, :project_file => i.to_s)}
140
- @projects.should_receive(:projects).once.and_return(prjs)
141
- @projects.should_receive(:current).once.and_return prjs[2]
122
+ flexmock(Ruber[:projects]).should_receive(:projects).once.and_return(prjs)
123
+ flexmock(Ruber[:projects]).should_receive(:current).once.and_return prjs[2]
142
124
  @plug.send(:gather_settings).should have_entries(:open_projects => %w[2 0 1 3 4])
143
125
  end
144
126
 
145
127
  it 'stores the project files in an arbitrary order if there\'s no active project' do
146
128
  prjs = 5.times.map{|i| flexmock(i.to_s){|m| m.should_receive(:project_file).and_return i.to_s}}
147
- @projects.should_receive(:projects).once.and_return(prjs)
148
- @projects.should_receive(:current).once.and_return nil
129
+ flexmock(Ruber[:projects]).should_receive(:projects).once.and_return(prjs)
130
+ flexmock(Ruber[:projects]).should_receive(:current).once.and_return nil
149
131
  @plug.send(:gather_settings).should have_entries(:open_projects => (0...5).map(&:to_s))
150
132
  end
151
133
 
@@ -153,87 +135,209 @@ describe Ruber::State::Plugin do
153
135
  @plug.send(:gather_settings).should have_entries(:open_projects => [])
154
136
  end
155
137
 
156
- it 'stores a list of the paths of the files associated with all open documents under the :open_files key' do
157
- docs = 5.times.map{|i| flexmock(i.to_s){|m| m.should_receive(:path).and_return i.to_s}}
158
- @documents.should_receive(:documents).once.and_return(docs)
159
- @plug.send(:gather_settings).should have_entries(:open_documents => (0...5).map(&:to_s))
138
+ it 'stores a list of the URLs of the files associated with all open documents under the :open_files key' do
139
+ docs = 5.times.map{|i| flexmock(i.to_s, :has_file? => true, :view => flexmock){|m| m.should_receive(:url).and_return KDE::Url.new("file:///xyz/file #{i}")}}
140
+ flexmock(Ruber[:documents]).should_receive(:documents).once.and_return(docs)
141
+ exp = [
142
+ 'file:///xyz/file%200',
143
+ 'file:///xyz/file%201',
144
+ 'file:///xyz/file%202',
145
+ 'file:///xyz/file%203',
146
+ 'file:///xyz/file%204',
147
+ ]
148
+ @plug.send(:gather_settings).should have_entries(:open_documents => exp)
160
149
  end
161
150
 
162
- it 'ignores documents which aren\'t associated with a file' do
151
+ it 'stores nil in place of documents not associated with files' do
163
152
  docs = 5.times.map do |i|
164
- flexmock(i.to_s) do |m|
165
- m.should_receive(:path).and_return(i % 2 == 0 ? i.to_s : '')
153
+ flexmock(i.to_s, :view => flexmock) do |m|
154
+ m.should_receive(:url).and_return(i % 2 == 0 ? KDE::Url.new("file:///xyz/file #{i}") : KDE::Url.new)
155
+ m.should_receive(:has_file?).and_return(i % 2 == 0)
166
156
  end
167
157
  end
168
- @documents.should_receive(:documents).once.and_return(docs)
169
- @plug.send(:gather_settings).should have_entries(:open_documents => %w[0 2 4])
170
- end
171
-
172
- it 'stores an empty array under the :open_files key if there are no open documents or if no open document is associated with a file' do
173
- docs = 5.times.map{flexmock(:path => '')}
174
- @documents.should_receive(:documents).once.and_return(docs).once
175
- @documents.should_receive(:documents).once.and_return([]).once
176
- @plug.send(:gather_settings).should have_entries(:open_documents => [])
158
+ flexmock(Ruber[:documents]).should_receive(:documents).once.and_return(docs)
159
+ exp = [
160
+ 'file:///xyz/file%200',
161
+ nil,
162
+ 'file:///xyz/file%202',
163
+ nil,
164
+ 'file:///xyz/file%204',
165
+ ]
166
+ @plug.send(:gather_settings).should have_entries(:open_documents => exp)
167
+ end
168
+
169
+ it 'stores an empty array under the :open_files key if there are no open documents' do
177
170
  @plug.send(:gather_settings).should have_entries(:open_documents => [])
178
171
  end
179
172
 
180
- it 'stores the path of the active document under the :active_document key' do
181
- docs = 5.times.map{|i| flexmock(i.to_s){|m| m.should_receive(:path).and_return i.to_s}}
182
- @documents.should_receive(:documents).once.and_return(docs)
183
- @mw.should_receive(:current_document).once.and_return(docs[1])
184
- @plug.send(:gather_settings).should have_entries(:active_document => "1")
185
- end
186
-
187
- it 'stores nil under the :active_document key if there\'s no current document' do
188
- @mw.should_receive(:current_document).once.and_return nil
189
- @plug.send(:gather_settings).should have_entries(:active_document => nil)
190
- end
191
-
192
- it 'stores nil under the :active_document key if the current document isn\'t associated with a file' do
193
- doc = flexmock('doc', :path => '')
194
- @mw.should_receive(:current_document).once.and_return doc
195
- @plug.send(:gather_settings).should have_entries(:active_document => nil)
173
+ it 'stores a tree of the open editors for each tab under the tabs entry' do
174
+ docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map! do |f|
175
+ f ? Ruber[:documents].document(f) : Ruber[:documents].new_document
176
+ end
177
+ views = [
178
+ docs[1].create_view,
179
+ docs[0].create_view,
180
+ docs[3].create_view,
181
+ docs[2].create_view,
182
+ docs[1].create_view,
183
+ docs[0].create_view
184
+ ]
185
+ tab1 = Ruber::Pane.new views[0]
186
+ tab1.split views[0], views[1], Qt::Vertical
187
+ tab1.split views[0], views[2], Qt::Horizontal
188
+ tab2 = Ruber::Pane.new views[3]
189
+ tab2.split views[3], views[4], Qt::Horizontal
190
+ tab3 = Ruber::Pane.new views[5]
191
+ flexmock(Ruber[:main_window]).should_receive(:tabs).once.and_return [tab1, tab2, tab3]
192
+ exp = [
193
+ [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
194
+ [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
195
+ [0]
196
+ ]
197
+ @plug.send(:gather_settings)[:tabs].should == exp
198
+ end
199
+
200
+ it 'uses arrays with a single element in the :tabs entry to represent tabs with a single view' do
201
+ docs = [__FILE__, nil].map{|f| f ? Ruber[:documents].document(f) : Ruber[:documents].new_document}
202
+ views = docs.reverse.map{|d| d.create_view}
203
+ tabs = views.map{|v| Ruber::Pane.new v}
204
+ flexmock(Ruber[:main_window]).should_receive(:tabs).once.and_return tabs
205
+ exp = [[0], ['file://' + __FILE__]]
206
+ @plug.send(:gather_settings)[:tabs].should == exp
207
+ end
208
+
209
+ it 'stores an empty array under the tabs entry if there aren\'t open editors' do
210
+ docs = [
211
+ Ruber[:documents].new_document,
212
+ Ruber[:documents].document(__FILE__),
213
+ ]
214
+ @plug.send(:gather_settings)[:tabs].should == []
215
+ end
216
+
217
+ it 'stores the active view as an array of integers referring to the tabs entry in the active_view entry' do
218
+ docs = [
219
+ Ruber[:documents].new_document,
220
+ Ruber[:documents].document(__FILE__),
221
+ Ruber[:documents].document(File.join(File.dirname(__FILE__), 'common.rb')),
222
+ Ruber[:documents].new_document,
223
+ ]
224
+ views = [
225
+ docs[1].create_view,
226
+ docs[0].create_view,
227
+ docs[3].create_view,
228
+ docs[2].create_view,
229
+ docs[1].create_view,
230
+ docs[0].create_view
231
+ ]
232
+ tab1 = Ruber::Pane.new views[0]
233
+ tab1.split views[0], views[1], Qt::Vertical
234
+ tab1.split views[0], views[2], Qt::Horizontal
235
+ tab2 = Ruber::Pane.new views[3]
236
+ tab2.split views[3], views[4], Qt::Horizontal
237
+ tab3 = Ruber::Pane.new views[5]
238
+ flexmock(Ruber[:main_window]).should_receive(:tabs).once.and_return [tab1, tab2, tab3]
239
+ exp = [
240
+ [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
241
+ [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
242
+ [0]
243
+ ]
244
+ flexmock(Ruber[:main_window]).should_receive(:active_editor).and_return(views[2])
245
+ flexmock(Ruber[:main_window]).should_receive(:tab).with(views[2]).and_return tab1
246
+ @plug.send(:gather_settings)[:active_view].should == [0,1]
247
+ end
248
+
249
+ it 'sets the active_view entry to nil if there isn\'t an active editor' do
250
+ docs = [
251
+ Ruber[:documents].new_document,
252
+ Ruber[:documents].document(__FILE__),
253
+ ]
254
+ @plug.send(:gather_settings)[:active_view].should be_nil
255
+ end
256
+
257
+ it 'stores the cursor position for each view in each tab in the cursor_positions entry' do
258
+ docs = [
259
+ Ruber[:documents].new_document,
260
+ Ruber[:documents].document(__FILE__),
261
+ Ruber[:documents].document(File.join(File.dirname(__FILE__), 'common.rb')),
262
+ Ruber[:documents].new_document,
263
+ ]
264
+ views = [
265
+ docs[1].create_view,
266
+ docs[0].create_view,
267
+ docs[3].create_view,
268
+ docs[2].create_view,
269
+ docs[1].create_view,
270
+ docs[0].create_view
271
+ ]
272
+ tab1 = Ruber::Pane.new views[0]
273
+ tab1.split views[0], views[1], Qt::Vertical
274
+ tab1.split views[1], views[2], Qt::Horizontal
275
+ tab2 = Ruber::Pane.new views[3]
276
+ tab2.split views[3], views[4], Qt::Horizontal
277
+ tab3 = Ruber::Pane.new views[5]
278
+ cursor_positions = [
279
+ [[5, 1], [95,102], [1, 4]],
280
+ [[0,0], [45,93]],
281
+ [[12,42]]
282
+ ]
283
+ i = 0
284
+ cursor_positions.each do |t|
285
+ t.each do |pos|
286
+ flexmock(views[i]).should_receive(:cursor_position).and_return(KTextEditor::Cursor.new(*pos))
287
+ i += 1
288
+ end
289
+ end
290
+ flexmock(Ruber[:main_window]).should_receive(:tabs).once.and_return [tab1, tab2, tab3]
291
+ @plug.send(:gather_settings)[:cursor_positions].should == cursor_positions
196
292
  end
197
-
293
+
198
294
  end
199
295
 
200
296
  describe '#save_settings' do
201
297
 
202
298
  it 'stores the value corresponding to the :open_projects key in the hash returned by gather_settings in the state/open_projects setting' do
203
299
  flexmock(@plug).should_receive(:gather_settings).once.and_return(:open_projects => %w[x y z])
204
- @config.should_receive(:[]=).with(:state, :open_projects, %w[x y z]).once
205
- @config.should_receive(:[]=)
300
+ flexmock(Ruber[:config]).should_receive(:[]=).with(:state, :open_projects, %w[x y z]).once
301
+ flexmock(Ruber[:config]).should_receive(:[]=)
206
302
  @plug.save_settings
207
303
  end
208
304
 
209
305
  it 'stores the value corresponding to the :open_documents key in the hash returned by gather_settings in the state/open_documents setting' do
210
306
  flexmock(@plug).should_receive(:gather_settings).once.and_return(:open_documents => %w[x y z])
211
- @config.should_receive(:[]=).with(:state, :open_documents, %w[x y z]).once
212
- @config.should_receive(:[]=)
307
+ flexmock(Ruber[:config]).should_receive(:[]=).with(:state, :open_documents, %w[x y z]).once
308
+ flexmock(Ruber[:config]).should_receive(:[]=)
213
309
  @plug.save_settings
214
310
  end
215
311
 
216
- it 'stores the value corresponding to the :active_document key in the hash returned by gather_settings in the state/active_document setting' do
217
- flexmock(@plug).should_receive(:gather_settings).once.and_return(:active_document => 'x')
218
- @config.should_receive(:[]=).with(:state, :active_document, 'x').once
219
- @config.should_receive(:[]=)
312
+ it 'stores the value corresponding to the :active_view key in the hash returned by gather_settings in the state/active_editor setting' do
313
+ flexmock(@plug).should_receive(:gather_settings).once.and_return(:active_view => [1, 2])
314
+ flexmock(Ruber[:config]).should_receive(:[]=).with(:state, :active_view, [1,2]).once
315
+ flexmock(Ruber[:config]).should_receive(:[]=)
220
316
  @plug.save_settings
221
317
  end
222
318
 
319
+ it 'stores the value corresponding to the :tabs key of the has returned by gather_settings in the state/tabs setting' do
320
+ flexmock(@plug).should_receive(:gather_settings).once.and_return(:tabs => [Qt::Horizontal, 'file://'+__FILE__, 0])
321
+ flexmock(Ruber[:config]).should_receive(:[]=).with(:state, :tabs, [Qt::Horizontal, 'file://'+__FILE__, 0]).once
322
+ flexmock(Ruber[:config]).should_receive(:[]=)
323
+ @plug.save_settings
324
+
325
+ end
326
+
223
327
  end
224
328
 
225
329
  describe '#restore_cursor_position?' do
226
330
 
227
331
  it 'returns the value of the state/restore_cursor_position config entry if the @force_restore_cursor_position instance variable is nil' do
228
- @config.should_receive(:[]).with(:state, :restore_cursor_position).once.and_return(true)
229
- @config.should_receive(:[]).with(:state, :restore_cursor_position).once.and_return(false)
332
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_cursor_position).once.and_return(true)
333
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_cursor_position).once.and_return(false)
230
334
  @plug.instance_variable_set :@force_restore_cursor_position, nil
231
335
  @plug.restore_cursor_position?.should == true
232
336
  @plug.restore_cursor_position?.should == false
233
337
  end
234
338
 
235
339
  it 'returns the value of the @force_restore_cursor_position instance variable if it is not nil' do
236
- @config.should_receive(:[]).with(:state, :restore_cursor_position).never
340
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_cursor_position).never
237
341
  @plug.instance_variable_set :@force_restore_cursor_position, true
238
342
  @plug.restore_cursor_position?.should == true
239
343
  @plug.instance_variable_set :@force_restore_cursor_position, false
@@ -245,15 +349,15 @@ describe Ruber::State::Plugin do
245
349
  describe '#restore_project_files?' do
246
350
 
247
351
  it 'returns the value of the state/restore_project_files config entry if the @force_restore_project_files instance variable is nil' do
248
- @config.should_receive(:[]).with(:state, :restore_project_files).once.and_return(true)
249
- @config.should_receive(:[]).with(:state, :restore_project_files).once.and_return(false)
352
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_project_files).once.and_return(true)
353
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_project_files).once.and_return(false)
250
354
  @plug.instance_variable_set :@force_restore_project_files, nil
251
355
  @plug.restore_project_files?.should == true
252
356
  @plug.restore_project_files?.should == false
253
357
  end
254
358
 
255
359
  it 'returns the value of the @force_restore_project_files instance variable if it is not nil' do
256
- @config.should_receive(:[]).with(:state, :restore_project_files).never
360
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_project_files).never
257
361
  @plug.instance_variable_set :@force_restore_project_files, true
258
362
  @plug.restore_project_files?.should == true
259
363
  @plug.instance_variable_set :@force_restore_project_files, false
@@ -268,7 +372,8 @@ describe Ruber::State::Plugin do
268
372
  hash = {
269
373
  :open_projects => %w[a b c],
270
374
  :open_documents => %w[x y z],
271
- :active_document => 'z'
375
+ :tabs => [Qt::Horizontal, 'file://'+__FILE__, 0],
376
+ :active_view => [0,0]
272
377
  }
273
378
  flexmock(@plug).should_receive(:gather_settings).once.and_return hash
274
379
  res = @plug.session_data
@@ -284,13 +389,15 @@ describe Ruber::State::Plugin do
284
389
  'State' => {
285
390
  :open_projects => %w[a b c],
286
391
  :open_documents => %w[x y z],
287
- :active_document => 'z'
392
+ :tabs => [Qt::Horizontal, 'file://'+__FILE__, 0],
393
+ :active_view => [0,0]
288
394
  }
289
395
  }
290
396
  exp_hash = {
291
397
  [:state, :open_projects] => %w[a b c],
292
398
  [:state, :open_documents] => %w[x y z],
293
- [:state, :active_document] => 'z'
399
+ [:state, :active_view] => [0,0],
400
+ [:state, :tabs] => [Qt::Horizontal, 'file://'+__FILE__, 0],
294
401
  }
295
402
  default = {:open_projects => [], :open_documents => [], :active_document => nil}
296
403
  flexmock(@plug).should_receive(:with).with({:restore_cursor_position => true, :restore_project_files => true, :force => true}, FlexMock.on{|a| a.call || a.is_a?(Proc)}).once
@@ -512,60 +619,54 @@ describe Ruber::State::Plugin do
512
619
 
513
620
  describe '#restore_projects' do
514
621
 
515
- before do
516
- @projects = flexmock('projects'){|m| m.should_ignore_missing}
517
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
518
- @mw = flexmock{|m| m.should_ignore_missing}
519
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
520
- end
521
-
522
622
  it 'closes all projects' do
523
623
  prjs = 3.times.map{|i| flexmock(i.to_s)}
524
- prjs.each{|pr| @projects.should_receive(:close_project).with(pr).once}
525
- @projects.should_receive(:to_a).once.and_return(prjs)
624
+ prjs.each{|pr| flexmock(Ruber[:projects]).should_receive(:close_project).with(pr).once}
625
+ flexmock(Ruber[:projects]).should_receive(:to_a).once.and_return(prjs)
526
626
  @plug.restore_projects
527
627
  end
528
628
 
529
629
  it 'uses the safe_open_project method of the main window to open the first entry of the state/open_projects setting' do
530
- @config.should_receive(:[]).with(:state, :open_projects).once.and_return %w[/x/y/z.ruprj /a/b/c.ruprj]
531
- prj = flexmock('project')
532
- @mw.should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return prj
630
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).once.and_return %w[/x/y/z.ruprj /a/b/c.ruprj]
631
+ prj = flexmock('project', :project_file => '/x/y/z.ruprj')
632
+ flexmock(Ruber[:main_window]).should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return prj
633
+ flexmock(Ruber[:projects]).should_receive(:current_project=)
533
634
  @plug.restore_projects
534
635
  end
535
636
 
536
637
  it 'activates the project returned by safe_open_project' do
537
- @config.should_receive(:[]).with(:state, :open_projects).once.and_return %w[/x/y/z.ruprj /a/b/c.ruprj]
638
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).once.and_return %w[/x/y/z.ruprj /a/b/c.ruprj]
538
639
  prj = flexmock('project')
539
- @mw.should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return prj
540
- @projects.should_receive(:current_project=).once.with(prj)
640
+ flexmock(Ruber[:main_window]).should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return prj
641
+ flexmock(Ruber[:projects]).should_receive(:current_project=).once.with(prj)
541
642
  @plug.restore_projects
542
643
  end
543
644
 
544
645
  it 'doesn\'t attempt to activate the project if safe_open_project returned nil' do
545
- @config.should_receive(:[]).with(:state, :open_projects).once.and_return %w[/x/y/z.ruprj /a/b/c.ruprj]
646
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).once.and_return %w[/x/y/z.ruprj /a/b/c.ruprj]
546
647
  prj = flexmock('project')
547
- @mw.should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return nil
548
- @projects.should_receive(:current_project=).never
648
+ flexmock(Ruber[:main_window]).should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return nil
649
+ flexmock(Ruber[:projects]).should_receive(:current_project=).never
549
650
  lambda{@plug.restore_projects}.should_not raise_error
550
651
  end
551
652
 
552
653
  it 'does nothing if the state/open_projects setting is empty' do
553
- @config.should_receive(:[]).with(:state, :open_projects).once.and_return []
654
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).once.and_return []
554
655
  prj = flexmock('project')
555
- @projects.should_receive(:project).never
556
- @projects.should_receive(:current_project=).never
656
+ flexmock(Ruber[:projects]).should_receive(:project).never
657
+ flexmock(Ruber[:projects]).should_receive(:current_project=).never
557
658
  @plug.restore_projects
558
659
  end
559
660
 
560
661
  it 'reads the settings from the argument, if given, rather than from the config object' do
561
- @config.should_receive(:[]).never
662
+ flexmock(Ruber[:config]).should_receive(:[]).never
562
663
  h = {[:state, :open_projects] => ['/x/y/z.ruprj']}
563
664
  def h.[] group, name
564
665
  super [group, name]
565
666
  end
566
667
  prj = flexmock('project')
567
- @mw.should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return prj
568
- @projects.should_receive(:current_project=).once.with(prj)
668
+ flexmock(Ruber[:main_window]).should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return prj
669
+ flexmock(Ruber[:projects]).should_receive(:current_project=).once.with(prj)
569
670
  @plug.restore_projects h
570
671
  end
571
672
 
@@ -573,63 +674,165 @@ describe Ruber::State::Plugin do
573
674
 
574
675
  describe '#restore_documents' do
575
676
 
576
- before do
577
- @mw = flexmock('main window'){|m| m.should_ignore_missing}
578
- @docs = flexmock('documents'){|m| m.should_ignore_missing}
579
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
580
- flexmock(Ruber).should_receive(:[]).with(:docs).and_return(@docs).by_default
677
+ it 'closes all open documents' do
678
+ flexmock(Ruber[:documents]).should_receive(:close_all).once.and_return true
679
+ @plug.restore_documents
581
680
  end
582
681
 
583
- it 'closes all open documents' do
584
- @docs.should_receive(:close_all).once
682
+ it 'does nothing if the user chooses to abort closing the documents' do
683
+ flexmock(Ruber[:documents]).should_receive(:close_all).once.and_return false
684
+ files = [__FILE__, File.join(File.dirname(__FILE__), 'common.rb'), File.join(File.dirname(__FILE__), 'framework.rb')].map{|f| "file://#{f}"}
685
+ Ruber[:config][:state, :open_documents] = files
686
+ flexmock(Ruber[:documents]).should_receive(:document).never
585
687
  @plug.restore_documents
586
688
  end
587
689
 
588
- it 'creates a new document for each entry in the state/open_documents from within a block passed to the main window\'s without_activating method' do
589
- files = %w[/x/y/f1.rb /a/b/f2.rb /f3.rb]
590
- @config.should_receive(:[]).with(:state, :open_documents).once.and_return files
591
- @config.should_receive(:[]).with(:state, :active_document)
592
- files.each{|f| @mw.should_receive(:editor_for!).once.with(f).ordered}
593
- @mw.should_receive(:without_activating).once.with(FlexMock.on{|a| a.call || a.is_a?(Proc)})
690
+ it 'creates a new document for each entry in the state/open_documents' do
691
+ files = [__FILE__, File.join(File.dirname(__FILE__), 'common.rb'), File.join(File.dirname(__FILE__), 'framework.rb')].map{|f| "file://#{f}"}
692
+ Ruber[:config][:state, :open_documents] = files
594
693
  @plug.restore_documents
694
+ Ruber[:documents].count.should == files.count
695
+ Ruber[:documents].each_with_index do |doc, i|
696
+ doc.url.url.should == files[i]
697
+ end
595
698
  end
596
699
 
597
- it 'activates the document corresponding to the file specified in the state/active_document setting' do
598
- files = %w[/x/y/f1.rb /a/b/f2.rb /f3.rb]
599
- @config.should_receive(:[]).with(:state, :open_documents).once.and_return files
600
- @config.should_receive(:[]).with(:state, :active_document).once.and_return files[1]
601
- 3.times{|i| @mw.should_receive(:editor_for!).once.with(files[i])}
602
- @mw.should_receive(:display_document).once.with(files[1])
603
- @mw.should_receive(:without_activating).once.with(FlexMock.on{|a| a.call || a.is_a?(Proc)})
700
+ it 'creates empty documents for numeric entries under the state/open_documents key' do
701
+ files = [0, 'file:///x/y/f1.rb', 'file:///a/b/f2.rb', 2]
702
+ Ruber[:config][:state, :open_documents] = files
703
+ flexmock(Ruber[:documents]).should_receive(:new_document).once.ordered
704
+ flexmock(Ruber[:documents]).should_receive(:document).once.with(KDE::Url.new(files[1])).ordered
705
+ flexmock(Ruber[:documents]).should_receive(:document).once.with(KDE::Url.new(files[2])).ordered
706
+ flexmock(Ruber[:documents]).should_receive(:new_document).once.ordered
707
+ flexmock(Ruber[:main_window]).should_receive(:without_activating)
604
708
  @plug.restore_documents
605
709
  end
606
710
 
607
- it 'it activates the last document if the state/active_document setting is nil or if it doesn\'t correspond to an existing document' do
608
- files = %w[/x/y/f1.rb /a/b/f2.rb /f3.rb]
609
- @config.should_receive(:[]).with(:state, :open_documents).twice.and_return files
610
- @config.should_receive(:[]).with(:state, :active_document).once.and_return nil
611
- @config.should_receive(:[]).with(:state, :active_document).once.and_return random_string
612
- @mw.should_receive(:display_document).twice.with(files[-1])
613
- @mw.should_receive(:without_activating).twice.with(FlexMock.on{|a| a.call || a.is_a?(Proc)})
711
+ it 'creates a tab for each array in the :tabs entry if all of them contain a single element' do
712
+ docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map{|f| f ? 'file://' + f : nil}
713
+ views = [[docs[1]], [1], [0]]
714
+ Ruber[:config][:state, :open_documents] = docs
715
+ Ruber[:config][:state, :tabs] = views
614
716
  @plug.restore_documents
717
+ tabs = Ruber[:main_window].tabs
718
+ tabs.count.should == 3
719
+ tabs[0].view.document.path.should == __FILE__
720
+ tabs[1].view.document.should == Ruber[:documents][3]
721
+ tabs[2].view.document.should == Ruber[:documents][0]
722
+ end
723
+
724
+ it 'creates nested tabs for each element of the :tabs entry which is a nested array' do
725
+ docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map{|f| f ? 'file://' + f : nil}
726
+ views =[
727
+ [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
728
+ [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
729
+ [0]
730
+ ]
731
+ Ruber[:config][:state, :open_documents] = docs
732
+ Ruber[:config][:state, :tabs] = views
615
733
  @plug.restore_documents
734
+ tabs = Ruber[:main_window].tabs
735
+ tabs.count.should == 3
736
+ tabs[0].orientation.should == Qt::Vertical
737
+ child_pane = tabs[0].splitter.widget(0)
738
+ child_pane.orientation.should == Qt::Horizontal
739
+ view_list = child_pane.to_a
740
+ view_list[0].document.path.should == __FILE__
741
+ view_list[1].document.should == Ruber[:documents][-1]
742
+ tabs[0].splitter.widget(1).view.document.should == Ruber[:documents][0]
743
+ tabs[1].orientation.should == Qt::Horizontal
744
+ view_list = tabs[1].to_a
745
+ view_list[0].document.path.should == File.join(File.dirname(__FILE__), 'common.rb')
746
+ view_list[1].document.path.should == __FILE__
747
+ tabs[2].should be_single_view
748
+ tabs[2].view.document.should == Ruber[:documents][0]
749
+ end
750
+
751
+ it 'moves the cursor position of each view according to the contents of the :cursor_positions entry' do
752
+ docs = ['file://'+__FILE__, 'file://'+File.join(File.dirname(__FILE__), 'common.rb'), 'file://'+File.join(File.dirname(__FILE__), 'framework.rb')]
753
+ views =[
754
+ [Qt::Vertical, [Qt::Horizontal, docs[0], docs[1] ], docs[2]],
755
+ [docs[1]]
756
+ ]
757
+ positions = [
758
+ [[30, 16], [53,33], [1,2]],
759
+ [[2,6]]
760
+ ]
761
+ Ruber[:config][:state, :open_documents] = docs
762
+ Ruber[:config][:state, :tabs] = views
763
+ Ruber[:config][:state, :cursor_positions] = positions
764
+ @plug.restore_documents
765
+ tabs = Ruber[:main_window].tabs
766
+ tabs.each_with_index do |t, i|
767
+ t.to_a.each_with_index do |v, j|
768
+ c = v.cursor_position
769
+ c.line.should == positions[i][j][0]
770
+ c.column.should == positions[i][j][1]
771
+ end
772
+ end
616
773
  end
617
774
 
618
- it 'does nothing if the state/open_files entry is empty' do
619
- @config.should_receive(:[]).with(:state, :open_documents).once.and_return []
620
- lambda{@plug.restore_documents}.should_not raise_error
775
+ it 'doesn\'t attempt to change the cursor positions if the cursor_positions entry is empty' do
776
+ docs = ['file://'+__FILE__, 'file://'+File.join(File.dirname(__FILE__), 'common.rb'), 'file://'+File.join(File.dirname(__FILE__), 'framework.rb')]
777
+ views =[
778
+ [Qt::Vertical, [Qt::Horizontal, docs[0], docs[1] ], docs[2]],
779
+ [docs[1]]
780
+ ]
781
+ Ruber[:config][:state, :open_documents] = docs
782
+ Ruber[:config][:state, :tabs] = views
783
+ @plug.restore_documents
784
+ tabs = Ruber[:main_window].tabs
785
+ tabs.each_with_index do |t, i|
786
+ t.to_a.each_with_index do |v, j|
787
+ c = v.cursor_position
788
+ c.line.should == 0
789
+ c.column.should == 0
790
+ end
791
+ end
621
792
  end
622
793
 
623
- it 'reads the settings from the argument, if given, rather than from the config object' do
624
- @config.should_receive(:[]).never
625
- files = %w[/x/y/f1.rb /a/b/f2.rb /f3.rb]
626
- files.each{|f| @mw.should_receive(:editor_for!).once.with(f).ordered}
627
- @mw.should_receive(:without_activating).once.with(FlexMock.on{|a| a.call || a.is_a?(Proc)})
628
- h = {[:state, :open_documents] => files, [:state, :active_document] => nil}
629
- def h.[] group, name
630
- super [group, name]
794
+ it 'gives focus to the editor corresponding to the value in the active_editor entry' do
795
+ docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map{|f| f ? 'file://' + f : nil}
796
+ views =[
797
+ [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
798
+ [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
799
+ [0]
800
+ ]
801
+ Ruber[:config][:state, :open_documents] = docs
802
+ Ruber[:config][:state, :tabs] = views
803
+ Ruber[:config][:state, :active_view] = [1, 1]
804
+ flexmock(Ruber[:main_window]).should_receive(:focus_on_editor).once.with(FlexMock.on{|v, h| v == Ruber[:main_window].tabs[1].to_a[1]})
805
+ @plug.restore_documents
806
+ end
807
+
808
+ it 'doesn\'t attempt to give focus to an editor if the active_editor entry is nil' do
809
+ docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map{|f| f ? 'file://' + f : nil}
810
+ views =[
811
+ [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
812
+ [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
813
+ [0]
814
+ ]
815
+ Ruber[:config][:state, :open_documents] = docs
816
+ Ruber[:config][:state, :tabs] = views
817
+ Ruber[:config][:state, :active_view] = nil
818
+ flexmock(Ruber[:main_window]).should_receive(:focus_on_editor).never
819
+ @plug.restore_documents
820
+ end
821
+
822
+ it 'uses the settings stored in the object passed as a argument instead of those in the global configuration object' do
823
+ docs = [nil, 'file://'+__FILE__]
824
+ conf = flexmock do |m|
825
+ m.should_receive(:[]).with(:state, :open_documents).once.and_return docs
826
+ m.should_receive(:[]).with(:state, :tabs).once.and_return []
827
+ m.should_receive(:[]).with(:state, :active_view).once.and_return nil
828
+ m.should_receive(:[]).with(:state, :cursor_positions).once.and_return []
631
829
  end
632
- @plug.restore_documents h
830
+ flexmock(Ruber[:config]).should_receive(:[]).never
831
+ @plug.restore_documents conf
832
+ documents = Ruber[:documents].to_a
833
+ documents.size.should == 2
834
+ documents[0].should be_pristine
835
+ documents[1].path.should == __FILE__
633
836
  end
634
837
 
635
838
  end
@@ -637,19 +840,19 @@ describe Ruber::State::Plugin do
637
840
  describe 'restore' do
638
841
 
639
842
  it 'calls the restore_projects method if the state/open_project setting is not empty' do
640
- @config.should_receive(:[]).with(:state, :open_projects).and_return %w[/xyz/abc.ruprj]
641
- flexmock(@plug).should_receive(:restore_projects).once.with(@config)
843
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).and_return %w[/xyz/abc.ruprj]
844
+ flexmock(@plug).should_receive(:restore_projects).once.with(Ruber[:config])
642
845
  @plug.restore
643
846
  end
644
847
 
645
848
  it 'calls the restore_documents method if the state/open_projects setting is empty' do
646
- @config.should_receive(:[]).with(:state, :open_projects).and_return []
647
- flexmock(@plug).should_receive(:restore_documents).once.with(@config)
849
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).and_return []
850
+ flexmock(@plug).should_receive(:restore_documents).once.with(Ruber[:config])
648
851
  @plug.restore
649
852
  end
650
853
 
651
854
  it 'uses the argument, rather than the config object, if one is given' do
652
- @config.should_receive(:[]).never
855
+ flexmock(Ruber[:config]).should_receive(:[]).never
653
856
  h = {[:state, :open_projects] => %w[/xyz/abc.ruprj]}
654
857
  def h.[](group, name)
655
858
  super [group, name]
@@ -668,7 +871,7 @@ describe Ruber::State::Plugin do
668
871
  describe ', when the state/startup_behaviour option is :restore_all' do
669
872
 
670
873
  it 'calls the restore method' do
671
- @config.should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_all
874
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_all
672
875
  flexmock(@plug).should_receive(:restore).once
673
876
  @plug.restore_last_state
674
877
  end
@@ -678,7 +881,7 @@ describe Ruber::State::Plugin do
678
881
  describe ', when the state/startup_behaviour option is :restore_projects_only' do
679
882
 
680
883
  it 'calls restore_project from within a with block with :restore_project_files set to false' do
681
- @config.should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_projects_only
884
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_projects_only
682
885
  flexmock(@plug).should_receive(:restore_projects).once
683
886
  flexmock(@plug).should_receive(:with).once.with({:restore_project_files => false}, FlexMock.on{|a| a.call || a.is_a?(Proc)})
684
887
  @plug.restore_last_state
@@ -689,7 +892,7 @@ describe Ruber::State::Plugin do
689
892
  describe ', when the state/startup_behaviour option is :restore_documents_only' do
690
893
 
691
894
  it 'calls restore_documents' do
692
- @config.should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_documents_only
895
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_documents_only
693
896
  flexmock(@plug).should_receive(:restore_documents).once
694
897
  @plug.restore_last_state
695
898
  end
@@ -699,7 +902,7 @@ describe Ruber::State::Plugin do
699
902
  describe ', when the state/startup_behaviour option is :restore_nothing' do
700
903
 
701
904
  it 'does nothing' do
702
- @config.should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_nothing
905
+ flexmock(Ruber[:config]).should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_nothing
703
906
  flexmock(@plug).should_receive(:with).never
704
907
  flexmock(@plug).should_receive(:restore_projects).never
705
908
  flexmock(@plug).should_receive(:restore_documents).never
@@ -715,6 +918,21 @@ end
715
918
 
716
919
  describe Ruber::State::DocumentExtension do
717
920
 
921
+ before do
922
+ Ruber[:components].load_plugin 'plugins/state/'
923
+ Ruber[:documents].close_all(false)
924
+ @plug = Ruber[:components][:state]
925
+ @doc = Ruber[:documents].document __FILE__
926
+ @prj = @doc.own_project
927
+ @ext = @doc.own_project.extension(:state)
928
+ end
929
+
930
+ after do
931
+ Ruber[:documents].close_all(false)
932
+ Ruber[:components].unload_plugin :state
933
+ end
934
+
935
+
718
936
  it 'inherits from Qt::Object' do
719
937
  Ruber::State::DocumentExtension.ancestors.should include(Qt::Object)
720
938
  end
@@ -723,18 +941,10 @@ describe Ruber::State::DocumentExtension do
723
941
  Ruber::State::DocumentExtension.ancestors.should include(Ruber::Extension)
724
942
  end
725
943
 
726
- before do
727
- @components = flexmock{|m| m.should_ignore_missing}
728
- flexmock(Ruber).should_receive(:[]).with(:components).and_return(@components).by_default
729
- @doc = Ruber::Document.new nil, __FILE__
730
- @ext = Ruber::State::DocumentExtension.new @doc.own_project
731
- @doc.own_project.add_extension :state, @ext
732
- end
733
-
734
944
  describe ', when created' do
735
945
 
736
- it 'connects the document\'s view_created(QObject*, QObject*) signal to its auto_restore slot' do
737
- flexmock(@ext).should_receive(:auto_restore).once
946
+ it 'connects the document\'s view_created(QObject*, QObject*) signal to its auto_restore slot, passing the view to it' do
947
+ flexmock(@ext).should_receive(:auto_restore).once.with(Ruber::EditorView)
738
948
  @doc.create_view
739
949
  end
740
950
 
@@ -742,68 +952,158 @@ describe Ruber::State::DocumentExtension do
742
952
 
743
953
  describe '#restore' do
744
954
 
745
- before do
746
- #Needed to avoid the need of creating a mock State plugin
747
- @doc.disconnect SIGNAL('view_created(QObject*, QObject*)'), @ext
748
- end
749
-
750
- it 'moves the cursor to the position stored in the document\'s project state/cursor_position setting' do
751
- view = @doc.create_view
752
- flexmock(@doc.own_project).should_receive(:[]).with(:state, :cursor_position).once.and_return([100, 20])
753
- flexmock(@doc.view).should_receive(:go_to).with(100, 20).once
754
- @ext.restore
955
+ context 'if no other view associated with the document received focus before' do
956
+
957
+ it 'moves the cursor to the position specified in the state/cursor_position entry of the document project' do
958
+ exp = [10, 5]
959
+ views = 3.times.map{@doc.create_view}
960
+ @prj[:state, :cursor_position] = exp
961
+ @ext.restore views[1]
962
+ cur = views[1].cursor_position
963
+ cur.line.should == exp[0]
964
+ cur.column.should == exp[1]
965
+ end
966
+
755
967
  end
756
968
 
757
- it 'does nothing if the document doesn\'t have a view' do
758
- lambda{@ext.restore}.should_not raise_error
969
+ context 'if another view associated with the document has received focus before' do
970
+
971
+ it 'moves the cursor to the position of the cursor in the view which last received focus' do
972
+ exp = [10, 5]
973
+ views = 3.times.map{@doc.create_view}
974
+ views[0].instance_eval{emit focus_in(self)}
975
+ flexmock(@prj).should_receive(:[]).with(:state, :cursor_position).never
976
+ flexmock(views[0]).should_receive(:cursor_position).and_return(KTextEditor::Cursor.new(*exp))
977
+ @ext.restore views[1]
978
+ cur = views[1].cursor_position
979
+ cur.line.should == exp[0]
980
+ cur.column.should == exp[1]
981
+ end
982
+
759
983
  end
760
-
984
+
761
985
  end
762
986
 
763
987
  describe '#save_settings' do
764
988
 
765
- before do
766
- #Needed to avoid the need of creating a mock State plugin
767
- @doc.disconnect SIGNAL('view_created(QObject*, QObject*)'), @ext
768
- end
769
-
770
- it 'stores an array containing the cursor position in the document\'s project state/cursor_position setting' do
771
- view = @doc.create_view
772
- flexmock(@doc.own_project).should_receive(:[]=).with(:state, :cursor_position, [100, 20]).once
773
- cur = KTextEditor::Cursor.new(100, 20)
774
- flexmock(@doc.view).should_receive(:cursor_position).once.and_return cur
989
+ it 'stores the cursor position in the view which last got focus under the state/cursor_position key' do
990
+ views = 3.times.map{@doc.create_view}
991
+ #simply calling set_focus to give focus to the view wouldn't work because
992
+ #set_focus relies on a running event loop
993
+ views[1].instance_eval{emit focus_in(self)}
994
+ views[0].instance_eval{emit focus_in(self)}
995
+ views[2].instance_eval{emit focus_in(self)}
996
+ flexmock(views[1]).should_receive(:cursor_position).and_return(KTextEditor::Cursor.new(120,25))
997
+ flexmock(views[0]).should_receive(:cursor_position).and_return(KTextEditor::Cursor.new(33,45))
998
+ flexmock(views[2]).should_receive(:cursor_position).and_return(KTextEditor::Cursor.new(50,15))
775
999
  @ext.save_settings
776
- end
1000
+ @prj[:state, :cursor_position].should == [50,15]
1001
+ end
1002
+
1003
+ # it 'keeps using the view which last got focus' do
1004
+ # views = 3.times.map{@doc.create_view}
1005
+ # views[1].instance_eval{emit focus_in(self)}
1006
+ # views[0].instance_eval{emit focus_in(self)}
1007
+ # flexmock(@ext).should_receive(:save_settings)
1008
+ # views[1].close
1009
+ # flexmock(@prj).should_receive(:[]).with(:state, :cursor_position).never
1010
+ # flexmock(views[0]).should_receive(:cursor_position).once.and_return(KTextEditor::Cursor.new(2,3))
1011
+ # @doc.create_view
1012
+ # end
1013
+
777
1014
 
778
- it 'uses [0,0] as cursor position if the document doesn\'t have any view' do
779
- flexmock(@doc.own_project).should_receive(:[]=).with(:state, :cursor_position, [0, 0]).once
780
- lambda{@ext.save_settings}.should_not raise_error
1015
+ it 'does nothing if none of the views associated with the document have received focus' do
1016
+ views = 3.times.map{@doc.create_view}
1017
+ flexmock(views[1]).should_receive(:cursor_position).never
1018
+ flexmock(views[0]).should_receive(:cursor_position).never
1019
+ flexmock(views[2]).should_receive(:cursor_position).never
1020
+ flexmock(@prj).should_receive(:[]=).with(:state, :cursor_position).never
1021
+ @ext.save_settings
781
1022
  end
782
1023
 
783
1024
  end
784
1025
 
785
1026
  describe 'auto_restore' do
1027
+
1028
+ context 'if the state plugin wants the cursor position restored' do
786
1029
 
787
- before do
788
- @plug = Object.new
789
- @plug.instance_variable_set :@force_restore_cursor_position, nil
790
- flexmock(Ruber).should_receive(:[]).with(:state).and_return(@plug).by_default
791
- end
1030
+ it 'calls the restore method if the State plugins wants the curesor position restored' do
1031
+ view = @doc.create_view
1032
+ flexmock(@plug).should_receive(:restore_cursor_position?).once.and_return true
1033
+ flexmock(@ext).should_receive(:restore).once.with(view)
1034
+ @ext.send :auto_restore, view
1035
+ end
792
1036
 
793
- it 'calls the restore method if the State plugins wants the curesor position restored' do
794
- flexmock(@plug).should_receive(:restore_cursor_position?).once.and_return true
795
- flexmock(@ext).should_receive(:restore).once
796
- @ext.send :auto_restore
797
1037
  end
798
1038
 
799
- it 'does noting if the State plugins doesn\'t want the curesor position restored' do
800
- flexmock(@plug).should_receive(:restore_cursor_position?).once.and_return false
801
- flexmock(@ext).should_receive(:restore).never
802
- @ext.send :auto_restore
1039
+ context 'if the state plugin doesn\'t want the cursor position restored' do
1040
+
1041
+ it 'does nothing' do
1042
+ view = @doc.create_view
1043
+ flexmock(@plug).should_receive(:restore_cursor_position?).once.and_return false
1044
+ flexmock(@ext).should_receive(:restore).never
1045
+ @ext.send :auto_restore, view
1046
+ end
1047
+
803
1048
  end
804
1049
 
805
1050
  end
1051
+
1052
+ context 'when a view associated with the document is closed' do
1053
+
1054
+ context 'and the view is the one which last got focus' do
1055
+
1056
+ it 'calls the save_settings method' do
1057
+ views = 3.times.map{@doc.create_view}
1058
+ views[1].instance_eval{emit focus_in(self)}
1059
+ views[0].instance_eval{emit focus_in(self)}
1060
+ flexmock(@ext).should_receive(:save_settings).once
1061
+ views[0].close
1062
+ #needed because otherwise the save_settings method is called again when
1063
+ #the document is closed in the after block
1064
+ flexmock(@ext).should_receive(:save_settings)
1065
+ end
1066
+
1067
+ it 'after behaves as if no other view had ever got focus' do
1068
+ views = 3.times.map{@doc.create_view}
1069
+ views[1].instance_eval{emit focus_in(self)}
1070
+ views[0].instance_eval{emit focus_in(self)}
1071
+ flexmock(@ext).should_receive(:save_settings)
1072
+ views[0].close
1073
+ flexmock(@prj).should_receive(:[]).with(:state, :cursor_position).once.and_return([10,2])
1074
+ @doc.create_view
1075
+ end
1076
+
1077
+ end
806
1078
 
1079
+ context 'and the view isn\'t the last one which got focus' do
1080
+
1081
+ it 'does nothing if the view is not the last which got focus' do
1082
+ views = 3.times.map{@doc.create_view}
1083
+ views[1].instance_eval{emit focus_in(self)}
1084
+ views[0].instance_eval{emit focus_in(self)}
1085
+ flexmock(@ext).should_receive(:save_settings).never
1086
+ views[1].close
1087
+ #needed because otherwise the save_settings method is called again when
1088
+ #the document is closed in the after block
1089
+ flexmock(@ext).should_receive(:save_settings)
1090
+ end
1091
+
1092
+ it 'keeps using the view which last got focus' do
1093
+ views = 3.times.map{@doc.create_view}
1094
+ views[1].instance_eval{emit focus_in(self)}
1095
+ views[0].instance_eval{emit focus_in(self)}
1096
+ flexmock(@ext).should_receive(:save_settings)
1097
+ views[1].close
1098
+ flexmock(@prj).should_receive(:[]).with(:state, :cursor_position).never
1099
+ flexmock(views[0]).should_receive(:cursor_position).once.and_return(KTextEditor::Cursor.new(2,3))
1100
+ @doc.create_view
1101
+ end
1102
+
1103
+ end
1104
+
1105
+ end
1106
+
807
1107
  end
808
1108
 
809
1109
  describe Ruber::State::ProjectExtension do
@@ -817,19 +1117,18 @@ describe Ruber::State::ProjectExtension do
817
1117
  end
818
1118
 
819
1119
  before do
1120
+ Ruber[:documents].close_all(false)
1121
+ Ruber[:components].load_plugin 'plugins/state/'
1122
+ @plug = Ruber[:components][:state]
820
1123
  @dir = File.join Dir.tmpdir, random_string(10)
821
1124
  FileUtils.mkdir @dir
822
- @components = flexmock{|m| m.should_ignore_missing}
823
- @projects = Qt::Object.new
824
- flexmock(Ruber).should_receive(:[]).with(:components).and_return(@components).by_default
825
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
826
- @prj = Ruber::Project.new 'Test', File.join(@dir, 'test.ruprj')
827
- @ext = Ruber::State::ProjectExtension.new @prj
828
- @prj.add_extension :state, @ext
1125
+ @prj = Ruber[:projects].new_project File.join(@dir, 'test.ruprj'), 'Test'
1126
+ @ext = @prj.extension :state
829
1127
  end
830
1128
 
831
1129
  after do
832
1130
  FileUtils.rm_rf @dir
1131
+ Ruber[:components].unload_plugin :state
833
1132
  end
834
1133
 
835
1134
  describe ', when created' do
@@ -839,148 +1138,62 @@ describe Ruber::State::ProjectExtension do
839
1138
  @prj.activate
840
1139
  end
841
1140
 
842
- end
843
-
844
- describe '#restore' do
845
-
846
- before do
847
- @mw = flexmock('main window'){|m| m.should_ignore_missing}
848
- @config = flexmock('config')
849
- @docs = flexmock('docs'){|m| m.should_ignore_missing}
850
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
851
- flexmock(Ruber).should_receive(:[]).with(:config).and_return(@config).by_default
852
- flexmock(Ruber).should_receive(:[]).with(:docs).and_return(@docs).by_default
853
- end
854
-
855
- it 'calls the document list\'s close_all method' do
856
- @docs.should_receive(:close_all).once
857
- flexmock(@prj).should_receive(:[]).with(:state, :open_documents).once.and_return []
858
- @ext.restore
1141
+ it 'connects the save_settings slot to the deactivated signal of the project' do
1142
+ flexmock(@ext).should_receive(:save_settings).once
1143
+ @prj.instance_eval{emit deactivated}
859
1144
  end
860
1145
 
861
- it 'it calls the main_window\'s editor_for! for each entry in the project\'s state/open_documents setting from within a without_activating call' do
862
- files = %w[/a.rb /b.rb /c.rb]
863
- flexmock(@prj).should_receive(:[]).with(:state, :open_documents).once.and_return files
864
- flexmock(@prj).should_receive(:[]).with(:state, :active_document).once.and_return nil
865
- files.each{|f| @mw.should_receive(:editor_for!).with(f).once}
866
- @mw.should_receive(:without_activating).once.with(FlexMock.on{|a| a.call || a.is_a?(Proc)})
867
- @ext.restore
868
- end
869
-
870
- it 'activates the editor corresponding to the file in the project\'s state/active_document entry' do
871
- files = %w[/a.rb /b.rb /c.rb]
872
- flexmock(@prj).should_receive(:[]).with(:state, :open_documents).once.and_return files
873
- flexmock(@prj).should_receive(:[]).with(:state, :active_document).once.and_return files[1]
874
- @mw.should_receive(:without_activating).once.with(FlexMock.on{|a| a.call || a.is_a?(Proc)})
875
- @mw.should_receive(:display_document).once.with files[1]
876
- @ext.restore
877
- end
878
-
879
- it 'activates the editor corresponding to the last entry file in the project\'s state/open_documents entry if the state/active_documents entry is nil' do
880
- files = %w[/a.rb /b.rb /c.rb]
881
- editors = 3.times.map{|i| flexmock(i.to_s)}
882
- flexmock(@prj).should_receive(:[]).with(:state, :open_documents).once.and_return files
883
- flexmock(@prj).should_receive(:[]).with(:state, :active_document).once.and_return nil
884
- @mw.should_receive(:without_activating).once.with(FlexMock.on{|a| a.call || a.is_a?(Proc)})
885
- @mw.should_receive(:display_document).once.with files[-1]
886
- @ext.restore
887
- end
1146
+ end
888
1147
 
889
- it 'activates the editor corresponding to the last entry file in the project\'s state/open_documents entry if the state/active_documents doesn\'t correspond to one of the open files' do
890
- files = %w[/a.rb /b.rb /c.rb]
891
- flexmock(@prj).should_receive(:[]).with(:state, :open_documents).once.and_return files
892
- flexmock(@prj).should_receive(:[]).with(:state, :active_document).once.and_return '/d.rb'
893
- @mw.should_receive(:without_activating).once.with(FlexMock.on{|a| a.call || a.is_a?(Proc)})
894
- @mw.should_receive(:display_document).once.with files[-1]
895
- @ext.restore
896
- end
1148
+ describe '#restore' do
897
1149
 
898
- it 'doesn\'t open any editor if the project\'s state/open_documents entry is empty' do
899
- files = []
900
- flexmock(@prj).should_receive(:[]).with(:state, :open_documents).once.and_return files
901
- flexmock(@prj).should_receive(:[]).with(:state, :active_document).and_return nil
902
- @mw.should_receive(:editor_for!).never
903
- @mw.should_receive(:editor_for).never
904
- @mw.should_receive(:without_activating).never
905
- @mw.should_receive(:activate_editor).never
1150
+ it 'calls the restore_documents method of the state plugin passing the project as argument' do
1151
+ flexmock(Ruber[:state]).should_receive(:restore_documents).once.with(@prj)
906
1152
  @ext.restore
907
1153
  end
908
1154
 
909
1155
  end
910
-
1156
+
911
1157
  describe '#save_settings' do
912
1158
 
913
- before do
914
- @mw = flexmock('main window'){|m| m.should_ignore_missing}
915
- @docs = flexmock('docs'){|m| m.should_ignore_missing}
916
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
917
- flexmock(Ruber).should_receive(:[]).with(:docs).and_return(@docs).by_default
918
- end
919
-
920
- it 'stores the paths of the open documents associated with a file in the project\'s state/open_documents entry' do
921
- docs = %w[a b c].map{|i| flexmock(i.to_s, :path => "/#{i}")}
922
- @docs.should_receive(:documents_with_file).once.and_return docs
923
- flexmock(@prj).should_receive(:[]=).once.with :state, :open_documents, %w[a b c].map{|i| "/#{i}"}
924
- flexmock(@prj).should_receive(:[]=)
925
- @ext.save_settings
926
- end
927
-
928
- it 'stores an empty array in the project\'s state/open_documents entry if there\'s no open file or if none of them is associated with a document' do
929
- @docs.should_receive(:documents_with_file).once.and_return []
930
- flexmock(@prj).should_receive(:[]=).once.with :state, :open_documents, []
931
- flexmock(@prj).should_receive(:[]=)
932
- @ext.save_settings
933
- end
934
-
935
- it 'stores the path of the current document in the project\'s state/active_document entry' do
936
- docs = %w[a b c].map{|i| flexmock(i.to_s, :path => "/#{i}")}
937
- active = flexmock('doc', :path => '/b')
938
- @docs.should_receive(:documents_with_file).once.and_return docs
939
- @mw.should_receive(:current_document).once.and_return active
940
- flexmock(@prj).should_receive(:[]=).once.with :state, :active_document, '/b'
941
- flexmock(@prj).should_receive(:[]=)
942
- @ext.save_settings
943
- end
944
-
945
- it 'stores nil in the project\'s state/active_document entry if there\'s no active document or the active document isn\'t associated with a file' do
946
- docs = %w[a b c].map{|i| flexmock(i.to_s, :path => "/#{i}")}
947
- active = flexmock('doc', :path => '')
948
- @docs.should_receive(:documents_with_file).twice.and_return docs
949
- @mw.should_receive(:current_document).once.and_return active
950
- @mw.should_receive(:current_document).once.and_return nil
951
- flexmock(@prj).should_receive(:[]=).twice.with :state, :active_document, nil
952
- flexmock(@prj).should_receive(:[]=)
953
- @ext.save_settings
1159
+ it 'stores the entries returned by the documents_state and tabs_state entries of the state plugin in the project' do
1160
+ @prj.activate
1161
+ docs_state = ['file://'+__FILE__, nil]
1162
+ tabs_state = {
1163
+ :tabs => [['file://'+__FILE__], [0]],
1164
+ :cursor_positions => [],
1165
+ :active_view => [[1,0]]
1166
+ }
1167
+ state = Ruber[:state]
1168
+ flexmock(state).should_receive(:documents_state).once.and_return(docs_state)
1169
+ flexmock(state).should_receive(:tabs_state).once.and_return(tabs_state)
954
1170
  @ext.save_settings
1171
+ @prj[:state, :open_documents].should == docs_state
1172
+ @prj[:state, :tabs].should == tabs_state[:tabs]
1173
+ @prj[:state, :active_view].should == tabs_state[:active_view]
1174
+ @prj[:state, :cursor_positions].should == tabs_state[:cursor_positions]
955
1175
  end
956
1176
 
957
1177
  end
958
1178
 
959
1179
  describe 'auto_restore' do
960
1180
 
961
- before do
962
- @config = flexmock('config')
963
- flexmock(Ruber).should_receive(:[]).with(:config).and_return(@config).by_default
964
- @plug = Object.new
965
- @plug.instance_variable_set :@force_restore_project_files, nil
966
- flexmock(Ruber).should_receive(:[]).with(:state).and_return(@plug).by_default
967
- end
968
1181
 
969
1182
  it 'disconnects the project\'s activated() signal from the extension' do
970
- flexmock(@plug).should_receive(:restore_project_files?).once.and_return false
1183
+ flexmock(Ruber[:state]).should_receive(:restore_project_files?).once.and_return false
971
1184
  @ext.send :auto_restore
972
1185
  flexmock(@ext).should_receive(:auto_restore).never
973
1186
  flexmock(@prj).instance_eval{emit activated}
974
1187
  end
975
1188
 
976
1189
  it 'calls the restore method if the State plugins wants the project files restored' do
977
- flexmock(@plug).should_receive(:restore_project_files?).once.and_return true
1190
+ flexmock(Ruber[:state]).should_receive(:restore_project_files?).once.and_return true
978
1191
  flexmock(@ext).should_receive(:restore).once
979
1192
  @ext.send :auto_restore
980
1193
  end
981
1194
 
982
1195
  it 'does noting if the State plugins doesn\'t want the project_files restored' do
983
- flexmock(@plug).should_receive(:restore_project_files?).once.and_return false
1196
+ flexmock(Ruber[:state]).should_receive(:restore_project_files?).once.and_return false
984
1197
  flexmock(@ext).should_receive(:restore).never
985
1198
  @ext.send :auto_restore
986
1199
  end